fix some rotating issues

This commit is contained in:
Andrew Dolgov 2011-09-10 12:16:59 +04:00
parent 09fed5025f
commit 0e58bef54c
3 changed files with 43 additions and 13 deletions

View File

@ -1,5 +1,7 @@
package org.fox.ttrss;
import java.sql.SQLData;
import android.app.Activity;
import android.app.Fragment;
import android.content.SharedPreferences;
@ -20,6 +22,7 @@ public class ArticleFragment extends Fragment {
protected SharedPreferences m_prefs;
protected int m_articleId;
protected SQLiteDatabase m_db;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -31,11 +34,11 @@ public class ArticleFragment extends Fragment {
View view = inflater.inflate(R.layout.article_fragment, container, false);
DatabaseHelper dh = new DatabaseHelper(getActivity());
SQLiteDatabase db = dh.getReadableDatabase();
m_db = dh.getReadableDatabase();
Log.d(TAG, "Opening article #" + m_articleId);
Cursor c = db.query("articles", null, BaseColumns._ID + "=?",
Cursor c = m_db.query("articles", null, BaseColumns._ID + "=?",
new String[] { String.valueOf(m_articleId) }, null, null, null);
c.moveToFirst();
@ -59,7 +62,6 @@ public class ArticleFragment extends Fragment {
}
c.close();
db.close();
return view;
}
@ -71,6 +73,8 @@ public class ArticleFragment extends Fragment {
@Override
public void onDestroy() {
super.onDestroy();
m_db.close();
}
@Override

View File

@ -29,6 +29,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
m_feedId = savedInstanceState.getInt("feedId");
}
View view = inflater.inflate(R.layout.headlines_fragment, container, false);
DatabaseHelper helper = new DatabaseHelper(getActivity());
@ -114,4 +118,11 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
}
@Override
public void onSaveInstanceState (Bundle out) {
super.onSaveInstanceState(out);
out.putInt("feedId", m_feedId);
}
}

View File

@ -42,6 +42,7 @@ public class MainActivity extends Activity {
private SharedPreferences m_prefs;
private String m_themeName = "";
private boolean m_feedsOpened = false;
private boolean m_splashDisabled = false;
protected String m_sessionId;
protected int m_offset = 0;
protected int m_limit = 30;
@ -107,13 +108,14 @@ public class MainActivity extends Activity {
m_limit = savedInstanceState.getInt("limit");
m_updateMode = savedInstanceState.getInt("updateMode");
m_maxId = savedInstanceState.getInt("maxId");
m_splashDisabled = savedInstanceState.getBoolean("splashDisabled");
}
// allow database to upgrade before we do anything else
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
SQLiteDatabase db = dh.getWritableDatabase();
if (m_updateMode == UPDATE_INITIAL) {
if (m_updateMode == UPDATE_INITIAL && !m_splashDisabled) {
db.execSQL("DELETE FROM feeds;");
db.execSQL("DELETE FROM articles;");
}
@ -127,10 +129,6 @@ public class MainActivity extends Activity {
LayoutTransition transitioner = new LayoutTransition();
wrapper.setLayoutTransition(transitioner);
m_feedsTask = new FeedsTask();
m_feedsTimer = new Timer("UpdateFeeds");
m_feedsTimer.schedule(m_feedsTask, 1000L, 60*1000L);
if (!m_feedsOpened) {
Log.d(TAG, "Opening feeds fragment...");
@ -142,6 +140,20 @@ public class MainActivity extends Activity {
ft.commit();
m_feedsOpened = true;
}
if (m_splashDisabled) {
ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper);
if (vf != null && vf.getDisplayedChild() == 0)
vf.showNext();
scheduleNextUpdate();
} else {
m_feedsTask = new FeedsTask();
m_feedsTimer = new Timer("UpdateFeeds");
m_feedsTimer.schedule(m_feedsTask, 1000L, 60*1000L);
}
//scheduleNextUpdate();
@ -157,6 +169,7 @@ public class MainActivity extends Activity {
out.putInt("limit", m_limit);
out.putInt("updateMode", m_updateMode);
out.putInt("maxId", m_maxId);
out.putBoolean("splashDisabled", m_splashDisabled);
}
@Override
@ -174,13 +187,13 @@ public class MainActivity extends Activity {
public void onDestroy() {
super.onDestroy();
m_feedsTask.cancel();
m_articlesTask.cancel();
if (m_feedsTask != null) m_feedsTask.cancel();
if (m_articlesTask != null) m_articlesTask.cancel();
m_feedsTimer.cancel();
if (m_feedsTimer != null) m_feedsTimer.cancel();
m_feedsTimer = null;
m_articlesTimer.cancel();
if (m_articlesTimer != null) m_articlesTimer.cancel();
m_articlesTimer = null;
}
@ -269,7 +282,7 @@ public class MainActivity extends Activity {
List<Article> articles = api.m_gson.fromJson(feeds_object, listType);
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
SQLiteDatabase db = dh.getWritableDatabase();
SQLiteDatabase db = dh.getWritableDatabase(); // TODO rework to m_writableDb etc to prevent crashes on rotate/recreate
/* db.execSQL("DELETE FROM articles"); */
@ -369,6 +382,8 @@ public class MainActivity extends Activity {
}
}
m_splashDisabled = true;
runOnUiThread(new Runnable() {
@Override
public void run() {