-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[app] app list: sort with running state
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...on/src/main/java/github/tornaco/android/thanos/common/sort/AppRunningStateComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package github.tornaco.android.thanos.common.sort; | ||
|
||
import android.content.Context; | ||
|
||
import com.elvishew.xlog.XLog; | ||
|
||
import java.util.Comparator; | ||
|
||
import github.tornaco.android.thanos.common.AppListModel; | ||
import github.tornaco.android.thanos.core.app.ActivityManager; | ||
import github.tornaco.android.thanos.core.app.ThanosManager; | ||
import util.PinyinComparatorUtils; | ||
|
||
public class AppRunningStateComparator implements Comparator<AppListModel> { | ||
private final ActivityManager activityManager; | ||
|
||
public AppRunningStateComparator(Context context) { | ||
this.activityManager = ThanosManager.from(context).getActivityManager(); | ||
} | ||
|
||
@Override | ||
public int compare(AppListModel o1, AppListModel o2) { | ||
try { | ||
boolean isO1Running = activityManager.isPackageRunning(o1.appInfo.getPkgName()); | ||
boolean isO2Running = activityManager.isPackageRunning(o2.appInfo.getPkgName()); | ||
|
||
if (isO1Running != isO2Running) { | ||
if (isO1Running) return -1; | ||
else return 1; | ||
} | ||
|
||
} catch (Throwable e) { | ||
XLog.e("AppLabelComparator error", e); | ||
} | ||
|
||
return PinyinComparatorUtils.compare(o1.appInfo.getAppLabel(), o2.appInfo.getAppLabel()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters