diff --git a/src/org/fox/ttrss/OfflineActivity.java b/src/org/fox/ttrss/OfflineActivity.java index 2edcee85..325bfcbc 100644 --- a/src/org/fox/ttrss/OfflineActivity.java +++ b/src/org/fox/ttrss/OfflineActivity.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; +import org.fox.ttrss.ArticleOps.RelativeArticle; + import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; @@ -187,7 +189,7 @@ public class OfflineActivity extends FragmentActivity { finish(); } - public int getActiveOfflineFeedId() { + public int getActiveFeedId() { return m_activeFeedId; } @@ -735,69 +737,108 @@ public class OfflineActivity extends FragmentActivity { } } - /* @Override + @Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { - HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + int nextId = getRelativeArticleId(m_selectedArticleId, m_activeFeedId, RelativeArticle.AFTER); + + if (nextId != 0 && ohf != null) { + if (m_prefs.getBoolean("combined_mode", false)) { + ohf.setActiveArticleId(nextId); + + SQLiteStatement stmt = getWritableDb().compileStatement("UPDATE articles SET unread = 0 " + + "WHERE " + BaseColumns._ID + " = ?"); + + stmt.bindLong(1, nextId); + stmt.execute(); + stmt.close(); - if (hf != null && m_activeFeed != null) { - Article base = hf.getArticleById(hf.getActiveArticleId()); - - Article next = base != null ? getRelativeArticle(base, RelativeArticle.AFTER) : hf.getArticleAtPosition(0); - - if (next != null) { - hf.setActiveArticleId(next.id); - - boolean combinedMode = m_prefs.getBoolean("combined_mode", false); - - if (combinedMode || m_selectedArticle == null) { - next.unread = false; - saveArticleUnread(next); - } else { - openArticle(next, 0); - } - } + } else { + openArticle(nextId, 0); + } } } return true; case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_UP) { - HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + int prevId = getRelativeArticleId(m_selectedArticleId, m_activeFeedId, RelativeArticle.BEFORE); + + if (prevId != 0 && ohf != null) { + if (m_prefs.getBoolean("combined_mode", false)) { + ohf.setActiveArticleId(prevId); + + SQLiteStatement stmt = getWritableDb().compileStatement("UPDATE articles SET unread = 0 " + + "WHERE " + BaseColumns._ID + " = ?"); + + stmt.bindLong(1, prevId); + stmt.execute(); + stmt.close(); - if (hf != null && m_activeFeed != null) { - Article base = hf.getArticleById(hf.getActiveArticleId()); - - Article prev = base != null ? getRelativeArticle(base, RelativeArticle.BEFORE) : hf.getArticleAtPosition(0); - - if (prev != null) { - hf.setActiveArticleId(prev.id); - - boolean combinedMode = m_prefs.getBoolean("combined_mode", false); - - if (combinedMode || m_selectedArticle == null) { - prev.unread = false; - saveArticleUnread(prev); - } else { - openArticle(prev, 0); - } - } + } else { + openArticle(prevId, 0); + } } - } return true; default: return super.dispatchKeyEvent(event); } - } */ + } public void deselectAllArticles() { getWritableDb().execSQL("UPDATE articles SET selected = 0 "); } + public int getRelativeArticleId(int baseId, int feedId, ArticleOps.RelativeArticle mode) { + + Cursor c; + + /* if (baseId == 0) { + c = getReadableDb().query("articles", + null, "feed_id = ?", + new String[] { String.valueOf(feedId) }, null, null, "updated DESC LIMIT 1"); + + if (c.moveToFirst()) { + baseId = c.getInt(0); + } + + c.close(); + + return baseId; + } */ + + if (mode == RelativeArticle.BEFORE) { + c = getReadableDb().query("articles", + null, "updated > (SELECT updated FROM articles WHERE "+BaseColumns._ID+" = ?) AND feed_id = ?", + new String[] { String.valueOf(baseId), String.valueOf(feedId) }, null, null, "updated LIMIT 1"); + + } else { + c = getReadableDb().query("articles", + null, "updated < (SELECT updated FROM articles WHERE "+BaseColumns._ID+" = ?) AND feed_id = ?", + new String[] { String.valueOf(baseId), String.valueOf(feedId) }, null, null, "updated DESC LIMIT 1"); + } + + int id = 0; + + if (c.moveToFirst()) { + id = c.getInt(0); + } + + c.close(); + + return id; + } + public void viewFeed(int feedId) { m_activeFeedId = feedId; @@ -827,6 +868,13 @@ public class OfflineActivity extends FragmentActivity { if (hf != null) { hf.setActiveArticleId(articleId); } + + SQLiteStatement stmt = getWritableDb().compileStatement("UPDATE articles SET unread = 0 " + + "WHERE " + BaseColumns._ID + " = ?"); + + stmt.bindLong(1, articleId); + stmt.execute(); + stmt.close(); OfflineArticleFragment frag = new OfflineArticleFragment(); diff --git a/src/org/fox/ttrss/OfflineArticleFragment.java b/src/org/fox/ttrss/OfflineArticleFragment.java index ac7febf8..6c68d62c 100644 --- a/src/org/fox/ttrss/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/OfflineArticleFragment.java @@ -7,7 +7,6 @@ import org.fox.ttrss.ArticleOps.RelativeArticle; import android.app.Activity; import android.content.SharedPreferences; -import android.content.pm.PackageManager; import android.database.Cursor; import android.os.Bundle; import android.preference.PreferenceManager; @@ -26,7 +25,6 @@ import android.webkit.WebView; import android.widget.ImageView; import android.widget.TextView; -import com.google.ads.AdRequest; import com.google.ads.AdView; public class OfflineArticleFragment extends Fragment implements OnClickListener { @@ -35,6 +33,8 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener private SharedPreferences m_prefs; private int m_articleId; + private int m_nextArticleId; + private int m_prevArticleId; private GestureDetector m_gestureDetector; private View.OnTouchListener m_gestureListener; private Cursor m_cursor; @@ -44,6 +44,8 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener if (savedInstanceState != null) { m_articleId = savedInstanceState.getInt("articleId"); + m_prevArticleId = savedInstanceState.getInt("prevArticleId"); + m_nextArticleId = savedInstanceState.getInt("nextArticleId"); } View view = inflater.inflate(R.layout.article_fragment, container, false); @@ -163,21 +165,21 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener ImageView next = (ImageView)view.findViewById(R.id.next_article); if (next != null) { -// if (m_nextArticle != null) { -// next.setOnClickListener(this); -// } else { + if (m_nextArticleId != 0) { + next.setOnClickListener(this); + } else { next.setImageResource(R.drawable.ic_next_article_disabled); -// } + } } ImageView prev = (ImageView)view.findViewById(R.id.prev_article); if (prev != null) { -// if (m_prevArticle != null) { -// prev.setOnClickListener(this); -// } else { + if (m_prevArticleId != 0) { + prev.setOnClickListener(this); + } else { prev.setImageResource(R.drawable.ic_prev_article_disabled); -// } + } } } @@ -197,6 +199,9 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener super.onSaveInstanceState(out); out.putInt("articleId", m_articleId); + out.putInt("prevArticleId", m_prevArticleId); + out.putInt("nextArticleId", m_nextArticleId); + } @Override @@ -205,21 +210,21 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); - m_articleId = ((OfflineActivity)activity).getSelectedArticleId(); - /* m_articleOps = (ArticleOps)activity; - m_article = m_articleOps.getSelectedArticle(); + OfflineActivity oa = (OfflineActivity)activity; - m_prevArticle = m_articleOps.getRelativeArticle(m_article, RelativeArticle.BEFORE); - m_nextArticle = m_articleOps.getRelativeArticle(m_article, RelativeArticle.AFTER); */ + m_articleId = oa.getSelectedArticleId(); + + m_prevArticleId = oa.getRelativeArticleId(m_articleId, oa.getActiveFeedId(), RelativeArticle.BEFORE); + m_nextArticleId = oa.getRelativeArticleId(m_articleId, oa.getActiveFeedId(), RelativeArticle.AFTER); } @Override public void onClick(View v) { - /* if (v.getId() == R.id.next_article) { - m_articleOps.openArticle(m_nextArticle, 0); + if (v.getId() == R.id.next_article) { + ((OfflineActivity)getActivity()).openArticle(m_nextArticleId, 0); } else if (v.getId() == R.id.prev_article) { - m_articleOps.openArticle(m_prevArticle, R.anim.slide_right); - } */ + ((OfflineActivity)getActivity()).openArticle(m_prevArticleId, R.anim.slide_right); + } } // http://blog.blackmoonit.com/2010/07/gesture-detection-swipe-detection_4292.html @@ -238,14 +243,14 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener if (dX>0) { //Log.d(TAG, "Right swipe"); - //if (m_prevArticle != null) - // m_articleOps.openArticle(m_prevArticle, R.anim.slide_right); - + if (m_prevArticleId != 0) + ((OfflineActivity)getActivity()).openArticle(m_prevArticleId, 0); + } else { //Log.d(TAG, "Left swipe"); - - //if (m_nextArticle != null) - // m_articleOps.openArticle(m_nextArticle, 0); + + if (m_nextArticleId != 0) + ((OfflineActivity)getActivity()).openArticle(m_nextArticleId, 0); } return true; diff --git a/src/org/fox/ttrss/OfflineFeedsFragment.java b/src/org/fox/ttrss/OfflineFeedsFragment.java index 9dd8b266..369ca5db 100644 --- a/src/org/fox/ttrss/OfflineFeedsFragment.java +++ b/src/org/fox/ttrss/OfflineFeedsFragment.java @@ -89,7 +89,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene list.setAdapter(m_adapter); list.setOnItemClickListener(this); - list.setEmptyView(view.findViewById(R.id.no_unread_feeds)); + list.setEmptyView(view.findViewById(R.id.no_feeds)); registerForContextMenu(list); view.findViewById(R.id.loading_container).setVisibility(View.GONE); diff --git a/src/org/fox/ttrss/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/OfflineHeadlinesFragment.java index e00b8fda..bd689d88 100644 --- a/src/org/fox/ttrss/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/OfflineHeadlinesFragment.java @@ -131,6 +131,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis list.setAdapter(m_adapter); list.setOnItemClickListener(this); + list.setEmptyView(view.findViewById(R.id.no_headlines)); registerForContextMenu(list); view.findViewById(R.id.loading_progress).setVisibility(View.GONE); @@ -146,7 +147,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis @Override public void onAttach(Activity activity) { super.onAttach(activity); - m_feedId = ((OfflineActivity)activity).getActiveOfflineFeedId(); + m_feedId = ((OfflineActivity)activity).getActiveFeedId(); m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); m_combinedMode = m_prefs.getBoolean("combined_mode", false); }