show indeterminate progress when installing and uninstalling
This should make the buttons in AppDetails show the realistic state a lot better. closes #1145 refs #1357
This commit is contained in:
parent
6c66697762
commit
be560f7179
@ -488,15 +488,15 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
case Downloading:
|
case Downloading:
|
||||||
if (newStatus.progressMax == 0) {
|
if (newStatus.progressMax == 0) {
|
||||||
// The first progress notification we get telling us our status is "Downloading"
|
// 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 {
|
} else {
|
||||||
adapter.setProgress(newStatus.progressCurrent, newStatus.progressMax, 0);
|
adapter.setProgress(newStatus.progressCurrent, newStatus.progressMax);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ReadyToInstall:
|
case ReadyToInstall:
|
||||||
if (justReceived) {
|
if (justReceived) {
|
||||||
adapter.clearProgress();
|
adapter.setIndeterminateProgress(R.string.installing);
|
||||||
localBroadcastManager.registerReceiver(installReceiver,
|
localBroadcastManager.registerReceiver(installReceiver,
|
||||||
Installer.getInstallIntentFilter(Uri.parse(newStatus.getUniqueKey())));
|
Installer.getInstallIntentFilter(Uri.parse(newStatus.getUniqueKey())));
|
||||||
}
|
}
|
||||||
@ -517,6 +517,9 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Installing:
|
case Installing:
|
||||||
|
adapter.setIndeterminateProgress(R.string.installing);
|
||||||
|
break;
|
||||||
|
|
||||||
case Installed:
|
case Installed:
|
||||||
case UpdateAvailable:
|
case UpdateAvailable:
|
||||||
case InstallError:
|
case InstallError:
|
||||||
@ -553,7 +556,7 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case Installer.ACTION_INSTALL_STARTED:
|
case Installer.ACTION_INSTALL_STARTED:
|
||||||
adapter.setProgress(-1, -1, R.string.installing);
|
adapter.setIndeterminateProgress(R.string.installing);
|
||||||
break;
|
break;
|
||||||
case Installer.ACTION_INSTALL_COMPLETE:
|
case Installer.ACTION_INSTALL_COMPLETE:
|
||||||
adapter.clearProgress();
|
adapter.clearProgress();
|
||||||
@ -625,7 +628,7 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case Installer.ACTION_UNINSTALL_STARTED:
|
case Installer.ACTION_UNINSTALL_STARTED:
|
||||||
adapter.setProgress(-1, -1, R.string.uninstalling);
|
adapter.setIndeterminateProgress(R.string.uninstalling);
|
||||||
break;
|
break;
|
||||||
case Installer.ACTION_UNINSTALL_COMPLETE:
|
case Installer.ACTION_UNINSTALL_COMPLETE:
|
||||||
adapter.clearProgress();
|
adapter.clearProgress();
|
||||||
|
@ -34,9 +34,7 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
@ -204,12 +202,20 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearProgress() {
|
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) {
|
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) {
|
public void clearProgress() {
|
||||||
if (bytesDownloaded == 0 && totalBytes == 0) {
|
progressLayout.setVisibility(View.GONE);
|
||||||
// Remove progress bar
|
buttonLayout.setVisibility(View.VISIBLE);
|
||||||
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("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure it's visible
|
public void setIndeterminateProgress(int resIdString) {
|
||||||
if (progressLayout.getVisibility() != View.VISIBLE) {
|
progressLayout.setVisibility(View.VISIBLE);
|
||||||
progressLayout.setVisibility(View.VISIBLE);
|
buttonLayout.setVisibility(View.GONE);
|
||||||
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("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user