mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 10:56:50 +01:00
improved sorting performance
This commit is contained in:
parent
8e27556cd4
commit
d5cd59ae6b
@ -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)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user