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 = "facebook.com";
|
||||||
private static final String FB_HOST_WWW = "www." + FB_HOST;
|
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() {
|
public FacebookKeyserver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
|
|
||||||
if (query != null && query.length() > 0) {
|
if (query != null && query.length() > 0) {
|
||||||
// display keyserver fragment with query
|
// display keyserver fragment with query
|
||||||
startTopCloudFragment(query, false, null);
|
startTopCloudFragment(query, null);
|
||||||
|
|
||||||
// action: search immediately
|
// action: search immediately
|
||||||
startListFragment(null, null, query, null);
|
startListFragment(null, null, query, null);
|
||||||
@@ -190,9 +190,6 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
if (isFingerprintValid(fingerprint)) {
|
if (isFingerprintValid(fingerprint)) {
|
||||||
String query = "0x" + fingerprint;
|
String query = "0x" + fingerprint;
|
||||||
|
|
||||||
// display keyserver fragment with query
|
|
||||||
startTopCloudFragment(query, true, null);
|
|
||||||
|
|
||||||
// action: search immediately
|
// action: search immediately
|
||||||
startListFragment(null, null, query, null);
|
startListFragment(null, null, query, null);
|
||||||
}
|
}
|
||||||
@@ -210,27 +207,35 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
|
|
||||||
Preferences.CloudSearchPrefs cloudSearchPrefs =
|
Preferences.CloudSearchPrefs cloudSearchPrefs =
|
||||||
new Preferences.CloudSearchPrefs(false, true, true, null);
|
new Preferences.CloudSearchPrefs(false, true, true, null);
|
||||||
// we allow our users to edit the query if they wish
|
|
||||||
startTopCloudFragment(fbUsername, false, cloudSearchPrefs);
|
|
||||||
// search immediately
|
// search immediately
|
||||||
startListFragment(null, null, fbUsername, cloudSearchPrefs);
|
startListFragment(null, null, fbUsername, cloudSearchPrefs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_SEARCH_KEYSERVER_FROM_URL: {
|
case ACTION_SEARCH_KEYSERVER_FROM_URL: {
|
||||||
// need to process URL to get search query and keyserver authority
|
// get keyserver from URL
|
||||||
String query = dataUri.getQueryParameter("search");
|
ParcelableHkpKeyserver keyserver = new ParcelableHkpKeyserver(
|
||||||
// if query not specified, we still allow users to search the keyserver in the link
|
dataUri.getScheme() + "://" + dataUri.getAuthority());
|
||||||
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());
|
|
||||||
Preferences.CloudSearchPrefs cloudSearchPrefs = new Preferences.CloudSearchPrefs(
|
Preferences.CloudSearchPrefs cloudSearchPrefs = new Preferences.CloudSearchPrefs(
|
||||||
true, true, true, keyserver);
|
true, false, false, keyserver);
|
||||||
// we allow our users to edit the query if they wish
|
Log.d(Constants.TAG, "Using keyserver: " + keyserver);
|
||||||
startTopCloudFragment(query, false, cloudSearchPrefs);
|
|
||||||
// search immediately (if query is not null)
|
// process URL to get operation and query
|
||||||
startListFragment(null, null, query, cloudSearchPrefs);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_IMPORT_KEY_FROM_FILE:
|
case ACTION_IMPORT_KEY_FROM_FILE:
|
||||||
@@ -241,7 +246,7 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
startTopCloudFragment(null, false, null);
|
startTopCloudFragment(null, null);
|
||||||
startListFragment(null, null, null, null);
|
startListFragment(null, null, null, null);
|
||||||
break;
|
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
|
* loads the CloudFragment, which enables the search bar
|
||||||
* visually.
|
|
||||||
*
|
*
|
||||||
* @param query search query
|
* @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
|
* @param cloudSearchPrefs keyserver authority to use for search, if null will use keyserver
|
||||||
* specified in user preferences
|
* specified in user preferences
|
||||||
*/
|
*/
|
||||||
private void startTopCloudFragment(String query, boolean disableQueryEdit,
|
private void startTopCloudFragment(String query,
|
||||||
Preferences.CloudSearchPrefs cloudSearchPrefs) {
|
Preferences.CloudSearchPrefs cloudSearchPrefs) {
|
||||||
|
|
||||||
FragmentManager fM = getSupportFragmentManager();
|
FragmentManager fM = getSupportFragmentManager();
|
||||||
if (fM.findFragmentByTag(TAG_FRAG_TOP) == null) {
|
if (fM.findFragmentByTag(TAG_FRAG_TOP) == null) {
|
||||||
Fragment importCloudFragment = ImportKeysCloudFragment.newInstance(query,
|
Fragment importCloudFragment = ImportKeysCloudFragment.newInstance(query,
|
||||||
disableQueryEdit, cloudSearchPrefs);
|
cloudSearchPrefs);
|
||||||
fM.beginTransaction().add(importCloudFragment, TAG_FRAG_TOP).commit();
|
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 class ImportKeysCloudFragment extends Fragment {
|
||||||
|
|
||||||
public static final String ARG_QUERY = "query";
|
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";
|
public static final String ARG_CLOUD_SEARCH_PREFS = "cloud_search_prefs";
|
||||||
|
|
||||||
private static final String CURSOR_SUGGESTION = "suggestion";
|
private static final String CURSOR_SUGGESTION = "suggestion";
|
||||||
@@ -74,18 +73,16 @@ public class ImportKeysCloudFragment extends Fragment {
|
|||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*
|
*
|
||||||
* @param query query to search for
|
* @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
|
* @param cloudSearchPrefs search parameters to use. If null will retrieve from user's
|
||||||
* preferences.
|
* preferences.
|
||||||
*/
|
*/
|
||||||
public static ImportKeysCloudFragment newInstance(String query, boolean disableQueryEdit,
|
public static ImportKeysCloudFragment newInstance(String query,
|
||||||
CloudSearchPrefs cloudSearchPrefs) {
|
CloudSearchPrefs cloudSearchPrefs) {
|
||||||
|
|
||||||
ImportKeysCloudFragment frag = new ImportKeysCloudFragment();
|
ImportKeysCloudFragment frag = new ImportKeysCloudFragment();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_QUERY, query);
|
args.putString(ARG_QUERY, query);
|
||||||
args.putBoolean(ARG_DISABLE_QUERY_EDIT, disableQueryEdit);
|
|
||||||
args.putParcelable(ARG_CLOUD_SEARCH_PREFS, cloudSearchPrefs);
|
args.putParcelable(ARG_CLOUD_SEARCH_PREFS, cloudSearchPrefs);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
@@ -104,6 +101,8 @@ public class ImportKeysCloudFragment extends Fragment {
|
|||||||
new int[]{android.R.id.text1}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
new int[]{android.R.id.text1}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
// no view, just search view
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +172,11 @@ public class ImportKeysCloudFragment extends Fragment {
|
|||||||
|
|
||||||
searchItem.expandActionView();
|
searchItem.expandActionView();
|
||||||
|
|
||||||
|
String query = getArguments().getString(ARG_QUERY);
|
||||||
|
if (query != null) {
|
||||||
|
searchView.setQuery(query, false);
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -539,9 +539,6 @@
|
|||||||
<string name="btn_refresh">"Refresh"</string>
|
<string name="btn_refresh">"Refresh"</string>
|
||||||
<string name="btn_go_to_key">"Go to key"</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 -->
|
<!-- Generic result toast -->
|
||||||
<string name="snackbar_details">"Details"</string>
|
<string name="snackbar_details">"Details"</string>
|
||||||
<string name="with_warnings">", with warnings"</string>
|
<string name="with_warnings">", with warnings"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user