Don't show progress in AppDetails when using a cached download.
The ApkDownloader now returns true or false depending on whether it is using a cached version on disk, or hitting the network. I was also a little more defensive about checking for if downloadHandler is null before deciding to show a progress dialog.
This commit is contained in:
parent
2f7d6f6452
commit
009c8a6be5
@ -425,7 +425,6 @@ public class AppDetails extends ListActivity implements ProgressListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.d(TAG, "onresume");
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
// register observer to know when install status changes
|
// register observer to know when install status changes
|
||||||
@ -1021,9 +1020,10 @@ public class AppDetails extends ListActivity implements ProgressListener {
|
|||||||
private void startDownload(Apk apk, String repoAddress) {
|
private void startDownload(Apk apk, String repoAddress) {
|
||||||
downloadHandler = new ApkDownloader(apk, repoAddress, Utils.getApkCacheDir(getBaseContext()));
|
downloadHandler = new ApkDownloader(apk, repoAddress, Utils.getApkCacheDir(getBaseContext()));
|
||||||
downloadHandler.setProgressListener(this);
|
downloadHandler.setProgressListener(this);
|
||||||
downloadHandler.download();
|
if (downloadHandler.download()) {
|
||||||
updateProgressDialog();
|
updateProgressDialog();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void installApk(File file, String packageName) {
|
private void installApk(File file, String packageName) {
|
||||||
setProgressBarIndeterminateVisibility(true);
|
setProgressBarIndeterminateVisibility(true);
|
||||||
|
|
||||||
@ -1052,10 +1052,6 @@ public class AppDetails extends ListActivity implements ProgressListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (operation == Installer.InstallerCallback.OPERATION_INSTALL) {
|
if (operation == Installer.InstallerCallback.OPERATION_INSTALL) {
|
||||||
if (downloadHandler != null) {
|
|
||||||
downloadHandler = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
PackageManagerCompat.setInstaller(mPm, app.id);
|
PackageManagerCompat.setInstaller(mPm, app.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1121,8 +1117,13 @@ public class AppDetails extends ListActivity implements ProgressListener {
|
|||||||
pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
Log.d(TAG, "User clicked 'cancel' on download, attempting to interrupt download thread.");
|
||||||
|
if (downloadHandler != null) {
|
||||||
downloadHandler.cancel();
|
downloadHandler.cancel();
|
||||||
downloadHandler = null;
|
downloadHandler = null;
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Tried to cancel, but the downloadHandler doesn't exist.");
|
||||||
|
}
|
||||||
progressDialog = null;
|
progressDialog = null;
|
||||||
Toast.makeText(AppDetails.this, getString(R.string.download_cancelled), Toast.LENGTH_LONG).show();
|
Toast.makeText(AppDetails.this, getString(R.string.download_cancelled), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
@ -1148,10 +1149,13 @@ public class AppDetails extends ListActivity implements ProgressListener {
|
|||||||
* {@link org.fdroid.fdroid.ProgressListener.Event}.
|
* {@link org.fdroid.fdroid.ProgressListener.Event}.
|
||||||
*/
|
*/
|
||||||
private void updateProgressDialog() {
|
private void updateProgressDialog() {
|
||||||
|
if (downloadHandler != null) {
|
||||||
updateProgressDialog(downloadHandler.getProgress(), downloadHandler.getTotalSize());
|
updateProgressDialog(downloadHandler.getProgress(), downloadHandler.getTotalSize());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateProgressDialog(int progress, int total) {
|
private void updateProgressDialog(int progress, int total) {
|
||||||
|
if (downloadHandler != null) {
|
||||||
ProgressDialog pd = getProgressDialog(downloadHandler.getRemoteAddress());
|
ProgressDialog pd = getProgressDialog(downloadHandler.getRemoteAddress());
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
pd.setIndeterminate(false);
|
pd.setIndeterminate(false);
|
||||||
@ -1162,8 +1166,12 @@ public class AppDetails extends ListActivity implements ProgressListener {
|
|||||||
pd.setProgress(progress);
|
pd.setProgress(progress);
|
||||||
pd.setMax(0);
|
pd.setMax(0);
|
||||||
}
|
}
|
||||||
|
if (!pd.isShowing()) {
|
||||||
|
Log.d(TAG, "Showing progress dialog for download.");
|
||||||
pd.show();
|
pd.show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(Event event) {
|
public void onProgress(Event event) {
|
||||||
|
@ -131,12 +131,17 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void download() {
|
/**
|
||||||
|
* If the download successfully spins up a new thread to start downloading, then we return
|
||||||
|
* true, otherwise false. This is useful, e.g. when we use a cached version, and so don't
|
||||||
|
* want to bother with progress dialogs et al.
|
||||||
|
*/
|
||||||
|
public boolean download() {
|
||||||
|
|
||||||
// Can we use the cached version?
|
// Can we use the cached version?
|
||||||
if (verifyOrDeleteCachedVersion()) {
|
if (verifyOrDeleteCachedVersion()) {
|
||||||
sendMessage(EVENT_APK_DOWNLOAD_COMPLETE);
|
sendMessage(EVENT_APK_DOWNLOAD_COMPLETE);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String remoteAddress = getRemoteAddress();
|
String remoteAddress = getRemoteAddress();
|
||||||
@ -147,12 +152,15 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|||||||
Downloader downloader = new HttpDownloader(remoteAddress, localFile);
|
Downloader downloader = new HttpDownloader(remoteAddress, localFile);
|
||||||
dlWrapper = new AsyncDownloadWrapper(downloader, this);
|
dlWrapper = new AsyncDownloadWrapper(downloader, this);
|
||||||
dlWrapper.download();
|
dlWrapper.download();
|
||||||
|
return true;
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
onErrorDownloading(e.getLocalizedMessage());
|
onErrorDownloading(e.getLocalizedMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
onErrorDownloading(e.getLocalizedMessage());
|
onErrorDownloading(e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(String type) {
|
private void sendMessage(String type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user