some more work on supertoast and result parcel stuff

This commit is contained in:
Vincent Breitmoser 2014-07-27 00:46:38 +02:00
parent 8132b9ac74
commit a8782272b3
15 changed files with 87 additions and 120 deletions

View File

@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult;
import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;
@ -123,14 +123,14 @@ public class PgpImportExport {
} }
/** Imports keys from given data. If keyIds is given only those are imported */ /** Imports keys from given data. If keyIds is given only those are imported */
public ImportResult importKeyRings(List<ParcelableKeyRing> entries) { public ImportKeyResult importKeyRings(List<ParcelableKeyRing> entries) {
updateProgress(R.string.progress_importing, 0, 100); updateProgress(R.string.progress_importing, 0, 100);
// If there aren't even any keys, do nothing here. // If there aren't even any keys, do nothing here.
if (entries == null || entries.size() == 0) { if (entries == null || entries.size() == 0) {
return new ImportResult( return new ImportKeyResult(
ImportResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0); ImportKeyResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0);
} }
int newKeys = 0, oldKeys = 0, badKeys = 0; int newKeys = 0, oldKeys = 0, badKeys = 0;
@ -185,26 +185,26 @@ public class PgpImportExport {
int resultType = 0; int resultType = 0;
// special return case: no new keys at all // special return case: no new keys at all
if (badKeys == 0 && newKeys == 0 && oldKeys == 0) { if (badKeys == 0 && newKeys == 0 && oldKeys == 0) {
resultType = ImportResult.RESULT_FAIL_NOTHING; resultType = ImportKeyResult.RESULT_FAIL_NOTHING;
} else { } else {
if (newKeys > 0) { if (newKeys > 0) {
resultType |= ImportResult.RESULT_OK_NEWKEYS; resultType |= ImportKeyResult.RESULT_OK_NEWKEYS;
} }
if (oldKeys > 0) { if (oldKeys > 0) {
resultType |= ImportResult.RESULT_OK_UPDATED; resultType |= ImportKeyResult.RESULT_OK_UPDATED;
} }
if (badKeys > 0) { if (badKeys > 0) {
resultType |= ImportResult.RESULT_WITH_ERRORS; resultType |= ImportKeyResult.RESULT_WITH_ERRORS;
if (newKeys == 0 && oldKeys == 0) { if (newKeys == 0 && oldKeys == 0) {
resultType |= ImportResult.RESULT_ERROR; resultType |= ImportKeyResult.RESULT_ERROR;
} }
} }
if (log.containsWarnings()) { if (log.containsWarnings()) {
resultType |= ImportResult.RESULT_WITH_WARNINGS; resultType |= ImportKeyResult.RESULT_WITH_WARNINGS;
} }
} }
return new ImportResult(resultType, log, newKeys, oldKeys, badKeys); return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys);
} }

View File

@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AccountSettings;
import org.sufficientlysecure.keychain.ui.EditKeyActivityOld; import org.sufficientlysecure.keychain.ui.CreateKeyActivity;
import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment; import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment;
import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter;
import org.sufficientlysecure.keychain.util.AlgorithmNames; import org.sufficientlysecure.keychain.util.AlgorithmNames;
@ -163,12 +163,9 @@ public class AccountSettingsFragment extends Fragment implements
} }
private void createKey() { private void createKey() {
Intent intent = new Intent(getActivity(), EditKeyActivityOld.class); Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
intent.setAction(EditKeyActivityOld.ACTION_CREATE_KEY); // startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
intent.putExtra(EditKeyActivityOld.EXTRA_GENERATE_DEFAULT_KEYS, true); startActivity(intent);
// set default user id to account name
intent.putExtra(EditKeyActivityOld.EXTRA_USER_IDS, mAccSettings.getAccountName());
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
} }
@Override @Override

View File

@ -53,6 +53,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;
@ -390,7 +391,7 @@ public class KeychainIntentService extends IntentService
List<ParcelableKeyRing> entries = data.getParcelableArrayList(IMPORT_KEY_LIST); List<ParcelableKeyRing> entries = data.getParcelableArrayList(IMPORT_KEY_LIST);
PgpImportExport pgpImportExport = new PgpImportExport(this, this); PgpImportExport pgpImportExport = new PgpImportExport(this, this);
OperationResults.ImportResult result = pgpImportExport.importKeyRings(entries); ImportKeyResult result = pgpImportExport.importKeyRings(entries);
Bundle resultData = new Bundle(); Bundle resultData = new Bundle();
resultData.putParcelable(RESULT, result); resultData.putParcelable(RESULT, result);

View File

@ -391,14 +391,6 @@ public class OperationResultParcel implements Parcelable {
mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null));
} }
public LogEntryParcel getResultId() {
LogEntryParcel entry = get(size()-1);
if (entry.mLevel != LogLevel.OK && entry.mLevel != LogLevel.ERROR) {
return new LogEntryParcel(LogLevel.ERROR, LogType.INTERNAL_ERROR, 0);
}
return entry;
}
public boolean containsWarnings() { public boolean containsWarnings() {
for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(mParcels.iterator())) { for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(mParcels.iterator())) {
if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) { if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) {

View File

@ -12,12 +12,13 @@ import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style; import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
public abstract class OperationResults { public abstract class OperationResults {
public static class ImportResult extends OperationResultParcel { public static class ImportKeyResult extends OperationResultParcel {
public final int mNewKeys, mUpdatedKeys, mBadKeys; public final int mNewKeys, mUpdatedKeys, mBadKeys;
@ -47,14 +48,14 @@ public abstract class OperationResults {
return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING;
} }
public ImportResult(Parcel source) { public ImportKeyResult(Parcel source) {
super(source); super(source);
mNewKeys = source.readInt(); mNewKeys = source.readInt();
mUpdatedKeys = source.readInt(); mUpdatedKeys = source.readInt();
mBadKeys = source.readInt(); mBadKeys = source.readInt();
} }
public ImportResult(int result, OperationLog log, public ImportKeyResult(int result, OperationLog log,
int newKeys, int updatedKeys, int badKeys) { int newKeys, int updatedKeys, int badKeys) {
super(result, log); super(result, log);
mNewKeys = newKeys; mNewKeys = newKeys;
@ -70,13 +71,13 @@ public abstract class OperationResults {
dest.writeInt(mBadKeys); dest.writeInt(mBadKeys);
} }
public static Creator<ImportResult> CREATOR = new Creator<ImportResult>() { public static Creator<ImportKeyResult> CREATOR = new Creator<ImportKeyResult>() {
public ImportResult createFromParcel(final Parcel source) { public ImportKeyResult createFromParcel(final Parcel source) {
return new ImportResult(source); return new ImportKeyResult(source);
} }
public ImportResult[] newArray(final int size) { public ImportKeyResult[] newArray(final int size) {
return new ImportResult[size]; return new ImportKeyResult[size];
} }
}; };
@ -92,7 +93,7 @@ public abstract class OperationResults {
String withWarnings; String withWarnings;
// Any warnings? // Any warnings?
if ((resultType & ImportResult.RESULT_WITH_WARNINGS) > 0) { if ((resultType & ImportKeyResult.RESULT_WITH_WARNINGS) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; color = Style.ORANGE;
withWarnings = activity.getResources().getString(R.string.import_with_warnings); withWarnings = activity.getResources().getString(R.string.import_with_warnings);
@ -151,7 +152,7 @@ public abstract class OperationResults {
public void onClick(View view, Parcelable token) { public void onClick(View view, Parcelable token) {
Intent intent = new Intent( Intent intent = new Intent(
activity, LogDisplayActivity.class); activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportResult.this); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
activity.startActivity(intent); activity.startActivity(intent);
} }
} }
@ -164,6 +165,25 @@ public abstract class OperationResults {
} }
public static class EditKeyResult extends OperationResultParcel {
public EditKeyResult(Parcel source) {
super(source);
}
public static Creator<EditKeyResult> CREATOR = new Creator<EditKeyResult>() {
public EditKeyResult createFromParcel(final Parcel source) {
return new EditKeyResult(source);
}
public EditKeyResult[] newArray(final int size) {
return new EditKeyResult[size];
}
};
}
public static class SaveKeyringResult extends OperationResultParcel { public static class SaveKeyringResult extends OperationResultParcel {
public SaveKeyringResult(int result, OperationLog log) { public SaveKeyringResult(int result, OperationLog log) {

View File

@ -33,7 +33,7 @@ public class EditKeyActivity extends ActionBarActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.edit_key_activity_new); setContentView(R.layout.edit_key_activity);
Uri dataUri = getIntent().getData(); Uri dataUri = getIntent().getData();
if (dataUri == null) { if (dataUri == null) {

View File

@ -48,6 +48,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.OperationResults; import org.sufficientlysecure.keychain.service.OperationResults;
import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
@ -480,12 +481,19 @@ public class EditKeyFragment extends LoaderFragment implements
return; return;
} }
// if good -> finish, return result to showkey and display there!
// if bad -> display here! // if bad -> display here!
if (!result.success()) {
result.createNotify(getActivity()).show();
return;
}
// result.displayNotify(ImportKeysActivity.this); // if good -> finish, return result to showkey and display there!
Intent intent = new Intent();
intent.putExtra(ImportKeyResult.EXTRA_RESULT, result);
getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
getActivity().finish();
// getActivity().finish();
} }
} }
}; };

View File

@ -45,7 +45,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult;
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -427,7 +427,7 @@ public class ImportKeysActivity extends ActionBarActivity {
if (returnData == null) { if (returnData == null) {
return; return;
} }
final ImportResult result = final ImportKeyResult result =
returnData.getParcelable(KeychainIntentService.RESULT); returnData.getParcelable(KeychainIntentService.RESULT);
if (result == null) { if (result == null) {
return; return;
@ -435,7 +435,7 @@ public class ImportKeysActivity extends ActionBarActivity {
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())) { if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(EXTRA_RESULT, result); intent.putExtra(ImportKeyResult.EXTRA_RESULT, result);
ImportKeysActivity.this.setResult(RESULT_OK, intent); ImportKeysActivity.this.setResult(RESULT_OK, intent);
ImportKeysActivity.this.finish(); ImportKeysActivity.this.finish();
return; return;
@ -451,7 +451,7 @@ public class ImportKeysActivity extends ActionBarActivity {
return; return;
} }
result.displayNotify(ImportKeysActivity.this); result.createNotify(ImportKeysActivity.this).show();
} }
} }
}; };

View File

@ -103,11 +103,8 @@ public class KeyListFragment extends LoaderFragment
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(getActivity(), EditKeyActivity.class); Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
intent.setAction(EditKeyActivity.ACTION_CREATE_KEY); startActivity(intent);
intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true);
intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view
startActivityForResult(intent, 0);
} }
}); });
mButtonEmptyImport = (Button) view.findViewById(R.id.key_list_empty_button_import); mButtonEmptyImport = (Button) view.findViewById(R.id.key_list_empty_button_import);

View File

@ -19,7 +19,6 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -53,7 +52,6 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;

View File

@ -1,46 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<TextView
style="@style/SectionHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="@string/label_passphrase" />
<CheckBox
android:id="@+id/edit_key_no_passphrase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_no_passphrase" />
<Button
android:id="@+id/edit_key_btn_change_passphrase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp" android:layout_height="match_parent">
android:padding="4dp"
android:text="@string/btn_set_passphrase"
android:drawableLeft="@drawable/ic_action_edit"
android:background="@drawable/button_edgy" />
<LinearLayout <include layout="@layout/notify_area"/>
android:id="@+id/edit_key_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView> <FrameLayout
android:id="@+id/edit_key_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/edit_key_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>

View File

@ -2,16 +2,19 @@
<android.support.v4.widget.FixedDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.FixedDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:id="@+id/card_container" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:orientation="vertical" />
<include layout="@layout/notify_area"/>
<include layout="@layout/key_list_content"/> <include layout="@layout/key_list_content"/>
<include layout="@layout/drawer_list" /> <include layout="@layout/drawer_list" />
</LinearLayout>
</android.support.v4.widget.FixedDrawerLayout> </android.support.v4.widget.FixedDrawerLayout>

View File

@ -6,7 +6,6 @@
android:id="@+id/card_container" android:id="@+id/card_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/emphasis"
android:orientation="vertical" /> android:orientation="vertical" />
</merge> </merge>

View File

@ -4,11 +4,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <include layout="@layout/notify_area"/>
android:id="@+id/card_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"