diff options
author | Andrew Dolgov <[email protected]> | 2011-11-22 15:49:21 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2011-11-22 15:49:21 +0300 |
commit | 2c12a4b67761ac74f0acb4590d21ce9b5c42cecb (patch) | |
tree | 17f59e11023a2fec281f00a3adedfcdcee1a06c4 | |
parent | d9d778c56503cf65dbbd13079890412621d551c8 (diff) |
more cleanup, initial async apirequest stuff
-rw-r--r-- | res/layout/feeds_fragment.xml | 12 | ||||
-rw-r--r-- | res/layout/headlines_fragment.xml | 13 | ||||
-rw-r--r-- | res/layout/main.xml | 8 | ||||
-rw-r--r-- | res/values/strings.xml | 5 | ||||
-rw-r--r-- | src/org/fox/ttrss/ApiRequest.java | 59 | ||||
-rw-r--r-- | src/org/fox/ttrss/MainActivity.java | 30 |
6 files changed, 91 insertions, 36 deletions
diff --git a/res/layout/feeds_fragment.xml b/res/layout/feeds_fragment.xml index 9b22dce8..09a975ee 100644 --- a/res/layout/feeds_fragment.xml +++ b/res/layout/feeds_fragment.xml @@ -2,14 +2,8 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
- <ListView android:layout_weight="1"
- android:layout_width="match_parent" android:id="@+id/feeds" android:layout_height="match_parent"></ListView>
- </LinearLayout>
- <TextView android:id="@+id/no_unread_feeds"
- android:visibility="invisible"
- android:layout_gravity="center" android:color="#909090"
- android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_unread_feeds"></TextView>
+ android:layout_height="fill_parent"> + <TextView android:layout_width="wrap_content" android:id="@+id/no_unread_feeds" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="@string/no_unread_feeds" android:layout_gravity="center" ></TextView> + <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/feeds"></ListView>
</FrameLayout>
diff --git a/res/layout/headlines_fragment.xml b/res/layout/headlines_fragment.xml index 4be9fe5b..ffcad32c 100644 --- a/res/layout/headlines_fragment.xml +++ b/res/layout/headlines_fragment.xml @@ -2,15 +2,8 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent" android:id="@+id/headlines_fragment">
- <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
- <ListView android:layout_weight="1" android:background="#fafafa"
- android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/headlines"></ListView>
- </LinearLayout>
-
- <TextView android:id="@+id/no_headlines"
- android:visibility="invisible"
- android:layout_gravity="center"
- android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_headlines"></TextView>
+ android:layout_height="fill_parent" android:id="@+id/headlines_fragment"> + <ListView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/headlines" android:background="#fafafa"></ListView> + <TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="@string/no_unread_headlines" android:layout_gravity="center" android:id="@+id/no_unread_headlines"></TextView>
</FrameLayout>
diff --git a/res/layout/main.xml b/res/layout/main.xml index 65a5be25..86fcf5fa 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -8,14 +8,6 @@ </LinearLayout> </FrameLayout> <LinearLayout android:id="@+id/main" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> - <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/linearLayout4" android:layout_weight="1.5"> - <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/feeds_container" android:layout_weight="1"></LinearLayout> - <ImageView android:paddingLeft="2dip" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_weight="1" android:background="?feedlistDivider" android:paddingRight="2dip"></ImageView> - </LinearLayout> - <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/headlines_wrapper" android:layout_weight="0.5" android:orientation="vertical"> - <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/headlines_container" android:layout_weight="1"></LinearLayout> - <LinearLayout android:visibility="gone" android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/article_container" android:layout_weight="1"></LinearLayout> - </LinearLayout> </LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml index c24d6911..72aa1cb6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -24,9 +24,6 @@ <string name="login_wrong_password">Login failed: username or password incorrect.</string> <string name="login_success">Logged in.</string> <string name="no_unread_feeds">No unread feeds.</string> - <string name="offline">Offline</string> - <string name="online">Online</string> - <string name="synchronizing">Synchronizing...</string> - <string name="no_headlines">No articles found.</string> + <string name="no_unread_headlines">No unread headlines.</string> <string name="loading_message">Loading, please wait...</string> </resources> diff --git a/src/org/fox/ttrss/ApiRequest.java b/src/org/fox/ttrss/ApiRequest.java index 4a88b48e..5e06d682 100644 --- a/src/org/fox/ttrss/ApiRequest.java +++ b/src/org/fox/ttrss/ApiRequest.java @@ -10,6 +10,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
+import android.os.AsyncTask;
import android.util.Log;
import com.google.gson.Gson;
@@ -17,10 +18,62 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-public class ApiRequest {
+public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonElement> {
private final String TAG = this.getClass().getSimpleName();
- protected String m_sessionId;
+ protected static final int STATUS_LOGIN_FAILED = 0;
+ protected static final int STATUS_OK = 1;
+ protected static final int STATUS_API_DISABLED = 2;
+ protected static final int STATUS_OTHER_ERROR = 3;
+
+ private String m_api;
+
+ protected void setApi(String api) {
+ m_api = api;
+ }
+
+ @Override
+ protected JsonElement doInBackground(HashMap<String, String>... params) {
+
+ Gson gson = new Gson();
+
+ String requestStr = gson.toJson(new HashMap<String,String>(params[0]));
+
+ Log.d(TAG, ">>> (" + requestStr + ") " + m_api);
+
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpPost httpPost = new HttpPost(m_api + "/api/");
+
+ try {
+ httpPost.setEntity(new StringEntity(requestStr, "utf-8"));
+ HttpResponse execute = client.execute(httpPost);
+
+ InputStream content = execute.getEntity().getContent();
+
+ BufferedReader buffer = new BufferedReader(
+ new InputStreamReader(content));
+
+ String s = "";
+ String response = "";
+
+ while ((s = buffer.readLine()) != null) {
+ response += s;
+ }
+
+ Log.d(TAG, "<<< " + response);
+
+ JsonParser parser = new JsonParser();
+
+ return parser.parse(response);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+ /* protected String m_sessionId;
protected String m_apiEndpoint;
protected String m_login;
protected String m_password;
@@ -173,5 +226,5 @@ public class ApiRequest { }
return null;
- }
+ } */
}
diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 1525a439..03937ac2 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -72,12 +72,37 @@ public class MainActivity extends Activity { } setContentView(R.layout.main); - - ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper); + + ApiRequest ar = new ApiRequest(); + ar.setApi(m_prefs.getString("ttrss_url", null)); + + HashMap<String,String> loginMap = new HashMap<String,String>() { + { + put("op", "login"); + put("user", m_prefs.getString("login", null)); + put("password", m_prefs.getString("password", null)); + } + }; + + ar.execute(loginMap); + + /* ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper); if (vf != null) { vf.showNext(); } + + HeadlinesFragment hf = new HeadlinesFragment(); + FeedsFragment ff = new FeedsFragment(); + ArticleFragment af = new ArticleFragment(); + + FragmentTransaction ft = getFragmentManager().beginTransaction(); + ft.add(R.id.main, ff); + ft.add(R.id.main, hf); + ft.add(R.id.main, af); + ft.hide(hf); + ft.hide(af); + ft.commit(); */ } @Override @@ -123,4 +148,5 @@ public class MainActivity extends Activity { return super.onOptionsItemSelected(item); } } + }
\ No newline at end of file |