-
-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2202 from marunjar/fixed_result_order
predictable order of results
- Loading branch information
Showing
11 changed files
with
217 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/fr/neamar/kiss/searcher/PojoWithTagSearcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package fr.neamar.kiss.searcher; | ||
|
||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import fr.neamar.kiss.KissApplication; | ||
import fr.neamar.kiss.MainActivity; | ||
import fr.neamar.kiss.pojo.Pojo; | ||
import fr.neamar.kiss.pojo.PojoWithTags; | ||
|
||
/** | ||
* Returns a list of all results that match the specified pojo with tags. | ||
*/ | ||
public abstract class PojoWithTagSearcher extends Searcher { | ||
|
||
private final SharedPreferences prefs; | ||
|
||
public PojoWithTagSearcher(MainActivity activity, String query) { | ||
super(activity, query); | ||
prefs = PreferenceManager.getDefaultSharedPreferences(activity); | ||
} | ||
|
||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
MainActivity activity = activityWeakReference.get(); | ||
if (activity == null) | ||
return null; | ||
|
||
KissApplication.getApplication(activity).getDataHandler().requestAllRecords(this); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public boolean addResults(List<? extends Pojo> pojos) { | ||
List<Pojo> filteredPojos = new ArrayList<>(); | ||
for (Pojo pojo : pojos) { | ||
if (!(pojo instanceof PojoWithTags)) { | ||
continue; | ||
} | ||
PojoWithTags pojoWithTags = (PojoWithTags) pojo; | ||
if (acceptPojo(pojoWithTags)) { | ||
filteredPojos.add(pojoWithTags); | ||
} | ||
} | ||
|
||
MainActivity activity = activityWeakReference.get(); | ||
if (activity == null) { | ||
return false; | ||
} | ||
|
||
KissApplication.getApplication(activity).getDataHandler().applyRelevanceFromHistory(filteredPojos, getTaggedResultSortMode()); | ||
|
||
return super.addResults(filteredPojos); | ||
} | ||
|
||
@NonNull | ||
private String getTaggedResultSortMode() { | ||
String sortMode = prefs.getString("tagged-result-sort-mode", "default"); | ||
if ("default".equals(sortMode)) { | ||
sortMode = KissApplication.getApplication(activityWeakReference.get()).getDataHandler().getHistoryMode(); | ||
} | ||
return sortMode; | ||
|
||
} | ||
|
||
protected int getMaxResultCount() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
abstract protected boolean acceptPojo(PojoWithTags pojoWithTags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 4 additions & 41 deletions
45
app/src/main/java/fr/neamar/kiss/searcher/TagsSearcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,19 @@ | ||
package fr.neamar.kiss.searcher; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import fr.neamar.kiss.KissApplication; | ||
import fr.neamar.kiss.MainActivity; | ||
import fr.neamar.kiss.pojo.Pojo; | ||
import fr.neamar.kiss.pojo.PojoWithTags; | ||
|
||
/** | ||
* Returns a list of all applications that match the specified tag | ||
* Returns a list of all results that match the specified tag | ||
*/ | ||
|
||
public class TagsSearcher extends Searcher { | ||
public class TagsSearcher extends PojoWithTagSearcher { | ||
public TagsSearcher(MainActivity activity, String query) { | ||
super(activity, query == null ? "<tags>" : query); | ||
} | ||
|
||
@Override | ||
public boolean addResults(List<? extends Pojo> pojos) { | ||
List<Pojo> filteredPojos = new ArrayList<>(); | ||
for (Pojo pojo : pojos) { | ||
if (!(pojo instanceof PojoWithTags)) { | ||
continue; | ||
} | ||
PojoWithTags pojoWithTags = (PojoWithTags) pojo; | ||
if (pojoWithTags.getTags() == null || pojoWithTags.getTags().isEmpty()) { | ||
continue; | ||
} | ||
|
||
if (!pojoWithTags.getTags().contains(query)) { | ||
continue; | ||
} | ||
|
||
filteredPojos.add(pojoWithTags); | ||
} | ||
return super.addResults(filteredPojos); | ||
protected boolean acceptPojo(PojoWithTags pojoWithTags) { | ||
return pojoWithTags.getTags() != null && pojoWithTags.getTags().contains(query); | ||
} | ||
|
||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
MainActivity activity = activityWeakReference.get(); | ||
if (activity == null) | ||
return null; | ||
|
||
KissApplication.getApplication(activity).getDataHandler().requestAllRecords(this); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
int getMaxResultCount() { | ||
return 250; | ||
} | ||
} |
Oops, something went wrong.