New error dialog on failed installs
This commit is contained in:
parent
5f1b7488f0
commit
0b92806327
@ -407,9 +407,14 @@
|
|||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<!-- Note: AppThemeTransparent, this activity shows dialogs only -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".installer.DefaultInstallerActivity"
|
android:name=".installer.DefaultInstallerActivity"
|
||||||
android:theme="@style/AppThemeTransparent" />
|
android:theme="@style/AppThemeTransparent" />
|
||||||
|
<!-- Note: AppThemeTransparent, this activity shows dialogs only -->
|
||||||
|
<activity
|
||||||
|
android:name=".installer.ErrorDialogActivity"
|
||||||
|
android:theme="@style/AppThemeTransparent" />
|
||||||
|
|
||||||
<receiver android:name=".receiver.StartupReceiver" >
|
<receiver android:name=".receiver.StartupReceiver" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -574,7 +574,7 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(errorMessage)) {
|
if (!TextUtils.isEmpty(errorMessage)) {
|
||||||
Log.e(TAG, "Installer aborted with errorMessage: " + errorMessage);
|
Log.e(TAG, "install aborted with errorMessage: " + errorMessage);
|
||||||
|
|
||||||
String title = String.format(
|
String title = String.format(
|
||||||
getString(R.string.install_error_notify_title),
|
getString(R.string.install_error_notify_title),
|
||||||
@ -629,7 +629,7 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(errorMessage)) {
|
if (!TextUtils.isEmpty(errorMessage)) {
|
||||||
Log.e(TAG, "Installer aborted with errorMessage: " + errorMessage);
|
Log.e(TAG, "uninstall aborted with errorMessage: " + errorMessage);
|
||||||
|
|
||||||
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetails.this);
|
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetails.this);
|
||||||
alertBuilder.setTitle(R.string.uninstall_error_notify_title);
|
alertBuilder.setTitle(R.string.uninstall_error_notify_title);
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 3
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.fdroid.fdroid.installer;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
|
|
||||||
|
public class ErrorDialogActivity extends FragmentActivity {
|
||||||
|
|
||||||
|
public static final String EXTRA_TITLE = "title";
|
||||||
|
public static final String EXTRA_MESSAGE = "message";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
final Intent intent = getIntent();
|
||||||
|
final String title = intent.getStringExtra(EXTRA_TITLE);
|
||||||
|
final String message = intent.getStringExtra(EXTRA_MESSAGE);
|
||||||
|
|
||||||
|
// hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
|
||||||
|
ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());
|
||||||
|
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
|
||||||
|
builder.setTitle(title);
|
||||||
|
builder.setNeutralButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
setResult(Activity.RESULT_OK);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setOnCancelListener(
|
||||||
|
new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
setResult(Activity.RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setMessage(message);
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
|
}
|
@ -284,9 +284,19 @@ public class InstallManagerService extends Service {
|
|||||||
String errorMessage =
|
String errorMessage =
|
||||||
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
||||||
|
|
||||||
|
// show notification if app details is not visible
|
||||||
if (!TextUtils.isEmpty(errorMessage)) {
|
if (!TextUtils.isEmpty(errorMessage)) {
|
||||||
App app = getAppFromActive(originatingUri.toString());
|
App app = getAppFromActive(originatingUri.toString());
|
||||||
notifyError(app, originatingUri.toString(), errorMessage, false);
|
String title = String.format(
|
||||||
|
getString(R.string.install_error_notify_title),
|
||||||
|
app.name);
|
||||||
|
|
||||||
|
// show notification if app details is not visible
|
||||||
|
if (AppDetails.isAppVisible(app.packageName)) {
|
||||||
|
cancelNotification(originatingUri.toString());
|
||||||
|
} else {
|
||||||
|
notifyError(originatingUri.toString(), title, errorMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localBroadcastManager.unregisterReceiver(this);
|
localBroadcastManager.unregisterReceiver(this);
|
||||||
@ -379,19 +389,25 @@ public class InstallManagerService extends Service {
|
|||||||
notificationManager.notify(downloadUrlId, notification);
|
notificationManager.notify(downloadUrlId, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyError(App app, String urlString, String text, boolean uninstall) {
|
private void notifyError(String urlString, String title, String text) {
|
||||||
String title;
|
|
||||||
if (uninstall) {
|
|
||||||
title = String.format(getString(R.string.uninstall_error_notify_title), app.name);
|
|
||||||
} else {
|
|
||||||
title = String.format(getString(R.string.install_error_notify_title), app.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
int downloadUrlId = urlString.hashCode();
|
int downloadUrlId = urlString.hashCode();
|
||||||
|
|
||||||
|
Intent errorDialogIntent = new Intent(this, ErrorDialogActivity.class);
|
||||||
|
errorDialogIntent.putExtra(
|
||||||
|
ErrorDialogActivity.EXTRA_TITLE, title);
|
||||||
|
errorDialogIntent.putExtra(
|
||||||
|
ErrorDialogActivity.EXTRA_MESSAGE, text);
|
||||||
|
PendingIntent errorDialogPendingIntent = PendingIntent.getActivity(
|
||||||
|
getApplicationContext(),
|
||||||
|
downloadUrlId,
|
||||||
|
errorDialogIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
NotificationCompat.Builder builder =
|
NotificationCompat.Builder builder =
|
||||||
new NotificationCompat.Builder(this)
|
new NotificationCompat.Builder(this)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
|
.setContentIntent(errorDialogPendingIntent)
|
||||||
.setSmallIcon(R.drawable.ic_issues)
|
.setSmallIcon(R.drawable.ic_issues)
|
||||||
.setContentText(text);
|
.setContentText(text);
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user