Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ljoonal
Copy link

@ljoonal ljoonal commented May 15, 2024

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 😄

@peterfajdiga
Copy link
Owner

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.

Copy link
Owner

@peterfajdiga peterfajdiga left a 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.

Comment on lines +50 to +53
<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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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.

Comment on lines +32 to +33
android:entries="@array/pref_sortMethod_option_labels"
android:entryValues="@array/pref_sortMethod_option_values"
Copy link
Owner

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>
Copy link
Owner

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).

Comment on lines +17 to +18
final FiledShortcutItem newShortcutItem = activity.shortcutItemManager.shortcutFromIntent(context, data);
activity.shortcutItemManager.saveShortcut(context, newShortcutItem);
Copy link
Owner

@peterfajdiga peterfajdiga May 18, 2024

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 {
Copy link
Owner

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Owner

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;
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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>.

@peterfajdiga
Copy link
Owner

peterfajdiga commented May 19, 2024

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.

@ljoonal
Copy link
Author

ljoonal commented Jul 4, 2024

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:

  1. Increment an app's launch count value, and having it "decay" with time. Can store for example when it was last decremented, and then on day change/launcher open process the decays at once. For example multiply the launch count of the app by 0.99 each day, so after a week it'd be 0.99^7, etc; As an example, an app with 12 launches would be 12*(0.99^30)≈8.8 after a month. Probably would need to tweak the constant a bit, or allow users to adjust the decay rate (am imagining a logarithmic-like slider, aka 1=no decay, 0.999=slow, 0.99=moderate, 0.9=fast, etc).
  2. Could store launches in buckets (launches on the 04.07.2024 or for example week27year24) to have a bit more privacy, and then have weights for previous launches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants