2011-12-05 19:19:11 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
import org.fox.ttrss.OnlineServices.RelativeArticle;
|
2011-12-06 10:24:57 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
2011-12-06 16:07:14 +00:00
|
|
|
import android.app.NotificationManager;
|
2011-12-16 18:06:07 +00:00
|
|
|
import android.content.Context;
|
2011-12-05 19:19:11 +00:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2012-01-17 15:43:11 +00:00
|
|
|
import android.content.res.Configuration;
|
2011-12-06 06:03:55 +00:00
|
|
|
import android.database.Cursor;
|
2011-12-05 19:19:11 +00:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.database.sqlite.SQLiteStatement;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.provider.BaseColumns;
|
2011-12-10 07:22:27 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
2011-12-05 19:19:11 +00:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
import android.util.Log;
|
2011-12-09 18:49:12 +00:00
|
|
|
import android.view.ActionMode;
|
2011-12-05 19:19:11 +00:00
|
|
|
import android.view.Display;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2012-01-17 09:54:52 +00:00
|
|
|
import android.view.ViewGroup;
|
2011-12-05 19:19:11 +00:00
|
|
|
import android.view.animation.AnimationUtils;
|
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
public class OfflineActivity extends FragmentActivity implements
|
|
|
|
OfflineServices {
|
2011-12-05 19:19:11 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
private SharedPreferences m_prefs;
|
|
|
|
private String m_themeName = "";
|
|
|
|
private Menu m_menu;
|
|
|
|
private boolean m_smallScreenMode;
|
|
|
|
private boolean m_unreadOnly = true;
|
|
|
|
private boolean m_unreadArticlesOnly = true;
|
|
|
|
private boolean m_compatMode = false;
|
|
|
|
private boolean m_enableCats = false;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
private int m_activeFeedId = 0;
|
|
|
|
private int m_selectedArticleId = 0;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
private SQLiteDatabase m_readableDb;
|
|
|
|
private SQLiteDatabase m_writableDb;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-05 19:19:11 +00:00
|
|
|
public boolean isSmallScreen() {
|
|
|
|
return m_smallScreenMode;
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-09 18:49:12 +00:00
|
|
|
private ActionMode m_headlinesActionMode;
|
2011-12-09 19:28:37 +00:00
|
|
|
private HeadlinesActionModeCallback m_headlinesActionModeCallback;
|
|
|
|
|
|
|
|
private class HeadlinesActionModeCallback implements ActionMode.Callback {
|
2011-12-09 18:49:12 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
deselectAllArticles();
|
|
|
|
m_headlinesActionMode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.headlines_action_menu, menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
onOptionsItemSelected(item);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2011-12-07 12:30:06 +00:00
|
|
|
initDatabase();
|
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
m_prefs = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(getApplicationContext());
|
2011-12-05 19:19:11 +00:00
|
|
|
|
|
|
|
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
|
|
|
setTheme(R.style.DarkTheme);
|
|
|
|
} else {
|
|
|
|
setTheme(R.style.LightTheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
NotificationManager nmgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
2011-12-06 16:07:14 +00:00
|
|
|
nmgr.cancel(OfflineDownloadService.NOTIFY_DOWNLOADING);
|
2011-12-05 19:19:11 +00:00
|
|
|
|
|
|
|
m_themeName = m_prefs.getString("theme", "THEME_DARK");
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
m_unreadOnly = savedInstanceState.getBoolean("unreadOnly");
|
2011-12-07 08:29:19 +00:00
|
|
|
m_unreadArticlesOnly = savedInstanceState
|
|
|
|
.getBoolean("unreadArticlesOnly");
|
2011-12-06 06:03:55 +00:00
|
|
|
m_activeFeedId = savedInstanceState.getInt("offlineActiveFeedId");
|
|
|
|
m_selectedArticleId = savedInstanceState.getInt("offlineArticleId");
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
m_enableCats = m_prefs.getBoolean("enable_cats", false);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2012-01-17 15:43:11 +00:00
|
|
|
m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
|
|
|
|
Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
setContentView(R.layout.main);
|
|
|
|
|
|
|
|
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
|
|
|
|
Log.d(TAG, "m_compatMode=" + m_compatMode);
|
|
|
|
|
|
|
|
if (!m_compatMode) {
|
2012-01-17 09:54:52 +00:00
|
|
|
new TransitionHelper((ViewGroup) findViewById(R.id.main));
|
2011-12-09 19:28:37 +00:00
|
|
|
|
|
|
|
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initMainMenu();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
|
|
|
|
2011-12-06 06:16:41 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
if (m_selectedArticleId != 0) {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
} else if (m_activeFeedId != 0) {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
} else {
|
2012-01-17 09:54:52 +00:00
|
|
|
//findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
2011-12-07 08:29:19 +00:00
|
|
|
// findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if (m_enableCats && m_activeCategory == null) {
|
|
|
|
* findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
* findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
|
|
|
* } else {
|
|
|
|
* findViewById(R.id.cats_fragment).setVisibility(View.GONE); }
|
|
|
|
*/
|
|
|
|
|
2011-12-06 06:16:41 +00:00
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_selectedArticleId == 0) {
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if (!m_enableCats || m_activeCategory != null)
|
|
|
|
* findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
* else
|
|
|
|
* findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
*/
|
|
|
|
|
2011-12-06 06:16:41 +00:00
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:16:41 +00:00
|
|
|
} else {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
if (m_activeFeedId == 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
|
.beginTransaction();
|
|
|
|
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
2011-12-05 19:19:11 +00:00
|
|
|
ft.replace(R.id.feeds_fragment, frag);
|
|
|
|
ft.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void initDatabase() {
|
2011-12-05 19:19:11 +00:00
|
|
|
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
|
|
|
|
m_writableDb = dh.getWritableDatabase();
|
|
|
|
m_readableDb = dh.getReadableDatabase();
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-05 19:19:11 +00:00
|
|
|
public synchronized SQLiteDatabase getReadableDb() {
|
|
|
|
return m_readableDb;
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-05 19:19:11 +00:00
|
|
|
public synchronized SQLiteDatabase getWritableDb() {
|
|
|
|
return m_writableDb;
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void switchOnline() {
|
2011-12-16 18:06:07 +00:00
|
|
|
SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = localPrefs.edit();
|
2011-12-05 19:19:11 +00:00
|
|
|
editor.putBoolean("offline_mode_active", false);
|
|
|
|
editor.commit();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
Intent refresh = new Intent(this, MainActivity.class);
|
|
|
|
startActivity(refresh);
|
|
|
|
finish();
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-06 10:24:57 +00:00
|
|
|
public int getActiveFeedId() {
|
2011-12-06 06:03:55 +00:00
|
|
|
return m_activeFeedId;
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void setLoadingStatus(int status, boolean showProgress) {
|
2011-12-07 08:29:19 +00:00
|
|
|
TextView tv = (TextView) findViewById(R.id.loading_message);
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (tv != null) {
|
|
|
|
tv.setText(status);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
View pb = findViewById(R.id.loading_progress);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (pb != null) {
|
|
|
|
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
2011-12-07 08:29:19 +00:00
|
|
|
public void onSaveInstanceState(Bundle out) {
|
2011-12-05 19:19:11 +00:00
|
|
|
super.onSaveInstanceState(out);
|
|
|
|
|
|
|
|
out.putBoolean("unreadOnly", m_unreadOnly);
|
|
|
|
out.putBoolean("unreadArticlesOnly", m_unreadArticlesOnly);
|
2011-12-06 06:03:55 +00:00
|
|
|
out.putInt("offlineActiveFeedId", m_activeFeedId);
|
|
|
|
out.putInt("offlineArticleId", m_selectedArticleId);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void setUnreadOnly(boolean unread) {
|
2011-12-06 06:03:55 +00:00
|
|
|
m_unreadOnly = unread;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 09:26:19 +00:00
|
|
|
refreshViews();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if (!m_enableCats || m_activeCategory != null ) refreshFeeds(); else
|
|
|
|
* refreshCategories();
|
|
|
|
*/
|
2011-12-06 06:03:55 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-06 06:03:55 +00:00
|
|
|
public boolean getUnreadOnly() {
|
|
|
|
return m_unreadOnly;
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2011-12-07 12:30:06 +00:00
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
boolean needRefresh = !m_prefs.getString("theme", "THEME_DARK").equals(
|
|
|
|
m_themeName)
|
|
|
|
|| m_prefs.getBoolean("enable_cats", false) != m_enableCats;
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (needRefresh) {
|
|
|
|
Intent refresh = new Intent(this, OfflineActivity.class);
|
|
|
|
startActivity(refresh);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
2011-12-06 06:03:55 +00:00
|
|
|
inflater.inflate(R.menu.offline_menu, menu);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
m_menu = menu;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
initMainMenu();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
MenuItem item = menu.findItem(R.id.show_feeds);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
if (getUnreadOnly()) {
|
2011-12-05 19:19:11 +00:00
|
|
|
item.setTitle(R.string.menu_all_feeds);
|
|
|
|
} else {
|
|
|
|
item.setTitle(R.string.menu_unread_feeds);
|
2011-12-06 06:03:55 +00:00
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void setMenuLabel(int id, int labelId) {
|
2011-12-05 19:19:11 +00:00
|
|
|
MenuItem mi = m_menu.findItem(id);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (mi != null) {
|
|
|
|
mi.setTitle(labelId);
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
2011-12-07 05:51:10 +00:00
|
|
|
public void onBackPressed() {
|
2011-12-07 08:29:19 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
if (m_selectedArticleId != 0) {
|
|
|
|
closeArticle();
|
|
|
|
} else if (m_activeFeedId != 0) {
|
|
|
|
if (m_compatMode) {
|
|
|
|
findViewById(R.id.main).setAnimation(
|
|
|
|
AnimationUtils.loadAnimation(this,
|
|
|
|
R.anim.slide_right));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if (m_activeFeed != null && m_activeFeed.is_cat) {
|
|
|
|
* findViewById
|
|
|
|
* (R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
* findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
|
|
|
*
|
|
|
|
* refreshCategories(); } else {
|
|
|
|
*/
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
|
|
|
// }
|
2011-12-07 05:51:10 +00:00
|
|
|
m_activeFeedId = 0;
|
|
|
|
refreshViews();
|
2011-12-07 08:29:19 +00:00
|
|
|
initMainMenu();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_selectedArticleId != 0) {
|
|
|
|
closeArticle();
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if
|
|
|
|
* (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
*
|
|
|
|
* if (m_smallScreenMode) { if (m_selectedArticleId != 0) { closeArticle();
|
|
|
|
* } else if (m_activeFeedId != 0) { if (m_compatMode) {
|
|
|
|
* findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this,
|
|
|
|
* R.anim.slide_right)); }
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if (m_activeFeed != null && m_activeFeed.is_cat) {
|
|
|
|
* findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
* findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
|
|
|
*
|
|
|
|
* refreshCategories(); } else {
|
|
|
|
*//*
|
|
|
|
* findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
* findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE); //}
|
|
|
|
* m_activeFeedId = 0; refreshViews(); initMainMenu();
|
|
|
|
*
|
|
|
|
* } else { finish(); } } else { if (m_selectedArticleId != 0) {
|
|
|
|
* closeArticle(); } else { finish(); } }
|
|
|
|
*
|
|
|
|
* return false; } return super.onKeyDown(keyCode, event); }
|
|
|
|
*/
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private Cursor getArticleById(int articleId) {
|
2011-12-07 08:29:19 +00:00
|
|
|
Cursor c = getReadableDb().query("articles", null,
|
|
|
|
BaseColumns._ID + "=?",
|
2011-12-06 06:03:55 +00:00
|
|
|
new String[] { String.valueOf(articleId) }, null, null, null);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
c.moveToFirst();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
return c;
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void shareArticle(int articleId) {
|
2011-12-06 06:03:55 +00:00
|
|
|
|
|
|
|
Cursor article = getArticleById(articleId);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 09:26:19 +00:00
|
|
|
if (article != null) {
|
|
|
|
shareArticle(article);
|
|
|
|
article.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void shareArticle(Cursor article) {
|
2011-12-06 09:26:19 +00:00
|
|
|
|
|
|
|
if (article != null) {
|
|
|
|
String title = article.getString(article.getColumnIndex("title"));
|
|
|
|
String link = article.getString(article.getColumnIndex("link"));
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
intent.setType("text/plain");
|
2011-12-06 09:26:19 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, title);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, link);
|
2011-12-06 06:03:55 +00:00
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
startActivity(Intent.createChooser(intent,
|
|
|
|
getString(R.id.share_article)));
|
2011-12-06 09:26:19 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 09:26:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void refreshHeadlines() {
|
2011-12-07 08:29:19 +00:00
|
|
|
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.headlines_fragment);
|
2011-12-06 06:03:55 +00:00
|
|
|
|
2011-12-06 06:59:32 +00:00
|
|
|
if (ohf != null) {
|
|
|
|
ohf.refresh();
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2011-12-07 08:29:19 +00:00
|
|
|
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.headlines_fragment);
|
2011-12-06 06:59:32 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
switch (item.getItemId()) {
|
2011-12-09 19:19:04 +00:00
|
|
|
case android.R.id.home:
|
|
|
|
closeArticle();
|
|
|
|
return true;
|
2011-12-05 19:19:11 +00:00
|
|
|
case R.id.preferences:
|
|
|
|
Intent intent = new Intent(this, PreferencesActivity.class);
|
|
|
|
startActivityForResult(intent, 0);
|
|
|
|
return true;
|
|
|
|
case R.id.go_online:
|
|
|
|
switchOnline();
|
2011-12-06 06:03:55 +00:00
|
|
|
return true;
|
2011-12-06 06:59:32 +00:00
|
|
|
case R.id.headlines_select:
|
|
|
|
if (ohf != null) {
|
|
|
|
Dialog dialog = new Dialog(this);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.headlines_select_dialog);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
builder.setSingleChoiceItems(new String[] {
|
|
|
|
getString(R.string.headlines_select_all),
|
|
|
|
getString(R.string.headlines_select_unread),
|
|
|
|
getString(R.string.headlines_select_none) }, 0,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
switch (which) {
|
|
|
|
case 0:
|
|
|
|
SQLiteStatement stmtSelectAll = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET selected = 1 WHERE feed_id = ?");
|
|
|
|
stmtSelectAll.bindLong(1, m_activeFeedId);
|
|
|
|
stmtSelectAll.execute();
|
|
|
|
stmtSelectAll.close();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
SQLiteStatement stmtSelectUnread = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET selected = 1 WHERE feed_id = ? AND unread = 1");
|
|
|
|
stmtSelectUnread
|
|
|
|
.bindLong(1, m_activeFeedId);
|
|
|
|
stmtSelectUnread.execute();
|
|
|
|
stmtSelectUnread.close();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
deselectAllArticles();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshViews();
|
|
|
|
initMainMenu();
|
|
|
|
|
|
|
|
dialog.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-12-06 06:59:32 +00:00
|
|
|
dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.headlines_mark_as_read:
|
|
|
|
if (m_activeFeedId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = 0 WHERE feed_id = ?");
|
2011-12-06 06:59:32 +00:00
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
2011-12-06 09:26:19 +00:00
|
|
|
refreshViews();
|
2011-12-06 06:59:32 +00:00
|
|
|
}
|
|
|
|
return true;
|
2011-12-06 06:03:55 +00:00
|
|
|
case R.id.share_article:
|
|
|
|
shareArticle(m_selectedArticleId);
|
|
|
|
return true;
|
2011-12-06 06:59:32 +00:00
|
|
|
case R.id.toggle_marked:
|
|
|
|
if (m_selectedArticleId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET marked = NOT marked WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?");
|
2011-12-06 06:59:32 +00:00
|
|
|
stmt.bindLong(1, m_selectedArticleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
2011-12-06 09:26:19 +00:00
|
|
|
refreshViews();
|
2011-12-06 06:59:32 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_select_none:
|
2011-12-06 09:26:19 +00:00
|
|
|
deselectAllArticles();
|
|
|
|
return true;
|
2011-12-06 06:59:32 +00:00
|
|
|
case R.id.selection_toggle_unread:
|
2011-12-06 09:26:19 +00:00
|
|
|
if (getSelectedArticleCount() > 0 && m_activeFeedId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET unread = NOT unread WHERE selected = 1 AND feed_id = ?");
|
2011-12-06 09:26:19 +00:00
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
|
|
|
return true;
|
2011-12-06 06:59:32 +00:00
|
|
|
case R.id.selection_toggle_marked:
|
2011-12-06 09:26:19 +00:00
|
|
|
if (getSelectedArticleCount() > 0 && m_activeFeedId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET marked = NOT marked WHERE selected = 1 AND feed_id = ?");
|
2011-12-06 09:26:19 +00:00
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
|
|
|
return true;
|
2011-12-06 06:59:32 +00:00
|
|
|
case R.id.selection_toggle_published:
|
2011-12-06 09:26:19 +00:00
|
|
|
if (getSelectedArticleCount() > 0 && m_activeFeedId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET published = NOT published WHERE selected = 1 AND feed_id = ?");
|
2011-12-06 09:26:19 +00:00
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
2011-12-06 06:59:32 +00:00
|
|
|
return true;
|
|
|
|
case R.id.toggle_published:
|
|
|
|
if (m_selectedArticleId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET published = NOT published WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?");
|
2011-12-06 06:59:32 +00:00
|
|
|
stmt.bindLong(1, m_selectedArticleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
2011-12-06 09:26:19 +00:00
|
|
|
refreshViews();
|
2011-12-06 06:59:32 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.catchup_above:
|
2011-12-06 09:26:19 +00:00
|
|
|
if (m_selectedArticleId != 0 && m_activeFeedId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = 0 WHERE updated >= "
|
|
|
|
+ "(SELECT updated FROM articles WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?) AND feed_id = ?");
|
2011-12-06 09:26:19 +00:00
|
|
|
stmt.bindLong(1, m_selectedArticleId);
|
|
|
|
stmt.bindLong(2, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
2011-12-06 06:59:32 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.set_unread:
|
|
|
|
if (m_selectedArticleId != 0) {
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = 1 WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?");
|
2011-12-06 06:59:32 +00:00
|
|
|
stmt.bindLong(1, m_selectedArticleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
2011-12-06 09:26:19 +00:00
|
|
|
refreshViews();
|
2011-12-06 06:59:32 +00:00
|
|
|
}
|
|
|
|
return true;
|
2011-12-06 06:03:55 +00:00
|
|
|
case R.id.show_feeds:
|
|
|
|
setUnreadOnly(!getUnreadOnly());
|
|
|
|
|
|
|
|
if (getUnreadOnly()) {
|
|
|
|
item.setTitle(R.string.menu_all_feeds);
|
|
|
|
} else {
|
|
|
|
item.setTitle(R.string.menu_unread_feeds);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
return true;
|
|
|
|
default:
|
2011-12-07 08:29:19 +00:00
|
|
|
Log.d(TAG,
|
|
|
|
"onOptionsItemSelected, unhandled id=" + item.getItemId());
|
2011-12-05 19:19:11 +00:00
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void refreshFeeds() {
|
2011-12-07 08:29:19 +00:00
|
|
|
OfflineFeedsFragment frag = (OfflineFeedsFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.feeds_fragment);
|
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
if (frag != null) {
|
|
|
|
frag.refresh();
|
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
private void closeArticle() {
|
|
|
|
if (m_compatMode) {
|
2011-12-07 08:29:19 +00:00
|
|
|
findViewById(R.id.main).setAnimation(
|
|
|
|
AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_smallScreenMode) {
|
2011-12-07 08:29:19 +00:00
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
2011-12-05 19:19:11 +00:00
|
|
|
} else {
|
2011-12-06 11:46:15 +00:00
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-10 07:22:27 +00:00
|
|
|
// we don't want to lose selected article in headlines so we refresh them before setting selected id to 0
|
|
|
|
refreshViews();
|
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
m_selectedArticleId = 0;
|
2011-12-05 19:19:11 +00:00
|
|
|
|
|
|
|
initMainMenu();
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private int getSelectedArticleCount() {
|
2011-12-07 08:29:19 +00:00
|
|
|
Cursor c = getReadableDb().query("articles",
|
|
|
|
new String[] { "COUNT(*)" }, "selected = 1", null, null, null,
|
|
|
|
null);
|
2011-12-06 06:59:32 +00:00
|
|
|
c.moveToFirst();
|
2011-12-06 09:26:19 +00:00
|
|
|
int selected = c.getInt(0);
|
2011-12-06 06:59:32 +00:00
|
|
|
c.close();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 09:26:19 +00:00
|
|
|
return selected;
|
2011-12-06 06:59:32 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-05 19:19:11 +00:00
|
|
|
public void initMainMenu() {
|
|
|
|
if (m_menu != null) {
|
2011-12-07 08:29:19 +00:00
|
|
|
int numSelected = getSelectedArticleCount();
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
2011-12-07 08:29:19 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_article, false);
|
2011-12-06 06:03:55 +00:00
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
if (numSelected != 0) {
|
2011-12-09 18:49:12 +00:00
|
|
|
if (m_compatMode) {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
|
|
|
|
} else {
|
|
|
|
if (m_headlinesActionMode == null)
|
|
|
|
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
} else if (m_selectedArticleId != 0) {
|
2011-12-06 06:03:55 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_article, true);
|
2011-12-07 08:29:19 +00:00
|
|
|
} else if (m_activeFeedId != 0 /*|| m_activeCategory != null */) {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, true);
|
2011-12-06 06:03:55 +00:00
|
|
|
} else {
|
2011-12-07 08:29:19 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, true);
|
2011-12-06 06:03:55 +00:00
|
|
|
}
|
2011-12-09 18:49:12 +00:00
|
|
|
|
|
|
|
if (numSelected == 0 && m_headlinesActionMode != null) {
|
|
|
|
m_headlinesActionMode.finish();
|
|
|
|
}
|
2011-12-09 19:19:04 +00:00
|
|
|
|
|
|
|
if (!m_compatMode) {
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0);
|
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
m_readableDb.close();
|
|
|
|
m_writableDb.close();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void refreshViews() {
|
2011-12-06 09:26:19 +00:00
|
|
|
refreshFeeds();
|
|
|
|
refreshHeadlines();
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
2011-12-07 08:29:19 +00:00
|
|
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
|
|
|
.getMenuInfo();
|
|
|
|
|
|
|
|
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.headlines_fragment);
|
|
|
|
OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.feeds_fragment);
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.browse_articles:
|
|
|
|
// TODO cat stuff
|
|
|
|
return true;
|
|
|
|
case R.id.browse_feeds:
|
|
|
|
// TODO cat stuff
|
|
|
|
return true;
|
|
|
|
case R.id.catchup_category:
|
|
|
|
// TODO cat stuff
|
|
|
|
return true;
|
|
|
|
case R.id.catchup_feed:
|
|
|
|
if (ff != null) {
|
|
|
|
int feedId = ff.getFeedIdAtPosition(info.position);
|
|
|
|
|
|
|
|
if (feedId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = 0 WHERE feed_id = ?");
|
|
|
|
stmt.bindLong(1, feedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_unread:
|
|
|
|
if (getSelectedArticleCount() > 0 && m_activeFeedId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET unread = NOT unread WHERE selected = 1 AND feed_id = ?");
|
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
} else {
|
|
|
|
int articleId = hf.getArticleIdAtPosition(info.position);
|
|
|
|
if (articleId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = NOT unread WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?");
|
|
|
|
stmt.bindLong(1, articleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_marked:
|
|
|
|
if (getSelectedArticleCount() > 0 && m_activeFeedId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET marked = NOT marked WHERE selected = 1 AND feed_id = ?");
|
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
} else {
|
|
|
|
int articleId = hf.getArticleIdAtPosition(info.position);
|
|
|
|
if (articleId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET marked = NOT marked WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?");
|
2011-12-06 09:26:19 +00:00
|
|
|
stmt.bindLong(1, articleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
2011-12-07 08:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_published:
|
|
|
|
if (getSelectedArticleCount() > 0 && m_activeFeedId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb()
|
|
|
|
.compileStatement(
|
|
|
|
"UPDATE articles SET published = NOT published WHERE selected = 1 AND feed_id = ?");
|
|
|
|
stmt.bindLong(1, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
} else {
|
|
|
|
int articleId = hf.getArticleIdAtPosition(info.position);
|
|
|
|
if (articleId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET published = NOT published WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?");
|
|
|
|
stmt.bindLong(1, articleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.share_article:
|
|
|
|
Cursor article = hf.getArticleAtPosition(info.position);
|
|
|
|
|
|
|
|
if (article != null) {
|
|
|
|
shareArticle(article);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.catchup_above:
|
|
|
|
int articleId = hf.getArticleIdAtPosition(info.position);
|
|
|
|
|
|
|
|
if (articleId != 0 && m_activeFeedId != 0) {
|
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = 0 WHERE updated >= "
|
|
|
|
+ "(SELECT updated FROM articles WHERE "
|
|
|
|
+ BaseColumns._ID + " = ?) AND feed_id = ?");
|
|
|
|
stmt.bindLong(1, articleId);
|
|
|
|
stmt.bindLong(2, m_activeFeedId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
|
|
|
refreshViews();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
Log.d(TAG,
|
|
|
|
"onContextItemSelected, unhandled id=" + item.getItemId());
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 10:24:57 +00:00
|
|
|
@Override
|
2011-12-05 19:19:11 +00:00
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
2011-12-07 08:29:19 +00:00
|
|
|
int action = event.getAction();
|
|
|
|
int keyCode = event.getKeyCode();
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
|
|
|
if (action == KeyEvent.ACTION_DOWN) {
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
openArticle(nextId, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
|
|
|
if (action == KeyEvent.ACTION_UP) {
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
openArticle(prevId, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
private void deselectAllArticles() {
|
2011-12-06 06:59:32 +00:00
|
|
|
getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-07 08:29:19 +00:00
|
|
|
public int getRelativeArticleId(int baseId, int feedId,
|
|
|
|
OnlineServices.RelativeArticle mode) {
|
|
|
|
|
2011-12-06 10:24:57 +00:00
|
|
|
Cursor c;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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");
|
|
|
|
|
2011-12-06 10:24:57 +00:00
|
|
|
} else {
|
2011-12-07 08:29:19 +00:00
|
|
|
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");
|
2011-12-06 10:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int id = 0;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
if (c.moveToFirst()) {
|
2011-12-06 10:24:57 +00:00
|
|
|
id = c.getInt(0);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 10:24:57 +00:00
|
|
|
c.close();
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-06 06:03:55 +00:00
|
|
|
public void viewFeed(int feedId) {
|
|
|
|
m_activeFeedId = feedId;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
initMainMenu();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-06 06:59:32 +00:00
|
|
|
deselectAllArticles();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2011-12-07 08:29:19 +00:00
|
|
|
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
|
2011-12-05 19:19:11 +00:00
|
|
|
ft.replace(R.id.headlines_fragment, frag);
|
|
|
|
ft.commit();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-06 06:03:55 +00:00
|
|
|
public void openArticle(int articleId, int compatAnimation) {
|
|
|
|
m_selectedArticleId = articleId;
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
initMainMenu();
|
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.headlines_fragment);
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (hf != null) {
|
|
|
|
hf.setActiveArticleId(articleId);
|
|
|
|
}
|
2011-12-06 10:24:57 +00:00
|
|
|
|
2011-12-07 08:29:19 +00:00
|
|
|
SQLiteStatement stmt = getWritableDb().compileStatement(
|
|
|
|
"UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID
|
|
|
|
+ " = ?");
|
|
|
|
|
2011-12-06 10:24:57 +00:00
|
|
|
stmt.bindLong(1, articleId);
|
|
|
|
stmt.execute();
|
|
|
|
stmt.close();
|
2011-12-07 08:29:19 +00:00
|
|
|
|
2011-12-10 07:22:27 +00:00
|
|
|
Fragment frag;
|
|
|
|
|
|
|
|
if (m_smallScreenMode) {
|
|
|
|
frag = new OfflineArticlePager(articleId);
|
|
|
|
} else {
|
|
|
|
frag = new OfflineArticleFragment(articleId);
|
|
|
|
}
|
2011-12-07 08:29:19 +00:00
|
|
|
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2011-12-05 19:19:11 +00:00
|
|
|
ft.replace(R.id.article_fragment, frag);
|
|
|
|
ft.commit();
|
2011-12-10 07:22:27 +00:00
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
if (m_compatMode) {
|
|
|
|
if (compatAnimation == 0)
|
2011-12-07 08:29:19 +00:00
|
|
|
findViewById(R.id.main).setAnimation(
|
|
|
|
AnimationUtils.loadAnimation(this, R.anim.slide_left));
|
2011-12-05 19:19:11 +00:00
|
|
|
else
|
2011-12-07 08:29:19 +00:00
|
|
|
findViewById(R.id.main).setAnimation(
|
|
|
|
AnimationUtils.loadAnimation(this, compatAnimation));
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_smallScreenMode) {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-06 13:01:08 +00:00
|
|
|
@Override
|
2011-12-06 06:03:55 +00:00
|
|
|
public int getSelectedArticleId() {
|
|
|
|
return m_selectedArticleId;
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|
2011-12-10 07:22:27 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSelectedArticleId(int articleId) {
|
|
|
|
m_selectedArticleId = articleId;
|
|
|
|
refreshViews();
|
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
}
|