2011-09-07 05:56:46 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
|
|
|
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-08 16:05:00 +00:00
|
|
|
import android.os.AsyncTask;
|
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-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-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-08 12:45:08 +00:00
|
|
|
private boolean m_feedsOpened = false;
|
2011-09-08 10:23:44 +00:00
|
|
|
|
2011-09-07 05:56:46 +00:00
|
|
|
/** Called when the activity is first created. */
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2011-09-07 07:11:48 +00:00
|
|
|
|
2011-09-08 10:23:44 +00:00
|
|
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
|
|
|
|
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-07 07:11:48 +00:00
|
|
|
|
2011-09-08 12:45:08 +00:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
m_feedsOpened = savedInstanceState.getBoolean("feedsOpened");
|
2011-09-08 10:23:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 11:28:38 +00:00
|
|
|
setContentView(R.layout.main);
|
|
|
|
|
2011-09-08 12:45:08 +00:00
|
|
|
if (!m_feedsOpened) {
|
|
|
|
Log.d(TAG, "Opening feeds fragment...");
|
|
|
|
|
|
|
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
|
|
|
FeedsFragment frag = new FeedsFragment();
|
2011-09-08 11:28:38 +00:00
|
|
|
|
2011-09-08 12:45:08 +00:00
|
|
|
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
|
|
|
ft.replace(R.id.feeds_container, frag);
|
|
|
|
ft.commit();
|
|
|
|
|
|
|
|
m_feedsOpened = true;
|
|
|
|
}
|
2011-09-08 11:28:38 +00:00
|
|
|
|
2011-09-07 05:56:46 +00:00
|
|
|
}
|
2011-09-08 10:23:44 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState (Bundle out) {
|
|
|
|
super.onSaveInstanceState(out);
|
|
|
|
|
2011-09-08 12:45:08 +00:00
|
|
|
out.putBoolean("feedsOpened", m_feedsOpened);
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.main_menu, menu);
|
|
|
|
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-09-08 16:05:00 +00:00
|
|
|
|
2011-09-07 05:56:46 +00:00
|
|
|
}
|