tt-rss-android/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java

151 lines
4.4 KiB
Java
Raw Normal View History

package org.fox.ttrss.offline;
2012-09-17 19:20:59 +00:00
import org.fox.ttrss.GlobalState;
import org.fox.ttrss.HeadlinesFragment;
import org.fox.ttrss.R;
import android.content.Intent;
import android.content.SharedPreferences;
2012-09-17 19:20:59 +00:00
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.os.Bundle;
import android.preference.PreferenceManager;
2012-09-17 19:20:59 +00:00
import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
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");
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();
2012-09-17 19:20:59 +00:00
Cursor c;
if (isCat) {
c = getCatById(feedId);
} else {
c = getFeedById(feedId);
}
2012-09-17 19:20:59 +00:00
if (c != null) {
setTitle(c.getString(c.getColumnIndex("title")));
c.close();
}
}
}
setLoadingStatus(R.string.blank, false);
findViewById(R.id.loading_container).setVisibility(View.GONE);
initMenu();
}
@Override
public void onArticleSelected(int articleId, boolean open) {
2012-09-17 19:20:59 +00:00
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID
+ " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
if (open) {
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
/* OfflineArticlePager af = new OfflineArticlePager(articleId, hf.getFeedId(), hf.getFeedIsCat());
af.setSearchQuery(hf.getSearchQuery());
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
2012-09-17 19:20:59 +00:00
ft.commit(); */
OfflineArticlePager af = (OfflineArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
af.setArticleId(articleId);
} else {
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
hf.setActiveArticleId(articleId);
}
GlobalState.getInstance().m_selectedArticleId = articleId;
2012-09-17 19:20:59 +00:00
initMenu();
refresh();
}
@Override
protected void initMenu() {
super.initMenu();
if (m_menu != null) {
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.getSelectedArticleCount() == 0);
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.getSelectedArticleCount() != 0);
Fragment af = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
}
}
@Override
public void onArticleSelected(int articleId) {
onArticleSelected(articleId, true);
}
}