From c3a80f1be4a1fe84e0f468aaaa519d7d86e50a3f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 12 Feb 2015 13:09:54 +0300 Subject: [PATCH] add fragment transitions for headlines --- .../java/org/fox/ttrss/CommonActivity.java | 4 +- .../java/org/fox/ttrss/FeedsActivity.java | 58 +++++++------------ .../java/org/fox/ttrss/HeadlinesActivity.java | 10 +--- .../java/org/fox/ttrss/HeadlinesFragment.java | 18 +++++- 4 files changed, 39 insertions(+), 51 deletions(-) mode change 100644 => 100755 org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java old mode 100644 new mode 100755 index 705de8af..23b14386 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java @@ -130,8 +130,8 @@ public class CommonActivity extends ActionBarActivity { public void onCreate(Bundle savedInstanceState) { m_prefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); - - if (savedInstanceState != null) { + + if (savedInstanceState != null) { m_theme = savedInstanceState.getString("theme"); m_fullScreen = savedInstanceState.getBoolean("fullscreen"); } else { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java index ebde85c6..9f7583e9 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java @@ -8,7 +8,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import android.os.Handler; import android.os.Parcelable; import android.preference.PreferenceManager; import android.support.v4.app.ActivityCompat; @@ -53,7 +52,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe .getDefaultSharedPreferences(getApplicationContext()); setAppTheme(m_prefs); - + super.onCreate(savedInstanceState); setContentView(R.layout.headlines); @@ -154,9 +153,9 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe //m_pullToRefreshAttacher.setRefreshing(true); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - + if (m_prefs.getBoolean("enable_cats", false)) { - ft.replace(R.id.feeds_fragment, new FeedCategoriesFragment(), FRAG_CATS); + ft.replace(R.id.feeds_fragment, new FeedCategoriesFragment(), FRAG_CATS); } else { ft.replace(R.id.feeds_fragment, new FeedsFragment(), FRAG_FEEDS); } @@ -239,46 +238,31 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe } public void onFeedSelected(Feed feed, final boolean selectedByUser) { - //GlobalState.getInstance().m_loadedArticles.clear(); - //m_pullToRefreshAttacher.setRefreshing(true); - FragmentTransaction ft = getSupportFragmentManager() - .beginTransaction(); + FragmentTransaction ft = getSupportFragmentManager() + .beginTransaction(); - ft.replace(R.id.headlines_fragment, new LoadingFragment(), null); - ft.commit(); + HeadlinesFragment hf = new HeadlinesFragment(); + hf.initialize(feed); - final Feed fFeed = feed; - - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - FragmentTransaction ft = getSupportFragmentManager() - .beginTransaction(); + ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); - HeadlinesFragment hf = new HeadlinesFragment(); - hf.initialize(fFeed); - ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); - - ft.commit(); + ft.commit(); - m_feedIsSelected = true; - m_userFeedSelected = selectedByUser; - //m_feedWasSelected = true; - - if (m_drawerLayout != null) { - m_drawerLayout.closeDrawers(); - } - } - }, 10); - + m_feedIsSelected = true; + m_userFeedSelected = selectedByUser; + //m_feedWasSelected = true; - Date date = new Date(); + if (m_drawerLayout != null) { + m_drawerLayout.closeDrawers(); + } - if (date.getTime() - m_lastRefresh > 10000) { - m_lastRefresh = date.getTime(); - refresh(false); - } + Date date = new Date(); + + if (date.getTime() - m_lastRefresh > 10000) { + m_lastRefresh = date.getTime(); + refresh(false); + } } public void onCatSelected(FeedCategory cat, boolean openAsFeed) { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java index 1ea943ab..3296964e 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java @@ -152,15 +152,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - - Intent resultIntent = new Intent(); - //resultIntent.putParcelableArrayListExtra("articles", m_articles); - resultIntent.putExtra("articles", (Parcelable)m_articles); - resultIntent.putExtra("activeArticle", m_activeArticle); - - setResult(Activity.RESULT_OK, resultIntent); - - finish(); + onBackPressed(); return true; default: Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index 21377654..e99207f9 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -20,6 +20,8 @@ import android.support.v4.app.Fragment; import android.support.v4.view.ViewCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.text.Html; +import android.transition.Fade; +import android.transition.Transition; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; @@ -274,6 +276,16 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } } + public HeadlinesFragment() { + super(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Transition fade = new Fade(); + + setEnterTransition(fade); + setReenterTransition(fade); + } + } @Override public void onCreateContextMenu(ContextMenu menu, View v, @@ -300,9 +312,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - if (savedInstanceState != null) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + if (savedInstanceState != null) { m_feed = savedInstanceState.getParcelable("feed"); if (! (m_activity instanceof HeadlinesActivity)) {