mirror of
https://gitlab.com/openlp/android.git
synced 2024-12-22 11:52:49 +00:00
Fix Custom search
This commit is contained in:
parent
2cae45c903
commit
632e655c96
@ -3,14 +3,8 @@ package org.openlp.android2.fragments;
|
|||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.text.Html;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -20,11 +14,7 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ListAdapter;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleAdapter;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -46,6 +36,7 @@ import org.openlp.android2.dialogs.SearchSelectionDialog;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
@ -59,7 +50,8 @@ public class SearchFragment extends Fragment {
|
|||||||
protected String calledURL;
|
protected String calledURL;
|
||||||
protected OpenLPHttpClient httpClient;
|
protected OpenLPHttpClient httpClient;
|
||||||
protected String updateUrl;
|
protected String updateUrl;
|
||||||
protected String seachedPlugin;
|
protected String searchedPlugin;
|
||||||
|
protected Map<String, String> pluginMap = new HashMap<String, String>();
|
||||||
|
|
||||||
public SearchFragment() {
|
public SearchFragment() {
|
||||||
Log.d(LOG_TAG, "Constructor");
|
Log.d(LOG_TAG, "Constructor");
|
||||||
@ -97,8 +89,8 @@ public class SearchFragment extends Fragment {
|
|||||||
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
seachedPlugin = spinner.getSelectedItem().toString();
|
searchedPlugin = pluginMap.get(spinner.getSelectedItem().toString());
|
||||||
requestSearch(spinner.getSelectedItem().toString(), tv.getText().toString());
|
requestSearch(tv.getText().toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -123,6 +115,7 @@ public class SearchFragment extends Fragment {
|
|||||||
private void populatePluginList(String response, Boolean notInError) {
|
private void populatePluginList(String response, Boolean notInError) {
|
||||||
Log.i(LOG_TAG, "populatePluginList - entry");
|
Log.i(LOG_TAG, "populatePluginList - entry");
|
||||||
List<String> categories = new ArrayList<String>();
|
List<String> categories = new ArrayList<String>();
|
||||||
|
pluginMap.clear();
|
||||||
|
|
||||||
if (notInError) {
|
if (notInError) {
|
||||||
try {
|
try {
|
||||||
@ -130,6 +123,7 @@ public class SearchFragment extends Fragment {
|
|||||||
for (int i = 0; i < items.length(); ++i) {
|
for (int i = 0; i < items.length(); ++i) {
|
||||||
JSONArray item = items.getJSONArray(i);
|
JSONArray item = items.getJSONArray(i);
|
||||||
categories.add(item.get(1).toString());
|
categories.add(item.get(1).toString());
|
||||||
|
pluginMap.put(item.get(1).toString(),item.get(0).toString());
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, response);
|
Log.e(LOG_TAG, response);
|
||||||
@ -143,17 +137,6 @@ public class SearchFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void itemClicked(int position) {
|
|
||||||
try {
|
|
||||||
String request = JsonHelpers.createRequestJSON("id", Integer.toString(position));
|
|
||||||
triggerTextRequest(String.format("%s%s", Api.SERVICE_SET, request));
|
|
||||||
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), position(%s)",
|
|
||||||
Api.SERVICE_SET, position));
|
|
||||||
} catch (JsonHelpers.JSONHandlerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(context, "Request Failed", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected void triggerTextRequest(String url) {
|
protected void triggerTextRequest(String url) {
|
||||||
calledURL = url;
|
calledURL = url;
|
||||||
Log.d(LOG_TAG, "Trigger Request for url " + url);
|
Log.d(LOG_TAG, "Trigger Request for url " + url);
|
||||||
@ -178,13 +161,13 @@ public class SearchFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestSearch(String plugin, String text) {
|
public void requestSearch(String text) {
|
||||||
updateUrl = Api.SEARCH_PLUGIN_FORMATTED;
|
updateUrl = Api.SEARCH_PLUGIN_FORMATTED;
|
||||||
try {
|
try {
|
||||||
String request = JsonHelpers.createRequestJSON("text", text);
|
String request = JsonHelpers.createRequestJSON("text", text);
|
||||||
String url = String.format(Api.SEARCH_PLUGIN_FORMATTED, plugin.toLowerCase());
|
String url = String.format(Api.SEARCH_PLUGIN_FORMATTED, searchedPlugin);
|
||||||
triggerTextRequest(String.format("%s%s", url, request));
|
triggerTextRequest(String.format("%s%s", url, request));
|
||||||
Log.d(LOG_TAG, String.format("Search request. apiBase(%s), text(%s)", plugin, text));
|
Log.d(LOG_TAG, String.format("Search request. apiBase(%s), text(%s)", searchedPlugin, text));
|
||||||
} catch (JsonHelpers.JSONHandlerException e) {
|
} catch (JsonHelpers.JSONHandlerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Toast.makeText(context, "Search Request Failed", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Search Request Failed", Toast.LENGTH_SHORT).show();
|
||||||
@ -227,7 +210,7 @@ public class SearchFragment extends Fragment {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("plugin", seachedPlugin);
|
args.putString("plugin", searchedPlugin);
|
||||||
args.putString("text", it);
|
args.putString("text", it);
|
||||||
args.putString("key", Long.toString(id));
|
args.putString("key", Long.toString(id));
|
||||||
DialogFragment newFragment = new SearchSelectionDialog();
|
DialogFragment newFragment = new SearchSelectionDialog();
|
||||||
|
Loading…
Reference in New Issue
Block a user