add fragment transitions for headlines

This commit is contained in:
Andrew Dolgov 2015-02-12 13:09:54 +03:00
parent 70056d68ac
commit c3a80f1be4
4 changed files with 39 additions and 51 deletions

View File

@ -131,7 +131,7 @@ public class CommonActivity extends ActionBarActivity {
m_prefs = PreferenceManager m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext()); .getDefaultSharedPreferences(getApplicationContext());
if (savedInstanceState != null) { if (savedInstanceState != null) {
m_theme = savedInstanceState.getString("theme"); m_theme = savedInstanceState.getString("theme");
m_fullScreen = savedInstanceState.getBoolean("fullscreen"); m_fullScreen = savedInstanceState.getBoolean("fullscreen");
} else { } else {

View File

@ -8,7 +8,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable; import android.os.Parcelable;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
@ -239,46 +238,31 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} }
public void onFeedSelected(Feed feed, final boolean selectedByUser) { public void onFeedSelected(Feed feed, final boolean selectedByUser) {
//GlobalState.getInstance().m_loadedArticles.clear();
//m_pullToRefreshAttacher.setRefreshing(true);
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
ft.replace(R.id.headlines_fragment, new LoadingFragment(), null); HeadlinesFragment hf = new HeadlinesFragment();
ft.commit(); hf.initialize(feed);
final Feed fFeed = feed; ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
new Handler().postDelayed(new Runnable() { ft.commit();
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
HeadlinesFragment hf = new HeadlinesFragment(); m_feedIsSelected = true;
hf.initialize(fFeed); m_userFeedSelected = selectedByUser;
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); //m_feedWasSelected = true;
ft.commit(); if (m_drawerLayout != null) {
m_drawerLayout.closeDrawers();
}
m_feedIsSelected = true; Date date = new Date();
m_userFeedSelected = selectedByUser;
//m_feedWasSelected = true;
if (m_drawerLayout != null) { if (date.getTime() - m_lastRefresh > 10000) {
m_drawerLayout.closeDrawers(); m_lastRefresh = date.getTime();
} refresh(false);
} }
}, 10);
Date date = new Date();
if (date.getTime() - m_lastRefresh > 10000) {
m_lastRefresh = date.getTime();
refresh(false);
}
} }
public void onCatSelected(FeedCategory cat, boolean openAsFeed) { public void onCatSelected(FeedCategory cat, boolean openAsFeed) {

View File

@ -152,15 +152,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
onBackPressed();
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();
return true; return true;
default: default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());

View File

@ -20,6 +20,8 @@ import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.text.Html; import android.text.Html;
import android.transition.Fade;
import android.transition.Transition;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; 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 @Override
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
@ -302,7 +314,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) { if (savedInstanceState != null) {
m_feed = savedInstanceState.getParcelable("feed"); m_feed = savedInstanceState.getParcelable("feed");
if (! (m_activity instanceof HeadlinesActivity)) { if (! (m_activity instanceof HeadlinesActivity)) {