prepare ordering

This commit is contained in:
Thomas 2020-12-07 17:00:45 +01:00
parent acfc183eec
commit 53553940d3
3 changed files with 17 additions and 10 deletions

View File

@ -22,15 +22,15 @@ class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel
private final WeakReference<DatabaseManager> databaseManagerRef;
private final WeakReference<Listener> listenerRef;
order userOrderChoice;
List<order> userOrderChoices;
ComputeAppListTask(WeakReference<PackageManager> packageManagerRef,
WeakReference<DatabaseManager> databaseManagerRef,
WeakReference<Listener> listenerRef, order orderCoice) {
WeakReference<Listener> listenerRef, List<order> orderChoices) {
this.packageManagerRef = packageManagerRef;
this.databaseManagerRef = databaseManagerRef;
this.listenerRef = listenerRef;
userOrderChoice = orderCoice;
userOrderChoices = orderChoices;
}
protected List<ApplicationViewModel> doInBackground(Void... params) {
@ -44,12 +44,19 @@ class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel
convertPackagesToViewModels(vms, databaseManager, packageManager);
}
//Reordering should done here
if (userOrderChoice != order.DEFAULT) {
if (userOrderChoices != null) {
vms = order(vms, userOrderChoices);
}
return vms;
}
private List<ApplicationViewModel> order(List<ApplicationViewModel> vms, List<order> orderChoices) {
List<ApplicationViewModel> applicationViewModels = new ArrayList<>();
return applicationViewModels;
}
public enum order {
DEFAULT,
MOST_TRACKERS,

View File

@ -77,7 +77,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
onAppsComputed(applications);
if (applications.isEmpty())
displayAppListAsync();
displayAppListAsync(null);
if (startRefreshAsked && last_refresh == null)
startRefresh();
else if (refreshInProgress) {
@ -127,7 +127,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
refreshInProgress = false;
homeBinding.layoutProgress.setVisibility(View.GONE);
homeBinding.swipeRefresh.setRefreshing(false);
displayAppListAsync();
displayAppListAsync(null);
}
public void setNetworkListener(NetworkListener listener) {
@ -180,7 +180,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
appListFragment.setFilter(AppListFragment.Type.NAME, filter);
}
private void displayAppListAsync() {
private void displayAppListAsync(List<ComputeAppListTask.order> orderList) {
homeBinding.noAppFound.setVisibility(View.GONE);
if (applications.isEmpty()) {
homeBinding.retrieveApp.setVisibility(View.VISIBLE);
@ -190,7 +190,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
new ComputeAppListTask(
new WeakReference<>(packageManager),
new WeakReference<>(DatabaseManager.getInstance(getActivity())),
new WeakReference<>(this), ComputeAppListTask.order.DEFAULT
new WeakReference<>(this), orderList
).execute();
}

View File

@ -115,7 +115,7 @@ public class TrackerFragment extends Fragment implements ComputeAppListTask.List
new ComputeAppListTask(
new WeakReference<>(packageManager),
new WeakReference<>(DatabaseManager.getInstance(getActivity())),
new WeakReference<>(this), ComputeAppListTask.order.DEFAULT
new WeakReference<>(this), null
).execute();
}