2011-09-07 05:56:46 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
import java.lang.reflect.Type;
|
2011-12-06 21:17:20 +00:00
|
|
|
import android.app.ActionBar;
|
2011-09-09 06:02:31 +00:00
|
|
|
import java.util.HashMap;
|
2011-12-05 12:19:24 +00:00
|
|
|
import java.util.List;
|
2011-11-23 17:19:35 +00:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
2011-09-09 06:02:31 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
import android.app.ActionBar.Tab;
|
2011-11-29 17:48:09 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
2011-12-06 16:07:14 +00:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.ComponentName;
|
2011-11-27 10:18:04 +00:00
|
|
|
import android.content.Context;
|
2011-11-29 17:48:09 +00:00
|
|
|
import android.content.DialogInterface;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.content.Intent;
|
2011-12-06 16:07:14 +00:00
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.ServiceConnection;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.content.SharedPreferences;
|
2011-12-05 12:19:24 +00:00
|
|
|
import android.content.pm.PackageInfo;
|
2011-12-06 11:29:57 +00:00
|
|
|
import android.database.Cursor;
|
2011-12-05 13:01:44 +00:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.database.sqlite.SQLiteStatement;
|
2011-11-29 02:37:06 +00:00
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.NetworkInfo;
|
2011-09-07 05:56:46 +00:00
|
|
|
import android.os.Bundle;
|
2011-12-06 16:07:14 +00:00
|
|
|
import android.os.IBinder;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2011-12-05 13:01:44 +00:00
|
|
|
import android.provider.BaseColumns;
|
2011-11-25 18:37:02 +00:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
2011-09-08 12:45:08 +00:00
|
|
|
import android.util.Log;
|
2011-11-26 07:11:24 +00:00
|
|
|
import android.view.Display;
|
2011-11-25 08:47:07 +00:00
|
|
|
import android.view.KeyEvent;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2011-11-22 14:30:09 +00:00
|
|
|
import android.view.View;
|
2011-11-26 09:29:19 +00:00
|
|
|
import android.view.animation.AnimationUtils;
|
2011-11-29 17:00:37 +00:00
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
2011-11-25 09:15:27 +00:00
|
|
|
import android.widget.LinearLayout;
|
2011-11-22 14:30:09 +00:00
|
|
|
import android.widget.TextView;
|
2011-09-07 05:56:46 +00:00
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
import com.google.gson.Gson;
|
2011-09-09 06:02:31 +00:00
|
|
|
import com.google.gson.JsonElement;
|
2011-11-22 14:30:09 +00:00
|
|
|
import com.google.gson.JsonObject;
|
2011-12-05 13:01:44 +00:00
|
|
|
import com.google.gson.reflect.TypeToken;
|
2011-09-09 06:02:31 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
public class MainActivity extends FragmentActivity implements OnlineServices {
|
2011-09-08 12:45:08 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
private SharedPreferences m_prefs;
|
|
|
|
private String m_themeName = "";
|
2011-11-23 16:38:21 +00:00
|
|
|
private String m_sessionId;
|
|
|
|
private Article m_selectedArticle;
|
|
|
|
private Feed m_activeFeed;
|
2011-11-28 17:14:50 +00:00
|
|
|
private FeedCategory m_activeCategory;
|
2011-11-23 17:19:35 +00:00
|
|
|
private Timer m_refreshTimer;
|
|
|
|
private RefreshTask m_refreshTask;
|
2011-11-24 05:59:11 +00:00
|
|
|
private Menu m_menu;
|
2011-11-26 07:11:24 +00:00
|
|
|
private boolean m_smallScreenMode;
|
2011-11-24 05:59:11 +00:00
|
|
|
private boolean m_unreadOnly = true;
|
2011-11-26 08:46:17 +00:00
|
|
|
private boolean m_unreadArticlesOnly = true;
|
2011-11-27 08:56:31 +00:00
|
|
|
private boolean m_compatMode = false;
|
2011-11-28 17:14:50 +00:00
|
|
|
private boolean m_enableCats = false;
|
2011-12-05 12:19:24 +00:00
|
|
|
private int m_isLicensed = -1;
|
2011-11-29 05:25:13 +00:00
|
|
|
private int m_apiLevel = 0;
|
2011-12-05 15:14:06 +00:00
|
|
|
private boolean m_isOffline = false;
|
2011-12-05 12:19:24 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
private ActionBar m_bar = null;
|
|
|
|
private Tab m_feedTab;
|
|
|
|
private Tab m_rootTab;
|
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
private SQLiteDatabase m_readableDb;
|
|
|
|
private SQLiteDatabase m_writableDb;
|
2011-12-06 16:07:14 +00:00
|
|
|
|
|
|
|
private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context content, Intent intent) {
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).
|
|
|
|
setMessage(R.string.dialog_offline_success).
|
|
|
|
setPositiveButton(R.string.dialog_offline_go, new Dialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Intent refresh = new Intent(MainActivity.this, OfflineActivity.class);
|
|
|
|
startActivity(refresh);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}).
|
|
|
|
setNegativeButton(R.string.dialog_cancel, new Dialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog dlg = builder.create();
|
|
|
|
dlg.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2011-12-05 13:01:44 +00:00
|
|
|
|
2011-11-27 12:22:03 +00:00
|
|
|
public void updateHeadlines() {
|
|
|
|
HeadlinesFragment frag = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
if (frag != null) {
|
|
|
|
frag.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-12-05 12:19:24 +00:00
|
|
|
public boolean getLicensed() {
|
|
|
|
return m_isLicensed == 1;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-29 05:25:13 +00:00
|
|
|
public int getApiLevel() {
|
|
|
|
return m_apiLevel;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private boolean hasPendingOfflineData() {
|
2011-12-06 11:29:57 +00:00
|
|
|
Cursor c = getReadableDb().query("articles",
|
|
|
|
new String[] { "COUNT(*)" }, "modified = 1", null, null, null, null);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
int modified = c.getInt(0);
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
return modified > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearPendingOfflineData() {
|
|
|
|
getWritableDb().execSQL("UPDATE articles SET modified = 0");
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private boolean hasOfflineData() {
|
2011-12-06 11:29:57 +00:00
|
|
|
Cursor c = getReadableDb().query("articles",
|
|
|
|
new String[] { "COUNT(*)" }, null, null, null, null, null);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
int modified = c.getInt(0);
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
return modified > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-27 13:20:27 +00:00
|
|
|
@SuppressWarnings({ "unchecked", "serial" })
|
2011-11-27 12:22:03 +00:00
|
|
|
public void saveArticleUnread(final Article article) {
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
|
|
|
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", String.valueOf(article.id));
|
2011-11-27 12:55:22 +00:00
|
|
|
put("mode", article.unread ? "1" : "0");
|
2011-11-27 12:22:03 +00:00
|
|
|
put("field", "2");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
2011-11-27 13:20:27 +00:00
|
|
|
@SuppressWarnings({ "unchecked", "serial" })
|
2011-11-27 12:22:03 +00:00
|
|
|
public void saveArticleMarked(final Article article) {
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
|
|
|
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", String.valueOf(article.id));
|
|
|
|
put("mode", article.marked ? "1" : "0");
|
|
|
|
put("field", "0");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
2011-11-27 13:20:27 +00:00
|
|
|
@SuppressWarnings({ "unchecked", "serial" })
|
2011-11-27 12:22:03 +00:00
|
|
|
public void saveArticlePublished(final Article article) {
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
|
|
|
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", String.valueOf(article.id));
|
|
|
|
put("mode", article.published ? "1" : "0");
|
|
|
|
put("field", "1");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
2011-11-29 11:09:27 +00:00
|
|
|
public static String articlesToIdString(ArticleList articles) {
|
|
|
|
String tmp = "";
|
|
|
|
|
|
|
|
for (Article a : articles)
|
|
|
|
tmp += String.valueOf(a.id) + ",";
|
|
|
|
|
|
|
|
return tmp.replaceAll(",$", "");
|
|
|
|
}
|
|
|
|
|
2011-11-29 12:40:23 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void catchupFeed(final Feed feed) {
|
|
|
|
Log.d(TAG, "catchupFeed=" + feed);
|
|
|
|
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (!m_enableCats || m_activeCategory != null)
|
|
|
|
refreshFeeds();
|
|
|
|
else
|
|
|
|
refreshCategories();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "catchupFeed");
|
|
|
|
put("feed_id", String.valueOf(feed.id));
|
|
|
|
if (feed.is_cat) put("is_cat", "1");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
2011-11-29 11:09:27 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-12-06 12:52:33 +00:00
|
|
|
private void toggleArticlesMarked(final ArticleList articles) {
|
2011-11-29 11:09:27 +00:00
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", articlesToIdString(articles));
|
|
|
|
put("mode", "2");
|
|
|
|
put("field", "0");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2011-12-06 12:52:33 +00:00
|
|
|
private void toggleArticlesUnread(final ArticleList articles) {
|
2011-11-29 11:09:27 +00:00
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", articlesToIdString(articles));
|
|
|
|
put("mode", "2");
|
|
|
|
put("field", "2");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2011-12-06 12:52:33 +00:00
|
|
|
private void toggleArticlesPublished(final ArticleList articles) {
|
2011-11-29 11:09:27 +00:00
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", articlesToIdString(articles));
|
|
|
|
put("mode", "2");
|
|
|
|
put("field", "1");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
}
|
|
|
|
|
2011-11-23 17:19:35 +00:00
|
|
|
private class RefreshTask extends TimerTask {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2011-11-29 02:37:06 +00:00
|
|
|
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
|
if (cm.getBackgroundDataSetting()) {
|
|
|
|
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
|
|
|
if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) {
|
|
|
|
|
|
|
|
if (!m_enableCats || m_activeCategory != null)
|
|
|
|
refreshFeeds();
|
|
|
|
else
|
|
|
|
refreshCategories();
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 17:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void refreshFeeds() {
|
2011-12-05 18:32:45 +00:00
|
|
|
if (m_sessionId != null) {
|
|
|
|
FeedsFragment frag = (FeedsFragment) getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
|
|
|
|
|
|
|
|
Log.d(TAG, "Refreshing feeds...");
|
|
|
|
|
|
|
|
if (frag != null) {
|
|
|
|
frag.refresh(true);
|
|
|
|
}
|
2011-11-23 17:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 17:14:50 +00:00
|
|
|
public synchronized void refreshCategories() {
|
|
|
|
FeedCategoriesFragment frag = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentById(R.id.cats_fragment);
|
|
|
|
|
|
|
|
Log.d(TAG, "Refreshing categories...");
|
|
|
|
|
|
|
|
if (frag != null) {
|
|
|
|
frag.refresh(true);
|
|
|
|
}
|
|
|
|
}
|
2011-11-24 05:59:11 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void setUnreadOnly(boolean unread) {
|
2011-11-24 05:59:11 +00:00
|
|
|
m_unreadOnly = unread;
|
2011-11-28 17:14:50 +00:00
|
|
|
|
|
|
|
if (!m_enableCats || m_activeCategory != null )
|
|
|
|
refreshFeeds();
|
|
|
|
else
|
|
|
|
refreshCategories();
|
2011-11-24 05:59:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-24 05:59:11 +00:00
|
|
|
public boolean getUnreadOnly() {
|
|
|
|
return m_unreadOnly;
|
|
|
|
}
|
2011-11-26 08:46:17 +00:00
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
/* private void setUnreadArticlesOnly(boolean unread) {
|
2011-11-26 08:46:17 +00:00
|
|
|
m_unreadArticlesOnly = unread;
|
|
|
|
|
|
|
|
HeadlinesFragment frag = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
|
|
|
|
if (frag != null) frag.refresh(false);
|
2011-12-06 16:07:14 +00:00
|
|
|
} */
|
2011-11-24 05:59:11 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-26 08:46:17 +00:00
|
|
|
public boolean getUnreadArticlesOnly() {
|
|
|
|
return m_unreadArticlesOnly;
|
|
|
|
}
|
2011-11-24 05:59:11 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-23 17:19:35 +00:00
|
|
|
public String getSessionId() {
|
2011-09-09 06:02:31 +00:00
|
|
|
return m_sessionId;
|
|
|
|
}
|
2011-11-22 14:30:09 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-28 09:45:19 +00:00
|
|
|
public boolean isSmallScreen() {
|
|
|
|
return m_smallScreenMode;
|
|
|
|
}
|
|
|
|
|
2011-09-09 16:36:09 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2011-09-08 10:23:44 +00:00
|
|
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-11-27 08:56:31 +00:00
|
|
|
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
2011-12-05 08:45:50 +00:00
|
|
|
setTheme(R.style.DarkTheme);
|
2011-09-08 10:23:44 +00:00
|
|
|
} else {
|
2011-12-05 08:45:50 +00:00
|
|
|
setTheme(R.style.LightTheme);
|
2011-09-08 10:23:44 +00:00
|
|
|
}
|
|
|
|
|
2011-11-26 08:17:38 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
m_themeName = m_prefs.getString("theme", "THEME_DARK");
|
2011-11-22 14:30:09 +00:00
|
|
|
|
2011-09-08 12:45:08 +00:00
|
|
|
if (savedInstanceState != null) {
|
2011-09-09 06:02:31 +00:00
|
|
|
m_sessionId = savedInstanceState.getString("sessionId");
|
2011-11-25 10:13:10 +00:00
|
|
|
m_unreadOnly = savedInstanceState.getBoolean("unreadOnly");
|
|
|
|
m_activeFeed = savedInstanceState.getParcelable("activeFeed");
|
2011-11-25 10:32:32 +00:00
|
|
|
m_selectedArticle = savedInstanceState.getParcelable("selectedArticle");
|
2011-11-26 08:46:17 +00:00
|
|
|
m_unreadArticlesOnly = savedInstanceState.getBoolean("unreadArticlesOnly");
|
2011-11-28 17:14:50 +00:00
|
|
|
m_activeCategory = savedInstanceState.getParcelable("activeCategory");
|
2011-11-29 05:25:13 +00:00
|
|
|
m_apiLevel = savedInstanceState.getInt("apiLevel");
|
2011-12-05 12:19:24 +00:00
|
|
|
m_isLicensed = savedInstanceState.getInt("isLicensed");
|
2011-09-08 10:23:44 +00:00
|
|
|
}
|
2011-11-23 10:55:05 +00:00
|
|
|
|
2011-11-28 17:14:50 +00:00
|
|
|
m_enableCats = m_prefs.getBoolean("enable_cats", false);
|
|
|
|
|
2011-11-26 15:04:54 +00:00
|
|
|
Display display = getWindowManager().getDefaultDisplay();
|
2011-11-26 07:11:24 +00:00
|
|
|
|
2011-11-30 10:43:02 +00:00
|
|
|
int width = display.getWidth();
|
|
|
|
int height = display.getHeight();
|
|
|
|
|
|
|
|
if (height > width) { int tmp = height; width = tmp; height = width; }
|
|
|
|
|
|
|
|
m_smallScreenMode = width < 960 || height < 720;
|
|
|
|
|
|
|
|
setContentView(R.layout.main);
|
2011-12-05 17:22:31 +00:00
|
|
|
|
|
|
|
initDatabase();
|
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
IntentFilter filter = new IntentFilter("org.fox.ttrss.intent.action.DownloadComplete");
|
|
|
|
filter.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
|
|
|
|
|
registerReceiver(m_broadcastReceiver, filter);
|
|
|
|
|
2011-12-05 18:54:54 +00:00
|
|
|
m_isOffline = m_prefs.getBoolean("offline_mode_active", false);
|
2011-11-26 07:11:24 +00:00
|
|
|
|
2011-12-05 15:14:06 +00:00
|
|
|
Log.d(TAG, "m_isOffline=" + m_isOffline);
|
2011-11-26 15:04:54 +00:00
|
|
|
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
|
2011-11-27 08:56:31 +00:00
|
|
|
Log.d(TAG, "m_compatMode=" + m_compatMode);
|
2011-11-23 10:55:05 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
|
|
|
|
m_bar = getActionBar();
|
|
|
|
|
|
|
|
m_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
|
|
|
m_bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
|
|
|
|
//m_bar.setDisplayHomeAsUpEnabled(true); TODO
|
|
|
|
|
2011-11-27 08:56:31 +00:00
|
|
|
if (!m_compatMode) {
|
2011-12-03 14:22:06 +00:00
|
|
|
new TransitionHelper((LinearLayout)findViewById(R.id.main));
|
2011-11-25 18:37:02 +00:00
|
|
|
}
|
2011-12-05 12:19:24 +00:00
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
if (m_isOffline) {
|
2011-12-05 19:19:11 +00:00
|
|
|
Intent refresh = new Intent(this, OfflineActivity.class);
|
|
|
|
startActivity(refresh);
|
|
|
|
finish();
|
2011-12-05 17:22:31 +00:00
|
|
|
} else {
|
2011-12-05 19:19:11 +00:00
|
|
|
List<PackageInfo> pkgs = getPackageManager().getInstalledPackages(0);
|
|
|
|
|
|
|
|
for (PackageInfo p : pkgs) {
|
|
|
|
if ("org.fox.ttrss.key".equals(p.packageName)) {
|
|
|
|
m_isLicensed = 1;
|
|
|
|
Log.d(TAG, "license apk found");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 17:22:31 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
if (!m_compatMode && !m_smallScreenMode) {
|
|
|
|
if (m_enableCats && !m_prefs.getBoolean("browse_cats_like_feeds", false)) {
|
|
|
|
m_rootTab = m_bar.newTab().setText("Categories").setTabListener(new RootTabListener());
|
|
|
|
m_bar.addTab(m_rootTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
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_activeFeed != null) {
|
|
|
|
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 {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
//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-11-26 07:11:24 +00:00
|
|
|
} else {
|
2011-12-05 17:22:31 +00:00
|
|
|
if (m_selectedArticle == null) {
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (!m_enableCats || m_activeCategory != null)
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
2011-11-28 17:14:50 +00:00
|
|
|
|
|
|
|
} else {
|
2011-12-05 17:22:31 +00:00
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
2011-11-28 17:14:50 +00:00
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
2011-11-26 07:11:24 +00:00
|
|
|
}
|
2011-12-05 18:54:54 +00:00
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
if (m_sessionId != null) {
|
|
|
|
loginSuccess();
|
2011-11-28 18:36:13 +00:00
|
|
|
} else {
|
2011-12-05 17:22:31 +00:00
|
|
|
login();
|
2011-11-28 18:36:13 +00:00
|
|
|
}
|
2011-11-26 07:11:24 +00:00
|
|
|
}
|
2011-12-05 19:19:11 +00:00
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void initDatabase() {
|
2011-12-05 13:01:44 +00:00
|
|
|
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
|
|
|
|
m_writableDb = dh.getWritableDatabase();
|
|
|
|
m_readableDb = dh.getReadableDatabase();
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
public synchronized SQLiteDatabase getReadableDb() {
|
|
|
|
return m_readableDb;
|
|
|
|
}
|
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
public synchronized SQLiteDatabase getWritableDb() {
|
|
|
|
return m_writableDb;
|
2011-09-09 16:36:09 +00:00
|
|
|
}
|
2011-12-05 15:05:11 +00:00
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-12-06 12:52:33 +00:00
|
|
|
private void switchOffline() {
|
2011-12-05 13:01:44 +00:00
|
|
|
|
2011-12-06 12:15:55 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this).
|
|
|
|
setMessage(R.string.dialog_offline_switch_prompt).
|
|
|
|
setPositiveButton(R.string.dialog_offline_go, new Dialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
if (m_sessionId != null) {
|
2011-12-06 16:07:14 +00:00
|
|
|
Log.d(TAG, "offline: starting");
|
2011-12-05 18:54:54 +00:00
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
ServiceConnection m_serviceConnection = new ServiceConnection() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onServiceDisconnected(ComponentName name) {
|
|
|
|
Log.d(TAG, "download service disconnected");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
|
Log.d(TAG, "download service connected");
|
|
|
|
//((OfflineDownloadService.LocalBinder)service).getService().download();
|
2011-12-06 12:15:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
Intent intent = new Intent(MainActivity.this, OfflineDownloadService.class);
|
|
|
|
intent.putExtra("sessionId", m_sessionId);
|
2011-12-06 12:15:55 +00:00
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
startService(intent);
|
|
|
|
|
|
|
|
//bindService(intent, m_serviceConnection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 12:15:55 +00:00
|
|
|
}).
|
|
|
|
setNegativeButton(R.string.dialog_cancel, new Dialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog dlg = builder.create();
|
|
|
|
dlg.show();
|
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void switchOfflineSuccess() {
|
2011-12-05 17:22:31 +00:00
|
|
|
logout();
|
|
|
|
//setLoadingStatus(R.string.blank, false);
|
|
|
|
|
2011-12-05 18:54:54 +00:00
|
|
|
SharedPreferences.Editor editor = m_prefs.edit();
|
|
|
|
editor.putBoolean("offline_mode_active", true);
|
|
|
|
editor.commit();
|
|
|
|
|
2011-12-05 19:19:11 +00:00
|
|
|
Intent refresh = new Intent(this, OfflineActivity.class);
|
2011-12-05 18:54:54 +00:00
|
|
|
startActivity(refresh);
|
|
|
|
finish();
|
2011-12-05 17:22:31 +00:00
|
|
|
|
2011-12-05 13:01:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void setLoadingStatus(int status, boolean showProgress) {
|
2011-11-22 14:30:09 +00:00
|
|
|
TextView tv = (TextView)findViewById(R.id.loading_message);
|
|
|
|
|
|
|
|
if (tv != null) {
|
|
|
|
tv.setText(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
View pb = findViewById(R.id.loading_progress);
|
|
|
|
|
|
|
|
if (pb != null) {
|
|
|
|
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState (Bundle out) {
|
|
|
|
super.onSaveInstanceState(out);
|
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
out.putString("sessionId", m_sessionId);
|
2011-11-25 10:13:10 +00:00
|
|
|
out.putBoolean("unreadOnly", m_unreadOnly);
|
|
|
|
out.putParcelable("activeFeed", m_activeFeed);
|
2011-11-25 10:32:32 +00:00
|
|
|
out.putParcelable("selectedArticle", m_selectedArticle);
|
2011-11-26 08:46:17 +00:00
|
|
|
out.putBoolean("unreadArticlesOnly", m_unreadArticlesOnly);
|
2011-11-28 17:14:50 +00:00
|
|
|
out.putParcelable("activeCategory", m_activeCategory);
|
2011-11-29 05:25:13 +00:00
|
|
|
out.putInt("apiLevel", m_apiLevel);
|
2011-12-05 12:19:24 +00:00
|
|
|
out.putInt("isLicensed", m_isLicensed);
|
2011-09-08 10:23:44 +00:00
|
|
|
}
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2011-11-28 17:14:50 +00:00
|
|
|
boolean needRefresh = !m_prefs.getString("theme", "THEME_DARK").equals(m_themeName) ||
|
|
|
|
m_prefs.getBoolean("enable_cats", false) != m_enableCats;
|
|
|
|
|
|
|
|
if (needRefresh) {
|
2011-09-08 16:05:00 +00:00
|
|
|
Intent refresh = new Intent(this, MainActivity.class);
|
2011-09-08 10:23:44 +00:00
|
|
|
startActivity(refresh);
|
|
|
|
finish();
|
2011-11-29 04:12:43 +00:00
|
|
|
} else if (m_sessionId != null) {
|
|
|
|
m_refreshTask = new RefreshTask();
|
|
|
|
m_refreshTimer = new Timer("Refresh");
|
|
|
|
|
|
|
|
m_refreshTimer.schedule(m_refreshTask, 60*1000L, 120*1000L);
|
2011-11-26 06:31:14 +00:00
|
|
|
}
|
2011-09-08 10:23:44 +00:00
|
|
|
}
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.main_menu, menu);
|
2011-11-24 05:59:11 +00:00
|
|
|
|
|
|
|
m_menu = menu;
|
2011-11-25 10:13:10 +00:00
|
|
|
|
|
|
|
initMainMenu();
|
2011-11-26 08:46:17 +00:00
|
|
|
|
|
|
|
MenuItem item = menu.findItem(R.id.show_feeds);
|
|
|
|
|
|
|
|
if (getUnreadOnly()) {
|
|
|
|
item.setTitle(R.string.menu_all_feeds);
|
|
|
|
} else {
|
|
|
|
item.setTitle(R.string.menu_unread_feeds);
|
|
|
|
}
|
|
|
|
|
2011-11-30 09:59:23 +00:00
|
|
|
/* item = menu.findItem(R.id.show_all_articles);
|
2011-11-26 08:46:17 +00:00
|
|
|
|
|
|
|
if (getUnreadArticlesOnly()) {
|
|
|
|
item.setTitle(R.string.show_all_articles);
|
|
|
|
} else {
|
|
|
|
item.setTitle(R.string.show_unread_articles);
|
2011-11-30 09:59:23 +00:00
|
|
|
} */
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void setMenuLabel(int id, int labelId) {
|
2011-11-24 05:59:11 +00:00
|
|
|
MenuItem mi = m_menu.findItem(id);
|
|
|
|
|
|
|
|
if (mi != null) {
|
|
|
|
mi.setTitle(labelId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-25 08:47:07 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
closeArticle();
|
2011-12-05 19:19:11 +00:00
|
|
|
} else if (m_activeFeed != null) {
|
2011-11-27 08:56:31 +00:00
|
|
|
if (m_compatMode) {
|
|
|
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
|
|
|
}
|
2011-11-26 09:29:19 +00:00
|
|
|
|
2011-12-05 18:32:45 +00:00
|
|
|
if (m_activeFeed != null && m_activeFeed.is_cat) {
|
2011-11-29 10:02:16 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
refreshFeeds();
|
|
|
|
}
|
|
|
|
m_activeFeed = null;
|
2011-12-06 21:17:20 +00:00
|
|
|
|
|
|
|
|
2011-11-26 07:15:37 +00:00
|
|
|
initMainMenu();
|
2011-11-28 17:14:50 +00:00
|
|
|
|
|
|
|
} else if (m_activeCategory != null) {
|
|
|
|
if (m_compatMode) {
|
|
|
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
|
|
|
}
|
|
|
|
|
2011-11-28 18:36:13 +00:00
|
|
|
closeCategory();
|
2011-11-28 17:14:50 +00:00
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
2011-11-25 08:47:07 +00:00
|
|
|
} else {
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
closeArticle();
|
2011-11-28 18:36:13 +00:00
|
|
|
} else if (m_activeCategory != null) {
|
2011-12-06 21:17:20 +00:00
|
|
|
closeCategory();
|
2011-11-26 07:11:24 +00:00
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
2011-11-25 08:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2011-11-28 18:36:13 +00:00
|
|
|
private void closeCategory() {
|
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
if (m_bar != null) {
|
|
|
|
m_bar.selectTab(m_rootTab);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
m_activeCategory = null;
|
|
|
|
|
|
|
|
initMainMenu();
|
|
|
|
refreshCategories();
|
|
|
|
}
|
2011-11-28 18:36:13 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 17:00:37 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-09-08 10:23:44 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2011-12-06 06:03:55 +00:00
|
|
|
final HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
2011-11-29 11:09:27 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.preferences:
|
|
|
|
Intent intent = new Intent(this, PreferencesActivity.class);
|
|
|
|
startActivityForResult(intent, 0);
|
|
|
|
return true;
|
2011-11-24 16:11:10 +00:00
|
|
|
case R.id.update_feeds:
|
2011-11-29 05:25:13 +00:00
|
|
|
if (!m_enableCats || m_activeCategory != null )
|
|
|
|
refreshFeeds();
|
|
|
|
else
|
|
|
|
refreshCategories();
|
2011-11-24 06:06:47 +00:00
|
|
|
return true;
|
2011-11-24 13:04:58 +00:00
|
|
|
case R.id.logout:
|
|
|
|
logout();
|
|
|
|
return true;
|
|
|
|
case R.id.login:
|
|
|
|
login();
|
|
|
|
return true;
|
2011-12-05 15:05:11 +00:00
|
|
|
case R.id.go_offline:
|
|
|
|
switchOffline();
|
2011-12-05 13:01:44 +00:00
|
|
|
return true;
|
2011-11-24 14:57:44 +00:00
|
|
|
case R.id.close_article:
|
|
|
|
closeArticle();
|
|
|
|
return true;
|
2011-11-28 18:36:13 +00:00
|
|
|
case R.id.back_to_categories:
|
|
|
|
closeCategory();
|
|
|
|
return true;
|
2011-11-29 17:48:09 +00:00
|
|
|
case R.id.headlines_select:
|
|
|
|
if (hf != null) {
|
|
|
|
Dialog dialog = new Dialog(this);
|
2011-12-06 12:15:55 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setTitle(R.string.headlines_select_dialog)
|
|
|
|
.setSingleChoiceItems(new String[] { getString(R.string.headlines_select_all),
|
2011-11-29 17:48:09 +00:00
|
|
|
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:
|
2011-12-06 06:03:55 +00:00
|
|
|
hf.setSelection(HeadlinesFragment.ArticlesSelection.ALL);
|
2011-11-29 17:48:09 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-12-06 06:03:55 +00:00
|
|
|
hf.setSelection(HeadlinesFragment.ArticlesSelection.UNREAD);
|
2011-11-29 17:48:09 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2011-12-06 06:03:55 +00:00
|
|
|
hf.setSelection(HeadlinesFragment.ArticlesSelection.NONE);
|
2011-11-29 17:48:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
dialog.cancel();
|
2011-12-06 06:44:30 +00:00
|
|
|
initMainMenu();
|
2011-11-29 17:48:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
}
|
2011-11-29 11:09:27 +00:00
|
|
|
return true;
|
2011-11-30 09:59:23 +00:00
|
|
|
case R.id.headlines_mark_as_read:
|
2011-11-29 11:09:27 +00:00
|
|
|
if (hf != null) {
|
2011-11-30 09:59:23 +00:00
|
|
|
ArticleList articles = hf.getUnreadArticles();
|
2011-11-29 11:09:27 +00:00
|
|
|
|
2011-11-30 09:59:23 +00:00
|
|
|
for (Article a : articles)
|
|
|
|
a.unread = false;
|
2011-11-30 15:46:12 +00:00
|
|
|
|
|
|
|
hf.notifyUpdated();
|
2011-11-30 09:59:23 +00:00
|
|
|
|
2011-11-30 11:45:23 +00:00
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
2011-11-30 09:59:23 +00:00
|
|
|
|
|
|
|
final String articleIds = articlesToIdString(articles);
|
|
|
|
|
2011-11-29 17:00:37 +00:00
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
2011-11-30 09:59:23 +00:00
|
|
|
put("article_ids", articleIds);
|
2011-11-29 17:00:37 +00:00
|
|
|
put("mode", "0");
|
|
|
|
put("field", "2");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
2011-11-29 11:09:27 +00:00
|
|
|
}
|
|
|
|
return true;
|
2011-11-25 10:46:11 +00:00
|
|
|
case R.id.share_article:
|
|
|
|
shareArticle(m_selectedArticle);
|
|
|
|
return true;
|
2011-11-27 12:22:03 +00:00
|
|
|
case R.id.toggle_marked:
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
m_selectedArticle.marked = !m_selectedArticle.marked;
|
|
|
|
saveArticleMarked(m_selectedArticle);
|
|
|
|
updateHeadlines();
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-30 19:11:56 +00:00
|
|
|
case R.id.selection_select_none:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
selected.clear();
|
2011-12-07 05:14:13 +00:00
|
|
|
initMainMenu();
|
2011-11-30 19:11:56 +00:00
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-30 08:54:42 +00:00
|
|
|
case R.id.selection_toggle_unread:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
for (Article a : selected)
|
|
|
|
a.unread = !a.unread;
|
|
|
|
|
|
|
|
toggleArticlesUnread(selected);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 07:22:27 +00:00
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_marked:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
for (Article a : selected)
|
|
|
|
a.marked = !a.marked;
|
|
|
|
|
|
|
|
toggleArticlesMarked(selected);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_published:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
for (Article a : selected)
|
|
|
|
a.published = !a.published;
|
|
|
|
|
|
|
|
toggleArticlesPublished(selected);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-27 12:22:03 +00:00
|
|
|
case R.id.toggle_published:
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
m_selectedArticle.published = !m_selectedArticle.published;
|
|
|
|
saveArticlePublished(m_selectedArticle);
|
|
|
|
updateHeadlines();
|
|
|
|
}
|
|
|
|
return true;
|
2011-12-01 05:32:17 +00:00
|
|
|
case R.id.catchup_above:
|
|
|
|
if (hf != null) {
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
ArticleList articles = hf.getAllArticles();
|
|
|
|
ArticleList tmp = new ArticleList();
|
|
|
|
for (Article a : articles) {
|
|
|
|
a.unread = false;
|
|
|
|
tmp.add(a);
|
|
|
|
if (m_selectedArticle.id == a.id)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tmp.size() > 0) {
|
|
|
|
toggleArticlesUnread(tmp);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-27 12:55:22 +00:00
|
|
|
case R.id.set_unread:
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
m_selectedArticle.unread = true;
|
|
|
|
saveArticleUnread(m_selectedArticle);
|
|
|
|
updateHeadlines();
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-24 05:59:11 +00:00
|
|
|
case R.id.show_feeds:
|
2011-11-26 08:46:17 +00:00
|
|
|
setUnreadOnly(!getUnreadOnly());
|
|
|
|
|
2011-11-24 05:59:11 +00:00
|
|
|
if (getUnreadOnly()) {
|
2011-11-26 08:46:17 +00:00
|
|
|
item.setTitle(R.string.menu_all_feeds);
|
|
|
|
} else {
|
2011-11-24 05:59:11 +00:00
|
|
|
item.setTitle(R.string.menu_unread_feeds);
|
2011-11-26 08:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-11-30 09:59:23 +00:00
|
|
|
/* case R.id.show_all_articles:
|
2011-11-26 08:46:17 +00:00
|
|
|
setUnreadArticlesOnly(!getUnreadArticlesOnly());
|
|
|
|
|
|
|
|
if (getUnreadArticlesOnly()) {
|
|
|
|
item.setTitle(R.string.show_all_articles);
|
2011-11-24 06:06:47 +00:00
|
|
|
} else {
|
2011-11-26 08:46:17 +00:00
|
|
|
item.setTitle(R.string.show_unread_articles);
|
2011-11-24 05:59:11 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 09:59:23 +00:00
|
|
|
return true; */
|
2011-09-08 10:23:44 +00:00
|
|
|
default:
|
2011-11-30 19:06:11 +00:00
|
|
|
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
|
2011-09-08 10:23:44 +00:00
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2011-11-29 17:00:37 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void shareArticle(Article article) {
|
2011-11-25 10:46:11 +00:00
|
|
|
if (article != null) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
|
|
|
intent.setType("text/plain");
|
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, article.title);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, article.link);
|
|
|
|
|
|
|
|
startActivity(Intent.createChooser(intent, getString(R.id.share_article)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 18:36:13 +00:00
|
|
|
private void closeArticle() {
|
2011-11-27 08:56:31 +00:00
|
|
|
if (m_compatMode) {
|
|
|
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
|
|
|
}
|
|
|
|
|
2011-12-04 09:28:59 +00:00
|
|
|
//boolean browseCats = m_prefs.getBoolean("browse_cats_like_feeds", false);
|
2011-12-03 19:09:51 +00:00
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
2011-12-04 09:28:59 +00:00
|
|
|
|
|
|
|
if (m_activeFeed != null) {
|
|
|
|
if (m_activeFeed.is_cat) {
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
2011-11-26 07:11:24 +00:00
|
|
|
}
|
2011-11-25 10:32:32 +00:00
|
|
|
|
2011-11-25 11:38:12 +00:00
|
|
|
m_selectedArticle = null;
|
|
|
|
|
2011-11-25 10:32:32 +00:00
|
|
|
initMainMenu();
|
2011-11-25 11:03:14 +00:00
|
|
|
refreshFeeds();
|
2011-11-28 17:14:50 +00:00
|
|
|
|
2011-11-24 14:57:44 +00:00
|
|
|
}
|
2011-11-25 10:13:10 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-26 14:42:46 +00:00
|
|
|
public void initMainMenu() {
|
2011-11-25 10:13:10 +00:00
|
|
|
if (m_menu != null) {
|
|
|
|
if (m_sessionId != null) {
|
2011-12-07 05:14:13 +00:00
|
|
|
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
int numSelected = 0;
|
|
|
|
|
|
|
|
if (hf != null)
|
|
|
|
numSelected = hf.getSelectedArticles().size();
|
2011-11-29 14:41:12 +00:00
|
|
|
|
2011-11-29 06:46:36 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_logged_in, true);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_logged_out, false);
|
|
|
|
|
2011-12-07 05:14:13 +00:00
|
|
|
if (m_activeFeed == null) {
|
2011-11-29 06:46:36 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
2011-11-30 07:22:27 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
2011-11-29 06:46:36 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 05:14:13 +00:00
|
|
|
if (m_selectedArticle != null && numSelected == 0) {
|
2011-11-29 06:46:36 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_article, true);
|
|
|
|
|
2011-11-30 07:22:27 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
2011-11-29 06:46:36 +00:00
|
|
|
|
2011-12-07 05:14:13 +00:00
|
|
|
//if (m_smallScreenMode) {
|
2011-11-30 07:22:27 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
2011-12-07 05:14:13 +00:00
|
|
|
//} else {
|
|
|
|
// m_menu.setGroupVisible(R.id.menu_group_headlines, true);
|
|
|
|
//}
|
2011-11-29 06:46:36 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_article, false);
|
2011-11-30 07:22:27 +00:00
|
|
|
|
|
|
|
if (m_activeFeed != null) {
|
|
|
|
|
2011-12-07 05:14:13 +00:00
|
|
|
if (numSelected != 0) {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
|
2011-11-30 07:22:27 +00:00
|
|
|
} else {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, true);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
|
|
|
}
|
2011-12-07 05:14:13 +00:00
|
|
|
|
2011-11-30 07:22:27 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
|
|
|
} else {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, true);
|
|
|
|
}
|
|
|
|
|
2011-12-07 05:14:13 +00:00
|
|
|
/* if (!m_smallScreenMode || m_activeFeed == null) {
|
2011-11-29 06:46:36 +00:00
|
|
|
m_menu.findItem(R.id.show_feeds).setVisible(true);
|
|
|
|
m_menu.findItem(R.id.update_feeds).setVisible(true);
|
2011-12-07 05:14:13 +00:00
|
|
|
} */
|
2011-11-29 06:46:36 +00:00
|
|
|
|
|
|
|
m_menu.findItem(R.id.back_to_categories).setVisible(m_activeCategory != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_logged_in, false);
|
2011-11-29 14:41:12 +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_article, false);
|
2011-12-03 14:22:06 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
2011-12-05 17:22:31 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
/* if (m_isOffline) {
|
2011-12-05 17:22:31 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_logged_out, false);
|
2011-12-05 18:54:54 +00:00
|
|
|
m_menu.findItem(R.id.go_online).setVisible(true);
|
2011-12-05 17:22:31 +00:00
|
|
|
|
2011-12-06 06:03:55 +00:00
|
|
|
} else { */
|
2011-12-05 17:22:31 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_logged_out, true);
|
2011-12-06 06:03:55 +00:00
|
|
|
//}
|
2011-11-29 06:46:36 +00:00
|
|
|
}
|
2011-11-25 10:13:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 04:12:43 +00:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
|
|
|
|
if (m_refreshTask != null) {
|
|
|
|
m_refreshTask.cancel();
|
|
|
|
m_refreshTask = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_refreshTimer != null) {
|
|
|
|
m_refreshTimer.cancel();
|
|
|
|
m_refreshTimer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
unregisterReceiver(m_broadcastReceiver);
|
|
|
|
|
2011-12-05 17:22:31 +00:00
|
|
|
m_readableDb.close();
|
|
|
|
m_writableDb.close();
|
|
|
|
|
|
|
|
}
|
2011-12-06 11:29:57 +00:00
|
|
|
|
|
|
|
private void syncOfflineRead() {
|
|
|
|
Log.d(TAG, "syncing modified offline data... (read)");
|
|
|
|
|
|
|
|
final String ids = getOfflineModifiedIds(ModifiedCriteria.READ);
|
|
|
|
|
|
|
|
if (ids.length() > 0) {
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (result != null) {
|
|
|
|
syncOfflineMarked();
|
|
|
|
} else {
|
|
|
|
setLoadingStatus(getErrorMessage(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", ids);
|
|
|
|
put("mode", "0");
|
|
|
|
put("field", "2");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
} else {
|
|
|
|
syncOfflineMarked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void syncOfflineMarked() {
|
|
|
|
Log.d(TAG, "syncing modified offline data... (marked)");
|
|
|
|
|
|
|
|
final String ids = getOfflineModifiedIds(ModifiedCriteria.MARKED);
|
|
|
|
|
|
|
|
if (ids.length() > 0) {
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (result != null) {
|
|
|
|
syncOfflinePublished();
|
|
|
|
} else {
|
|
|
|
setLoadingStatus(getErrorMessage(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", ids);
|
|
|
|
put("mode", "0");
|
|
|
|
put("field", "0");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
} else {
|
|
|
|
syncOfflinePublished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void syncOfflinePublished() {
|
|
|
|
Log.d(TAG, "syncing modified offline data... (published)");
|
|
|
|
|
|
|
|
final String ids = getOfflineModifiedIds(ModifiedCriteria.MARKED);
|
|
|
|
|
|
|
|
if (ids.length() > 0) {
|
|
|
|
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (result != null) {
|
|
|
|
loginSuccessInitUI();
|
|
|
|
loginSuccess();
|
|
|
|
clearPendingOfflineData();
|
|
|
|
} else {
|
|
|
|
setLoadingStatus(getErrorMessage(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "updateArticle");
|
|
|
|
put("article_ids", ids);
|
|
|
|
put("mode", "0");
|
|
|
|
put("field", "1");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
} else {
|
|
|
|
loginSuccessInitUI();
|
|
|
|
loginSuccess();
|
|
|
|
clearPendingOfflineData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void syncOfflineData() {
|
|
|
|
setLoadingStatus(R.string.syncing_offline_data, true);
|
|
|
|
syncOfflineRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loginSuccessInitUI() {
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
|
|
|
|
if (m_enableCats) {
|
|
|
|
FeedCategoriesFragment frag = new FeedCategoriesFragment();
|
|
|
|
ft.replace(R.id.cats_fragment, frag);
|
|
|
|
} else {
|
|
|
|
FeedsFragment frag = new FeedsFragment();
|
|
|
|
ft.replace(R.id.feeds_fragment, frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
ft.commit();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 17:22:31 +00:00
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
private void loginSuccess() {
|
|
|
|
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
|
|
|
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
|
|
|
|
2011-12-05 15:14:06 +00:00
|
|
|
m_isOffline = false;
|
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
initMainMenu();
|
|
|
|
|
|
|
|
if (m_refreshTask != null) {
|
|
|
|
m_refreshTask.cancel();
|
|
|
|
m_refreshTask = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_refreshTimer != null) {
|
|
|
|
m_refreshTimer.cancel();
|
|
|
|
m_refreshTimer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_refreshTask = new RefreshTask();
|
|
|
|
m_refreshTimer = new Timer("Refresh");
|
|
|
|
|
2011-11-29 02:37:06 +00:00
|
|
|
m_refreshTimer.schedule(m_refreshTask, 60*1000L, 120*1000L);
|
2011-11-25 10:13:10 +00:00
|
|
|
}
|
2011-11-24 14:57:44 +00:00
|
|
|
|
2011-12-06 11:29:57 +00:00
|
|
|
private enum ModifiedCriteria { READ, MARKED, PUBLISHED };
|
|
|
|
|
|
|
|
private String getOfflineModifiedIds(ModifiedCriteria criteria) {
|
|
|
|
|
|
|
|
String criteriaStr = "";
|
|
|
|
|
|
|
|
switch (criteria) {
|
|
|
|
case READ:
|
|
|
|
criteriaStr = "unread = 0";
|
|
|
|
break;
|
|
|
|
case MARKED:
|
|
|
|
criteriaStr = "marked = 1";
|
|
|
|
break;
|
|
|
|
case PUBLISHED:
|
|
|
|
criteriaStr = "published = 1";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cursor c = getReadableDb().query("articles",
|
|
|
|
null, "modified = 1 AND " + criteriaStr, null, null, null, null);
|
|
|
|
|
|
|
|
String tmp = "";
|
|
|
|
|
|
|
|
while (c.moveToNext()) {
|
|
|
|
tmp += c.getInt(0) + ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp.replaceAll(",$", "");
|
|
|
|
|
|
|
|
//Log.d(TAG, "getOfflineModifiedIds " + criteria + " = " + tmp);
|
|
|
|
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2011-11-22 14:30:09 +00:00
|
|
|
private class LoginRequest extends ApiRequest {
|
2011-11-27 10:18:04 +00:00
|
|
|
public LoginRequest(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
2011-11-22 14:30:09 +00:00
|
|
|
|
2011-11-29 11:09:27 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-11-22 14:30:09 +00:00
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (result != null) {
|
|
|
|
try {
|
2011-11-29 04:03:38 +00:00
|
|
|
JsonObject content = result.getAsJsonObject();
|
|
|
|
if (content != null) {
|
|
|
|
m_sessionId = content.get("session_id").getAsString();
|
|
|
|
|
|
|
|
Log.d(TAG, "Authenticated!");
|
|
|
|
|
2011-11-29 05:25:13 +00:00
|
|
|
ApiRequest req = new ApiRequest(m_context) {
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (result != null) {
|
|
|
|
m_apiLevel = result.getAsJsonObject().get("level").getAsInt();
|
|
|
|
} else {
|
|
|
|
m_apiLevel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d(TAG, "Received API level: " + m_apiLevel);
|
|
|
|
|
2011-12-06 11:29:57 +00:00
|
|
|
if (hasPendingOfflineData()) {
|
2011-11-29 05:25:13 +00:00
|
|
|
|
2011-12-06 11:29:57 +00:00
|
|
|
syncOfflineData();
|
|
|
|
|
|
|
|
//loginSuccess();
|
|
|
|
} else {
|
|
|
|
loginSuccessInitUI();
|
|
|
|
loginSuccess();
|
2011-12-02 05:35:27 +00:00
|
|
|
}
|
2011-11-29 05:25:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-29 11:09:27 +00:00
|
|
|
@SuppressWarnings("serial")
|
2011-11-29 05:25:13 +00:00
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("sid", m_sessionId);
|
|
|
|
put("op", "getApiLevel");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.execute(map);
|
|
|
|
|
2011-11-29 04:03:38 +00:00
|
|
|
setLoadingStatus(R.string.loading_message, true);
|
2011-11-22 14:30:09 +00:00
|
|
|
|
2011-11-29 04:03:38 +00:00
|
|
|
return;
|
2011-11-22 14:30:09 +00:00
|
|
|
}
|
2011-11-29 04:03:38 +00:00
|
|
|
|
2011-11-22 14:30:09 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2011-11-29 04:03:38 +00:00
|
|
|
|
|
|
|
m_sessionId = null;
|
|
|
|
|
|
|
|
setLoadingStatus(getErrorMessage(), false);
|
2011-12-06 11:29:57 +00:00
|
|
|
|
|
|
|
if (hasOfflineData()) {
|
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).
|
2011-12-06 11:29:57 +00:00
|
|
|
setMessage(R.string.dialog_offline_prompt).
|
|
|
|
setPositiveButton(R.string.dialog_offline_go, new Dialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
switchOfflineSuccess();
|
|
|
|
}
|
|
|
|
}).
|
|
|
|
setNegativeButton(R.string.dialog_cancel, new Dialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog dlg = builder.create();
|
|
|
|
dlg.show();
|
|
|
|
}
|
|
|
|
|
2011-11-30 18:44:36 +00:00
|
|
|
//m_menu.findItem(R.id.login).setVisible(true);
|
2011-11-27 07:04:28 +00:00
|
|
|
}
|
2011-11-29 04:03:38 +00:00
|
|
|
|
2011-11-22 14:30:09 +00:00
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFeedSelected(Feed feed) {
|
2011-11-26 06:52:50 +00:00
|
|
|
viewFeed(feed, false);
|
2011-11-25 10:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Article getSelectedArticle() {
|
|
|
|
return m_selectedArticle;
|
|
|
|
}
|
|
|
|
|
2011-11-26 06:52:50 +00:00
|
|
|
public void viewFeed(Feed feed, boolean append) {
|
2011-11-23 16:38:21 +00:00
|
|
|
m_activeFeed = feed;
|
2011-11-26 06:52:50 +00:00
|
|
|
|
|
|
|
initMainMenu();
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2011-11-26 06:52:50 +00:00
|
|
|
if (!append) {
|
|
|
|
HeadlinesFragment hf = new HeadlinesFragment();
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-11-26 06:52:50 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
ft.replace(R.id.headlines_fragment, hf);
|
|
|
|
ft.commit();
|
|
|
|
} else {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
if (hf != null) {
|
|
|
|
hf.refresh(true);
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 10:02:16 +00:00
|
|
|
public void viewCategory(FeedCategory cat, boolean openAsFeed) {
|
2011-11-28 17:14:50 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
Log.d(TAG, "viewCategory");
|
|
|
|
|
2011-11-29 10:02:16 +00:00
|
|
|
if (!openAsFeed) {
|
2011-12-06 21:17:20 +00:00
|
|
|
if (m_bar != null) {
|
|
|
|
if (m_feedTab != null) m_bar.removeTab(m_feedTab);
|
|
|
|
|
|
|
|
m_feedTab = m_bar.newTab().setText(cat.title).setTabListener(new CategoryTabListener(cat));
|
|
|
|
m_bar.addTab(m_feedTab);
|
|
|
|
m_bar.selectTab(m_feedTab);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
2011-11-29 10:02:16 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
m_activeCategory = cat;
|
|
|
|
|
|
|
|
FeedsFragment frag = new FeedsFragment();
|
|
|
|
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
ft.replace(R.id.feeds_fragment, frag);
|
|
|
|
ft.commit();
|
|
|
|
}
|
2011-11-29 10:02:16 +00:00
|
|
|
} else {
|
2011-11-29 11:34:54 +00:00
|
|
|
if (m_smallScreenMode) findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
2011-11-29 10:02:16 +00:00
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
m_activeFeed = new Feed(cat.id, cat.title, true);
|
|
|
|
|
|
|
|
HeadlinesFragment frag = new HeadlinesFragment();
|
|
|
|
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
ft.replace(R.id.headlines_fragment, frag);
|
|
|
|
ft.commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
initMainMenu();
|
2011-11-28 17:14:50 +00:00
|
|
|
}
|
|
|
|
|
2011-11-28 09:45:19 +00:00
|
|
|
public void openArticle(Article article, int compatAnimation) {
|
2011-11-23 16:38:21 +00:00
|
|
|
m_selectedArticle = article;
|
|
|
|
|
2011-11-28 09:45:19 +00:00
|
|
|
if (article.unread) {
|
|
|
|
article.unread = false;
|
|
|
|
saveArticleUnread(article);
|
|
|
|
}
|
|
|
|
|
2011-11-25 10:32:32 +00:00
|
|
|
initMainMenu();
|
2011-11-28 09:45:19 +00:00
|
|
|
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
|
|
|
|
if (hf != null) {
|
|
|
|
hf.setActiveArticleId(article.id);
|
|
|
|
}
|
2011-11-25 10:32:32 +00:00
|
|
|
|
2011-11-23 16:38:21 +00:00
|
|
|
ArticleFragment frag = new ArticleFragment();
|
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2011-11-23 16:38:21 +00:00
|
|
|
ft.replace(R.id.article_fragment, frag);
|
|
|
|
ft.commit();
|
2011-11-27 08:56:31 +00:00
|
|
|
|
|
|
|
if (m_compatMode) {
|
2011-11-28 09:45:19 +00:00
|
|
|
if (compatAnimation == 0)
|
|
|
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left));
|
|
|
|
else
|
|
|
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, compatAnimation));
|
2011-11-27 08:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_smallScreenMode) {
|
2011-11-26 07:11:24 +00:00
|
|
|
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);
|
2011-12-03 19:09:51 +00:00
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
2011-11-26 07:11:24 +00:00
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
2011-11-25 10:32:32 +00:00
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-23 16:38:21 +00:00
|
|
|
public Feed getActiveFeed() {
|
|
|
|
return m_activeFeed;
|
|
|
|
}
|
2011-11-24 13:04:58 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-28 17:14:50 +00:00
|
|
|
public FeedCategory getActiveCategory() {
|
|
|
|
return m_activeCategory;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
private void logout() {
|
2011-11-24 13:04:58 +00:00
|
|
|
if (m_refreshTask != null) {
|
|
|
|
m_refreshTask.cancel();
|
|
|
|
m_refreshTask = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_refreshTimer != null) {
|
|
|
|
m_refreshTimer.cancel();
|
|
|
|
m_refreshTimer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sessionId = null;
|
2011-11-25 11:53:32 +00:00
|
|
|
|
|
|
|
findViewById(R.id.loading_container).setVisibility(View.VISIBLE);
|
|
|
|
findViewById(R.id.main).setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
|
TextView tv = (TextView)findViewById(R.id.loading_message);
|
|
|
|
|
|
|
|
if (tv != null) {
|
|
|
|
tv.setText(R.string.login_ready);
|
|
|
|
}
|
|
|
|
|
|
|
|
findViewById(R.id.loading_progress).setVisibility(View.GONE);
|
|
|
|
|
|
|
|
initMainMenu();
|
2011-11-24 13:04:58 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
@Override
|
2011-11-27 13:20:27 +00:00
|
|
|
@SuppressWarnings({ "unchecked", "serial" })
|
2011-11-24 13:04:58 +00:00
|
|
|
public void login() {
|
|
|
|
|
|
|
|
logout();
|
|
|
|
|
2011-12-01 07:01:33 +00:00
|
|
|
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
|
2011-11-27 13:57:05 +00:00
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
setLoadingStatus(R.string.login_need_configure, false);
|
|
|
|
|
|
|
|
} else {
|
2011-11-24 13:04:58 +00:00
|
|
|
|
2011-12-06 16:07:14 +00:00
|
|
|
LoginRequest ar = new LoginRequest(getApplicationContext());
|
2011-11-27 07:04:28 +00:00
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("op", "login");
|
2011-12-01 07:01:33 +00:00
|
|
|
put("user", m_prefs.getString("login", "").trim());
|
|
|
|
put("password", m_prefs.getString("password", "").trim());
|
2011-11-25 18:37:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ar.execute(map);
|
|
|
|
|
|
|
|
setLoadingStatus(R.string.login_in_progress, true);
|
|
|
|
}
|
2011-11-24 13:04:58 +00:00
|
|
|
}
|
2011-11-29 17:00:37 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
|
|
|
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
FeedsFragment ff = (FeedsFragment)getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
|
|
|
|
FeedCategoriesFragment cf = (FeedCategoriesFragment)getSupportFragmentManager().findFragmentById(R.id.cats_fragment);
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.browse_articles:
|
|
|
|
if (cf != null) {
|
|
|
|
FeedCategory cat = cf.getCategoryAtPosition(info.position);
|
|
|
|
if (cat != null) {
|
|
|
|
viewCategory(cat, true);
|
|
|
|
cf.setSelectedCategory(cat);
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
return true;
|
2011-11-29 17:00:37 +00:00
|
|
|
case R.id.browse_feeds:
|
|
|
|
if (cf != null) {
|
|
|
|
FeedCategory cat = cf.getCategoryAtPosition(info.position);
|
|
|
|
if (cat != null) {
|
|
|
|
viewCategory(cat, false);
|
|
|
|
cf.setSelectedCategory(cat);
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
return true;
|
2011-11-29 17:00:37 +00:00
|
|
|
case R.id.catchup_category:
|
|
|
|
if (cf != null) {
|
|
|
|
FeedCategory cat = cf.getCategoryAtPosition(info.position);
|
|
|
|
if (cat != null) {
|
|
|
|
catchupFeed(new Feed(cat.id, cat.title, true));
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
return true;
|
2011-11-29 17:00:37 +00:00
|
|
|
case R.id.catchup_feed:
|
|
|
|
if (ff != null) {
|
|
|
|
Feed feed = ff.getFeedAtPosition(info.position);
|
|
|
|
if (feed != null) {
|
|
|
|
catchupFeed(feed);
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
return true;
|
2011-11-29 17:00:37 +00:00
|
|
|
case R.id.selection_toggle_marked:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
for (Article a : selected)
|
|
|
|
a.marked = !a.marked;
|
|
|
|
|
|
|
|
toggleArticlesMarked(selected);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
} else {
|
|
|
|
Article article = hf.getArticleAtPosition(info.position);
|
|
|
|
if (article != null) {
|
|
|
|
article.marked = !article.marked;
|
|
|
|
saveArticleMarked(article);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_published:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
for (Article a : selected)
|
|
|
|
a.published = !a.published;
|
|
|
|
|
|
|
|
toggleArticlesPublished(selected);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
} else {
|
|
|
|
Article article = hf.getArticleAtPosition(info.position);
|
|
|
|
if (article != null) {
|
|
|
|
article.published = !article.published;
|
|
|
|
saveArticlePublished(article);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.selection_toggle_unread:
|
|
|
|
if (hf != null) {
|
|
|
|
ArticleList selected = hf.getSelectedArticles();
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
for (Article a : selected)
|
|
|
|
a.unread = !a.unread;
|
|
|
|
|
|
|
|
toggleArticlesUnread(selected);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
} else {
|
|
|
|
Article article = hf.getArticleAtPosition(info.position);
|
|
|
|
if (article != null) {
|
|
|
|
article.unread = !article.unread;
|
|
|
|
saveArticleUnread(article);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-30 18:48:12 +00:00
|
|
|
case R.id.share_article:
|
|
|
|
if (hf != null) {
|
|
|
|
Article article = hf.getArticleAtPosition(info.position);
|
|
|
|
if (article != null)
|
|
|
|
shareArticle(article);
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
return true;
|
|
|
|
case R.id.catchup_above:
|
|
|
|
if (hf != null) {
|
|
|
|
Article article = hf.getArticleAtPosition(info.position);
|
|
|
|
if (article != null) {
|
2011-12-01 05:32:17 +00:00
|
|
|
ArticleList articles = hf.getAllArticles();
|
|
|
|
ArticleList tmp = new ArticleList();
|
|
|
|
for (Article a : articles) {
|
|
|
|
a.unread = false;
|
|
|
|
tmp.add(a);
|
|
|
|
if (article.id == a.id)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tmp.size() > 0) {
|
|
|
|
toggleArticlesUnread(tmp);
|
|
|
|
hf.notifyUpdated();
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
/* case R.id.set_unread:
|
2011-11-30 18:48:12 +00:00
|
|
|
if (hf != null) {
|
|
|
|
Article article = hf.getArticleAtPosition(info.position);
|
|
|
|
if (article != null) {
|
|
|
|
article.unread = true;
|
|
|
|
saveArticleUnread(article);
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 19:06:11 +00:00
|
|
|
break; */
|
|
|
|
default:
|
|
|
|
Log.d(TAG, "onContextItemSelected, unhandled id=" + item.getItemId());
|
|
|
|
return super.onContextItemSelected(item);
|
2011-11-29 17:00:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 09:45:19 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Article getRelativeArticle(Article article, RelativeArticle ra) {
|
|
|
|
HeadlinesFragment frag = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
if (frag != null) {
|
|
|
|
ArticleList articles = frag.getAllArticles();
|
|
|
|
for (int i = 0; i < articles.size(); i++) {
|
|
|
|
Article a = articles.get(i);
|
|
|
|
|
|
|
|
if (a.id == article.id) {
|
|
|
|
if (ra == RelativeArticle.AFTER) {
|
|
|
|
try {
|
|
|
|
return articles.get(i+1);
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return articles.get(i-1);
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2011-11-28 17:14:50 +00:00
|
|
|
|
2011-11-30 15:22:33 +00:00
|
|
|
@Override
|
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
|
|
|
int action = event.getAction();
|
|
|
|
int keyCode = event.getKeyCode();
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
|
|
|
if (action == KeyEvent.ACTION_DOWN) {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
|
|
|
|
if (hf != null && m_activeFeed != null) {
|
|
|
|
Article base = hf.getArticleById(hf.getActiveArticleId());
|
|
|
|
|
|
|
|
Article next = base != null ? getRelativeArticle(base, RelativeArticle.AFTER) : hf.getArticleAtPosition(0);
|
|
|
|
|
|
|
|
if (next != null) {
|
|
|
|
hf.setActiveArticleId(next.id);
|
|
|
|
|
|
|
|
boolean combinedMode = m_prefs.getBoolean("combined_mode", false);
|
|
|
|
|
|
|
|
if (combinedMode || m_selectedArticle == null) {
|
|
|
|
next.unread = false;
|
|
|
|
saveArticleUnread(next);
|
|
|
|
} else {
|
|
|
|
openArticle(next, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
|
|
|
if (action == KeyEvent.ACTION_UP) {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
|
|
|
|
|
|
if (hf != null && m_activeFeed != null) {
|
|
|
|
Article base = hf.getArticleById(hf.getActiveArticleId());
|
|
|
|
|
|
|
|
Article prev = base != null ? getRelativeArticle(base, RelativeArticle.BEFORE) : hf.getArticleAtPosition(0);
|
|
|
|
|
|
|
|
if (prev != null) {
|
|
|
|
hf.setActiveArticleId(prev.id);
|
|
|
|
|
|
|
|
boolean combinedMode = m_prefs.getBoolean("combined_mode", false);
|
|
|
|
|
|
|
|
if (combinedMode || m_selectedArticle == null) {
|
|
|
|
prev.unread = false;
|
|
|
|
saveArticleUnread(prev);
|
|
|
|
} else {
|
|
|
|
openArticle(prev, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 17:14:50 +00:00
|
|
|
@Override
|
|
|
|
public void onCatSelected(FeedCategory cat) {
|
2011-11-29 10:02:16 +00:00
|
|
|
Log.d(TAG, "onCatSelected");
|
2011-11-30 15:22:33 +00:00
|
|
|
boolean browse = m_prefs.getBoolean("browse_cats_like_feeds", false);
|
|
|
|
|
|
|
|
viewCategory(cat, browse && cat.id >= 0);
|
2011-11-28 17:14:50 +00:00
|
|
|
}
|
2011-12-05 15:05:11 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
private class RootTabListener implements ActionBar.TabListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(Tab arg0,
|
|
|
|
android.app.FragmentTransaction arg1) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(Tab arg0, android.app.FragmentTransaction arg1) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(Tab arg0,
|
|
|
|
android.app.FragmentTransaction arg1) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class CategoryTabListener implements ActionBar.TabListener {
|
|
|
|
|
|
|
|
private FeedCategory m_cat = null;
|
|
|
|
|
|
|
|
public CategoryTabListener(FeedCategory cat) {
|
|
|
|
m_cat = cat;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(Tab tab,
|
|
|
|
android.app.FragmentTransaction _ft) {
|
2011-12-07 05:14:13 +00:00
|
|
|
|
|
|
|
closeArticle();
|
2011-12-06 21:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(Tab tab, android.app.FragmentTransaction _ft) {
|
|
|
|
if (m_cat != null) {
|
|
|
|
m_activeCategory = m_cat;
|
|
|
|
|
|
|
|
initMainMenu();
|
|
|
|
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
FeedsFragment frag = new FeedsFragment();
|
|
|
|
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
ft.replace(R.id.feeds_fragment, frag);
|
|
|
|
ft.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(Tab tab,
|
|
|
|
android.app.FragmentTransaction _ft) {
|
2011-12-07 05:14:13 +00:00
|
|
|
|
|
|
|
closeArticle();
|
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
2011-12-05 15:05:11 +00:00
|
|
|
|
2011-12-06 21:17:20 +00:00
|
|
|
m_activeCategory = null;
|
|
|
|
|
|
|
|
initMainMenu();
|
|
|
|
refreshCategories();
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 17:22:31 +00:00
|
|
|
|
2011-09-07 05:56:46 +00:00
|
|
|
}
|