call add apis

This commit is contained in:
Tim Bentley 2016-01-06 18:10:41 +00:00
parent e193bf3496
commit afd85a2ba8
3 changed files with 38 additions and 15 deletions

View File

@ -45,7 +45,26 @@ abstract public class OpenLPDialog extends DialogFragment {
protected void triggerTextRequest(String url) {
calledURL = url;
Log.d(LOG_TAG, "Trigger Request for url " + url);
String callurl = String.format("%s%s", httpClient.getAbsoluteUrl(client), url );
String callurl = String.format("%s%s", httpClient.getAbsoluteUrl(client), url);
processCall(callurl);
}
protected void triggerAction(String api, String plugin, String id ) {
String request = null;
try {
request = JsonHelpers.createRequestJSON("text", id);
} catch (JsonHelpers.JSONHandlerException e) {
e.printStackTrace();
}
String url = String.format(api, plugin.toLowerCase());
triggerTextRequest(String.format("%s%s", url, request));
calledURL = url;
Log.d(LOG_TAG, "Trigger action for url " + url);
String callurl = String.format("%s%s", httpClient.getAbsoluteUrl(client), url);
processCall(callurl);
}
private void processCall(String callurl){
client.get(callurl, null, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {

View File

@ -26,7 +26,6 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import org.openlp.android2.R;
@ -38,7 +37,7 @@ import org.openlp.android2.common.OpenLPHttpClient;
public class SearchSelectionDialog extends OpenLPDialog {
private final String LOG_TAG = SearchSelectionDialog.class.getName();
public AlertDialog dialog;
private int num;
private String key;
private String plugin;
private String text;
private RadioButton sendLive;
@ -54,7 +53,7 @@ public class SearchSelectionDialog extends OpenLPDialog {
// title by default, but your custom layout might not need it. So here you can
// remove the dialog title, but you must call the superclass to get the Dialog.
num = getArguments().getInt("id");
key = getArguments().getString("key");
plugin = getArguments().getString("plugin");
text = getArguments().getString("text");
@ -74,14 +73,15 @@ public class SearchSelectionDialog extends OpenLPDialog {
sendLive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
triggerTextRequest(Api.DISPLAY_SHOW);
triggerAction(Api.SEARCH_PLUGIN_LIVE, plugin, key);
}
});
addToService = (RadioButton) view.findViewById(R.id.buttonLive);
addToService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
triggerTextRequest(Api.DISPLAY_BLANK);
triggerAction(Api.SEARCH_PLUGIN_ADD, plugin, key);
}
});

View File

@ -59,6 +59,7 @@ public class SearchFragment extends Fragment {
protected String calledURL;
protected OpenLPHttpClient httpClient;
protected String updateUrl;
protected String seachedPlugin;
public SearchFragment() {
Log.d(LOG_TAG, "Constructor");
@ -87,7 +88,7 @@ public class SearchFragment extends Fragment {
EditText editText = (EditText)view.findViewById(R.id.search_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
public boolean onEditorAction(TextView tv, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// Now close the keyboard as finished with
View view = getActivity().getCurrentFocus();
@ -96,10 +97,8 @@ public class SearchFragment extends Fragment {
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
//String text = spinner.getSelectedItem().toString();
// String text1 = v.getText().toString();
//Toast.makeText(context, "Search Called " + text + " " + text1, Toast.LENGTH_SHORT).show();
requestSearch(spinner.getSelectedItem().toString(), v.getText().toString());
seachedPlugin = spinner.getSelectedItem().toString();
requestSearch(spinner.getSelectedItem().toString(), tv.getText().toString());
return true;
}
return false;
@ -221,17 +220,22 @@ public class SearchFragment extends Fragment {
final JSONArray item = (JSONArray) parent.getItemAtPosition(position);
Toast.makeText(context, "Item Pressed " + String.valueOf(position) + item,
Toast.LENGTH_SHORT).show();
String it = "";
try {
it = (String)item.get(1);
} catch (JSONException e) {
e.printStackTrace();
}
Bundle args = new Bundle();
args.putString("plugin", "plugin");
args.putString("text", "text");
args.putInt("id", 123);
args.putString("plugin", seachedPlugin);
args.putString("text", it);
args.putString("key", Long.toString(id));
DialogFragment newFragment = new SearchSelectionDialog();
newFragment.setArguments(args);
newFragment.show(getFragmentManager(), "TAG");
}
});
Log.i(LOG_TAG, "populateListDisplay - exit");
}