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_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_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>
|
||||
|
@@ -41,6 +41,7 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONException;
|
||||
@@ -75,7 +76,8 @@ public class UpdatesActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_updates);
|
||||
|
||||
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.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
@@ -17,6 +17,7 @@ package org.lineageos.updater;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.format.DateUtils;
|
||||
@@ -49,6 +50,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
private List<String> mDownloadIds;
|
||||
private UpdaterControllerInt mUpdaterController;
|
||||
private Context mContext;
|
||||
private View mContainerView;
|
||||
|
||||
private enum Action {
|
||||
DOWNLOAD,
|
||||
@@ -86,8 +88,9 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
}
|
||||
}
|
||||
|
||||
public UpdatesListAdapter(Context context) {
|
||||
public UpdatesListAdapter(Context context, View containerView) {
|
||||
mContext = context;
|
||||
mContainerView = containerView;
|
||||
|
||||
TypedValue tv = new TypedValue();
|
||||
context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true);
|
||||
@@ -115,7 +118,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
|
||||
boolean busy = mUpdaterController.hasActiveDownloads() ||
|
||||
mUpdaterController.isVerifyingUpdate();
|
||||
boolean enabled = !busy && Utils.canInstall(update);
|
||||
|
||||
boolean canDelete = false;
|
||||
|
||||
@@ -150,7 +152,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
viewHolder.mProgressPercentage.setText(NumberFormat.getPercentInstance().format(1));
|
||||
} else {
|
||||
canDelete = true;
|
||||
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, enabled);
|
||||
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, !busy);
|
||||
String downloaded = Formatter.formatBytes(mContext.getResources(),
|
||||
update.getFile().length(), Formatter.FLAG_SHORTER).value;
|
||||
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
|
||||
@@ -174,15 +176,14 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
|
||||
boolean busy = mUpdaterController.hasActiveDownloads() ||
|
||||
mUpdaterController.isVerifyingUpdate();
|
||||
boolean enabled = !busy && Utils.canInstall(update);
|
||||
|
||||
if (update.getPersistentStatus() == UpdateStatus.Persistent.VERIFIED) {
|
||||
viewHolder.itemView.setOnLongClickListener(
|
||||
getDeleteClickListener(update.getDownloadId()));
|
||||
setButtonAction(viewHolder.mAction, Action.INSTALL, update.getDownloadId(), enabled);
|
||||
setButtonAction(viewHolder.mAction, Action.INSTALL, update.getDownloadId(), !busy);
|
||||
} else {
|
||||
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;
|
||||
case RESUME:
|
||||
case RESUME: {
|
||||
button.setImageResource(R.drawable.ic_resume);
|
||||
button.setContentDescription(
|
||||
mContext.getString(R.string.action_description_resume));
|
||||
button.setEnabled(enabled);
|
||||
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||
final boolean canInstall = Utils.canInstall(update);
|
||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||
@Override
|
||||
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.setContentDescription(
|
||||
mContext.getString(R.string.action_description_install));
|
||||
button.setEnabled(enabled);
|
||||
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||
final boolean canInstall = Utils.canInstall(update);
|
||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
@@ -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) {
|
||||
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||
int resId;
|
||||
|
Reference in New Issue
Block a user