2011-09-07 05:56:46 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
import java.lang.reflect.Type;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
|
2011-09-09 09:55:57 +00:00
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
|
2011-09-09 16:36:09 +00:00
|
|
|
import android.animation.LayoutTransition;
|
2011-09-07 05:56:46 +00:00
|
|
|
import android.app.Activity;
|
2011-09-08 11:28:38 +00:00
|
|
|
import android.app.FragmentTransaction;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2011-09-09 06:02:31 +00:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.database.sqlite.SQLiteStatement;
|
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-09-09 06:02:31 +00:00
|
|
|
import android.provider.BaseColumns;
|
2011-09-08 12:45:08 +00:00
|
|
|
import android.util.Log;
|
2011-09-08 10:23:44 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2011-09-09 16:36:09 +00:00
|
|
|
import android.widget.LinearLayout;
|
2011-09-10 08:03:32 +00:00
|
|
|
import android.widget.ViewFlipper;
|
2011-09-07 05:56:46 +00:00
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
|
2011-09-07 05:56:46 +00:00
|
|
|
public class MainActivity extends Activity {
|
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-09-09 06:02:31 +00:00
|
|
|
protected String m_sessionId;
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-09 09:23:56 +00:00
|
|
|
protected MenuItem m_syncStatus;
|
2011-09-09 06:02:31 +00:00
|
|
|
|
|
|
|
protected String getSessionId() {
|
|
|
|
return m_sessionId;
|
|
|
|
}
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
protected synchronized void setSessionId(String sessionId) {
|
|
|
|
m_sessionId = sessionId;
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-09-09 06:02:31 +00:00
|
|
|
SharedPreferences.Editor editor = m_prefs.edit();
|
|
|
|
editor.putString("last_session_id", m_sessionId);
|
|
|
|
editor.commit();
|
|
|
|
}
|
2011-09-09 16:36:09 +00:00
|
|
|
|
|
|
|
/** Called when the activity is first created. */
|
|
|
|
@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-09-09 06:02:31 +00:00
|
|
|
m_sessionId = m_prefs.getString("last_session_id", null);
|
2011-09-09 16:36: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-09-08 10:23:44 +00:00
|
|
|
}
|
2011-09-09 16:36:09 +00:00
|
|
|
|
|
|
|
setContentView(R.layout.main);
|
2011-11-22 12:49:21 +00:00
|
|
|
|
|
|
|
ApiRequest ar = new ApiRequest();
|
|
|
|
ar.setApi(m_prefs.getString("ttrss_url", null));
|
|
|
|
|
|
|
|
HashMap<String,String> loginMap = new HashMap<String,String>() {
|
|
|
|
{
|
|
|
|
put("op", "login");
|
|
|
|
put("user", m_prefs.getString("login", null));
|
|
|
|
put("password", m_prefs.getString("password", null));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ar.execute(loginMap);
|
|
|
|
|
|
|
|
/* ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper);
|
2011-09-09 09:23:56 +00:00
|
|
|
|
2011-11-22 12:13:02 +00:00
|
|
|
if (vf != null) {
|
|
|
|
vf.showNext();
|
2011-09-10 08:16:59 +00:00
|
|
|
}
|
2011-11-22 12:49:21 +00:00
|
|
|
|
|
|
|
HeadlinesFragment hf = new HeadlinesFragment();
|
|
|
|
FeedsFragment ff = new FeedsFragment();
|
|
|
|
ArticleFragment af = new ArticleFragment();
|
|
|
|
|
|
|
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
|
|
|
ft.add(R.id.main, ff);
|
|
|
|
ft.add(R.id.main, hf);
|
|
|
|
ft.add(R.id.main, af);
|
|
|
|
ft.hide(hf);
|
|
|
|
ft.hide(af);
|
|
|
|
ft.commit(); */
|
2011-09-09 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
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-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-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-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-09-09 16:36:09 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 12:49:21 +00:00
|
|
|
|
2011-09-07 05:56:46 +00:00
|
|
|
}
|