Skip to content

Commit

Permalink
reopen #163 (#182)
Browse files Browse the repository at this point in the history
Sort apps also on second priority

Co-authored-by: TIANGeng708 <1012721175@qq.com>
  • Loading branch information
TIANGeng708 and TIANGeng708 authored Apr 25, 2022
1 parent ff761c7 commit 9195820
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) -> {
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 9195820

Please sign in to comment.