Commit f9db59a5 authored by Rohit's avatar Rohit Committed by Romain Hunault
Browse files

[q] Updater: Improve UX for users taking version upgrades

parent d32d05fc
......@@ -35,6 +35,18 @@
android:textSize="16sp"
tools:text="LineageOS 15.1" />
<TextView
android:id="@+id/upgrade_type"
android:textColor="@color/theme_accent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/version_upgrade_dialog_title"
android:textSize="14sp"
android:visibility="gone"
tools:text="@string/version_upgrade_dialog_title"
tools:visibility="visible" />
<TextView
android:id="@+id/build_date"
android:layout_width="wrap_content"
......
......@@ -112,8 +112,12 @@
<string name="confirm_delete_dialog_message">Delete the selected update file?</string>
<string name="apply_update_dialog_title">Apply update</string>
<string name="apply_update_dialog_message">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will restart itself in recovery mode to install the update.\n\nNote: This feature requires a compatible Recovery or updates will need to be installed manually.</string>
<string name="apply_update_dialog_message_ab">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.</string>
<string name="apply_update_dialog_message">You are about to update to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will restart itself in recovery mode to install the update.</string>
<string name="apply_update_dialog_message_ab">You are about to update to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.</string>
<string name="version_upgrade_dialog_title">Version Upgrade!</string>
<string name="version_upgrade_dialog_message">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>, based on Android <xliff:g id="version_android">%2$s</xliff:g>\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press <xliff:g id="ok">%3$s</xliff:g>, the device will restart itself into recovery mode to install the update.</string>
<string name="version_upgrade_dialog_message_ab">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>, based on Android <xliff:g id="version_android">%2$s</xliff:g>.\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press <xliff:g id="ok">%3$s</xliff:g>, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.</string>
<string name="cancel_installation_dialog_message">Cancel the installation?</string>
......
......@@ -30,7 +30,7 @@ import java.util.List;
public class UpdatesDbHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 2;
public static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "updates.db";
public static class UpdateEntry implements BaseColumns {
......@@ -42,6 +42,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
public static final String COLUMN_NAME_TYPE = "type";
public static final String COLUMN_NAME_VERSION = "version";
public static final String COLUMN_NAME_DISPLAY_VERSION = "display_version";
public static final String COLUMN_NAME_ANDROID_VERSION = "android_version";
public static final String COLUMN_NAME_SIZE = "size";
}
......@@ -55,6 +56,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
UpdateEntry.COLUMN_NAME_TYPE + " TEXT," +
UpdateEntry.COLUMN_NAME_VERSION + " TEXT," +
UpdateEntry.COLUMN_NAME_DISPLAY_VERSION + " TEXT," +
UpdateEntry.COLUMN_NAME_ANDROID_VERSION + " TEXT," +
UpdateEntry.COLUMN_NAME_SIZE + " INTEGER)";
private static final String SQL_DELETE_ENTRIES =
......@@ -87,6 +89,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
values.put(UpdateEntry.COLUMN_NAME_TYPE, update.getType());
values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion());
values.put(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, update.getDisplayVersion());
values.put(UpdateEntry.COLUMN_NAME_ANDROID_VERSION, update.getAndroidVersion());
values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize());
return db.insert(UpdateEntry.TABLE_NAME, null, values);
}
......@@ -101,6 +104,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
values.put(UpdateEntry.COLUMN_NAME_TYPE, update.getType());
values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion());
values.put(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, update.getDisplayVersion());
values.put(UpdateEntry.COLUMN_NAME_ANDROID_VERSION, update.getAndroidVersion());
values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize());
return db.insertWithOnConflict(UpdateEntry.TABLE_NAME, null, values, conflictAlgorithm);
}
......@@ -166,6 +170,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
UpdateEntry.COLUMN_NAME_TYPE,
UpdateEntry.COLUMN_NAME_VERSION,
UpdateEntry.COLUMN_NAME_DISPLAY_VERSION,
UpdateEntry.COLUMN_NAME_ANDROID_VERSION,
UpdateEntry.COLUMN_NAME_STATUS,
UpdateEntry.COLUMN_NAME_SIZE,
};
......@@ -189,6 +194,8 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
update.setVersion(cursor.getString(index));
index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION);
update.setDisplayVersion(cursor.getString(index));
index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_ANDROID_VERSION);
update.setAndroidVersion(cursor.getString(index));
index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_STATUS);
update.setPersistentStatus(cursor.getInt(index));
index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_SIZE);
......
......@@ -21,6 +21,7 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.BatteryManager;
import android.os.Build;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.text.SpannableString;
......@@ -94,6 +95,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
public static class ViewHolder extends RecyclerView.ViewHolder {
private Button mAction;
private TextView mUpgradeType;
private TextView mBuildDate;
private TextView mBuildVersion;
private TextView mBuildSize;
......@@ -105,6 +107,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
super(view);
mAction = (Button) view.findViewById(R.id.update_action);
mUpgradeType = (TextView) view.findViewById(R.id.upgrade_type);
mBuildDate = (TextView) view.findViewById(R.id.build_date);
mBuildVersion = (TextView) view.findViewById(R.id.build_version);
mBuildSize = (TextView) view.findViewById(R.id.build_size);
......@@ -268,6 +271,9 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
String buildVersion = mActivity.getString(R.string.list_build_version,
update.getVersion());
if (!update.getAndroidVersion().equals(Build.VERSION.RELEASE)){
viewHolder.mUpgradeType.setVisibility(TextView.VISIBLE);
}
viewHolder.mBuildDate.setText(buildDate);
viewHolder.mBuildVersion.setText(buildVersion);
viewHolder.mBuildVersion.setCompoundDrawables(null, null, null, null);
......@@ -459,26 +465,42 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
.setPositiveButton(android.R.string.ok, null);
}
UpdateInfo update = mUpdaterController.getUpdate(downloadId);
int resId;
int title;
String message;
try {
if (Utils.isABUpdate(update.getFile())) {
resId = R.string.apply_update_dialog_message_ab;
String buildDate = StringGenerator.getDateLocalizedUTC(mActivity,
DateFormat.MEDIUM, update.getTimestamp());
String buildInfoText = mActivity.getString(R.string.list_build_version_date,
update.getVersion(), buildDate);
if(update.getAndroidVersion().equals(Build.VERSION.RELEASE)){
title = R.string.apply_update_dialog_title;
if (Utils.isABUpdate(update.getFile())) {
message = mActivity.getString(R.string.apply_update_dialog_message_ab, buildInfoText,
mActivity.getString(android.R.string.ok));
} else {
message = mActivity.getString(R.string.apply_update_dialog_message, buildInfoText,
mActivity.getString(android.R.string.ok));
}
} else {
resId = R.string.apply_update_dialog_message;
title = R.string.version_upgrade_dialog_title;
if (Utils.isABUpdate(update.getFile())) {
message = mActivity.getString(R.string.version_upgrade_dialog_message_ab, buildInfoText,
update.getAndroidVersion(), mActivity.getString(android.R.string.ok));
} else {
message = mActivity.getString(R.string.version_upgrade_dialog_message, buildInfoText,
update.getAndroidVersion(), mActivity.getString(android.R.string.ok));
}
}
} catch (IOException e) {
Log.e(TAG, "Could not determine the type of the update");
return null;
}
String buildDate = StringGenerator.getDateLocalizedUTC(mActivity,
DateFormat.MEDIUM, update.getTimestamp());
String buildInfoText = mActivity.getString(R.string.list_build_version_date,
update.getVersion(), buildDate);
return new AlertDialog.Builder(mActivity)
.setTitle(R.string.apply_update_dialog_title)
.setMessage(mActivity.getString(resId, buildInfoText,
mActivity.getString(android.R.string.ok)))
.setTitle(title)
.setMessage(message)
.setPositiveButton(android.R.string.ok,
(dialog, which) -> Utils.triggerUpdate(mActivity, downloadId))
.setNegativeButton(android.R.string.cancel, null);
......
......@@ -98,6 +98,7 @@ public class Utils {
update.setDownloadUrl(object.getString("url"));
update.setVersion(object.getString("version"));
update.setDisplayVersion(object.getString("display_version"));
update.setAndroidVersion(object.getString("android_version"));
return update;
}
......
......@@ -23,6 +23,7 @@ public class UpdateBase implements UpdateBaseInfo {
private long mTimestamp;
private String mType;
private String mVersion;
private String mAndroidVersion;
private String mDisplayVersion;
private long mFileSize;
......@@ -37,6 +38,7 @@ public class UpdateBase implements UpdateBaseInfo {
mType = update.getType();
mVersion = update.getVersion();
mDisplayVersion = update.getDisplayVersion();
mAndroidVersion = update.getAndroidVersion();
mFileSize = update.getFileSize();
}
......@@ -94,6 +96,15 @@ public class UpdateBase implements UpdateBaseInfo {
mDisplayVersion = displayVersion;
}
@Override
public String getAndroidVersion() {
return mAndroidVersion;
}
public void setAndroidVersion(String androidVersion) {
mAndroidVersion = androidVersion;
}
@Override
public String getDownloadUrl() {
return mDownloadUrl;
......
......@@ -28,6 +28,8 @@ public interface UpdateBaseInfo {
String getDisplayVersion();
String getAndroidVersion();
String getDownloadUrl();
long getFileSize();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment