basic work on offline mode stuff for tablets

This commit is contained in:
Andrew Dolgov 2012-09-17 19:32:33 +04:00
parent 2103396489
commit 4c148d0563
7 changed files with 153 additions and 38 deletions

View File

@ -126,9 +126,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
public void onFeedSelected(Feed feed) { public void onFeedSelected(Feed feed) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
TinyApplication.getInstance().m_loadedArticles.clear(); TinyApplication.getInstance().m_loadedArticles.clear();
if (isSmallScreen()) { if (isSmallScreen()) {
@ -144,17 +141,18 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
//ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES); //ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
//ft.addToBackStack(null); //ft.addToBackStack(null);
} else { } else {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
HeadlinesFragment hf = new HeadlinesFragment(feed); HeadlinesFragment hf = new HeadlinesFragment(feed);
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
}
ft.commit(); ft.commit();
} }
}
public void onCatSelected(FeedCategory cat, boolean openAsFeed) { public void onCatSelected(FeedCategory cat, boolean openAsFeed) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
if (!openAsFeed) { if (!openAsFeed) {
if (isSmallScreen()) { if (isSmallScreen()) {
@ -167,17 +165,19 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} else { } else {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
FeedsFragment ff = new FeedsFragment(cat); FeedsFragment ff = new FeedsFragment(cat);
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS); ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
ft.addToBackStack(null);
ft.commit();
} }
} else { } else {
Feed feed = new Feed(cat.id, cat.title, true); Feed feed = new Feed(cat.id, cat.title, true);
onFeedSelected(feed); onFeedSelected(feed);
} }
ft.addToBackStack(null);
ft.commit();
} }
public void onCatSelected(FeedCategory cat) { public void onCatSelected(FeedCategory cat) {

View File

@ -171,6 +171,9 @@ public class OfflineActivity extends CommonActivity {
.findFragmentByTag(FRAG_ARTICLE); .findFragmentByTag(FRAG_ARTICLE);
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.go_online: case R.id.go_online:
switchOnline(); switchOnline();
return true; return true;

View File

@ -1,5 +0,0 @@
package org.fox.ttrss.offline;
public interface OfflineArticleEventListener {
}

View File

@ -45,7 +45,7 @@ public class OfflineArticlePager extends Fragment {
feedClause = "feed_id = ?"; 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+")", 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[] { "articles."+BaseColumns._ID, "feeds.title AS feed_title" }, feedClause,
new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC");
@ -163,6 +163,16 @@ public class OfflineArticlePager extends Fragment {
} }
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() { public int getSelectedArticleId() {
return m_articleId; return m_articleId;
} }
@ -176,4 +186,8 @@ public class OfflineArticlePager extends Fragment {
out.putBoolean("isCat", m_isCat); out.putBoolean("isCat", m_isCat);
} }
public void setSearchQuery(String searchQuery) {
m_searchQuery = searchQuery;
}
} }

View File

@ -132,9 +132,6 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
} }
public void onCatSelected(int catId, boolean openAsFeed) { public void onCatSelected(int catId, boolean openAsFeed) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
if (openAsFeed) { if (openAsFeed) {
onFeedSelected(catId, true, true); onFeedSelected(catId, true, true);
} else { } else {
@ -144,15 +141,17 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} else { } else {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
OfflineFeedsFragment ff = new OfflineFeedsFragment(catId); OfflineFeedsFragment ff = new OfflineFeedsFragment(catId);
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS); ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
}
}
ft.addToBackStack(null); ft.addToBackStack(null);
ft.commit(); ft.commit();
}
}
} }
public void onFeedSelected(int feedId) { public void onFeedSelected(int feedId) {
@ -171,9 +170,13 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} else { } else {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
// TODO open OfflineHeadlinesFragment on R.id.headlines_fragment 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 { } 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 { } else {
refresh(); refresh();

View File

@ -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);
}
}

View File

@ -293,7 +293,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
feedClause = "feed_id = ?"; 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+")", 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[] { "articles.*", "feeds.title AS feed_title" }, feedClause,
new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); 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); int articleId = cursor.getInt(0);
if (!m_activity.isSmallScreen()) { if (getActivity().findViewById(R.id.article_fragment) != null) {
m_activeArticleId = articleId; m_activeArticleId = articleId;
} }
if (!m_combinedMode) { if (!m_combinedMode) {
m_listener.onArticleSelected(articleId); 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(); refresh();
@ -600,13 +608,17 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
public void setActiveArticleId(int articleId) { public void setActiveArticleId(int articleId) {
m_activeArticleId = 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) { if (list != null) {
list.setSelection(getArticleIdPosition(articleId)); list.setSelection(getArticleIdPosition(articleId));
} }
} catch (NullPointerException e) {
// invoked before view is created, nvm
}
} }
public Cursor getArticleAtPosition(int position) { public Cursor getArticleAtPosition(int position) {
@ -644,7 +656,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
public void setSearchQuery(String query) { public void setSearchQuery(String query) {
if (!m_searchQuery.equals(query)) { if (!m_searchQuery.equals(query)) {
m_searchQuery = query; m_searchQuery = query;
refresh();
} }
} }