Add restore to backup fragment, cleanup, renamings
This commit is contained in:
@@ -17,13 +17,13 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@@ -36,6 +36,8 @@ import android.view.ViewGroup;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
|
|
||||||
public class BackupRestoreFragment extends Fragment {
|
public class BackupRestoreFragment extends Fragment {
|
||||||
|
|
||||||
@@ -44,14 +46,16 @@ public class BackupRestoreFragment extends Fragment {
|
|||||||
// This index for remembering the number of master key.
|
// This index for remembering the number of master key.
|
||||||
private int mIndex;
|
private int mIndex;
|
||||||
|
|
||||||
static final int REQUEST_REPEAT_PASSPHRASE = 1;
|
private static final int REQUEST_REPEAT_PASSPHRASE = 0x00007002;
|
||||||
|
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.drawer_backup_fragment, container, false);
|
View view = inflater.inflate(R.layout.backup_restore_fragment, container, false);
|
||||||
|
|
||||||
View backupAll = view.findViewById(R.id.backup_all);
|
View backupAll = view.findViewById(R.id.backup_all);
|
||||||
View backupPublicKeys = view.findViewById(R.id.backup_public_keys);
|
View backupPublicKeys = view.findViewById(R.id.backup_public_keys);
|
||||||
|
final View restore = view.findViewById(R.id.restore);
|
||||||
|
|
||||||
backupAll.setOnClickListener(new View.OnClickListener() {
|
backupAll.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -67,6 +71,13 @@ public class BackupRestoreFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
restore.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
restore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +92,12 @@ public class BackupRestoreFragment extends Fragment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new AsyncTask<ContentResolver,Void,ArrayList<Long>>() {
|
new AsyncTask<ContentResolver, Void, ArrayList<Long>>() {
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<Long> doInBackground(ContentResolver... resolver) {
|
protected ArrayList<Long> doInBackground(ContentResolver... resolver) {
|
||||||
ArrayList<Long> askPassphraseIds = new ArrayList<>();
|
ArrayList<Long> askPassphraseIds = new ArrayList<>();
|
||||||
Cursor cursor = resolver[0].query(
|
Cursor cursor = resolver[0].query(
|
||||||
KeyRings.buildUnifiedKeyRingsUri(), new String[] {
|
KeyRings.buildUnifiedKeyRingsUri(), new String[]{
|
||||||
KeyRings.MASTER_KEY_ID,
|
KeyRings.MASTER_KEY_ID,
|
||||||
KeyRings.HAS_SECRET,
|
KeyRings.HAS_SECRET,
|
||||||
}, KeyRings.HAS_SECRET + " != 0", null, null);
|
}, KeyRings.HAS_SECRET + " != 0", null, null);
|
||||||
@@ -136,7 +147,6 @@ public class BackupRestoreFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}.execute(activity.getContentResolver());
|
}.execute(activity.getContentResolver());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startPassphraseActivity() {
|
private void startPassphraseActivity() {
|
||||||
@@ -153,25 +163,53 @@ public class BackupRestoreFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == REQUEST_REPEAT_PASSPHRASE) {
|
switch (requestCode) {
|
||||||
if (resultCode != Activity.RESULT_OK) {
|
case REQUEST_REPEAT_PASSPHRASE: {
|
||||||
return;
|
if (resultCode != Activity.RESULT_OK) {
|
||||||
}
|
return;
|
||||||
if (mIndex < mIdsForRepeatAskPassphrase.size()) {
|
}
|
||||||
startPassphraseActivity();
|
if (mIndex < mIdsForRepeatAskPassphrase.size()) {
|
||||||
return;
|
startPassphraseActivity();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
startBackup(true);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
startBackup(true);
|
case REQUEST_CODE_INPUT: {
|
||||||
|
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri uri = data.getData();
|
||||||
|
if (uri == null) {
|
||||||
|
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent intent = new Intent(getActivity(), DecryptActivity.class);
|
||||||
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
intent.setData(uri);
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBackup(boolean exportSecret) {
|
private void startBackup(boolean exportSecret) {
|
||||||
|
|
||||||
Intent intent = new Intent(getActivity(), BackupActivity.class);
|
Intent intent = new Intent(getActivity(), BackupActivity.class);
|
||||||
intent.putExtra(BackupActivity.EXTRA_SECRET, exportSecret);
|
intent.putExtra(BackupActivity.EXTRA_SECRET, exportSecret);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restore() {
|
||||||
|
FileHelper.openDocument(this, null, "*/*", false, REQUEST_CODE_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import android.app.Activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@@ -42,7 +41,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker;
|
import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
|
|
||||||
public class EncryptDecryptOverviewFragment extends Fragment {
|
public class EncryptDecryptFragment extends Fragment {
|
||||||
|
|
||||||
View mClipboardIcon;
|
View mClipboardIcon;
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ public class EncryptDecryptOverviewFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.encrypt_decrypt_overview_fragment, container, false);
|
View view = inflater.inflate(R.layout.encrypt_decrypt_fragment, container, false);
|
||||||
|
|
||||||
View mEncryptFile = view.findViewById(R.id.encrypt_files);
|
View mEncryptFile = view.findViewById(R.id.encrypt_files);
|
||||||
View mEncryptText = view.findViewById(R.id.encrypt_text);
|
View mEncryptText = view.findViewById(R.id.encrypt_text);
|
||||||
@@ -83,7 +82,7 @@ public class EncryptDecryptOverviewFragment extends Fragment {
|
|||||||
mDecryptFile.setOnClickListener(new View.OnClickListener() {
|
mDecryptFile.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
FileHelper.openDocument(EncryptDecryptOverviewFragment.this, null, "*/*", false, REQUEST_CODE_INPUT);
|
FileHelper.openDocument(EncryptDecryptFragment.this, null, "*/*", false, REQUEST_CODE_INPUT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac
|
|||||||
private void onEnDecryptSelected() {
|
private void onEnDecryptSelected() {
|
||||||
mToolbar.setTitle(R.string.nav_encrypt_decrypt);
|
mToolbar.setTitle(R.string.nav_encrypt_decrypt);
|
||||||
mDrawer.setSelectionByIdentifier(ID_ENCRYPT_DECRYPT, false);
|
mDrawer.setSelectionByIdentifier(ID_ENCRYPT_DECRYPT, false);
|
||||||
Fragment frag = new EncryptDecryptOverviewFragment();
|
Fragment frag = new EncryptDecryptFragment();
|
||||||
setFragment(frag, true);
|
setFragment(frag, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac
|
|||||||
if (frag instanceof KeyListFragment) {
|
if (frag instanceof KeyListFragment) {
|
||||||
mToolbar.setTitle(R.string.app_name);
|
mToolbar.setTitle(R.string.app_name);
|
||||||
mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_KEYS), false);
|
mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_KEYS), false);
|
||||||
} else if (frag instanceof EncryptDecryptOverviewFragment) {
|
} else if (frag instanceof EncryptDecryptFragment) {
|
||||||
mToolbar.setTitle(R.string.nav_encrypt_decrypt);
|
mToolbar.setTitle(R.string.nav_encrypt_decrypt);
|
||||||
mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_ENCRYPT_DECRYPT), false);
|
mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_ENCRYPT_DECRYPT), false);
|
||||||
} else if (frag instanceof AppsListFragment) {
|
} else if (frag instanceof AppsListFragment) {
|
||||||
|
|||||||
@@ -61,6 +61,28 @@
|
|||||||
android:text="@string/backup_public_keys"
|
android:text="@string/backup_public_keys"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/SectionHeader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/restore_section" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/restore"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="true"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableRight="@drawable/ic_folder_grey_24dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
|
android:text="@string/btn_decrypt_files"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dip"
|
android:layout_height="1dip"
|
||||||
@@ -1434,6 +1434,7 @@
|
|||||||
<string name="backup_all">"All keys + your own keys"</string>
|
<string name="backup_all">"All keys + your own keys"</string>
|
||||||
<string name="backup_public_keys">"All keys"</string>
|
<string name="backup_public_keys">"All keys"</string>
|
||||||
<string name="backup_section">"Backup"</string>
|
<string name="backup_section">"Backup"</string>
|
||||||
|
<string name="restore_section">"Restore"</string>
|
||||||
|
|
||||||
<!-- unsorted -->
|
<!-- unsorted -->
|
||||||
<string name="section_certifier_id">"Certifier"</string>
|
<string name="section_certifier_id">"Certifier"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user