diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java index 3ddc1b8d9..a2fbf06cb 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java @@ -488,15 +488,15 @@ public class AppDetails2 extends AppCompatActivity case Downloading: if (newStatus.progressMax == 0) { // The first progress notification we get telling us our status is "Downloading" - adapter.setProgress(-1, -1, R.string.download_pending); + adapter.setIndeterminateProgress(R.string.download_pending); } else { - adapter.setProgress(newStatus.progressCurrent, newStatus.progressMax, 0); + adapter.setProgress(newStatus.progressCurrent, newStatus.progressMax); } break; case ReadyToInstall: if (justReceived) { - adapter.clearProgress(); + adapter.setIndeterminateProgress(R.string.installing); localBroadcastManager.registerReceiver(installReceiver, Installer.getInstallIntentFilter(Uri.parse(newStatus.getUniqueKey()))); } @@ -517,6 +517,9 @@ public class AppDetails2 extends AppCompatActivity break; case Installing: + adapter.setIndeterminateProgress(R.string.installing); + break; + case Installed: case UpdateAvailable: case InstallError: @@ -553,7 +556,7 @@ public class AppDetails2 extends AppCompatActivity public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case Installer.ACTION_INSTALL_STARTED: - adapter.setProgress(-1, -1, R.string.installing); + adapter.setIndeterminateProgress(R.string.installing); break; case Installer.ACTION_INSTALL_COMPLETE: adapter.clearProgress(); @@ -625,7 +628,7 @@ public class AppDetails2 extends AppCompatActivity public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case Installer.ACTION_UNINSTALL_STARTED: - adapter.setProgress(-1, -1, R.string.uninstalling); + adapter.setIndeterminateProgress(R.string.uninstalling); break; case Installer.ACTION_UNINSTALL_COMPLETE: adapter.clearProgress(); diff --git a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java index a07982285..84bdbf378 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -34,9 +34,7 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; - import com.nostra13.universalimageloader.core.ImageLoader; - import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.R; import org.fdroid.fdroid.Utils; @@ -204,12 +202,20 @@ public class AppDetailsRecyclerViewAdapter } public void clearProgress() { - setProgress(0, 0, 0); + if (headerView != null) { + headerView.clearProgress(); + } } - public void setProgress(long bytesDownloaded, long totalBytes, int resIdString) { + public void setIndeterminateProgress(int resIdString) { if (headerView != null) { - headerView.setProgress(bytesDownloaded, totalBytes, resIdString); + headerView.setIndeterminateProgress(resIdString); + } + } + + public void setProgress(long bytesDownloaded, long totalBytes) { + if (headerView != null) { + headerView.setProgress(bytesDownloaded, totalBytes); } } @@ -360,38 +366,39 @@ public class AppDetailsRecyclerViewAdapter }); } - public void setProgress(long bytesDownloaded, long totalBytes, int resIdString) { - if (bytesDownloaded == 0 && totalBytes == 0) { - // Remove progress bar - progressLayout.setVisibility(View.GONE); - buttonLayout.setVisibility(View.VISIBLE); - } else { - progressBar.setMax(Utils.bytesToKb(totalBytes)); - progressBar.setProgress(Utils.bytesToKb(bytesDownloaded)); - progressBar.setIndeterminate(totalBytes == -1); - progressLabel.setContentDescription(""); - if (resIdString != 0) { - progressLabel.setText(resIdString); - progressLabel.setContentDescription(context.getString(R.string.downloading)); - progressPercent.setText(""); - } else if (totalBytes > 0 && bytesDownloaded >= 0) { - int percent = Utils.getPercent(bytesDownloaded, totalBytes); - progressLabel.setText(Utils.getFriendlySize(bytesDownloaded) - + " / " + Utils.getFriendlySize(totalBytes)); - progressLabel.setContentDescription(context.getString(R.string.app__tts__downloading_progress, - percent)); - progressPercent.setText(String.format(Locale.ENGLISH, "%d%%", percent)); - } else if (bytesDownloaded >= 0) { - progressLabel.setText(Utils.getFriendlySize(bytesDownloaded)); - progressLabel.setContentDescription(context.getString(R.string.downloading)); - progressPercent.setText(""); - } + public void clearProgress() { + progressLayout.setVisibility(View.GONE); + buttonLayout.setVisibility(View.VISIBLE); + } - // Make sure it's visible - if (progressLayout.getVisibility() != View.VISIBLE) { - progressLayout.setVisibility(View.VISIBLE); - buttonLayout.setVisibility(View.GONE); - } + public void setIndeterminateProgress(int resIdString) { + progressLayout.setVisibility(View.VISIBLE); + buttonLayout.setVisibility(View.GONE); + progressBar.setIndeterminate(true); + progressLabel.setText(resIdString); + progressLabel.setContentDescription(context.getString(R.string.downloading)); + progressPercent.setText(""); + } + + public void setProgress(long bytesDownloaded, long totalBytes) { + progressLayout.setVisibility(View.VISIBLE); + buttonLayout.setVisibility(View.GONE); + + progressBar.setMax(Utils.bytesToKb(totalBytes)); + progressBar.setProgress(Utils.bytesToKb(bytesDownloaded)); + progressBar.setIndeterminate(totalBytes <= 0); + progressLabel.setContentDescription(""); + if (totalBytes > 0 && bytesDownloaded >= 0) { + int percent = Utils.getPercent(bytesDownloaded, totalBytes); + progressLabel.setText(Utils.getFriendlySize(bytesDownloaded) + + " / " + Utils.getFriendlySize(totalBytes)); + progressLabel.setContentDescription(context.getString(R.string.app__tts__downloading_progress, + percent)); + progressPercent.setText(String.format(Locale.ENGLISH, "%d%%", percent)); + } else if (bytesDownloaded >= 0) { + progressLabel.setText(Utils.getFriendlySize(bytesDownloaded)); + progressLabel.setContentDescription(context.getString(R.string.downloading)); + progressPercent.setText(""); } }