offline mode fixes

This commit is contained in:
Andrew Dolgov 2012-06-19 21:32:56 +04:00
parent ff6f103900
commit 92ccf9ec0c
3 changed files with 67 additions and 106 deletions

View File

@ -46,6 +46,11 @@ public class OfflineActivity extends FragmentActivity implements
OfflineServices { OfflineServices {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
protected final static String FRAG_HEADLINES = "headlines";
protected final static String FRAG_ARTICLE = "article";
protected final static String FRAG_FEEDS = "feeds";
//protected final static String FRAG_CATS = "cats";
private SharedPreferences m_prefs; private SharedPreferences m_prefs;
private String m_themeName = ""; private String m_themeName = "";
private Menu m_menu; private Menu m_menu;
@ -139,13 +144,14 @@ public class OfflineActivity extends FragmentActivity implements
Log.d(TAG, "m_compatMode=" + m_compatMode); Log.d(TAG, "m_compatMode=" + m_compatMode);
if (!m_compatMode) { if (!m_compatMode) {
if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) { if (!m_smallScreenMode) {
if (!m_smallScreenMode) { findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticleId != 0 ? View.GONE : View.VISIBLE);
LayoutTransition transitioner = new LayoutTransition(); findViewById(R.id.article_fragment).setVisibility(m_selectedArticleId != 0 ? View.VISIBLE : View.GONE);
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
}
} }
LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.fragment_container)).setLayoutTransition(transitioner);
m_headlinesActionModeCallback = new HeadlinesActionModeCallback(); m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
} }
@ -153,37 +159,16 @@ public class OfflineActivity extends FragmentActivity implements
findViewById(R.id.loading_container).setVisibility(View.GONE); findViewById(R.id.loading_container).setVisibility(View.GONE);
/* if (m_smallScreenMode) {
if (m_selectedArticleId != 0) {
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
} else if (m_activeFeedId != 0) {
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
findViewById(R.id.article_fragment).setVisibility(View.GONE);
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
} else {
//findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
// findViewById(R.id.article_fragment).setVisibility(View.GONE);
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
}
} else {
if (m_selectedArticleId == 0) {
findViewById(R.id.article_fragment).setVisibility(View.GONE);
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
} else {
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
}
} */
if (m_activeFeedId == 0) { if (m_activeFeedId == 0) {
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
OfflineFeedsFragment frag = new OfflineFeedsFragment(); OfflineFeedsFragment frag = new OfflineFeedsFragment();
ft.replace(R.id.feeds_fragment, frag); if (m_smallScreenMode) {
ft.replace(R.id.fragment_container, frag, FRAG_FEEDS);
} else {
ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS);
}
ft.commit(); ft.commit();
} }
} }
@ -308,34 +293,10 @@ public class OfflineActivity extends FragmentActivity implements
if (m_selectedArticleId != 0) { if (m_selectedArticleId != 0) {
closeArticle(); closeArticle();
} else if (m_activeFeedId != 0) { } else if (m_activeFeedId != 0) {
//if (m_compatMode) {
findViewById(R.id.main).setAnimation(
AnimationUtils.loadAnimation(this,
R.anim.slide_right));
//}
/*
* if (m_activeFeed != null && m_activeFeed.is_cat) {
* findViewById
* (R.id.headlines_fragment).setVisibility(View.GONE);
* findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
*
* refreshCategories(); } else {
*/
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
// }
m_activeFeedId = 0; m_activeFeedId = 0;
OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment);
if (ff != null) {
ff.setSelectedFeedId(0);
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment()); ft.replace(R.id.fragment_container, new OfflineFeedsFragment(), FRAG_FEEDS);
ft.commit(); ft.commit();
refreshViews(); refreshViews();
@ -347,23 +308,23 @@ public class OfflineActivity extends FragmentActivity implements
} else { } else {
if (m_selectedArticleId != 0) { if (m_selectedArticleId != 0) {
closeArticle(); closeArticle();
} else if (m_activeFeedId != 0) { /* } else if (m_activeFeedId != 0) {
findViewById(R.id.headlines_fragment).setVisibility(View.INVISIBLE); findViewById(R.id.headlines_fragment).setVisibility(View.INVISIBLE);
m_activeFeedId = 0; m_activeFeedId = 0;
OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentByTag(FRAG_FEEDS);
if (ff != null) { if (ff != null) {
ff.setSelectedFeedId(0); ff.setSelectedFeedId(0);
} }
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment()); ft.replace(R.id.fragment_container, new OfflineHeadlinesFragment(), FRAG_HEADLINES);
ft.commit(); ft.commit();
refreshViews(); refreshViews();
initMainMenu(); initMainMenu(); */
} else if (allowQuit) { } else if (allowQuit) {
finish(); finish();
@ -457,7 +418,7 @@ public class OfflineActivity extends FragmentActivity implements
private void refreshHeadlines() { private void refreshHeadlines() {
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
if (ohf != null) { if (ohf != null) {
ohf.refresh(); ohf.refresh();
@ -467,7 +428,7 @@ public class OfflineActivity extends FragmentActivity implements
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
@ -680,7 +641,7 @@ public class OfflineActivity extends FragmentActivity implements
private void refreshFeeds() { private void refreshFeeds() {
OfflineFeedsFragment frag = (OfflineFeedsFragment) getSupportFragmentManager() OfflineFeedsFragment frag = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentByTag(FRAG_FEEDS);
if (frag != null) { if (frag != null) {
frag.refresh(); frag.refresh();
@ -688,27 +649,21 @@ public class OfflineActivity extends FragmentActivity implements
} }
private void closeArticle() { private void closeArticle() {
if (m_smallScreenMode) {
findViewById(R.id.main).setAnimation(
AnimationUtils.loadAnimation(this, R.anim.slide_right));
}
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);
}
// we don't want to lose selected article in headlines so we refresh them before setting selected id to 0 // we don't want to lose selected article in headlines so we refresh them before setting selected id to 0
refreshViews(); refreshViews();
m_selectedArticleId = 0; m_selectedArticleId = 0;
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, new DummyFragment());
if (m_smallScreenMode) {
ft.remove(getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE));
ft.show(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
} else {
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(View.GONE);
ft.replace(R.id.article_fragment, new DummyFragment(), FRAG_ARTICLE);
}
ft.commit(); ft.commit();
initMainMenu(); initMainMenu();
@ -757,7 +712,7 @@ public class OfflineActivity extends FragmentActivity implements
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
if (frag != null) { if (frag != null) {
frag.setSearchQuery(query); frag.setSearchQuery(query);
@ -771,7 +726,7 @@ public class OfflineActivity extends FragmentActivity implements
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) { if (newText.equals("") && !newText.equals(this.query)) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
if (frag != null) { if (frag != null) {
frag.setSearchQuery(newText); frag.setSearchQuery(newText);
@ -839,9 +794,9 @@ public class OfflineActivity extends FragmentActivity implements
.getMenuInfo(); .getMenuInfo();
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentByTag(FRAG_FEEDS);
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.article_link_copy: case R.id.article_link_copy:
@ -1004,7 +959,7 @@ public class OfflineActivity extends FragmentActivity implements
if (action == KeyEvent.ACTION_DOWN) { if (action == KeyEvent.ACTION_DOWN) {
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
int nextId = getRelativeArticleId(m_selectedArticleId, int nextId = getRelativeArticleId(m_selectedArticleId,
m_activeFeedId, RelativeArticle.AFTER); m_activeFeedId, RelativeArticle.AFTER);
@ -1033,7 +988,7 @@ public class OfflineActivity extends FragmentActivity implements
if (action == KeyEvent.ACTION_UP) { if (action == KeyEvent.ACTION_UP) {
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
int prevId = getRelativeArticleId(m_selectedArticleId, int prevId = getRelativeArticleId(m_selectedArticleId,
m_activeFeedId, RelativeArticle.BEFORE); m_activeFeedId, RelativeArticle.BEFORE);
@ -1123,13 +1078,6 @@ public class OfflineActivity extends FragmentActivity implements
initMainMenu(); initMainMenu();
if (m_smallScreenMode) {
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
}
deselectAllArticles(); deselectAllArticles();
if (m_menu != null) { if (m_menu != null) {
@ -1142,8 +1090,14 @@ public class OfflineActivity extends FragmentActivity implements
} }
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment(); OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment(feedId);
ft.replace(R.id.headlines_fragment, frag);
if (m_smallScreenMode) {
ft.replace(R.id.fragment_container, frag, FRAG_HEADLINES);
} else {
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
ft.replace(R.id.headlines_fragment, frag, FRAG_HEADLINES);
}
ft.commit(); ft.commit();
} }
@ -1155,7 +1109,7 @@ public class OfflineActivity extends FragmentActivity implements
initMainMenu(); initMainMenu();
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager() OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentByTag(FRAG_HEADLINES);
if (hf != null) { if (hf != null) {
hf.setActiveArticleId(articleId); hf.setActiveArticleId(articleId);
@ -1171,24 +1125,24 @@ public class OfflineActivity extends FragmentActivity implements
Fragment frag; Fragment frag;
if (m_smallScreenMode) { if (m_smallScreenMode || m_prefs.getBoolean("tablet_article_swipe", false)) {
frag = new OfflineArticlePager(articleId); frag = new OfflineArticlePager(articleId);
} else { } else {
frag = new OfflineArticleFragment(articleId); frag = new OfflineArticleFragment(articleId);
} }
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, frag);
ft.commit();
if (m_smallScreenMode) { if (m_smallScreenMode) {
if (compatAnimation == 0) ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
findViewById(R.id.main).setAnimation( ft.add(R.id.fragment_container, frag, FRAG_ARTICLE);
AnimationUtils.loadAnimation(this, R.anim.slide_left)); } else {
else findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
findViewById(R.id.main).setAnimation( findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
AnimationUtils.loadAnimation(this, compatAnimation)); ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
} }
ft.commit();
} }
@Override @Override

View File

@ -105,7 +105,7 @@ public class OfflineArticlePager extends Fragment {
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
m_hf = (OfflineHeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); m_hf = (OfflineHeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentByTag(OfflineActivity.FRAG_HEADLINES);
m_offlineServices = (OfflineServices)activity; m_offlineServices = (OfflineServices)activity;
} }

View File

@ -69,6 +69,14 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
}; };
public OfflineHeadlinesFragment(int feedId) {
m_feedId = feedId;
}
public OfflineHeadlinesFragment() {
//
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -164,7 +172,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
super.onAttach(activity); super.onAttach(activity);
m_offlineServices = (OfflineServices)activity; m_offlineServices = (OfflineServices)activity;
m_feedId = m_offlineServices.getActiveFeedId();
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
m_combinedMode = m_prefs.getBoolean("combined_mode", false); m_combinedMode = m_prefs.getBoolean("combined_mode", false);
} }