Fix import from keyservers using URL Intent
This commit is contained in:
@@ -52,10 +52,6 @@ public class FacebookKeyserver extends Keyserver {
|
||||
private static final String FB_HOST = "facebook.com";
|
||||
private static final String FB_HOST_WWW = "www." + FB_HOST;
|
||||
|
||||
public static final String FB_URL = "https://" + FB_HOST_WWW;
|
||||
|
||||
public static final String ORIGIN = FB_URL;
|
||||
|
||||
public FacebookKeyserver() {
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
|
||||
if (query != null && query.length() > 0) {
|
||||
// display keyserver fragment with query
|
||||
startTopCloudFragment(query, false, null);
|
||||
startTopCloudFragment(query, null);
|
||||
|
||||
// action: search immediately
|
||||
startListFragment(null, null, query, null);
|
||||
@@ -190,9 +190,6 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
if (isFingerprintValid(fingerprint)) {
|
||||
String query = "0x" + fingerprint;
|
||||
|
||||
// display keyserver fragment with query
|
||||
startTopCloudFragment(query, true, null);
|
||||
|
||||
// action: search immediately
|
||||
startListFragment(null, null, query, null);
|
||||
}
|
||||
@@ -210,27 +207,35 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
|
||||
Preferences.CloudSearchPrefs cloudSearchPrefs =
|
||||
new Preferences.CloudSearchPrefs(false, true, true, null);
|
||||
// we allow our users to edit the query if they wish
|
||||
startTopCloudFragment(fbUsername, false, cloudSearchPrefs);
|
||||
// search immediately
|
||||
startListFragment(null, null, fbUsername, cloudSearchPrefs);
|
||||
break;
|
||||
}
|
||||
case ACTION_SEARCH_KEYSERVER_FROM_URL: {
|
||||
// need to process URL to get search query and keyserver authority
|
||||
String query = dataUri.getQueryParameter("search");
|
||||
// if query not specified, we still allow users to search the keyserver in the link
|
||||
if (query == null) {
|
||||
Notify.create(this, R.string.import_url_warn_no_search_parameter, Notify.LENGTH_INDEFINITE,
|
||||
Notify.Style.WARN).show();
|
||||
}
|
||||
ParcelableHkpKeyserver keyserver = new ParcelableHkpKeyserver(dataUri.getAuthority());
|
||||
// get keyserver from URL
|
||||
ParcelableHkpKeyserver keyserver = new ParcelableHkpKeyserver(
|
||||
dataUri.getScheme() + "://" + dataUri.getAuthority());
|
||||
Preferences.CloudSearchPrefs cloudSearchPrefs = new Preferences.CloudSearchPrefs(
|
||||
true, true, true, keyserver);
|
||||
// we allow our users to edit the query if they wish
|
||||
startTopCloudFragment(query, false, cloudSearchPrefs);
|
||||
// search immediately (if query is not null)
|
||||
startListFragment(null, null, query, cloudSearchPrefs);
|
||||
true, false, false, keyserver);
|
||||
Log.d(Constants.TAG, "Using keyserver: " + keyserver);
|
||||
|
||||
// process URL to get operation and query
|
||||
String operation = dataUri.getQueryParameter("op");
|
||||
String query = dataUri.getQueryParameter("search");
|
||||
|
||||
// if query or operation not specified, we still allow users to search
|
||||
if (query == null || operation == null) {
|
||||
startTopCloudFragment(null, cloudSearchPrefs);
|
||||
startListFragment(null, null, null, cloudSearchPrefs);
|
||||
} else {
|
||||
if (operation.equalsIgnoreCase("get")) {
|
||||
// don't allow searching here, only one key!
|
||||
startListFragment(null, null, query, cloudSearchPrefs);
|
||||
} else { // for example: operation: index
|
||||
startTopCloudFragment(query, cloudSearchPrefs);
|
||||
startListFragment(null, null, query, cloudSearchPrefs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTION_IMPORT_KEY_FROM_FILE:
|
||||
@@ -241,7 +246,7 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
startTopCloudFragment(null, false, null);
|
||||
startTopCloudFragment(null, null);
|
||||
startListFragment(null, null, null, null);
|
||||
break;
|
||||
}
|
||||
@@ -279,21 +284,19 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the CloudFragment, which consists of the search bar, search button and settings icon
|
||||
* visually.
|
||||
* loads the CloudFragment, which enables the search bar
|
||||
*
|
||||
* @param query search query
|
||||
* @param disableQueryEdit if true, user will not be able to edit the search query
|
||||
* @param cloudSearchPrefs keyserver authority to use for search, if null will use keyserver
|
||||
* specified in user preferences
|
||||
*/
|
||||
private void startTopCloudFragment(String query, boolean disableQueryEdit,
|
||||
private void startTopCloudFragment(String query,
|
||||
Preferences.CloudSearchPrefs cloudSearchPrefs) {
|
||||
|
||||
FragmentManager fM = getSupportFragmentManager();
|
||||
if (fM.findFragmentByTag(TAG_FRAG_TOP) == null) {
|
||||
Fragment importCloudFragment = ImportKeysCloudFragment.newInstance(query,
|
||||
disableQueryEdit, cloudSearchPrefs);
|
||||
cloudSearchPrefs);
|
||||
fM.beginTransaction().add(importCloudFragment, TAG_FRAG_TOP).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ import static android.support.v7.widget.SearchView.OnSuggestionListener;
|
||||
public class ImportKeysCloudFragment extends Fragment {
|
||||
|
||||
public static final String ARG_QUERY = "query";
|
||||
public static final String ARG_DISABLE_QUERY_EDIT = "disable_query_edit";
|
||||
public static final String ARG_CLOUD_SEARCH_PREFS = "cloud_search_prefs";
|
||||
|
||||
private static final String CURSOR_SUGGESTION = "suggestion";
|
||||
@@ -74,18 +73,16 @@ public class ImportKeysCloudFragment extends Fragment {
|
||||
* Creates new instance of this fragment
|
||||
*
|
||||
* @param query query to search for
|
||||
* @param disableQueryEdit if true, user cannot edit query
|
||||
* @param cloudSearchPrefs search parameters to use. If null will retrieve from user's
|
||||
* preferences.
|
||||
*/
|
||||
public static ImportKeysCloudFragment newInstance(String query, boolean disableQueryEdit,
|
||||
public static ImportKeysCloudFragment newInstance(String query,
|
||||
CloudSearchPrefs cloudSearchPrefs) {
|
||||
|
||||
ImportKeysCloudFragment frag = new ImportKeysCloudFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_QUERY, query);
|
||||
args.putBoolean(ARG_DISABLE_QUERY_EDIT, disableQueryEdit);
|
||||
args.putParcelable(ARG_CLOUD_SEARCH_PREFS, cloudSearchPrefs);
|
||||
|
||||
frag.setArguments(args);
|
||||
@@ -104,6 +101,8 @@ public class ImportKeysCloudFragment extends Fragment {
|
||||
new int[]{android.R.id.text1}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// no view, just search view
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -173,6 +172,11 @@ public class ImportKeysCloudFragment extends Fragment {
|
||||
|
||||
searchItem.expandActionView();
|
||||
|
||||
String query = getArguments().getString(ARG_QUERY);
|
||||
if (query != null) {
|
||||
searchView.setQuery(query, false);
|
||||
}
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
|
||||
@@ -539,9 +539,6 @@
|
||||
<string name="btn_refresh">"Refresh"</string>
|
||||
<string name="btn_go_to_key">"Go to key"</string>
|
||||
|
||||
<!-- Import from URL -->
|
||||
<string name="import_url_warn_no_search_parameter">"No search query defined. You can still manually search on this keyserver."</string>
|
||||
|
||||
<!-- Generic result toast -->
|
||||
<string name="snackbar_details">"Details"</string>
|
||||
<string name="with_warnings">", with warnings"</string>
|
||||
|
||||
Reference in New Issue
Block a user