cleaned up code, prevented multiple app details screens popping up, fixed "no such app" toast after install

This commit is contained in:
Toby Kurien 2015-09-04 14:44:14 +02:00 committed by Peter Serwylo
parent e827be1b5b
commit efd4ebeadf
3 changed files with 21 additions and 19 deletions

View File

@ -365,21 +365,6 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
private String getAppIdFromIntent() { private String getAppIdFromIntent() {
Intent i = getIntent(); Intent i = getIntent();
if (!i.hasExtra(EXTRA_APPID)) { if (!i.hasExtra(EXTRA_APPID)) {
if (i.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
// we have been passed a DownloadManager download id, so get the app id for it
long downloadId = i.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
return AsyncDownloader.getAppId(this, downloadId);
}
if (i.hasExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS)) {
// we have been passed a DownloadManager download id, so get the app id for it
long[] downloadIds = i.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
if (downloadIds != null && downloadIds.length > 0) {
return AsyncDownloader.getAppId(this, downloadIds[0]);
}
}
Log.e(TAG, "No application ID found in the intent!");
return null; return null;
} }

View File

@ -150,10 +150,21 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
*/ */
public static long getDownloadId(Intent intent) { public static long getDownloadId(Intent intent) {
if (intent != null) { if (intent != null) {
return intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
} else { // we have been passed a DownloadManager download id, so get the app id for it
return -1; return intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
}
if (intent.hasExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS)) {
// we have been passed a DownloadManager download id, so get the app id for it
long[] downloadIds = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
if (downloadIds != null && downloadIds.length > 0) {
return downloadIds[0];
}
}
} }
return -1;
} }
/** /**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.AppDetails;
import org.fdroid.fdroid.net.AsyncDownloader;
/** /**
* Receive notifications from the Android DownloadManager * Receive notifications from the Android DownloadManager
@ -12,11 +13,16 @@ import org.fdroid.fdroid.AppDetails;
public class DownloadManagerReceiver extends BroadcastReceiver { public class DownloadManagerReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// work out the app Id to send to the AppDetails Screen
long downloadId = AsyncDownloader.getDownloadId(intent);
String appId = AsyncDownloader.getAppId(context, downloadId);
// pass the download manager broadcast onto the AppDetails screen and let it handle it // pass the download manager broadcast onto the AppDetails screen and let it handle it
Intent appDetails = new Intent(context, AppDetails.class); Intent appDetails = new Intent(context, AppDetails.class);
appDetails.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); appDetails.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
appDetails.setAction(intent.getAction()); appDetails.setAction(intent.getAction());
appDetails.putExtras(intent.getExtras()); appDetails.putExtras(intent.getExtras());
appDetails.putExtra(AppDetails.EXTRA_APPID, appId);
context.startActivity(appDetails); context.startActivity(appDetails);
} }
} }