refresh feeds automatically
This commit is contained in:
parent
9b38d7a0bd
commit
212031e3cf
@ -32,7 +32,7 @@ import com.google.gson.reflect.TypeToken;
|
||||
public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private SharedPreferences m_prefs;
|
||||
private String m_sessionId;
|
||||
//private String m_sessionId;
|
||||
//private int m_activeFeedId;
|
||||
private FeedListAdapter m_adapter;
|
||||
private List<Feed> m_feeds = new ArrayList<Feed>();
|
||||
@ -69,7 +69,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
|
||||
list.setOnItemClickListener(this);
|
||||
|
||||
if (m_sessionId != null)
|
||||
//if (m_sessionId != null)
|
||||
refresh();
|
||||
|
||||
return view;
|
||||
@ -87,7 +87,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||
m_feedSelectedListener = (OnFeedSelectedListener) activity;
|
||||
|
||||
m_sessionId = ((MainActivity)activity).getSessionId();
|
||||
//m_sessionId = ((MainActivity)activity).getSessionId();
|
||||
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
public void onSaveInstanceState (Bundle out) {
|
||||
super.onSaveInstanceState(out);
|
||||
|
||||
out.putString("sessionId", m_sessionId);
|
||||
//out.putString("sessionId", m_sessionId);
|
||||
//out.putInt("activeFeedId", m_activeFeedId);
|
||||
}
|
||||
|
||||
@ -114,16 +114,22 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
|
||||
fr.setApi(m_prefs.getString("ttrss_url", null));
|
||||
|
||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||
|
||||
if (sessionId != null) {
|
||||
|
||||
HashMap<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
put("op", "getFeeds");
|
||||
put("sid", m_sessionId);
|
||||
put("sid", sessionId);
|
||||
put("cat_id", "-3");
|
||||
put("unread_only", "true");
|
||||
}
|
||||
};
|
||||
|
||||
fr.execute(map);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setLoadingStatus(int status, boolean showProgress) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package org.fox.ttrss;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -29,10 +30,30 @@ public class MainActivity extends Activity implements FeedsFragment.OnFeedSelect
|
||||
private String m_sessionId;
|
||||
private Article m_selectedArticle;
|
||||
private Feed m_activeFeed;
|
||||
private Timer m_refreshTimer;
|
||||
private RefreshTask m_refreshTask;
|
||||
|
||||
protected MenuItem m_syncStatus;
|
||||
|
||||
public synchronized String getSessionId() {
|
||||
private class RefreshTask extends TimerTask {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Refreshing feeds...");
|
||||
|
||||
refreshFeeds();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void refreshFeeds() {
|
||||
FeedsFragment frag = (FeedsFragment) getFragmentManager().findFragmentById(R.id.feeds_fragment);
|
||||
|
||||
if (frag != null) {
|
||||
frag.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return m_sessionId;
|
||||
}
|
||||
|
||||
@ -127,6 +148,15 @@ public class MainActivity extends Activity implements FeedsFragment.OnFeedSelect
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (m_refreshTask != null) {
|
||||
m_refreshTask.cancel();
|
||||
m_refreshTask = null;
|
||||
}
|
||||
|
||||
if (m_refreshTimer != null) {
|
||||
m_refreshTimer.cancel();
|
||||
m_refreshTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -179,6 +209,21 @@ public class MainActivity extends Activity implements FeedsFragment.OnFeedSelect
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.feeds_fragment, frag);
|
||||
ft.commit();
|
||||
|
||||
if (m_refreshTask != null) {
|
||||
m_refreshTask.cancel();
|
||||
m_refreshTask = null;
|
||||
}
|
||||
|
||||
if (m_refreshTimer != null) {
|
||||
m_refreshTimer.cancel();
|
||||
m_refreshTimer = null;
|
||||
}
|
||||
|
||||
m_refreshTask = new RefreshTask();
|
||||
m_refreshTimer = new Timer("Refresh");
|
||||
|
||||
m_refreshTimer.schedule(m_refreshTask, 60*1000L, 60*1000L);
|
||||
}
|
||||
} else {
|
||||
JsonObject content = rv.get("content").getAsJsonObject();
|
||||
|
Loading…
Reference in New Issue
Block a user