Avoid to have a remaining refresh bar when going back to main screen.

This commit is contained in:
Thomas 2021-01-04 18:32:28 +01:00
parent e3f2325d00
commit 2f531d7d24
2 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package org.eu.exodus_privacy.exodusprivacy.fragments; package org.eu.exodus_privacy.exodusprivacy.fragments;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
@ -71,7 +72,7 @@ public class HomeFragment extends Fragment implements ComputeAppList.Listener, U
packageManager = context.getPackageManager(); packageManager = context.getPackageManager();
homeBinding.swipeRefresh.setOnRefreshListener(this::startRefresh); homeBinding.swipeRefresh.setOnRefreshListener(this::startRefresh);
SharedPreferences sharedPreferences = getContext().getSharedPreferences(Utils.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedPreferences = context.getSharedPreferences(Utils.APP_PREFS, MODE_PRIVATE);
last_refresh = sharedPreferences.getString(Utils.LAST_REFRESH, null); last_refresh = sharedPreferences.getString(Utils.LAST_REFRESH, null);
if (packageManager != null) { if (packageManager != null) {
@ -94,12 +95,13 @@ public class HomeFragment extends Fragment implements ComputeAppList.Listener, U
return homeBinding.getRoot(); return homeBinding.getRoot();
} }
public void startRefresh() { public void startRefresh() {
if (packageManager != null) { if (packageManager != null) {
refreshInProgress = true; refreshInProgress = true;
homeBinding.layoutProgress.setVisibility(View.VISIBLE); homeBinding.layoutProgress.setVisibility(View.VISIBLE);
homeBinding.swipeRefresh.setRefreshing(true); homeBinding.swipeRefresh.setRefreshing(true);
List<PackageInfo> packageInstalled = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS); @SuppressLint("QueryPermissionsNeeded") List<PackageInfo> packageInstalled = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
ArrayList<String> packageList = new ArrayList<>(); ArrayList<String> packageList = new ArrayList<>();
for (PackageInfo pkgInfo : packageInstalled) for (PackageInfo pkgInfo : packageInstalled)
packageList.add(pkgInfo.packageName); packageList.add(pkgInfo.packageName);
@ -114,6 +116,9 @@ public class HomeFragment extends Fragment implements ComputeAppList.Listener, U
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (!refreshInProgress && homeBinding.layoutProgress.getVisibility() == View.VISIBLE) {
onUpdateComplete();
}
} }

View File

@ -353,8 +353,8 @@ public class NetworkManager {
JSONObject object = makeDataRequest(mes.context, mes.listener, url); JSONObject object = makeDataRequest(mes.context, mes.listener, url);
if (object != null) { if (object != null) {
try { try {
JSONObject application = object.getJSONObject(handle);
if (handle != null) { if (handle != null) {
JSONObject application = object.getJSONObject(handle);
return parseApplication(application, handle); return parseApplication(application, handle);
} }
} catch (JSONException e) { } catch (JSONException e) {
@ -400,7 +400,7 @@ public class NetworkManager {
report.creationDate = Calendar.getInstance(); report.creationDate = Calendar.getInstance();
report.creationDate.setTimeZone(TimeZone.getTimeZone("UTC")); report.creationDate.setTimeZone(TimeZone.getTimeZone("UTC"));
report.creationDate.setTime(date); report.creationDate.setTime(date!=null?date:new Date());
date = dateFormat.parse(object.getString("creation_date")); date = dateFormat.parse(object.getString("creation_date"));
if (date != null) { if (date != null) {
report.creationDate.setTime(date); report.creationDate.setTime(date);