193 lines
4.8 KiB
Java
193 lines
4.8 KiB
Java
package org.fox.ttrss.offline;
|
|
|
|
import org.fox.ttrss.CommonActivity;
|
|
import org.fox.ttrss.R;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.database.Cursor;
|
|
import android.os.Bundle;
|
|
import android.preference.PreferenceManager;
|
|
import android.provider.BaseColumns;
|
|
import android.util.Log;
|
|
import android.view.Menu;
|
|
import android.view.MenuInflater;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
|
|
public class OfflineActivity extends CommonActivity {
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
protected SharedPreferences m_prefs;
|
|
protected Menu m_menu;
|
|
protected boolean m_unreadOnly;
|
|
|
|
@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.online);
|
|
|
|
setLoadingStatus(R.string.blank, false);
|
|
findViewById(R.id.loading_container).setVisibility(View.GONE);
|
|
|
|
initMenu();
|
|
|
|
Intent intent = getIntent();
|
|
|
|
if (intent.getExtras() != null) {
|
|
if (intent.getBooleanExtra("initial", false)) {
|
|
intent = new Intent(OfflineActivity.this, OfflineFeedsActivity.class);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
|
|
|
startActivityForResult(intent, 0);
|
|
finish();
|
|
}
|
|
}
|
|
|
|
if (savedInstanceState != null) {
|
|
m_unreadOnly = savedInstanceState.getBoolean("unreadOnly");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onSaveInstanceState(Bundle out) {
|
|
super.onSaveInstanceState(out);
|
|
|
|
out.putBoolean("unreadOnly", m_unreadOnly);
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
switch (item.getItemId()) {
|
|
case R.id.go_online:
|
|
switchOnline();
|
|
return true;
|
|
default:
|
|
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
MenuInflater inflater = getMenuInflater();
|
|
inflater.inflate(R.menu.offline_menu, menu);
|
|
|
|
m_menu = menu;
|
|
|
|
initMenu();
|
|
|
|
return true;
|
|
}
|
|
|
|
public boolean getUnreadOnly() {
|
|
return m_unreadOnly;
|
|
}
|
|
|
|
protected void initMenu() {
|
|
if (m_menu != null) {
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
|
m_menu.setGroupVisible(R.id.menu_group_article, false);
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
|
}
|
|
}
|
|
|
|
private void switchOnline() {
|
|
SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
|
|
SharedPreferences.Editor editor = localPrefs.edit();
|
|
editor.putBoolean("offline_mode_active", false);
|
|
editor.commit();
|
|
|
|
Intent refresh = new Intent(this, org.fox.ttrss.OnlineActivity.class);
|
|
startActivity(refresh);
|
|
finish();
|
|
}
|
|
|
|
protected Cursor getArticleById(int articleId) {
|
|
Cursor c = getReadableDb().query("articles", null,
|
|
BaseColumns._ID + "=?",
|
|
new String[] { String.valueOf(articleId) }, null, null, null);
|
|
|
|
c.moveToFirst();
|
|
|
|
return c;
|
|
}
|
|
|
|
protected Cursor getFeedById(int feedId) {
|
|
Cursor c = getReadableDb().query("feeds", null,
|
|
BaseColumns._ID + "=?",
|
|
new String[] { String.valueOf(feedId) }, null, null, null);
|
|
|
|
c.moveToFirst();
|
|
|
|
return c;
|
|
}
|
|
|
|
protected Cursor getCatById(int catId) {
|
|
Cursor c = getReadableDb().query("categories", null,
|
|
BaseColumns._ID + "=?",
|
|
new String[] { String.valueOf(catId) }, null, null, null);
|
|
|
|
c.moveToFirst();
|
|
|
|
return c;
|
|
}
|
|
|
|
protected Intent getShareIntent(Cursor article) {
|
|
String title = article.getString(article.getColumnIndex("title"));
|
|
String link = article.getString(article.getColumnIndex("link"));
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType("text/plain");
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, title);
|
|
intent.putExtra(Intent.EXTRA_TEXT, link);
|
|
|
|
return intent;
|
|
}
|
|
|
|
protected void shareArticle(int articleId) {
|
|
|
|
Cursor article = getArticleById(articleId);
|
|
|
|
if (article != null) {
|
|
shareArticle(article);
|
|
article.close();
|
|
}
|
|
}
|
|
|
|
private void shareArticle(Cursor article) {
|
|
if (article != null) {
|
|
Intent intent = getShareIntent(article);
|
|
|
|
startActivity(Intent.createChooser(intent,
|
|
getString(R.id.share_article)));
|
|
}
|
|
}
|
|
|
|
protected int getSelectedArticleCount() {
|
|
Cursor c = getReadableDb().query("articles",
|
|
new String[] { "COUNT(*)" }, "selected = 1", null, null, null,
|
|
null);
|
|
c.moveToFirst();
|
|
int selected = c.getInt(0);
|
|
c.close();
|
|
|
|
return selected;
|
|
}
|
|
|
|
}
|