cleaner preference handling in ApiRequest
make json data debugging optional
This commit is contained in:
parent
b5af258ee7
commit
16fd6cebd7
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.fox.ttrss"
|
package="org.fox.ttrss"
|
||||||
android:versionCode="12"
|
android:versionCode="13"
|
||||||
android:versionName="0.1.11">
|
android:versionName="0.1.12">
|
||||||
<uses-sdk android:minSdkVersion="8" />
|
<uses-sdk android:minSdkVersion="8" />
|
||||||
<!-- <supports-screens android:smallScreens="false" android:normalScreens="false" /> -->
|
<!-- <supports-screens android:smallScreens="false" android:normalScreens="false" /> -->
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<string name="login_login">Log in</string>
|
<string name="login_login">Log in</string>
|
||||||
<string name="logout">Log out</string>
|
<string name="logout">Log out</string>
|
||||||
<string name="login">Login</string>
|
<string name="login">Login</string>
|
||||||
|
<string name="debugging">Debugging</string>
|
||||||
<string name="password">Password</string>
|
<string name="password">Password</string>
|
||||||
<string name="default_url">http://example.domain/tt-rss/</string>
|
<string name="default_url">http://example.domain/tt-rss/</string>
|
||||||
<string name="authentication">Authentication</string>
|
<string name="authentication">Authentication</string>
|
||||||
@ -20,6 +21,7 @@
|
|||||||
<string name="theme_dark">Dark</string>
|
<string name="theme_dark">Dark</string>
|
||||||
<string name="preferences">Preferences</string>
|
<string name="preferences">Preferences</string>
|
||||||
<string name="theme_light">Light</string>
|
<string name="theme_light">Light</string>
|
||||||
|
<string name="connection">Connection</string>
|
||||||
<string name="login_api_disabled">Login failed: API disabled.</string>
|
<string name="login_api_disabled">Login failed: API disabled.</string>
|
||||||
<string name="login_no_data">Login failed: no data received.</string>
|
<string name="login_no_data">Login failed: no data received.</string>
|
||||||
<string name="login_wrong_password">Login failed: username or password incorrect.</string>
|
<string name="login_wrong_password">Login failed: username or password incorrect.</string>
|
||||||
@ -42,4 +44,5 @@
|
|||||||
<string name="error_no_feeds">No feeds to display.</string>
|
<string name="error_no_feeds">No feeds to display.</string>
|
||||||
<string name="error_invalid_object">Error: invalid object received.</string>
|
<string name="error_invalid_object">Error: invalid object received.</string>
|
||||||
<string name="blank"></string>
|
<string name="blank"></string>
|
||||||
|
<string name="transport_debugging">Log sent and received data</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -3,14 +3,13 @@
|
|||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/authentication">
|
<PreferenceCategory android:title="@string/connection">
|
||||||
|
|
||||||
<EditTextPreference android:title="@string/login" android:key="login" android:singleLine="true"></EditTextPreference>
|
<EditTextPreference android:title="@string/login" android:key="login" android:singleLine="true"></EditTextPreference>
|
||||||
<EditTextPreference android:title="@string/password" android:key="password" android:singleLine="true" android:password="true"></EditTextPreference>
|
<EditTextPreference android:title="@string/password" android:key="password" android:singleLine="true" android:password="true"></EditTextPreference>
|
||||||
<EditTextPreference android:key="ttrss_url" android:title="@string/ttrss_url" android:singleLine="true" textUri="true" android:hint="@string/default_url"></EditTextPreference>
|
<EditTextPreference android:key="ttrss_url" android:title="@string/ttrss_url" android:singleLine="true" textUri="true" android:hint="@string/default_url"></EditTextPreference>
|
||||||
<CheckBoxPreference android:defaultValue="false" android:title="@string/ssl_trust_any" android:key="ssl_trust_any" />
|
<CheckBoxPreference android:defaultValue="false" android:title="@string/ssl_trust_any" android:key="ssl_trust_any" />
|
||||||
|
</PreferenceCategory>
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/look_and_feel">
|
<PreferenceCategory android:title="@string/look_and_feel">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
@ -22,5 +21,9 @@
|
|||||||
|
|
||||||
<CheckBoxPreference android:title="@string/sort_feeds_by_unread" android:key="sort_feeds_by_unread"/>
|
<CheckBoxPreference android:title="@string/sort_feeds_by_unread" android:key="sort_feeds_by_unread"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/debugging">
|
||||||
|
<CheckBoxPreference android:defaultValue="false" android:title="@string/transport_debugging" android:key="transport_debugging" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@ -16,7 +16,10 @@ import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
|||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@ -33,13 +36,17 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
|
|||||||
|
|
||||||
private String m_api;
|
private String m_api;
|
||||||
private boolean m_trustAny = false;
|
private boolean m_trustAny = false;
|
||||||
|
private boolean m_transportDebugging = false;
|
||||||
|
private Context m_context;
|
||||||
|
|
||||||
protected void setApi(String api) {
|
public ApiRequest(Context context) {
|
||||||
m_api = api;
|
m_context = context;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTrustAny(boolean trust) {
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(m_context);
|
||||||
m_trustAny = trust;
|
|
||||||
|
m_api = prefs.getString("ttrss_url", null);
|
||||||
|
m_trustAny = prefs.getBoolean("ssl_trust_any", false);
|
||||||
|
m_transportDebugging = prefs.getBoolean("transport_debugging", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,7 +56,7 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
|
|||||||
|
|
||||||
String requestStr = gson.toJson(new HashMap<String,String>(params[0]));
|
String requestStr = gson.toJson(new HashMap<String,String>(params[0]));
|
||||||
|
|
||||||
//Log.d(TAG, ">>> (" + requestStr + ") " + m_api);
|
if (m_transportDebugging) Log.d(TAG, ">>> (" + requestStr + ") " + m_api);
|
||||||
|
|
||||||
DefaultHttpClient client;
|
DefaultHttpClient client;
|
||||||
|
|
||||||
@ -83,7 +90,7 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
|
|||||||
response += s;
|
response += s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "<<< " + response);
|
if (m_transportDebugging) Log.d(TAG, "<<< " + response);
|
||||||
|
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
list.setOnItemClickListener(this);
|
list.setOnItemClickListener(this);
|
||||||
|
|
||||||
if (m_feeds == null || m_feeds.size() == 0)
|
if (m_feeds == null || m_feeds.size() == 0)
|
||||||
refresh();
|
refresh(false);
|
||||||
else
|
else
|
||||||
view.findViewById(R.id.loading_progress).setVisibility(View.GONE);
|
view.findViewById(R.id.loading_progress).setVisibility(View.GONE);
|
||||||
|
|
||||||
@ -129,23 +129,22 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh(boolean background) {
|
||||||
FeedsRequest req = new FeedsRequest();
|
FeedsRequest req = new FeedsRequest(getActivity().getApplicationContext());
|
||||||
|
|
||||||
req.setApi(m_prefs.getString("ttrss_url", null));
|
|
||||||
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||||
final boolean unreadOnly = ((MainActivity)getActivity()).getUnreadOnly();
|
final boolean unreadOnly = ((MainActivity)getActivity()).getUnreadOnly();
|
||||||
|
|
||||||
if (sessionId != null) {
|
if (sessionId != null) {
|
||||||
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
if (!background) {
|
||||||
@Override
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
setLoadingStatus(R.string.blank, true);
|
public void run() {
|
||||||
}
|
setLoadingStatus(R.string.blank, true);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
HashMap<String,String> map = new HashMap<String,String>() {
|
HashMap<String,String> map = new HashMap<String,String>() {
|
||||||
{
|
{
|
||||||
@ -181,53 +180,57 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
|
|
||||||
private class FeedsRequest extends ApiRequest {
|
private class FeedsRequest extends ApiRequest {
|
||||||
|
|
||||||
protected void onPostExecute(JsonElement result) {
|
public FeedsRequest(Context context) {
|
||||||
if (result != null) {
|
super(context);
|
||||||
try {
|
|
||||||
JsonObject rv = result.getAsJsonObject();
|
|
||||||
|
|
||||||
Gson gson = new Gson();
|
|
||||||
|
|
||||||
int status = rv.get("status").getAsInt();
|
|
||||||
|
|
||||||
if (status == 0) {
|
|
||||||
JsonArray content = rv.get("content").getAsJsonArray();
|
|
||||||
if (content != null) {
|
|
||||||
Type listType = new TypeToken<List<Feed>>() {}.getType();
|
|
||||||
final List<Feed> feeds = gson.fromJson(content, listType);
|
|
||||||
|
|
||||||
m_feeds.clear();
|
|
||||||
|
|
||||||
for (Feed f : feeds)
|
|
||||||
m_feeds.add(f);
|
|
||||||
|
|
||||||
sortFeeds();
|
|
||||||
|
|
||||||
if (m_feeds.size() == 0)
|
|
||||||
setLoadingStatus(R.string.error_no_feeds, false);
|
|
||||||
else
|
|
||||||
setLoadingStatus(R.string.blank, false);
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MainActivity activity = (MainActivity)getActivity();
|
|
||||||
activity.login();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
setLoadingStatus(R.string.error_invalid_object, false);
|
|
||||||
// report invalid object received
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// report null object received, unless we've been awakened from sleep right in the right time
|
|
||||||
// so that current request failed
|
|
||||||
if (m_feeds.size() == 0) setLoadingStatus(R.string.error_no_data, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
if (result != null) {
|
||||||
|
try {
|
||||||
|
JsonObject rv = result.getAsJsonObject();
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
|
||||||
|
int status = rv.get("status").getAsInt();
|
||||||
|
|
||||||
|
if (status == 0) {
|
||||||
|
JsonArray content = rv.get("content").getAsJsonArray();
|
||||||
|
if (content != null) {
|
||||||
|
Type listType = new TypeToken<List<Feed>>() {}.getType();
|
||||||
|
final List<Feed> feeds = gson.fromJson(content, listType);
|
||||||
|
|
||||||
|
m_feeds.clear();
|
||||||
|
|
||||||
|
for (Feed f : feeds)
|
||||||
|
m_feeds.add(f);
|
||||||
|
|
||||||
|
sortFeeds();
|
||||||
|
|
||||||
|
if (m_feeds.size() == 0)
|
||||||
|
setLoadingStatus(R.string.error_no_feeds, false);
|
||||||
|
else
|
||||||
|
setLoadingStatus(R.string.blank, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MainActivity activity = (MainActivity)getActivity();
|
||||||
|
activity.login();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
setLoadingStatus(R.string.error_invalid_object, false);
|
||||||
|
// report invalid object received
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// report null object received, unless we've been awakened from sleep right in the right time
|
||||||
|
// so that current request failed
|
||||||
|
if (m_feeds.size() == 0) setLoadingStatus(R.string.error_no_data, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class FeedListAdapter extends ArrayAdapter<Feed> {
|
private class FeedListAdapter extends ArrayAdapter<Feed> {
|
||||||
private ArrayList<Feed> items;
|
private ArrayList<Feed> items;
|
||||||
|
|
||||||
|
@ -123,10 +123,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(boolean append) {
|
public void refresh(boolean append) {
|
||||||
HeadlinesRequest req = new HeadlinesRequest();
|
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext());
|
||||||
|
|
||||||
req.setApi(m_prefs.getString("ttrss_url", null));
|
//req.setApi(m_prefs.getString("ttrss_url", null));
|
||||||
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
//req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||||
final boolean showUnread = ((MainActivity)getActivity()).getUnreadArticlesOnly();
|
final boolean showUnread = ((MainActivity)getActivity()).getUnreadArticlesOnly();
|
||||||
@ -191,6 +191,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
private class HeadlinesRequest extends ApiRequest {
|
private class HeadlinesRequest extends ApiRequest {
|
||||||
int m_offset = 0;
|
int m_offset = 0;
|
||||||
|
|
||||||
|
public HeadlinesRequest(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
protected void onPostExecute(JsonElement result) {
|
protected void onPostExecute(JsonElement result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
try {
|
try {
|
||||||
@ -250,9 +254,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void catchupArticle(final Article article) {
|
public void catchupArticle(final Article article) {
|
||||||
ApiRequest req = new ApiRequest();
|
ApiRequest req = new ApiRequest(getActivity().getApplicationContext());
|
||||||
req.setApi(m_prefs.getString("ttrss_url", null));
|
//req.setApi(m_prefs.getString("ttrss_url", null));
|
||||||
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
//req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||||
|
|
||||||
@ -270,9 +274,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setArticleMarked(final Article article) {
|
public void setArticleMarked(final Article article) {
|
||||||
ApiRequest req = new ApiRequest();
|
ApiRequest req = new ApiRequest(getActivity().getApplicationContext());
|
||||||
req.setApi(m_prefs.getString("ttrss_url", null));
|
|
||||||
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Timer;
|
|||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import android.animation.LayoutTransition;
|
import android.animation.LayoutTransition;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -53,10 +54,10 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
public synchronized void refreshFeeds() {
|
public synchronized void refreshFeeds() {
|
||||||
FeedsFragment frag = (FeedsFragment) getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
|
FeedsFragment frag = (FeedsFragment) getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
|
||||||
|
|
||||||
Log.d(TAG, "Refreshing feeds..." + frag);
|
Log.d(TAG, "Refreshing feeds...");
|
||||||
|
|
||||||
if (frag != null) {
|
if (frag != null) {
|
||||||
frag.refresh();
|
frag.refresh(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +263,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
Log.d(TAG, "Overriding back button");
|
|
||||||
|
|
||||||
if (m_smallScreenMode) {
|
if (m_smallScreenMode) {
|
||||||
if (m_selectedArticle != null) {
|
if (m_selectedArticle != null) {
|
||||||
@ -450,6 +450,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class LoginRequest extends ApiRequest {
|
private class LoginRequest extends ApiRequest {
|
||||||
|
public LoginRequest(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
protected void onPostExecute(JsonElement result) {
|
protected void onPostExecute(JsonElement result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
@ -611,9 +614,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
LoginRequest ar = new LoginRequest();
|
LoginRequest ar = new LoginRequest(getApplicationContext());
|
||||||
ar.setApi(m_prefs.getString("ttrss_url", null));
|
//ar.setApi(m_prefs.getString("ttrss_url", null));
|
||||||
ar.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
//ar.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
||||||
|
|
||||||
HashMap<String,String> map = new HashMap<String,String>() {
|
HashMap<String,String> map = new HashMap<String,String>() {
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user