ImportKeys: Add possibility to go back to single card

This commit is contained in:
Andrea Torlaschi
2016-08-21 17:58:53 +02:00
parent f5e5a70d21
commit 0f996b012a
3 changed files with 34 additions and 7 deletions

View File

@@ -2,6 +2,12 @@ package org.sufficientlysecure.keychain.keyimport.processing;
public interface LoaderState {
/**
* Basic mode includes ability to import all keys retrieved from the selected source
* This doesn't make sense for all sources (for example keyservers..)
*
* @return if currently selected source supports basic mode
*/
boolean isBasicModeSupported();
}

View File

@@ -311,12 +311,21 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onBackPressed() {
FragmentManager fM = getSupportFragmentManager();
ImportKeysListFragment listFragment =
(ImportKeysListFragment) fM.findFragmentByTag(TAG_FRAG_LIST);
if ((listFragment == null) || listFragment.onBackPressed()) {
super.onBackPressed();
}
}
@Override
public void loadKeys(LoaderState loaderState) {
FragmentManager fM = getSupportFragmentManager();
ImportKeysListFragment listFragment = (ImportKeysListFragment) fM.findFragmentByTag(TAG_FRAG_LIST);
listFragment.loadState(loaderState);
((ImportKeysListFragment) fM.findFragmentByTag(TAG_FRAG_LIST)).loadState(loaderState);
}
@Override

View File

@@ -210,6 +210,21 @@ public class ImportKeysListFragment extends Fragment implements
}
}
/**
* User may want to go back to single card view if he's now in full key list
* Check if we are in full key list and if this import operation supports basic mode
*
* @return true if activity's back pressed can be performed
*/
public boolean onBackPressed() {
boolean advanced = mBinding.getAdvanced();
if (advanced && mLoaderState.isBasicModeSupported()) {
mBinding.setAdvanced(false);
return false;
}
return true;
}
public void loadState(LoaderState loaderState) {
mLoaderState = loaderState;
@@ -263,8 +278,7 @@ public class ImportKeysListFragment extends Fragment implements
@Override
public void onLoadFinished(
Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader,
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data
) {
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
mAdapter.setData(data.getResult());
int size = mAdapter.getItemCount();
@@ -329,8 +343,6 @@ public class ImportKeysListFragment extends Fragment implements
getKeyResult.createNotify(mActivity).show();
}
break;
default:
break;
}
}