From 9195820e44fff56ccf0589ed98fe59fc44c1461e Mon Sep 17 00:00:00 2001 From: TIANGeng708 <71835814+TIANGeng708@users.noreply.github.com> Date: Mon, 25 Apr 2022 22:41:54 +0800 Subject: [PATCH] reopen #163 (#182) Sort apps also on second priority Co-authored-by: TIANGeng708 <1012721175@qq.com> --- .../lastlauncher/LauncherActivity.java | 36 ++++++++++++++++--- .../dialogs/GlobalSettingsDialog.java | 5 +++ .../lastlauncher/utils/Constants.java | 4 +-- .../lastlauncher/utils/ConstantsTest.java | 27 ++++++++++++++ 4 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java diff --git a/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java b/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java index e9a11865..eef5f096 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java @@ -1291,6 +1291,12 @@ protected void onPostExecute(Void aVoid) { } + /**So this is where you sort your apps. + * We modified this method so that when the first sorting condition fails, it can sort by the frequency of use, which makes it easier for users to find the app they want to use. + * + * @param integers + * @return + */ @Override protected Void doInBackground(final Integer... integers) { final int type = integers[0]; @@ -1304,10 +1310,24 @@ protected Void doInBackground(final Integer... integers) { switch (type) { case SORT_BY_SIZE://descending - Collections.sort(mAppsList, (apps, t1) -> (t1.getSize() - apps.getSize())); + Collections.sort(mAppsList, (apps, t1) -> { + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + if (apps.getSize() != t1.getSize()) { + return t1.getSize() - apps.getSize(); + } else { + return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); + } + }); break; case SORT_BY_OPENING_COUNTS://descending - Collections.sort(mAppsList, (apps, t1) -> t1.getOpeningCounts() - apps.getOpeningCounts()); + Collections.sort(mAppsList, (apps, t1) -> { + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + if (t1.getOpeningCounts() != apps.getOpeningCounts()) { + return t1.getOpeningCounts() - apps.getOpeningCounts(); + }else { + return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); + } + }); break; case SORT_BY_COLOR: Collections.sort(mAppsList, (apps, t1) -> { @@ -1320,11 +1340,19 @@ protected Void doInBackground(final Integer... integers) { return (hsv[i] < another[i]) ? -1 : 1; } } - return 0; + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); }); break; case SORT_BY_UPDATE_TIME://descending - Collections.sort(mAppsList, (apps, t1) -> t1.getUpdateTime() - apps.getUpdateTime()); + Collections.sort(mAppsList, (apps, t1) -> { + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + if (t1.getUpdateTime()!=apps.getUpdateTime()){ + return t1.getUpdateTime() - apps.getUpdateTime(); + }else { + return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); + } + }); break; case SORT_BY_RECENT_OPEN://descending Collections.sort(mAppsList, (apps, t1) -> (t1.getRecentUsedWeight() - apps.getRecentUsedWeight())); diff --git a/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java b/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java index d5af5435..2c2b114f 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java @@ -169,6 +169,11 @@ public void onClick(View view) { } } + /**This method is used to control the order of apps. + * The code block we added is to give the newly added buttons the ability to sort them by name. + * + * @param view + */ private void sortApps(View view) { Context context; // set theme diff --git a/app/src/main/java/io/github/subhamtyagi/lastlauncher/utils/Constants.java b/app/src/main/java/io/github/subhamtyagi/lastlauncher/utils/Constants.java index 23a4a47f..b07821b3 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/utils/Constants.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/utils/Constants.java @@ -47,8 +47,8 @@ public class Constants { public static int dynamicHeight = 20; public static final int DEFAULT_TEXT_SIZE_NORMAL_APPS = dynamicHeight; public static final int DEFAULT_TEXT_SIZE_OFTEN_APPS = dynamicHeight * 9 / 5; - public static final int MAX_TEXT_SIZE_FOR_APPS=90; - public static final int MIN_TEXT_SIZE_FOR_APPS=14; + public static final int MAX_TEXT_SIZE_FOR_APPS = 90; + public static final int MIN_TEXT_SIZE_FOR_APPS = 14; } diff --git a/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java b/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java new file mode 100644 index 00000000..853f0c71 --- /dev/null +++ b/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java @@ -0,0 +1,27 @@ +package io.github.subhamtyagi.lastlauncher.utils; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ConstantsTest { + + private Constants constantsUnderTest; + + @Before + public void setUp() { + constantsUnderTest = new Constants(); + } + + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + @Test + public void testSortByName() { + Assert.assertEquals(Constants.SORT_BY_NAME, 1); + } + + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + @Test + public void testSortBySize() { + Assert.assertEquals(Constants.SORT_BY_SIZE, 2); + } +}