-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add usage based sorting #31
base: master
Are you sure you want to change the base?
Add usage based sorting #31
Conversation
Thank you for the PR! This is actually something that I've wanted to implement for a while, but I haven't found the time yet. :D I'll try to take a look at your PR soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for the PR! I really like how you've structured the code. I've left some comments to consider. If you don't have the time for this, then the comments will help future me. :)
Throughout the code I'd prefer to call this new feature ItemOrdering
instead of SortMethod
to communicate it's about launcher items, not e.g. categories.
<string name="pref_title_sortMethod">Sort method</string> | ||
<string name="pref_description_sortMethod">How to sort the apps</string> | ||
<string name="pref_label_sortMethod_alphabetical">Alphabetical</string> | ||
<string name="pref_label_sortMethod_usage">Most used</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<string name="pref_title_sortMethod">Sort method</string> | |
<string name="pref_description_sortMethod">How to sort the apps</string> | |
<string name="pref_label_sortMethod_alphabetical">Alphabetical</string> | |
<string name="pref_label_sortMethod_usage">Most used</string> | |
<string name="pref_title_itemOrdering">Order apps by</string> | |
<string name="pref_description_itemOrdering">%s</string> | |
<string name="pref_label_itemOrdering_name">Name</string> | |
<string name="pref_label_itemOrdering_usage">Most used</string> |
What do you think about this? The %s
makes the selection visible in place of the summary.
android:entries="@array/pref_sortMethod_option_labels" | ||
android:entryValues="@array/pref_sortMethod_option_values" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nitpick, but I think the "option" word is superfluous.
<item>@string/pref_label_sortMethod_usage</item> | ||
</array> | ||
<array name="pref_sortMethod_option_values"> | ||
<item>Alphabetical</item> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to "Name", so it won't look weird if we ever implement ordering by some other property (as unlikely as that would be).
final FiledShortcutItem newShortcutItem = activity.shortcutItemManager.shortcutFromIntent(context, data); | ||
activity.shortcutItemManager.saveShortcut(context, newShortcutItem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why move this? The reason it was before the if
was that Fast Draw may not be running (IIRC, this receiver can be triggered regardless) and getInstance
may return null because of that, but we still want to save the shortcut for when Fast Draw is eventually launched. Maybe I should add a comment... 🤔
@@ -0,0 +1,13 @@ | |||
package peterfajdiga.fastdraw.prefs; | |||
|
|||
public enum SortMethod { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
try { | ||
return valueOf(str); | ||
} catch (Exception ex) { | ||
return Alphabetical; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Alphabetical; | |
Log.w("ItemOrdering", "Unknown enumerator " + str, ex); | |
return Alphabetical; |
Maybe log a warning here, just to make it noticeable if it ever starts happening.
} | ||
|
||
@Override | ||
public void launch(final Context context, final LaunchManager launchManager, final Bundle opts, final Rect clipBounds) { | ||
final Intent intent = new Intent(this.intent); | ||
intent.setSourceBounds(clipBounds); | ||
launchManager.launch(intent, opts); | ||
statisticsManager.addLaunch(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving this call to CategoryAdapter
, next to the item.launchable.launch
call? You can use item.id
there.
This way you can undo a lot of changes in this PR that were needed to bring StatisticsManager
here.
import peterfajdiga.fastdraw.launcher.launcheritem.AppItem; | ||
|
||
public class StatisticsManager { | ||
private final HashMap<String, Integer> launchCounts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace this with a PrefMap, giving you persistence.
gradlew
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this file?
@NonNull final LaunchManager launchManager, | ||
final Postable dragEndService, | ||
@NonNull final StatisticsManager statisticsManager, | ||
@NonNull final SortMethod sortMethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing SortMethod
what do you think about passing an implementation of Comparator<DisplayItem>
?
We'd need two implementations, one for order-by-name and one for order-by-usage. This will also remove the need for DisplayItem
to implement Comparable<DisplayItem>
.
Btw, now that I've got someone technical to ask, what do you think about making it so that older statistics are less relevant than newer ones? For example, if the user launched app A 10 times one month ago, and app B 10 times today, then app B should be above app A. This is the idea, but I can't come up with a nice equation for this that would let me avoid storing the timestamp of each launch. |
A couple of ideas finally came to mind as I re-examined this though on how making old statistics less relevant could be done in a more privacy friendly way:
|
Something that I'd like to have is to order the most used apps to be first in the layout.
Not sure how this should actually be achieved or how Android apps should be structured, just been slapping stuff together until it builds 😆
Currently doesn't seem to work...
Think that once the data is actually persisted this should maybe work..?
Thought I'd open a WIP PR anyways since won't have time for a while to work on this again, and don't want to just throw all the potential changes into the void.
If this is something you don't want to get merged/maintain, do tell me 😄 or similarly, as I have very limited time, would love if this gets finished and incorporated into the launcher 😄