offline initialization stuff
This commit is contained in:
parent
18fd39e568
commit
3365de8096
@ -344,7 +344,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
initDatabase();
|
initDatabase();
|
||||||
|
|
||||||
m_isOffline = true;
|
m_isOffline = m_prefs.getBoolean("offline_mode_active", false);
|
||||||
|
|
||||||
Log.d(TAG, "m_isOffline=" + m_isOffline);
|
Log.d(TAG, "m_isOffline=" + m_isOffline);
|
||||||
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
|
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
|
||||||
@ -407,7 +407,21 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_isOffline) {
|
if (m_isOffline) {
|
||||||
switchOffline();
|
|
||||||
|
initMainMenu();
|
||||||
|
|
||||||
|
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
||||||
|
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (m_activeOfflineFeedId == 0) {
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
||||||
|
ft.replace(R.id.feeds_fragment, frag);
|
||||||
|
ft.commit();
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (m_sessionId != null) {
|
if (m_sessionId != null) {
|
||||||
loginSuccess();
|
loginSuccess();
|
||||||
@ -453,6 +467,18 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
req.execute(map);
|
req.execute(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void switchOnline() {
|
||||||
|
// TODO upload updated stuff here
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = m_prefs.edit();
|
||||||
|
editor.putBoolean("offline_mode_active", false);
|
||||||
|
editor.commit();
|
||||||
|
|
||||||
|
Intent refresh = new Intent(this, MainActivity.class);
|
||||||
|
startActivity(refresh);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void switchOffline() {
|
public void switchOffline() {
|
||||||
Log.d(TAG, "offline: starting");
|
Log.d(TAG, "offline: starting");
|
||||||
@ -464,8 +490,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
setLoadingStatus(R.string.offline_downloading, true);
|
setLoadingStatus(R.string.offline_downloading, true);
|
||||||
|
|
||||||
// TODO upload updated stuff here
|
|
||||||
|
|
||||||
// Download feeds
|
// Download feeds
|
||||||
|
|
||||||
getWritableDb().execSQL("DELETE FROM feeds;");
|
getWritableDb().execSQL("DELETE FROM feeds;");
|
||||||
@ -492,7 +516,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
stmtInsert.execute();
|
stmtInsert.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stmtInsert.close();
|
||||||
|
|
||||||
Log.d(TAG, "offline: done downloading feeds");
|
Log.d(TAG, "offline: done downloading feeds");
|
||||||
|
|
||||||
m_articleOffset = 0;
|
m_articleOffset = 0;
|
||||||
@ -531,20 +557,13 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
logout();
|
logout();
|
||||||
//setLoadingStatus(R.string.blank, false);
|
//setLoadingStatus(R.string.blank, false);
|
||||||
|
|
||||||
m_isOffline = true;
|
SharedPreferences.Editor editor = m_prefs.edit();
|
||||||
initMainMenu();
|
editor.putBoolean("offline_mode_active", true);
|
||||||
|
editor.commit();
|
||||||
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
|
||||||
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
Intent refresh = new Intent(this, MainActivity.class);
|
||||||
|
startActivity(refresh);
|
||||||
if (m_activeOfflineFeedId == 0) {
|
finish();
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
||||||
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
|
||||||
ft.replace(R.id.feeds_fragment, frag);
|
|
||||||
ft.commit();
|
|
||||||
} else {
|
|
||||||
offlineViewFeed(m_activeOfflineFeedId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,7 +729,10 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
final HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
HeadlinesFragment hf = null;
|
||||||
|
|
||||||
|
if (m_sessionId != null)
|
||||||
|
hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.preferences:
|
case R.id.preferences:
|
||||||
@ -729,6 +751,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
case R.id.login:
|
case R.id.login:
|
||||||
login();
|
login();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.go_online:
|
||||||
|
switchOnline();
|
||||||
|
return true;
|
||||||
case R.id.go_offline:
|
case R.id.go_offline:
|
||||||
switchOffline();
|
switchOffline();
|
||||||
return true;
|
return true;
|
||||||
@ -740,6 +765,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
return true;
|
return true;
|
||||||
case R.id.headlines_select:
|
case R.id.headlines_select:
|
||||||
if (hf != null) {
|
if (hf != null) {
|
||||||
|
final HeadlinesFragment fhf = hf;
|
||||||
Dialog dialog = new Dialog(this);
|
Dialog dialog = new Dialog(this);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(R.string.headlines_select_dialog);
|
builder.setTitle(R.string.headlines_select_dialog);
|
||||||
@ -750,13 +776,13 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case 0:
|
case 0:
|
||||||
hf.setSelection(HeadlinesFragment.ArticlesSelection.ALL);
|
fhf.setSelection(HeadlinesFragment.ArticlesSelection.ALL);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
hf.setSelection(HeadlinesFragment.ArticlesSelection.UNREAD);
|
fhf.setSelection(HeadlinesFragment.ArticlesSelection.UNREAD);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
hf.setSelection(HeadlinesFragment.ArticlesSelection.NONE);
|
fhf.setSelection(HeadlinesFragment.ArticlesSelection.NONE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
@ -1023,6 +1049,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
if (m_isOffline) {
|
if (m_isOffline) {
|
||||||
m_menu.setGroupVisible(R.id.menu_group_logged_out, false);
|
m_menu.setGroupVisible(R.id.menu_group_logged_out, false);
|
||||||
|
m_menu.findItem(R.id.go_online).setVisible(true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m_menu.setGroupVisible(R.id.menu_group_logged_out, true);
|
m_menu.setGroupVisible(R.id.menu_group_logged_out, true);
|
||||||
@ -1603,7 +1630,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stmtInsert.close();
|
||||||
|
|
||||||
//m_canGetMoreArticles = articles.size() == 30;
|
//m_canGetMoreArticles = articles.size() == 30;
|
||||||
m_articleOffset += articles.size();
|
m_articleOffset += articles.size();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user