use Notify helper everywhere, replace supertoasts with snackbar library

This commit is contained in:
Vincent Breitmoser
2015-01-19 15:43:35 +01:00
parent 491c12d5d3
commit 198ddfeff7
8 changed files with 198 additions and 210 deletions

View File

@@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
public class CertifyResult extends OperationResult {
@@ -78,30 +74,31 @@ public class CertifyResult extends OperationResult {
}
};
public SuperCardToast createNotify(final Activity activity) {
public Showable createNotify(final Activity activity) {
int resultType = getResult();
String str;
int duration, color;
int duration;
Style style;
// Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings;
duration = Duration.EXTRA_LONG;
color = Style.GREEN;
duration = Notify.LENGTH_LONG;
style = Style.OK;
withWarnings = "";
// Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0;
color = Style.ORANGE;
style = Style.WARN;
withWarnings += activity.getString(R.string.with_warnings);
}
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0;
color = Style.ORANGE;
style = Style.WARN;
withWarnings += activity.getString(R.string.with_cancelled);
}
@@ -111,46 +108,27 @@ public class CertifyResult extends OperationResult {
if (mCertifyError > 0) {
// definitely switch to warning-style message in this case!
duration = 0;
color = Style.RED;
style = Style.ERROR;
str += " " + activity.getResources().getQuantityString(
R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError);
}
} else {
duration = 0;
color = Style.RED;
style = Style.ERROR;
str = activity.getResources().getQuantityString(R.plurals.certify_error,
mCertifyError, mCertifyError);
}
boolean button = getLog() != null && !getLog().isEmpty();
SuperCardToast toast = new SuperCardToast(activity,
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(duration);
toast.setIndeterminate(duration == 0);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
return Notify.createNotify(activity, str, duration, style, new ActionListener() {
@Override
public void onAction() {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
activity.startActivity(intent);
}
}, R.string.view_log);
}

View File

@@ -24,15 +24,13 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
public class DeleteResult extends OperationResult {
@@ -68,31 +66,32 @@ public class DeleteResult extends OperationResult {
}
};
public SuperCardToast createNotify(final Activity activity) {
public Showable createNotify(final Activity activity) {
int resultType = getResult();
String str;
int duration, color;
int duration;
Style style;
// Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String untilCancelled;
duration = Duration.EXTRA_LONG;
color = Style.GREEN;
duration = Notify.LENGTH_LONG;
style = Style.OK;
untilCancelled = "";
// Any warnings?
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0;
color = Style.ORANGE;
style = Style.WARN;
untilCancelled += activity.getString(R.string.with_cancelled);
}
// New and updated keys
if (mOk > 0 && mFail > 0) {
color = Style.ORANGE;
style = Style.WARN;
duration = 0;
str = activity.getResources().getQuantityString(
R.plurals.delete_ok_but_fail_1, mOk, mOk);
@@ -105,13 +104,13 @@ public class DeleteResult extends OperationResult {
str = activity.getString(R.string.delete_cancelled);
} else {
duration = 0;
color = Style.RED;
style = Style.ERROR;
str = "internal error";
}
} else {
duration = 0;
color = Style.RED;
style = Style.ERROR;
if (mFail == 0) {
str = activity.getString(R.string.delete_nothing);
} else {
@@ -119,34 +118,15 @@ public class DeleteResult extends OperationResult {
}
}
boolean button = getLog() != null && !getLog().isEmpty();
SuperCardToast toast = new SuperCardToast(activity,
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(duration);
toast.setIndeterminate(duration == 0);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
return Notify.createNotify(activity, str, duration, style, new ActionListener() {
@Override
public void onAction() {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
activity.startActivity(intent);
}
}, R.string.view_log);
}

View File

@@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
public class ImportKeyResult extends OperationResult {
@@ -114,30 +110,31 @@ public class ImportKeyResult extends OperationResult {
}
};
public SuperCardToast createNotify(final Activity activity) {
public Showable createNotify(final Activity activity) {
int resultType = getResult();
String str;
int duration, color;
int duration;
Style style;
// Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings;
duration = Duration.EXTRA_LONG;
color = Style.GREEN;
duration = Notify.LENGTH_LONG;
style = Style.OK;
withWarnings = "";
// Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0;
color = Style.ORANGE;
style = Style.WARN;
withWarnings += activity.getString(R.string.with_warnings);
}
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0;
color = Style.ORANGE;
style = Style.WARN;
withWarnings += activity.getString(R.string.with_cancelled);
}
@@ -155,20 +152,20 @@ public class ImportKeyResult extends OperationResult {
R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings);
} else {
duration = 0;
color = Style.RED;
style = Style.ERROR;
str = "internal error";
}
if (isOkWithErrors()) {
// definitely switch to warning-style message in this case!
duration = 0;
color = Style.RED;
style = Style.ERROR;
str += " " + activity.getResources().getQuantityString(
R.plurals.import_keys_with_errors, mBadKeys, mBadKeys);
}
} else {
duration = 0;
color = Style.RED;
style = Style.ERROR;
if (isFailNothing()) {
str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0
? R.string.import_error_nothing_cancelled
@@ -178,34 +175,15 @@ public class ImportKeyResult extends OperationResult {
}
}
boolean button = getLog() != null && !getLog().isEmpty();
SuperCardToast toast = new SuperCardToast(activity,
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(duration);
toast.setIndeterminate(duration == 0);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
return Notify.createNotify(activity, str, duration, style, new ActionListener() {
@Override
public void onAction() {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
activity.startActivity(intent);
}
}, R.string.view_log);
}

View File

@@ -20,19 +20,24 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.Snackbar.SnackbarDuration;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.listeners.ActionClickListener;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
@@ -195,58 +200,44 @@ public abstract class OperationResult implements Parcelable {
}
public SuperCardToast createNotify(final Activity activity) {
int color;
public Showable createNotify(final Activity activity) {
Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast());
Log.d(Constants.TAG, "mLog.getLast().mType"+mLog.getLast().mType);
Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId());
// Take the last message as string
String str = activity.getString(mLog.getLast().mType.getMsgId());
int msgId = mLog.getLast().mType.getMsgId();
Style style;
// Not an overall failure
if (cancelled()) {
color = Style.RED;
style = Style.ERROR;
} else if (success()) {
if (getLog().containsWarnings()) {
color = Style.ORANGE;
style = Style.WARN;
} else {
color = Style.GREEN;
style = Style.OK;
}
} else {
color = Style.RED;
style = Style.ERROR;
}
boolean button = getLog() != null && !getLog().isEmpty();
SuperCardToast toast = new SuperCardToast(activity,
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
toast.setIndeterminate(false);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
activity.startActivity(intent);
}
}
));
if (getLog() == null || getLog().isEmpty()) {
return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style);
}
return toast;
return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style,
new ActionListener() {
@Override
public void onAction() {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
activity.startActivity(intent);
}
}, R.string.view_log);
}

View File

@@ -40,35 +40,6 @@ public class SingletonResult extends OperationResult {
mLog.add(reason, 0);
}
@Override
public SuperCardToast createNotify(final Activity activity) {
// there is exactly one error msg - use that one
String str = activity.getString(mLog.iterator().next().mType.getMsgId());
int color;
// Determine color by result type
if (cancelled()) {
color = Style.RED;
} else if (success()) {
if (getLog().containsWarnings()) {
color = Style.ORANGE;
} else {
color = Style.GREEN;
}
} else {
color = Style.RED;
}
SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
toast.setIndeterminate(false);
toast.setSwipeToDismiss(true);
return toast;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);