2011-09-07 05:56:46 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
import java.util.HashMap;
|
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-11-25 09:15:27 +00:00
|
|
|
import android.animation.LayoutTransition;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2011-09-07 05:56:46 +00:00
|
|
|
import android.os.Bundle;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.preference.PreferenceManager;
|
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-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-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-09-09 06:02:31 +00:00
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
public class MainActivity extends FragmentActivity implements FeedsFragment.OnFeedSelectedListener, HeadlinesFragment.OnArticleSelectedListener {
|
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-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-09-09 06:02:31 +00:00
|
|
|
|
2011-11-23 17:19:35 +00:00
|
|
|
private class RefreshTask extends TimerTask {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
refreshFeeds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void refreshFeeds() {
|
2011-11-25 18:37:02 +00:00
|
|
|
FeedsFragment frag = (FeedsFragment) getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
|
2011-11-25 10:13:10 +00:00
|
|
|
|
|
|
|
Log.d(TAG, "Refreshing feeds..." + frag);
|
|
|
|
|
2011-11-23 17:19:35 +00:00
|
|
|
if (frag != null) {
|
|
|
|
frag.refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-24 05:59:11 +00:00
|
|
|
|
|
|
|
public void setUnreadOnly(boolean unread) {
|
|
|
|
m_unreadOnly = unread;
|
|
|
|
refreshFeeds();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getUnreadOnly() {
|
|
|
|
return m_unreadOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-09-09 16:36:09 +00:00
|
|
|
/** Called when the activity is first created. */
|
2011-11-22 14:30:09 +00:00
|
|
|
|
2011-09-09 16:36:09 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
|
|
|
setTheme(R.style.DarkTheme);
|
|
|
|
} else {
|
|
|
|
setTheme(R.style.LightTheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-08 10:23:44 +00:00
|
|
|
}
|
2011-11-23 10:55:05 +00:00
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
Display display = getWindowManager().getDefaultDisplay();
|
|
|
|
|
|
|
|
if (display.getWidth() > 1000 && display.getHeight() >= 600) {
|
|
|
|
m_smallScreenMode = false;
|
|
|
|
|
|
|
|
setContentView(R.layout.main);
|
|
|
|
} else {
|
|
|
|
m_smallScreenMode = true;
|
|
|
|
|
|
|
|
setContentView(R.layout.main_small);
|
|
|
|
}
|
|
|
|
|
2011-11-23 10:55:05 +00:00
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
if (android.os.Build.VERSION.SDK_INT > 10) {
|
|
|
|
LayoutTransition transitioner = new LayoutTransition();
|
|
|
|
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
|
|
|
|
layout.setLayoutTransition(transitioner);
|
|
|
|
}
|
2011-11-25 09:15:27 +00:00
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
findViewById(R.id.feeds_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);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_selectedArticle == null)
|
|
|
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
2011-11-22 12:49:21 +00:00
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
if (m_sessionId != null) {
|
|
|
|
loginSuccess();
|
|
|
|
} else {
|
|
|
|
login();
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-09-09 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 14:30:09 +00:00
|
|
|
public void setLoadingStatus(int status, boolean showProgress) {
|
|
|
|
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-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();
|
|
|
|
|
|
|
|
if (!m_prefs.getString("theme", "THEME_DARK").equals(m_themeName)) {
|
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-26 06:31:14 +00:00
|
|
|
} else {
|
|
|
|
FeedsFragment frag = (FeedsFragment)getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
|
|
|
|
|
|
|
|
if (frag != null) {
|
|
|
|
frag.sortFeeds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
}
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2011-09-11 09:04:48 +00:00
|
|
|
|
2011-11-23 17:19:35 +00:00
|
|
|
if (m_refreshTask != null) {
|
|
|
|
m_refreshTask.cancel();
|
|
|
|
m_refreshTask = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_refreshTimer != null) {
|
|
|
|
m_refreshTimer.cancel();
|
|
|
|
m_refreshTimer = null;
|
|
|
|
}
|
2011-09-09 06:02:31 +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-09-09 16:36:09 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-24 05:59:11 +00:00
|
|
|
public void setMenuLabel(int id, int labelId) {
|
|
|
|
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) {
|
|
|
|
Log.d(TAG, "Overriding back button");
|
|
|
|
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_smallScreenMode) {
|
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
closeArticle();
|
|
|
|
} else if (m_activeFeed != null) {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
2011-11-25 08:47:07 +00:00
|
|
|
} else {
|
2011-11-26 07:11:24 +00:00
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
closeArticle();
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
2011-11-25 08:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
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-24 06:06:47 +00:00
|
|
|
refreshFeeds();
|
|
|
|
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-11-24 14:57:44 +00:00
|
|
|
case R.id.close_article:
|
|
|
|
closeArticle();
|
|
|
|
return true;
|
2011-11-26 06:52:50 +00:00
|
|
|
case R.id.load_more_articles:
|
|
|
|
viewFeed(m_activeFeed, true);
|
|
|
|
return true;
|
2011-11-25 10:46:11 +00:00
|
|
|
case R.id.share_article:
|
|
|
|
shareArticle(m_selectedArticle);
|
|
|
|
return true;
|
2011-11-24 05:59:11 +00:00
|
|
|
case R.id.show_feeds:
|
|
|
|
if (getUnreadOnly()) {
|
|
|
|
item.setTitle(R.string.menu_unread_feeds);
|
2011-11-24 06:06:47 +00:00
|
|
|
} else {
|
|
|
|
item.setTitle(R.string.menu_all_feeds);
|
2011-11-24 05:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setUnreadOnly(!getUnreadOnly());
|
|
|
|
return true;
|
2011-09-08 10:23:44 +00:00
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 12:49:21 +00:00
|
|
|
|
2011-11-25 10:46:11 +00:00
|
|
|
public void shareArticle(Article article) {
|
|
|
|
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-24 14:57:44 +00:00
|
|
|
public void closeArticle() {
|
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);
|
|
|
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
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-24 14:57:44 +00:00
|
|
|
}
|
2011-11-25 10:13:10 +00:00
|
|
|
|
|
|
|
private void initMainMenu() {
|
|
|
|
if (m_menu != null) {
|
|
|
|
|
|
|
|
if (m_sessionId != null) {
|
|
|
|
m_menu.findItem(R.id.login).setVisible(false);
|
|
|
|
|
|
|
|
m_menu.findItem(R.id.logout).setVisible(true);
|
|
|
|
|
2011-11-25 10:32:32 +00:00
|
|
|
if (m_selectedArticle != null) {
|
|
|
|
m_menu.findItem(R.id.close_article).setVisible(true);
|
|
|
|
m_menu.findItem(R.id.share_article).setVisible(true);
|
2011-11-25 11:53:32 +00:00
|
|
|
|
|
|
|
m_menu.findItem(R.id.update_feeds).setEnabled(false);
|
|
|
|
m_menu.findItem(R.id.show_feeds).setEnabled(false);
|
2011-11-25 10:32:32 +00:00
|
|
|
} else {
|
|
|
|
m_menu.findItem(R.id.close_article).setVisible(false);
|
|
|
|
m_menu.findItem(R.id.share_article).setVisible(false);
|
2011-11-25 11:53:32 +00:00
|
|
|
|
|
|
|
m_menu.findItem(R.id.update_feeds).setEnabled(true);
|
|
|
|
m_menu.findItem(R.id.show_feeds).setEnabled(true);
|
2011-11-25 10:32:32 +00:00
|
|
|
}
|
2011-11-26 06:52:50 +00:00
|
|
|
|
|
|
|
m_menu.findItem(R.id.load_more_articles).setVisible(m_activeFeed != null);
|
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
} else {
|
|
|
|
m_menu.findItem(R.id.login).setVisible(true);
|
|
|
|
|
|
|
|
m_menu.findItem(R.id.logout).setVisible(false);
|
|
|
|
m_menu.findItem(R.id.close_article).setVisible(false);
|
|
|
|
m_menu.findItem(R.id.share_article).setVisible(false);
|
2011-11-26 06:52:50 +00:00
|
|
|
m_menu.findItem(R.id.load_more_articles).setVisible(false);
|
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
m_menu.findItem(R.id.update_feeds).setEnabled(false);
|
|
|
|
m_menu.findItem(R.id.show_feeds).setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loginSuccess() {
|
|
|
|
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
|
|
|
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
m_refreshTimer.schedule(m_refreshTask, 60*1000L, 60*1000L);
|
|
|
|
}
|
2011-11-24 14:57:44 +00:00
|
|
|
|
2011-11-22 14:30:09 +00:00
|
|
|
private class LoginRequest extends ApiRequest {
|
|
|
|
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
|
|
|
if (result != null) {
|
|
|
|
try {
|
|
|
|
JsonObject rv = result.getAsJsonObject();
|
|
|
|
|
|
|
|
int status = rv.get("status").getAsInt();
|
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
|
JsonObject content = rv.get("content").getAsJsonObject();
|
|
|
|
if (content != null) {
|
|
|
|
m_sessionId = content.get("session_id").getAsString();
|
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
Log.d(TAG, "Authenticated!");
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
setLoadingStatus(R.string.loading_message, true);
|
|
|
|
|
2011-11-23 16:38:21 +00:00
|
|
|
FeedsFragment frag = new FeedsFragment();
|
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2011-11-23 16:38:21 +00:00
|
|
|
ft.replace(R.id.feeds_fragment, frag);
|
|
|
|
ft.commit();
|
2011-11-23 17:19:35 +00:00
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
loginSuccess();
|
2011-11-23 17:19:35 +00:00
|
|
|
|
2011-11-22 14:30:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
JsonObject content = rv.get("content").getAsJsonObject();
|
|
|
|
|
|
|
|
if (content != null) {
|
|
|
|
String error = content.get("error").getAsString();
|
|
|
|
|
|
|
|
m_sessionId = null;
|
|
|
|
|
|
|
|
if (error.equals("LOGIN_ERROR")) {
|
|
|
|
setLoadingStatus(R.string.login_wrong_password, false);
|
|
|
|
} else if (error.equals("API_DISABLED")) {
|
|
|
|
setLoadingStatus(R.string.login_api_disabled, false);
|
|
|
|
} else {
|
|
|
|
setLoadingStatus(R.string.login_failed, false);
|
|
|
|
}
|
2011-11-24 13:04:58 +00:00
|
|
|
|
|
|
|
m_menu.findItem(R.id.login).setVisible(true);
|
2011-11-22 14:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFeedSelected(Feed feed) {
|
|
|
|
Log.d(TAG, "Selected feed: " + feed.toString());
|
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-25 10:13:10 +00:00
|
|
|
public void openArticle(Article article) {
|
2011-11-23 16:38:21 +00:00
|
|
|
m_selectedArticle = article;
|
|
|
|
|
2011-11-25 10:32:32 +00:00
|
|
|
initMainMenu();
|
|
|
|
|
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-26 07:11:24 +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.article_fragment).setVisibility(View.VISIBLE);
|
|
|
|
}
|
2011-11-25 10:32:32 +00:00
|
|
|
|
2011-11-25 10:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArticleSelected(Article article) {
|
|
|
|
openArticle(article);
|
2011-11-23 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Feed getActiveFeed() {
|
|
|
|
return m_activeFeed;
|
|
|
|
}
|
2011-11-24 13:04:58 +00:00
|
|
|
|
|
|
|
public void logout() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void login() {
|
|
|
|
|
|
|
|
logout();
|
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
if (m_prefs.getString("ttrss_url", null) == null ||
|
|
|
|
m_prefs.getString("login", null) == null ||
|
|
|
|
m_prefs.getString("password", null) == null) {
|
|
|
|
|
|
|
|
setLoadingStatus(R.string.login_need_configure, false);
|
|
|
|
|
|
|
|
} else {
|
2011-11-24 13:04:58 +00:00
|
|
|
|
2011-11-25 18:37:02 +00:00
|
|
|
LoginRequest ar = new LoginRequest();
|
|
|
|
ar.setApi(m_prefs.getString("ttrss_url", null));
|
|
|
|
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("op", "login");
|
|
|
|
put("user", m_prefs.getString("login", null));
|
|
|
|
put("password", m_prefs.getString("password", null));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ar.execute(map);
|
|
|
|
|
|
|
|
setLoadingStatus(R.string.login_in_progress, true);
|
|
|
|
}
|
2011-11-24 13:04:58 +00:00
|
|
|
}
|
2011-09-07 05:56:46 +00:00
|
|
|
}
|