1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +01:00

improved sorting performance

This commit is contained in:
dakhnod 2019-12-04 00:46:02 +01:00
parent 8e27556cd4
commit d5cd59ae6b

View File

@ -19,6 +19,7 @@ import android.widget.Toast;
import java.util.Collections;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.List;
import androidx.annotation.NonNull;
@ -58,14 +59,19 @@ public class QHybridAppChoserActivity extends AbstractGBActivity {
new Thread(new Runnable() {
@Override
public void run() {
final IdentityHashMap<PackageInfo, String> nameMap = new IdentityHashMap(packages.size());
for(PackageInfo info : packages){
CharSequence label = manager.getApplicationLabel(info.applicationInfo);
if(label == null) label = info.packageName;
nameMap.put(info, label.toString());
}
Collections.sort(packages, new Comparator<PackageInfo>() {
@Override
public int compare(PackageInfo packageInfo, PackageInfo t1) {
return manager.getApplicationLabel(packageInfo.applicationInfo)
.toString()
return nameMap.get(packageInfo)
.compareToIgnoreCase(
manager.getApplicationLabel(t1.applicationInfo)
.toString()
nameMap.get(t1)
);
}
});