diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails.java b/app/src/main/java/org/fdroid/fdroid/AppDetails.java
index b63f1e8b5..a9288bed2 100644
--- a/app/src/main/java/org/fdroid/fdroid/AppDetails.java
+++ b/app/src/main/java/org/fdroid/fdroid/AppDetails.java
@@ -426,8 +426,8 @@ public class AppDetails extends AppCompatActivity {
@Override
protected void onResumeFragments() {
super.onResumeFragments();
+ headerFragment = (AppDetailsHeaderFragment)getSupportFragmentManager().findFragmentById(R.id.header);
refreshApkList();
- refreshHeader();
supportInvalidateOptionsMenu();
if (DownloaderService.isQueuedOrActive(activeDownloadUrlString)) {
registerDownloaderReceivers();
@@ -615,8 +615,6 @@ public class AppDetails extends AppCompatActivity {
}
private void refreshHeader() {
- headerFragment = (AppDetailsHeaderFragment)
- getSupportFragmentManager().findFragmentById(R.id.header);
if (headerFragment != null) {
headerFragment.updateViews();
}
@@ -1416,17 +1414,44 @@ public class AppDetails extends AppCompatActivity {
public void onResume() {
super.onResume();
updateViews();
+ restoreProgressBarOnResume();
+ }
+
+ /**
+ * After resuming the fragment, decide whether or not we need to show the progress bar.
+ * Also, put an appropriate message depending on whether or not the download is active or
+ * just queued.
+ *
+ * NOTE: this can't be done in the `updateViews` method as it currently stands. The reason
+ * is because that method gets called all the time, for all sorts of reasons. The progress
+ * bar is updated with actual progress values in response to async broadcasts. If we always
+ * tried to force the progress bar in `updateViews`, it would override the values that were
+ * set by the async progress broadcasts.
+ */
+ private void restoreProgressBarOnResume() {
+ if (appDetails.activeDownloadUrlString != null) {
+ // We don't actually know what the current progress is, so this will show an indeterminate
+ // progress bar until the first progress/complete event we receive.
+ final String message = DownloaderService.isQueued(appDetails.activeDownloadUrlString)
+ ? getString(R.string.download_pending)
+ : "";
+ showIndeterminateProgress(message);
+ }
}
/**
* Displays empty, indeterminate progress bar and related views.
*/
public void startProgress() {
+ showIndeterminateProgress(getString(R.string.download_pending));
+ updateViews();
+ }
+
+ private void showIndeterminateProgress(String message) {
setProgressVisible(true);
progressBar.setIndeterminate(true);
- progressSize.setText("");
+ progressSize.setText(message);
progressPercent.setText("");
- updateViews();
}
/**
diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java
index df1875e86..152f881e4 100644
--- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java
+++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java
@@ -328,18 +328,32 @@ public class DownloaderService extends Service {
}
/**
- * Check if a URL is waiting in the queue for downloading or if actively
- * being downloaded. This is useful for checking whether to re-register
- * {@link android.content.BroadcastReceiver}s in
- * {@link android.app.Activity#onResume()}
+ * Check if a URL is waiting in the queue for downloading or if actively being downloaded.
+ * This is useful for checking whether to re-register {@link android.content.BroadcastReceiver}s
+ * in {@link android.app.Activity#onResume()}.
+ * @see DownloaderService#isQueued(String)
+ * @see DownloaderService#isActive(String)
*/
public static boolean isQueuedOrActive(String urlString) {
+ return isQueued(urlString) || isActive(urlString);
+ }
+
+ /**
+ * Check if a URL is waiting in the queue for downloading.
+ */
+ public static boolean isQueued(String urlString) {
if (TextUtils.isEmpty(urlString)) {
return false;
}
Integer what = QUEUE_WHATS.get(urlString);
- return (what != null && serviceHandler.hasMessages(what))
- || (downloader != null && TextUtils.equals(urlString, downloader.sourceUrl.toString()));
+ return (what != null && serviceHandler.hasMessages(what));
+ }
+
+ /**
+ * Check if a URL is actively being downloaded.
+ */
+ public static boolean isActive(String urlString) {
+ return downloader != null && TextUtils.equals(urlString, downloader.sourceUrl.toString());
}
/**
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e3969b4c6..29a42b952 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -367,6 +367,7 @@
Do you want to uninstall this app?
Download completed, tap to install
Download unsuccessful
+ Waiting to start download…
New:
Provided by %1$s.