mirror of
https://gitlab.com/openlp/android.git
synced 2024-12-22 11:52:49 +00:00
we have dropdown
This commit is contained in:
parent
bb67f7a737
commit
c9f8413f16
@ -1,25 +1,53 @@
|
|||||||
package org.openlp.android2.fragments;
|
package org.openlp.android2.fragments;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
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.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
|
import android.widget.SimpleAdapter;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.loopj.android.http.AsyncHttpClient;
|
||||||
|
import com.loopj.android.http.TextHttpResponseHandler;
|
||||||
|
|
||||||
|
import org.apache.http.Header;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.openlp.android2.R;
|
import org.openlp.android2.R;
|
||||||
import org.openlp.android2.api.Api;
|
import org.openlp.android2.api.Api;
|
||||||
import org.openlp.android2.common.JsonHelpers;
|
import org.openlp.android2.common.JsonHelpers;
|
||||||
import org.openlp.android2.common.OpenLPFragment;
|
|
||||||
import org.openlp.android2.common.OpenLPHttpClient;
|
import org.openlp.android2.common.OpenLPHttpClient;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class SearchFragment extends OpenLPFragment {
|
public class SearchFragment extends Fragment {
|
||||||
|
|
||||||
private final String LOG_TAG = SearchFragment.class.getName();
|
private final String LOG_TAG = SearchFragment.class.getName();
|
||||||
|
private Spinner spinner;
|
||||||
|
private static AsyncHttpClient client = new AsyncHttpClient();
|
||||||
|
public Context context;
|
||||||
|
protected String calledURL;
|
||||||
|
protected OpenLPHttpClient httpClient;
|
||||||
|
protected String updateUrl;
|
||||||
|
|
||||||
public SearchFragment() {
|
public SearchFragment() {
|
||||||
Log.d(LOG_TAG, "Constructor");
|
Log.d(LOG_TAG, "Constructor");
|
||||||
@ -33,21 +61,25 @@ public class SearchFragment extends OpenLPFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
context = getActivity();
|
context = getActivity();
|
||||||
updateUrl = Api.SERVICE_LIST;
|
updateUrl = Api.SEARCHABLE_PLUGINS;
|
||||||
httpClient = new OpenLPHttpClient(context);
|
httpClient = new OpenLPHttpClient(context);
|
||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
View view = inflater.inflate(R.layout.fragment_search, container, false);
|
||||||
|
spinner = (Spinner)view.findViewById(R.id.search_spinner);
|
||||||
|
triggerTextRequest(Api.SEARCHABLE_PLUGINS);
|
||||||
|
//spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Log.d(LOG_TAG, "Resuming...");
|
Log.d(LOG_TAG, "Resuming...");
|
||||||
triggerTextRequest(Api.SEARCHABLE_PLUGINS);
|
//triggerTextRequest(Api.SEARCHABLE_PLUGINS);
|
||||||
Log.d(LOG_TAG, "Resumed...");
|
Log.d(LOG_TAG, "Resumed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,16 +90,35 @@ public class SearchFragment extends OpenLPFragment {
|
|||||||
|
|
||||||
public void manageResponse(String response, boolean notInError) {
|
public void manageResponse(String response, boolean notInError) {
|
||||||
if (calledURL.equals(updateUrl)) {
|
if (calledURL.equals(updateUrl)) {
|
||||||
populateTabDisplay(response);
|
populatePluginList(response);
|
||||||
}else {
|
} else {
|
||||||
processUpdate(response, notInError);
|
//processUpdate(response, notInError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateTabDisplay(String response){
|
private void populatePluginList(String response) {
|
||||||
int a = 1;
|
Log.i(LOG_TAG, "populatePluginList - entry");
|
||||||
|
List<String> categories = new ArrayList<String>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray items = new JSONObject(response).getJSONObject("results").getJSONArray("items");
|
||||||
|
for (int i = 0; i < items.length(); ++i) {
|
||||||
|
JSONArray item = items.getJSONArray(i);
|
||||||
|
categories.add(item.get(1).toString());
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(LOG_TAG, response);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ArrayAdapter<String> LTRadapter = new ArrayAdapter<String>(getActivity(),
|
||||||
|
android.R.layout.simple_spinner_item, categories);
|
||||||
|
LTRadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
spinner.setAdapter(LTRadapter);
|
||||||
|
|
||||||
|
Log.i(LOG_TAG, "populatePluginList - exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void itemClicked(int position) {
|
public void itemClicked(int position) {
|
||||||
try {
|
try {
|
||||||
String request = JsonHelpers.createRequestJSON("id", Integer.toString(position));
|
String request = JsonHelpers.createRequestJSON("id", Integer.toString(position));
|
||||||
@ -79,5 +130,27 @@ public class SearchFragment extends OpenLPFragment {
|
|||||||
Toast.makeText(context, "Request Failed", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Request Failed", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 );
|
||||||
|
client.get(callurl, null, new TextHttpResponseHandler() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(int statusCode, Header[] headers, String responseString) {
|
||||||
|
// called when response HTTP status is "200 OK"
|
||||||
|
manageResponse(responseString, true);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
||||||
|
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
|
||||||
|
if (statusCode == 401) {
|
||||||
|
Toast.makeText(context, R.string.httpreturn_unauthorised, Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
manageResponse(responseString, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,85 +1,78 @@
|
|||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/fragmentsearchlist"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="org.openlp.android2.fragments.SearchFragment"
|
android:layout_gravity="center_horizontal|top"
|
||||||
android:id="@+id/search_layout">
|
android:weightSum="1">
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="horizontal"
|
||||||
android:id="@+id/fragmentsearchlist"
|
android:id="@+id/fragmentsearchdetails"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal|top"
|
|
||||||
android:weightSum="1">
|
android:weightSum="1">
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
android:orientation="horizontal"
|
android:layout_width="wrap_content"
|
||||||
android:id="@+id/fragmentsearchdetails"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:weightSum="1">
|
android:text="Select Plugin"
|
||||||
|
android:id="@+id/search_title"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<TextView
|
<Spinner
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Select Plugin"
|
|
||||||
android:id="@+id/search_title"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<Spinner
|
|
||||||
android:layout_width="288dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/search_spinner"
|
|
||||||
android:layout_weight="0.58" />
|
|
||||||
|
|
||||||
<SearchView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/searchView"
|
|
||||||
android:layout_gravity="center_horizontal" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:id="@+id/fragmentsearchvalue"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:weightSum="1">
|
android:id="@+id/search_spinner"
|
||||||
|
android:layout_weight="0.58" />
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:text="Search Text"
|
|
||||||
android:id="@+id/search_value_desc" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/search_text"
|
|
||||||
style="@android:style/Animation.InputMethod"
|
|
||||||
android:layout_weight="0.87" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/fragmentsearchresults"
|
|
||||||
android:weightSum="1">
|
|
||||||
|
|
||||||
<ListView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="333dp"
|
|
||||||
android:id="@+id/searchresultsdetails" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
<SearchView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/searchView"
|
||||||
|
android:layout_gravity="center_horizontal" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:id="@+id/fragmentsearchvalue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:weightSum="1">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="Search Text"
|
||||||
|
android:id="@+id/search_value_desc" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/search_text"
|
||||||
|
style="@android:style/Animation.InputMethod"
|
||||||
|
android:layout_weight="0.87" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/fragmentsearchresults"
|
||||||
|
android:weightSum="1">
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="333dp"
|
||||||
|
android:id="@+id/searchresultsdetails" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user