wire up ProgressListener to new ApkDownloader structure
Conflicts: src/org/fdroid/fdroid/AppDetails.java
This commit is contained in:
parent
9588f30778
commit
19e722a9d7
@ -19,32 +19,28 @@
|
|||||||
|
|
||||||
package org.fdroid.fdroid;
|
package org.fdroid.fdroid;
|
||||||
|
|
||||||
import android.content.*;
|
import android.app.Activity;
|
||||||
import android.widget.*;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.data.*;
|
|
||||||
import org.fdroid.fdroid.installer.Installer;
|
|
||||||
import org.fdroid.fdroid.installer.Installer.AndroidNotCompatibleException;
|
|
||||||
import org.fdroid.fdroid.installer.Installer.InstallerCallback;
|
|
||||||
import org.fdroid.fdroid.net.Downloader;
|
|
||||||
import org.xml.sax.XMLReader;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.content.pm.Signature;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.Signature;
|
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Html.TagHandler;
|
import android.text.Html.TagHandler;
|
||||||
@ -59,16 +55,30 @@ import android.view.SubMenu;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.graphics.Bitmap;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Utils.CommaSeparatedList;
|
import org.fdroid.fdroid.Utils.CommaSeparatedList;
|
||||||
import org.fdroid.fdroid.compat.ActionBarCompat;
|
import org.fdroid.fdroid.compat.ActionBarCompat;
|
||||||
import org.fdroid.fdroid.compat.MenuManager;
|
import org.fdroid.fdroid.compat.MenuManager;
|
||||||
import org.fdroid.fdroid.compat.PackageManagerCompat;
|
import org.fdroid.fdroid.compat.PackageManagerCompat;
|
||||||
|
import org.fdroid.fdroid.data.Apk;
|
||||||
|
import org.fdroid.fdroid.data.ApkProvider;
|
||||||
|
import org.fdroid.fdroid.data.App;
|
||||||
|
import org.fdroid.fdroid.data.AppProvider;
|
||||||
|
import org.fdroid.fdroid.data.Repo;
|
||||||
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
|
import org.fdroid.fdroid.installer.Installer;
|
||||||
|
import org.fdroid.fdroid.installer.Installer.AndroidNotCompatibleException;
|
||||||
|
import org.fdroid.fdroid.installer.Installer.InstallerCallback;
|
||||||
|
import org.fdroid.fdroid.net.Downloader;
|
||||||
|
import org.xml.sax.XMLReader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
@ -99,7 +109,7 @@ public class AppDetails extends ListActivity {
|
|||||||
|
|
||||||
// observer to update view when package has been installed/deleted
|
// observer to update view when package has been installed/deleted
|
||||||
AppObserver myAppObserver;
|
AppObserver myAppObserver;
|
||||||
class AppObserver extends ContentObserver {
|
class AppObserver extends ContentObserver {
|
||||||
public AppObserver(Handler handler) {
|
public AppObserver(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
}
|
}
|
||||||
@ -906,6 +916,7 @@ public class AppDetails extends ListActivity {
|
|||||||
|
|
||||||
// Install the version of this app denoted by 'app.curApk'.
|
// Install the version of this app denoted by 'app.curApk'.
|
||||||
private void install(final Apk apk) {
|
private void install(final Apk apk) {
|
||||||
|
final Activity activity = this;
|
||||||
String [] projection = { RepoProvider.DataColumns.ADDRESS };
|
String [] projection = { RepoProvider.DataColumns.ADDRESS };
|
||||||
Repo repo = RepoProvider.Helper.findById(this, apk.repo, projection);
|
Repo repo = RepoProvider.Helper.findById(this, apk.repo, projection);
|
||||||
if (repo == null || repo.address == null) {
|
if (repo == null || repo.address == null) {
|
||||||
@ -921,9 +932,8 @@ public class AppDetails extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int whichButton) {
|
int whichButton) {
|
||||||
downloadHandler = new DownloadHandler(apk,
|
downloadHandler = new DownloadHandler(activity, apk,
|
||||||
repoaddress, Utils
|
repoaddress, Utils.getApkCacheDir(getBaseContext()));
|
||||||
.getApkCacheDir(getBaseContext()));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ask_alrt.setNegativeButton(getString(R.string.no),
|
ask_alrt.setNegativeButton(getString(R.string.no),
|
||||||
@ -952,7 +962,7 @@ public class AppDetails extends ListActivity {
|
|||||||
alert.show();
|
alert.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
downloadHandler = new DownloadHandler(apk, repoaddress,
|
downloadHandler = new DownloadHandler(activity, apk, repoaddress,
|
||||||
Utils.getApkCacheDir(getBaseContext()));
|
Utils.getApkCacheDir(getBaseContext()));
|
||||||
}
|
}
|
||||||
private void installApk(File file, String packageName) {
|
private void installApk(File file, String packageName) {
|
||||||
@ -1066,13 +1076,17 @@ public class AppDetails extends ListActivity {
|
|||||||
|
|
||||||
// Handler used to update the progress dialog while downloading.
|
// Handler used to update the progress dialog while downloading.
|
||||||
private class DownloadHandler extends Handler implements ProgressListener {
|
private class DownloadHandler extends Handler implements ProgressListener {
|
||||||
|
private static final String TAG = "AppDetails.DownloadHandler";
|
||||||
|
private Activity activity;
|
||||||
private ApkDownloader download;
|
private ApkDownloader download;
|
||||||
private ProgressDialog pd;
|
private ProgressDialog pd;
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public DownloadHandler(Apk apk, String repoaddress, File destdir) {
|
public DownloadHandler(Activity activity, Apk apk, String repoaddress, File destdir) {
|
||||||
|
this.activity = activity;
|
||||||
id = apk.id;
|
id = apk.id;
|
||||||
download = new ApkDownloader(apk, repoaddress, destdir);
|
download = new ApkDownloader(apk, repoaddress, destdir);
|
||||||
|
download.setProgressListener(this);
|
||||||
download.start();
|
download.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,27 +1096,41 @@ public class AppDetails extends ListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onProgress(ProgressListener.Event event) {
|
public void onProgress(final ProgressListener.Event event) {
|
||||||
boolean finished = false;
|
boolean finished = false;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case Downloader.EVENT_PROGRESS:
|
case Downloader.EVENT_PROGRESS:
|
||||||
if (pd == null) {
|
activity.runOnUiThread(new Runnable() {
|
||||||
pd = createProgressDialog(download.remoteFile(),
|
|
||||||
event.progress, event.total);
|
@Override
|
||||||
} else {
|
public void run() {
|
||||||
pd.setProgress(event.progress);
|
// this must be on the main UI thread
|
||||||
}
|
if (pd == null) {
|
||||||
|
pd = createProgressDialog(download.remoteFile(),
|
||||||
|
event.progress, event.total);
|
||||||
|
} else {
|
||||||
|
pd.setProgress(event.progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ApkDownloader.EVENT_ERROR_DOWNLOAD_FAILED:
|
case ApkDownloader.EVENT_ERROR_DOWNLOAD_FAILED:
|
||||||
case ApkDownloader.EVENT_ERROR_HASH_MISMATCH:
|
case ApkDownloader.EVENT_ERROR_HASH_MISMATCH:
|
||||||
case ApkDownloader.EVENT_ERROR_UNKNOWN:
|
case ApkDownloader.EVENT_ERROR_UNKNOWN:
|
||||||
String text;
|
final String text;
|
||||||
if (event.type == ApkDownloader.EVENT_ERROR_HASH_MISMATCH)
|
if (event.type == ApkDownloader.EVENT_ERROR_HASH_MISMATCH)
|
||||||
text = getString(R.string.corrupt_download);
|
text = getString(R.string.corrupt_download);
|
||||||
else
|
else
|
||||||
text = getString(R.string.details_notinstalled);
|
text = getString(R.string.details_notinstalled);
|
||||||
Toast.makeText(AppDetails.this, text, Toast.LENGTH_LONG).show();
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// this must be on the main UI thread
|
||||||
|
Toast.makeText(AppDetails.this, text, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
finished = true;
|
finished = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user