diff --git a/src/org/fox/ttrss/FeedsActivity.java b/src/org/fox/ttrss/FeedsActivity.java index a03f6270..713e53eb 100644 --- a/src/org/fox/ttrss/FeedsActivity.java +++ b/src/org/fox/ttrss/FeedsActivity.java @@ -126,9 +126,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe public void onFeedSelected(Feed feed) { - FragmentTransaction ft = getSupportFragmentManager() - .beginTransaction(); - TinyApplication.getInstance().m_loadedArticles.clear(); if (isSmallScreen()) { @@ -144,17 +141,18 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe //ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES); //ft.addToBackStack(null); } else { + FragmentTransaction ft = getSupportFragmentManager() + .beginTransaction(); + HeadlinesFragment hf = new HeadlinesFragment(feed); ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); + + ft.commit(); } - ft.commit(); } public void onCatSelected(FeedCategory cat, boolean openAsFeed) { - FragmentTransaction ft = getSupportFragmentManager() - .beginTransaction(); - if (!openAsFeed) { if (isSmallScreen()) { @@ -167,17 +165,19 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe startActivityForResult(intent, 0); } else { + FragmentTransaction ft = getSupportFragmentManager() + .beginTransaction(); + FeedsFragment ff = new FeedsFragment(cat); ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS); + + ft.addToBackStack(null); + ft.commit(); } } else { Feed feed = new Feed(cat.id, cat.title, true); onFeedSelected(feed); } - - ft.addToBackStack(null); - - ft.commit(); } public void onCatSelected(FeedCategory cat) { diff --git a/src/org/fox/ttrss/offline/OfflineActivity.java b/src/org/fox/ttrss/offline/OfflineActivity.java index b7b151b9..7ee15f2d 100644 --- a/src/org/fox/ttrss/offline/OfflineActivity.java +++ b/src/org/fox/ttrss/offline/OfflineActivity.java @@ -171,6 +171,9 @@ public class OfflineActivity extends CommonActivity { .findFragmentByTag(FRAG_ARTICLE); switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; case R.id.go_online: switchOnline(); return true; diff --git a/src/org/fox/ttrss/offline/OfflineArticleEventListener.java b/src/org/fox/ttrss/offline/OfflineArticleEventListener.java deleted file mode 100644 index 35b9de28..00000000 --- a/src/org/fox/ttrss/offline/OfflineArticleEventListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.fox.ttrss.offline; - -public interface OfflineArticleEventListener { - -} diff --git a/src/org/fox/ttrss/offline/OfflineArticlePager.java b/src/org/fox/ttrss/offline/OfflineArticlePager.java index 254e1edc..0209cbfb 100644 --- a/src/org/fox/ttrss/offline/OfflineArticlePager.java +++ b/src/org/fox/ttrss/offline/OfflineArticlePager.java @@ -45,7 +45,7 @@ public class OfflineArticlePager extends Fragment { feedClause = "feed_id = ?"; } - if (m_searchQuery.equals("")) { + if (m_searchQuery == null || m_searchQuery.equals("")) { return m_activity.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")", new String[] { "articles."+BaseColumns._ID, "feeds.title AS feed_title" }, feedClause, new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); @@ -162,6 +162,16 @@ public class OfflineArticlePager extends Fragment { m_cursor = createCursor(); } + + public void refresh() { + if (m_cursor != null && !m_cursor.isClosed()) m_cursor.close(); + + m_cursor = createCursor(); + + if (m_cursor != null) { + m_adapter.notifyDataSetChanged(); + } + } public int getSelectedArticleId() { return m_articleId; @@ -176,4 +186,8 @@ public class OfflineArticlePager extends Fragment { out.putBoolean("isCat", m_isCat); } + + public void setSearchQuery(String searchQuery) { + m_searchQuery = searchQuery; + } } diff --git a/src/org/fox/ttrss/offline/OfflineFeedsActivity.java b/src/org/fox/ttrss/offline/OfflineFeedsActivity.java index 075c372a..7af62970 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedsActivity.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsActivity.java @@ -132,9 +132,6 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead } public void onCatSelected(int catId, boolean openAsFeed) { - FragmentTransaction ft = getSupportFragmentManager() - .beginTransaction(); - if (openAsFeed) { onFeedSelected(catId, true, true); } else { @@ -144,15 +141,17 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead startActivityForResult(intent, 0); } else { + FragmentTransaction ft = getSupportFragmentManager() + .beginTransaction(); + OfflineFeedsFragment ff = new OfflineFeedsFragment(catId); - + ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS); + ft.addToBackStack(null); + + ft.commit(); } } - ft.addToBackStack(null); - - ft.commit(); - } public void onFeedSelected(int feedId) { @@ -171,9 +170,13 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead startActivityForResult(intent, 0); } else { - - // TODO open OfflineHeadlinesFragment on R.id.headlines_fragment + FragmentTransaction ft = getSupportFragmentManager() + .beginTransaction(); + OfflineHeadlinesFragment hf = new OfflineHeadlinesFragment(feedId, isCat); + ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); + + ft.commit(); } } } @@ -221,9 +224,15 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead } else { - // TODO open OfflineHeadlinesActivity - + OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); + Intent intent = new Intent(OfflineFeedsActivity.this, OfflineHeadlinesActivity.class); + intent.putExtra("feed", hf.getFeedId()); + intent.putExtra("isCat", hf.getFeedIsCat()); + intent.putExtra("article", articleId); + intent.putExtra("title", "FIXME-TITLE"); + + startActivityForResult(intent, 0); } } else { refresh(); diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java b/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java new file mode 100644 index 00000000..49ac2b59 --- /dev/null +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java @@ -0,0 +1,83 @@ +package org.fox.ttrss.offline; + +import org.fox.ttrss.R; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v4.app.FragmentTransaction; +import android.view.View; + +public class OfflineHeadlinesActivity extends OfflineActivity implements OfflineHeadlinesEventListener { + private final String TAG = this.getClass().getSimpleName(); + + protected SharedPreferences m_prefs; + + @Override + public void onCreate(Bundle savedInstanceState) { + m_prefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { + setTheme(R.style.DarkTheme); + } else { + setTheme(R.style.LightTheme); + } + + super.onCreate(savedInstanceState); + + setContentView(R.layout.headlines); + + if (!isCompatMode()) { + getActionBar().setDisplayHomeAsUpEnabled(true); + } + + setSmallScreen(findViewById(R.id.headlines_fragment) == null); + + if (savedInstanceState == null) { + Intent i = getIntent(); + + if (i.getExtras() != null) { + int feedId = i.getIntExtra("feed", 0); + boolean isCat = i.getBooleanExtra("isCat", false); + int articleId = i.getIntExtra("article", 0); + String searchQuery = i.getStringExtra("searchQuery"); + String title = i.getStringExtra("title"); + + OfflineHeadlinesFragment hf = new OfflineHeadlinesFragment(feedId, isCat); + OfflineArticlePager af = new OfflineArticlePager(articleId, feedId, isCat); + + hf.setActiveArticleId(articleId); + + hf.setSearchQuery(searchQuery); + af.setSearchQuery(searchQuery); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + + ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); + ft.replace(R.id.article_fragment, af, FRAG_ARTICLE); + + ft.commit(); + + setTitle(title); + } + } + + setLoadingStatus(R.string.blank, false); + findViewById(R.id.loading_container).setVisibility(View.GONE); + + initMenu(); + } + + @Override + public void onArticleSelected(int articleId, boolean open) { + + + } + + @Override + public void onArticleSelected(int articleId) { + onArticleSelected(articleId, true); + } +} diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index fd3fad37..a7902be8 100644 --- a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -293,7 +293,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis feedClause = "feed_id = ?"; } - if (m_searchQuery.equals("")) { + if (m_searchQuery == null || m_searchQuery.equals("")) { return m_activity.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")", new String[] { "articles.*", "feeds.title AS feed_title" }, feedClause, new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); @@ -326,12 +326,20 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis int articleId = cursor.getInt(0); - if (!m_activity.isSmallScreen()) { + if (getActivity().findViewById(R.id.article_fragment) != null) { m_activeArticleId = articleId; } if (!m_combinedMode) { m_listener.onArticleSelected(articleId); + } else { + SQLiteStatement stmt = m_activity.getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID + + " = ?"); + + stmt.bindLong(1, articleId); + stmt.execute(); + stmt.close(); } refresh(); @@ -600,13 +608,17 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis public void setActiveArticleId(int articleId) { m_activeArticleId = articleId; - // m_adapter.notifyDataSetChanged(); + try { + m_adapter.notifyDataSetChanged(); + + ListView list = (ListView)getView().findViewById(R.id.headlines); - ListView list = (ListView)getView().findViewById(R.id.headlines); - - if (list != null) { - list.setSelection(getArticleIdPosition(articleId)); - } + if (list != null) { + list.setSelection(getArticleIdPosition(articleId)); + } + } catch (NullPointerException e) { + // invoked before view is created, nvm + } } public Cursor getArticleAtPosition(int position) { @@ -644,7 +656,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis public void setSearchQuery(String query) { if (!m_searchQuery.equals(query)) { m_searchQuery = query; - refresh(); } }