Show a snackbar when trying to download/install invalid updates
Instead of disabling the action button, keep it enabled and make it show a snackbar to inform the user about the impossibility of installing the selected update.
This commit is contained in:
@@ -64,6 +64,8 @@
|
|||||||
<string name="snack_download_verification_failed">The update verification failed.</string>
|
<string name="snack_download_verification_failed">The update verification failed.</string>
|
||||||
<string name="snack_download_verified">Download completed.</string>
|
<string name="snack_download_verified">Download completed.</string>
|
||||||
|
|
||||||
|
<string name="snack_update_not_installable">This update can\'t be installed on top of the current build.</string>
|
||||||
|
|
||||||
<string name="header_title_text">LineageOS\n%1$s</string>
|
<string name="header_title_text">LineageOS\n%1$s</string>
|
||||||
<string name="header_android_version">Android <xliff:g id="version" example="7.1.2">%1$s</xliff:g></string>
|
<string name="header_android_version">Android <xliff:g id="version" example="7.1.2">%1$s</xliff:g></string>
|
||||||
<string name="header_last_updates_check">Last checked: <xliff:g id="date" example="1 January 1970">%1$s</xliff:g> (<xliff:g id="time" example="01:23">%2$s</xliff:g>)</string>
|
<string name="header_last_updates_check">Last checked: <xliff:g id="date" example="1 January 1970">%1$s</xliff:g> (<xliff:g id="time" example="01:23">%2$s</xliff:g>)</string>
|
||||||
|
@@ -41,6 +41,7 @@ import android.support.v7.widget.Toolbar;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@@ -75,7 +76,8 @@ public class UpdatesActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_updates);
|
setContentView(R.layout.activity_updates);
|
||||||
|
|
||||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||||
mAdapter = new UpdatesListAdapter(this);
|
View containerView = findViewById(R.id.main_container);
|
||||||
|
mAdapter = new UpdatesListAdapter(this, containerView);
|
||||||
recyclerView.setAdapter(mAdapter);
|
recyclerView.setAdapter(mAdapter);
|
||||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
@@ -17,6 +17,7 @@ package org.lineageos.updater;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
@@ -49,6 +50,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
private List<String> mDownloadIds;
|
private List<String> mDownloadIds;
|
||||||
private UpdaterControllerInt mUpdaterController;
|
private UpdaterControllerInt mUpdaterController;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private View mContainerView;
|
||||||
|
|
||||||
private enum Action {
|
private enum Action {
|
||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
@@ -86,8 +88,9 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdatesListAdapter(Context context) {
|
public UpdatesListAdapter(Context context, View containerView) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mContainerView = containerView;
|
||||||
|
|
||||||
TypedValue tv = new TypedValue();
|
TypedValue tv = new TypedValue();
|
||||||
context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true);
|
context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true);
|
||||||
@@ -115,7 +118,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
|
|
||||||
boolean busy = mUpdaterController.hasActiveDownloads() ||
|
boolean busy = mUpdaterController.hasActiveDownloads() ||
|
||||||
mUpdaterController.isVerifyingUpdate();
|
mUpdaterController.isVerifyingUpdate();
|
||||||
boolean enabled = !busy && Utils.canInstall(update);
|
|
||||||
|
|
||||||
boolean canDelete = false;
|
boolean canDelete = false;
|
||||||
|
|
||||||
@@ -150,7 +152,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
viewHolder.mProgressPercentage.setText(NumberFormat.getPercentInstance().format(1));
|
viewHolder.mProgressPercentage.setText(NumberFormat.getPercentInstance().format(1));
|
||||||
} else {
|
} else {
|
||||||
canDelete = true;
|
canDelete = true;
|
||||||
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, enabled);
|
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, !busy);
|
||||||
String downloaded = Formatter.formatBytes(mContext.getResources(),
|
String downloaded = Formatter.formatBytes(mContext.getResources(),
|
||||||
update.getFile().length(), Formatter.FLAG_SHORTER).value;
|
update.getFile().length(), Formatter.FLAG_SHORTER).value;
|
||||||
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
|
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
|
||||||
@@ -174,15 +176,14 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
|
|
||||||
boolean busy = mUpdaterController.hasActiveDownloads() ||
|
boolean busy = mUpdaterController.hasActiveDownloads() ||
|
||||||
mUpdaterController.isVerifyingUpdate();
|
mUpdaterController.isVerifyingUpdate();
|
||||||
boolean enabled = !busy && Utils.canInstall(update);
|
|
||||||
|
|
||||||
if (update.getPersistentStatus() == UpdateStatus.Persistent.VERIFIED) {
|
if (update.getPersistentStatus() == UpdateStatus.Persistent.VERIFIED) {
|
||||||
viewHolder.itemView.setOnLongClickListener(
|
viewHolder.itemView.setOnLongClickListener(
|
||||||
getDeleteClickListener(update.getDownloadId()));
|
getDeleteClickListener(update.getDownloadId()));
|
||||||
setButtonAction(viewHolder.mAction, Action.INSTALL, update.getDownloadId(), enabled);
|
setButtonAction(viewHolder.mAction, Action.INSTALL, update.getDownloadId(), !busy);
|
||||||
} else {
|
} else {
|
||||||
viewHolder.itemView.setOnLongClickListener(null);
|
viewHolder.itemView.setOnLongClickListener(null);
|
||||||
setButtonAction(viewHolder.mAction, Action.DOWNLOAD, update.getDownloadId(), enabled);
|
setButtonAction(viewHolder.mAction, Action.DOWNLOAD, update.getDownloadId(), !busy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,30 +276,46 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case RESUME:
|
case RESUME: {
|
||||||
button.setImageResource(R.drawable.ic_resume);
|
button.setImageResource(R.drawable.ic_resume);
|
||||||
button.setContentDescription(
|
button.setContentDescription(
|
||||||
mContext.getString(R.string.action_description_resume));
|
mContext.getString(R.string.action_description_resume));
|
||||||
button.setEnabled(enabled);
|
button.setEnabled(enabled);
|
||||||
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
|
final boolean canInstall = Utils.canInstall(update);
|
||||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mUpdaterController.resumeDownload(downloadId);
|
if (canInstall) {
|
||||||
|
mUpdaterController.resumeDownload(downloadId);
|
||||||
|
} else {
|
||||||
|
showSnackbar(R.string.snack_update_not_installable,
|
||||||
|
Snackbar.LENGTH_LONG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
}
|
||||||
case INSTALL:
|
break;
|
||||||
|
case INSTALL: {
|
||||||
button.setImageResource(R.drawable.ic_system_update);
|
button.setImageResource(R.drawable.ic_system_update);
|
||||||
button.setContentDescription(
|
button.setContentDescription(
|
||||||
mContext.getString(R.string.action_description_install));
|
mContext.getString(R.string.action_description_install));
|
||||||
button.setEnabled(enabled);
|
button.setEnabled(enabled);
|
||||||
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
|
final boolean canInstall = Utils.canInstall(update);
|
||||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
getInstallDialog(downloadId).show();
|
if (canInstall) {
|
||||||
|
getInstallDialog(downloadId).show();
|
||||||
|
} else {
|
||||||
|
showSnackbar(R.string.snack_update_not_installable,
|
||||||
|
Snackbar.LENGTH_LONG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
button.setAlpha(enabled ? 1.f : mAlphaDisabledValue);
|
button.setAlpha(enabled ? 1.f : mAlphaDisabledValue);
|
||||||
}
|
}
|
||||||
@@ -327,6 +344,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSnackbar(int stringId, int duration) {
|
||||||
|
Snackbar.make(mContainerView, stringId, duration).show();
|
||||||
|
}
|
||||||
|
|
||||||
private AlertDialog.Builder getInstallDialog(final String downloadId) {
|
private AlertDialog.Builder getInstallDialog(final String downloadId) {
|
||||||
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
int resId;
|
int resId;
|
||||||
|
Reference in New Issue
Block a user