From d6d7e57898900caffc9bf09262a4faf0637028d2 Mon Sep 17 00:00:00 2001 From: Shubham Date: Sun, 24 Apr 2022 14:51:18 +0530 Subject: [PATCH 1/4] Revert "As for the modification of issue162, all previous modifications are invalid" This reverts commit 6e530cc349cac3fb96b2b64d66e94536a636e9e6. --- .../lastlauncher/LauncherActivity.java | 36 ++-------- .../dialogs/GlobalSettingsDialog.java | 8 ++- .../lastlauncher/utils/Constants.java | 2 + app/src/main/res/menu/sort_apps_popups.xml | 8 ++- app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 + .../lastlauncher/LauncherActivityTest.java | 69 +++++++++++++++++++ .../lastlauncher/utils/ConstantsTest.java | 12 ++-- 8 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.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 eef5f096..e9a11865 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java @@ -1291,12 +1291,6 @@ 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]; @@ -1310,24 +1304,10 @@ protected Void doInBackground(final Integer... integers) { switch (type) { case SORT_BY_SIZE://descending - 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(); - } - }); + Collections.sort(mAppsList, (apps, t1) -> (t1.getSize() - apps.getSize())); break; case SORT_BY_OPENING_COUNTS://descending - 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(); - } - }); + Collections.sort(mAppsList, (apps, t1) -> t1.getOpeningCounts() - apps.getOpeningCounts()); break; case SORT_BY_COLOR: Collections.sort(mAppsList, (apps, t1) -> { @@ -1340,19 +1320,11 @@ protected Void doInBackground(final Integer... integers) { return (hsv[i] < another[i]) ? -1 : 1; } } - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 - return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); + return 0; }); break; case SORT_BY_UPDATE_TIME://descending - 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(); - } - }); + Collections.sort(mAppsList, (apps, t1) -> t1.getUpdateTime() - apps.getUpdateTime()); 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 2c2b114f..3a3b0f9d 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 @@ -189,8 +189,12 @@ private void sortApps(View view) { popupMenu.setOnMenuItemClickListener(menuItem -> { cancel(); switch (menuItem.getItemId()) { - case R.id.menu_sort_by_name: - launcherActivity.sortApps(Constants.SORT_BY_NAME); +// case R.id.menu_sort_by_name: +// launcherActivity.sortApps(Constants.SORT_BY_NAME); +// break; + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 + case R.id.menu_sort_by_name_modify: + launcherActivity.sortApps(Constants.SORT_BY_NAME_MODIFY); break; case R.id.menu_sort_by_opening_counts: launcherActivity.sortApps(Constants.SORT_BY_OPENING_COUNTS); 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 b07821b3..96c5bfe5 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 @@ -32,6 +32,8 @@ public class Constants { public static final int SORT_BY_CUSTOM = 5; public static final int SORT_BY_UPDATE_TIME = 6; public static final int SORT_BY_RECENT_OPEN = 7; + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 + public static final int SORT_BY_NAME_MODIFY = 1; public static final int RESTORE_REQUEST = 125; public static final int FONTS_REQUEST = 126; diff --git a/app/src/main/res/menu/sort_apps_popups.xml b/app/src/main/res/menu/sort_apps_popups.xml index dcb155c1..d5d95068 100644 --- a/app/src/main/res/menu/sort_apps_popups.xml +++ b/app/src/main/res/menu/sort_apps_popups.xml @@ -19,8 +19,12 @@ + android:id="@+id/menu_sort_by_name_modify" + android:title="@string/by_name_modify" /> + + + + 颜色 应用使用 明朝 + 名称 应用排序依据 选择字体 恢复默认字体 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7b7eda9a..33e64bc4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,6 +77,8 @@ Sort Apps By Name + + App Name App Usage diff --git a/app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.java b/app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.java new file mode 100644 index 00000000..cf099b1e --- /dev/null +++ b/app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.java @@ -0,0 +1,69 @@ +package io.github.subhamtyagi.lastlauncher; + +import android.view.View; +import io.github.subhamtyagi.lastlauncher.utils.Gestures; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class LauncherActivityTest { + + private LauncherActivity launcherActivityUnderTest; + + @Before + public void setUp() { + launcherActivityUnderTest = new LauncherActivity(); + } + + + @Test + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 + public void testOnClick() { + // Setup + final View view = new View(null); + + // Run the test + launcherActivityUnderTest.onClick(view); + + // Verify the results + } + + + @Test + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 + public void testOnLongClick() { + // Setup + final View view = new View(null); + + // Run the test + final boolean result = launcherActivityUnderTest.onLongClick(view); + + // Verify the results + assertTrue(result); + } + + + @Test + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 + public void testOnSwipe() { + // Setup + // Run the test + launcherActivityUnderTest.onSwipe(Gestures.Direction.SWIPE_UP); + + // Verify the results + } + + @Test + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 + public void testOnDoubleTap() { + // Setup + // Run the test + launcherActivityUnderTest.onDoubleTap(); + + // Verify the results + } + + +} 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 index 853f0c71..87aaab29 100644 --- a/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java +++ b/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java @@ -13,15 +13,11 @@ 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); + //CS304 Issue link: + public void testOnConstants() { + int a= Constants.SORT_BY_NAME_MODIFY; + Assert.assertEquals(1,a); } } From 65df4f9feefb140cc51333f08c58b29d1ac95c7a Mon Sep 17 00:00:00 2001 From: Shubham Date: Sun, 24 Apr 2022 14:51:18 +0530 Subject: [PATCH 2/4] Revert "A bug" This reverts commit b6c985fbfce3f65136fd51e3ce907530043a6b60. --- .../lastlauncher/LauncherActivity.java | 69 ++++++++++++------- .../dialogs/GlobalSettingsDialog.java | 13 +--- .../lastlauncher/utils/Constants.java | 6 +- app/src/main/res/menu/sort_apps_popups.xml | 8 +-- app/src/main/res/values-zh-rCN/strings.xml | 1 - app/src/main/res/values/strings.xml | 2 - .../lastlauncher/LauncherActivityTest.java | 69 ------------------- .../lastlauncher/utils/ConstantsTest.java | 12 ++-- 8 files changed, 60 insertions(+), 120 deletions(-) delete mode 100644 app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.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..bc228556 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java @@ -158,17 +158,17 @@ public class LauncherActivity extends Activity implements View.OnClickListener, private Gestures detector; private ShortcutUtils shortcutUtils; - private static final TextWatcher mTextWatcher= new TextWatcher() { + private static final TextWatcher mTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - mSearchTask=new SearchTask(); + mSearchTask = new SearchTask(); } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { //do here search - mSearchTask.execute(charSequence); + mSearchTask.execute(charSequence); } @Override @@ -177,7 +177,7 @@ public void afterTextChanged(Editable editable) { // do everything } }; - private static SearchTask mSearchTask; + private static SearchTask mSearchTask; //endregion private static void showSearchResult(ArrayList filteredApps) { @@ -567,9 +567,9 @@ protected void onStop() { dialogs = null; } - if (mSearchTask!=null) { + if (mSearchTask != null) { mSearchTask.cancel(true); - mSearchTask=null; + mSearchTask = null; } } @@ -860,9 +860,9 @@ public void onBackPressed() { imm.hideSoftInputFromWindow(mSearchBox.getWindowToken(), 0); searching = false; - if (mSearchTask!=null) { + if (mSearchTask != null) { mSearchTask.cancel(true); - mSearchTask=null; + mSearchTask = null; } mHomeLayout.setPadding(DbUtils.getPaddingLeft(), DbUtils.getPaddingTop(), DbUtils.getPaddingRight(), DbUtils.getPaddingBottom()); sortApps(DbUtils.getSortsTypes()); @@ -938,16 +938,16 @@ protected void onDestroy() { dialogs = null; } - if (mSearchTask!=null) { + if (mSearchTask != null) { mSearchTask.cancel(true); - mSearchTask=null; + mSearchTask = null; } - if (imm!=null){ - if(imm.isActive()){ + if (imm != null) { + if (imm.isActive()) { imm.hideSoftInputFromWindow(mSearchBox.getWindowToken(), 0); } - imm=null; + imm = null; } unregisterReceiver(broadcastReceiverAppInstall); @@ -1229,6 +1229,7 @@ public void onDoubleTap() { } private static Locale mLocale; + static class SearchTask extends AsyncTask> { @Override protected void onPostExecute(ArrayList filteredApps) { @@ -1244,11 +1245,11 @@ protected ArrayList doInBackground(CharSequence... charSequences) { filteredApps.add(app); } else if (Utils.simpleFuzzySearch(charSequences[0], app.getAppName())) { filteredApps.add(app); - } else{ + } else { // Support for searching non-ascii languages Apps using ascii characters. boolean isMatch = false; - switch (mLocale.getLanguage()){ - case "zh":{ + switch (mLocale.getLanguage()) { + case "zh": { // In case of Chinese, PinYin Search is supported. isMatch = PinYinSearchUtils.pinYinSimpleFuzzySearch(charSequences[0], app.getAppName()); break; @@ -1281,9 +1282,9 @@ protected void onPostExecute(Void aVoid) { // params.setNewLine(true); for (Apps app : mAppsList) { - AppTextView textView=app.getTextView(); - if (textView.getParent()!=null){ - ( (ViewGroup)textView.getParent()).removeView(textView); + AppTextView textView = app.getTextView(); + if (textView.getParent() != null) { + ((ViewGroup) textView.getParent()).removeView(textView); } mHomeLayout.addView(textView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } @@ -1304,10 +1305,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 +1335,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 3a3b0f9d..d5af5435 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,11 +169,6 @@ 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 @@ -189,12 +184,8 @@ private void sortApps(View view) { popupMenu.setOnMenuItemClickListener(menuItem -> { cancel(); switch (menuItem.getItemId()) { -// case R.id.menu_sort_by_name: -// launcherActivity.sortApps(Constants.SORT_BY_NAME); -// break; - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 - case R.id.menu_sort_by_name_modify: - launcherActivity.sortApps(Constants.SORT_BY_NAME_MODIFY); + case R.id.menu_sort_by_name: + launcherActivity.sortApps(Constants.SORT_BY_NAME); break; case R.id.menu_sort_by_opening_counts: launcherActivity.sortApps(Constants.SORT_BY_OPENING_COUNTS); 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 96c5bfe5..23a4a47f 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 @@ -32,8 +32,6 @@ public class Constants { public static final int SORT_BY_CUSTOM = 5; public static final int SORT_BY_UPDATE_TIME = 6; public static final int SORT_BY_RECENT_OPEN = 7; - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 - public static final int SORT_BY_NAME_MODIFY = 1; public static final int RESTORE_REQUEST = 125; public static final int FONTS_REQUEST = 126; @@ -49,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/main/res/menu/sort_apps_popups.xml b/app/src/main/res/menu/sort_apps_popups.xml index d5d95068..dcb155c1 100644 --- a/app/src/main/res/menu/sort_apps_popups.xml +++ b/app/src/main/res/menu/sort_apps_popups.xml @@ -19,12 +19,8 @@ - - - - + android:id="@+id/menu_sort_by_name" + android:title="@string/by_name" /> 颜色 应用使用 明朝 - 名称 应用排序依据 选择字体 恢复默认字体 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 33e64bc4..7b7eda9a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,8 +77,6 @@ Sort Apps By Name - - App Name App Usage diff --git a/app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.java b/app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.java deleted file mode 100644 index cf099b1e..00000000 --- a/app/src/test/java/io/github/subhamtyagi/lastlauncher/LauncherActivityTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.github.subhamtyagi.lastlauncher; - -import android.view.View; -import io.github.subhamtyagi.lastlauncher.utils.Gestures; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class LauncherActivityTest { - - private LauncherActivity launcherActivityUnderTest; - - @Before - public void setUp() { - launcherActivityUnderTest = new LauncherActivity(); - } - - - @Test - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 - public void testOnClick() { - // Setup - final View view = new View(null); - - // Run the test - launcherActivityUnderTest.onClick(view); - - // Verify the results - } - - - @Test - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 - public void testOnLongClick() { - // Setup - final View view = new View(null); - - // Run the test - final boolean result = launcherActivityUnderTest.onLongClick(view); - - // Verify the results - assertTrue(result); - } - - - @Test - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 - public void testOnSwipe() { - // Setup - // Run the test - launcherActivityUnderTest.onSwipe(Gestures.Direction.SWIPE_UP); - - // Verify the results - } - - @Test - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/165 - public void testOnDoubleTap() { - // Setup - // Run the test - launcherActivityUnderTest.onDoubleTap(); - - // Verify the results - } - - -} 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 index 87aaab29..77d1dbda 100644 --- a/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java +++ b/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java @@ -13,11 +13,15 @@ public void setUp() { constantsUnderTest = new Constants(); } + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + @Test + public void testSortBySize() { + Assert.assertEquals(Constants.SORT_BY_SIZE, 2); + } + //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 @Test - //CS304 Issue link: - public void testOnConstants() { - int a= Constants.SORT_BY_NAME_MODIFY; - Assert.assertEquals(1,a); + public void testSortByRecentOpen() { + Assert.assertEquals(Constants.SORT_BY_RECENT_OPEN, 7); } } From acd1ddea6658815fc0e75b1127783a0630290198 Mon Sep 17 00:00:00 2001 From: Shubham Date: Sun, 24 Apr 2022 14:51:18 +0530 Subject: [PATCH 3/4] Revert "some comment" This reverts commit 881d64481ed9839eb0b3a6469d43bcef9f9ebc2f. --- .../lastlauncher/LauncherActivity.java | 53 +++++++++---------- .../lastlauncher/utils/ConstantsTest.java | 6 +-- 2 files changed, 28 insertions(+), 31 deletions(-) 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 bc228556..7482e5fd 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java @@ -158,17 +158,17 @@ public class LauncherActivity extends Activity implements View.OnClickListener, private Gestures detector; private ShortcutUtils shortcutUtils; - private static final TextWatcher mTextWatcher = new TextWatcher() { + private static final TextWatcher mTextWatcher= new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - mSearchTask = new SearchTask(); + mSearchTask=new SearchTask(); } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { //do here search - mSearchTask.execute(charSequence); + mSearchTask.execute(charSequence); } @Override @@ -177,7 +177,7 @@ public void afterTextChanged(Editable editable) { // do everything } }; - private static SearchTask mSearchTask; + private static SearchTask mSearchTask; //endregion private static void showSearchResult(ArrayList filteredApps) { @@ -567,9 +567,9 @@ protected void onStop() { dialogs = null; } - if (mSearchTask != null) { + if (mSearchTask!=null) { mSearchTask.cancel(true); - mSearchTask = null; + mSearchTask=null; } } @@ -860,9 +860,9 @@ public void onBackPressed() { imm.hideSoftInputFromWindow(mSearchBox.getWindowToken(), 0); searching = false; - if (mSearchTask != null) { + if (mSearchTask!=null) { mSearchTask.cancel(true); - mSearchTask = null; + mSearchTask=null; } mHomeLayout.setPadding(DbUtils.getPaddingLeft(), DbUtils.getPaddingTop(), DbUtils.getPaddingRight(), DbUtils.getPaddingBottom()); sortApps(DbUtils.getSortsTypes()); @@ -938,16 +938,16 @@ protected void onDestroy() { dialogs = null; } - if (mSearchTask != null) { + if (mSearchTask!=null) { mSearchTask.cancel(true); - mSearchTask = null; + mSearchTask=null; } - if (imm != null) { - if (imm.isActive()) { + if (imm!=null){ + if(imm.isActive()){ imm.hideSoftInputFromWindow(mSearchBox.getWindowToken(), 0); } - imm = null; + imm=null; } unregisterReceiver(broadcastReceiverAppInstall); @@ -1229,7 +1229,6 @@ public void onDoubleTap() { } private static Locale mLocale; - static class SearchTask extends AsyncTask> { @Override protected void onPostExecute(ArrayList filteredApps) { @@ -1245,11 +1244,11 @@ protected ArrayList doInBackground(CharSequence... charSequences) { filteredApps.add(app); } else if (Utils.simpleFuzzySearch(charSequences[0], app.getAppName())) { filteredApps.add(app); - } else { + } else{ // Support for searching non-ascii languages Apps using ascii characters. boolean isMatch = false; - switch (mLocale.getLanguage()) { - case "zh": { + switch (mLocale.getLanguage()){ + case "zh":{ // In case of Chinese, PinYin Search is supported. isMatch = PinYinSearchUtils.pinYinSimpleFuzzySearch(charSequences[0], app.getAppName()); break; @@ -1282,9 +1281,9 @@ protected void onPostExecute(Void aVoid) { // params.setNewLine(true); for (Apps app : mAppsList) { - AppTextView textView = app.getTextView(); - if (textView.getParent() != null) { - ((ViewGroup) textView.getParent()).removeView(textView); + AppTextView textView=app.getTextView(); + if (textView.getParent()!=null){ + ( (ViewGroup)textView.getParent()).removeView(textView); } mHomeLayout.addView(textView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } @@ -1306,7 +1305,7 @@ protected Void doInBackground(final Integer... integers) { switch (type) { case SORT_BY_SIZE://descending Collections.sort(mAppsList, (apps, t1) -> { - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + //CS304 Issue link: if (apps.getSize() != t1.getSize()) { return t1.getSize() - apps.getSize(); } else { @@ -1316,10 +1315,10 @@ protected Void doInBackground(final Integer... integers) { break; case SORT_BY_OPENING_COUNTS://descending Collections.sort(mAppsList, (apps, t1) -> { - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + //CS304 Issue link: if (t1.getOpeningCounts() != apps.getOpeningCounts()) { return t1.getOpeningCounts() - apps.getOpeningCounts(); - } else { + }else { return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); } }); @@ -1335,16 +1334,16 @@ protected Void doInBackground(final Integer... integers) { return (hsv[i] < another[i]) ? -1 : 1; } } - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 + //CS304 Issue link: return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); }); break; case SORT_BY_UPDATE_TIME://descending Collections.sort(mAppsList, (apps, t1) -> { - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 - if (t1.getUpdateTime() != apps.getUpdateTime()) { + //CS304 Issue link: + if (t1.getUpdateTime()!=apps.getUpdateTime()){ return t1.getUpdateTime() - apps.getUpdateTime(); - } else { + }else { return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); } }); 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 index 77d1dbda..4e5ec0c9 100644 --- a/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java +++ b/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java @@ -13,15 +13,13 @@ public void setUp() { constantsUnderTest = new Constants(); } - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 @Test public void testSortBySize() { Assert.assertEquals(Constants.SORT_BY_SIZE, 2); } - //CS304 Issue link: https://github.com/SubhamTyagi/Last-Launcher/issues/162 @Test - public void testSortByRecentOpen() { - Assert.assertEquals(Constants.SORT_BY_RECENT_OPEN, 7); + public void testSortByRecentOpen(){ + Assert.assertEquals(Constants.SORT_BY_RECENT_OPEN,7); } } From 1c0dade2630ef1efc6b93474cddfd3441eae350e Mon Sep 17 00:00:00 2001 From: Shubham Date: Sun, 24 Apr 2022 14:51:18 +0530 Subject: [PATCH 4/4] Revert "issue second priority" This reverts commit 186e7d77ea7c6abbdbeafb6b8bf1d1e8e5a09b01. --- .../lastlauncher/LauncherActivity.java | 30 +++---------------- .../lastlauncher/utils/ConstantsTest.java | 25 ---------------- 2 files changed, 4 insertions(+), 51 deletions(-) delete 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 7482e5fd..e9a11865 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/LauncherActivity.java @@ -1304,24 +1304,10 @@ protected Void doInBackground(final Integer... integers) { switch (type) { case SORT_BY_SIZE://descending - Collections.sort(mAppsList, (apps, t1) -> { - //CS304 Issue link: - if (apps.getSize() != t1.getSize()) { - return t1.getSize() - apps.getSize(); - } else { - return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); - } - }); + Collections.sort(mAppsList, (apps, t1) -> (t1.getSize() - apps.getSize())); break; case SORT_BY_OPENING_COUNTS://descending - Collections.sort(mAppsList, (apps, t1) -> { - //CS304 Issue link: - if (t1.getOpeningCounts() != apps.getOpeningCounts()) { - return t1.getOpeningCounts() - apps.getOpeningCounts(); - }else { - return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); - } - }); + Collections.sort(mAppsList, (apps, t1) -> t1.getOpeningCounts() - apps.getOpeningCounts()); break; case SORT_BY_COLOR: Collections.sort(mAppsList, (apps, t1) -> { @@ -1334,19 +1320,11 @@ protected Void doInBackground(final Integer... integers) { return (hsv[i] < another[i]) ? -1 : 1; } } - //CS304 Issue link: - return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); + return 0; }); break; case SORT_BY_UPDATE_TIME://descending - Collections.sort(mAppsList, (apps, t1) -> { - //CS304 Issue link: - if (t1.getUpdateTime()!=apps.getUpdateTime()){ - return t1.getUpdateTime() - apps.getUpdateTime(); - }else { - return -t1.getRecentUsedWeight() + apps.getRecentUsedWeight(); - } - }); + Collections.sort(mAppsList, (apps, t1) -> t1.getUpdateTime() - apps.getUpdateTime()); break; case SORT_BY_RECENT_OPEN://descending Collections.sort(mAppsList, (apps, t1) -> (t1.getRecentUsedWeight() - apps.getRecentUsedWeight())); 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 deleted file mode 100644 index 4e5ec0c9..00000000 --- a/app/src/test/java/io/github/subhamtyagi/lastlauncher/utils/ConstantsTest.java +++ /dev/null @@ -1,25 +0,0 @@ -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(); - } - - @Test - public void testSortBySize() { - Assert.assertEquals(Constants.SORT_BY_SIZE, 2); - } - - @Test - public void testSortByRecentOpen(){ - Assert.assertEquals(Constants.SORT_BY_RECENT_OPEN,7); - } -}