Show alert dialog for major upgrades

Major upgrades are not possible with Updater and they are already
blocked. This commit adds a dialog with a link to a webpage that
explains how to upgrade manually.

Based on: d5d343d627

Change-Id: Ifb23e0a4db1060fc696d13e6694f3e849af70e2d
This commit is contained in:
Gabriele M
2017-08-25 20:05:57 +02:00
parent 88b6fd84bb
commit 17f35382d7
3 changed files with 49 additions and 1 deletions

9
res/drawable/ic_info.xml Normal file
View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z"/>
</vector>

View File

@@ -87,6 +87,7 @@
<string name="action_description_pause">Pause download</string>
<string name="action_description_resume">Resume download</string>
<string name="action_description_install">Install update</string>
<string name="action_description_info">Show information</string>
<string name="confirm_delete_dialog_title">Delete file</string>
<string name="confirm_delete_dialog_message">Delete the selected update file?</string>
@@ -121,4 +122,8 @@
<string name="update_on_mobile_data_message">You\'re about to download an update package using mobile data which is likely going to cause high data usage. Would you like to proceed?</string>
<string name="checkbox_mobile_data_warning">Do not show again</string>
<string name="menu_mobile_data_warning">Mobile data warning</string>
<string name="blocked_update_dialog_title">Update blocked</string>
<string name="blocked_update_dialog_message">This update cannot be installed using the updater app. Please read <xliff:g id="info_url">%1$s</xliff:g> for more information.</string>
<string name="blocked_update_info_url" translatable="false">http://wiki.lineageos.org/upgrading.html</string>
</resources>

View File

@@ -22,7 +22,10 @@ import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.format.Formatter;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
@@ -68,7 +71,8 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
DOWNLOAD,
PAUSE,
RESUME,
INSTALL
INSTALL,
INFO,
}
public static class ViewHolder extends RecyclerView.ViewHolder {
@@ -186,6 +190,9 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
if (update.getPersistentStatus() == UpdateStatus.Persistent.VERIFIED) {
viewHolder.itemView.setOnLongClickListener(getLongClickListener(update, true));
setButtonAction(viewHolder.mAction, Action.INSTALL, update.getDownloadId(), !isBusy());
} else if (!Utils.canInstall(update)) {
viewHolder.itemView.setOnLongClickListener(getLongClickListener(update, false));
setButtonAction(viewHolder.mAction, Action.INFO, update.getDownloadId(), !isBusy());
} else {
viewHolder.itemView.setOnLongClickListener(getLongClickListener(update, false));
setButtonAction(viewHolder.mAction, Action.DOWNLOAD, update.getDownloadId(), !isBusy());
@@ -358,6 +365,18 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
};
}
break;
case INFO: {
button.setImageResource(R.drawable.ic_info);
button.setContentDescription(mActivity.getString(R.string.action_description_info));
button.setEnabled(enabled);
clickListener = !enabled ? null : new View.OnClickListener() {
@Override
public void onClick(View view) {
showInfoDialog();
}
};
}
break;
default:
clickListener = null;
}
@@ -541,4 +560,19 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
}
stopActionMode();
}
private void showInfoDialog() {
String messageString = String.format(StringGenerator.getCurrentLocale(mActivity),
mActivity.getString(R.string.blocked_update_dialog_message),
mActivity.getString(R.string.blocked_update_info_url));
SpannableString message = new SpannableString(messageString);
Linkify.addLinks(message, Linkify.WEB_URLS);
AlertDialog dialog = new AlertDialog.Builder(mActivity)
.setTitle(R.string.blocked_update_dialog_title)
.setPositiveButton(android.R.string.ok, null)
.setMessage(message)
.show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
}