From 474af4f10f6e9a2e3de48b06430404c8ab4d3a6a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Sep 2014 19:50:42 -0700 Subject: #408 Animate fragment transitions --- src/github/daneren2005/dsub/activity/SubsonicActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 6544b685..2865ef8f 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -45,6 +45,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; @@ -542,6 +543,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(secondaryContainer == null) { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); trans.hide(oldFragment); trans.add(R.id.fragment_container, fragment, tag + ""); trans.commit(); @@ -555,12 +557,16 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(backStack.size() > 1) { // Move old right to left if there is a backstack already SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1); + if(replaceCurrent) { + trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); + } trans.remove(newLeftFragment); // Only move right to left if replaceCurrent is false if(!replaceCurrent) { SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2); oldLeftFragment.setSecondaryFragment(false); + trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); trans.hide(oldLeftFragment); // Make sure remove is finished before adding @@ -568,6 +574,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); + trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); trans.add(R.id.fragment_container, newLeftFragment, newLeftFragment.getSupportTag() + ""); } else { backStack.remove(backStack.size() - 1); @@ -594,6 +601,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(secondaryContainer == null) { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.remove(oldFrag); trans.show(currentFragment); trans.commit(); @@ -601,10 +609,12 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); // Remove old right fragment + trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.remove(oldFrag); // Only switch places if there is a backstack, otherwise primary container is correct if(backStack.size() > 0) { + trans.setCustomAnimations(0, 0, 0, 0); // Add current left fragment to right side trans.remove(currentFragment); @@ -613,12 +623,14 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); + trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + ""); SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1); newLeftFragment.setSecondaryFragment(true); trans.show(newLeftFragment); } else { + secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right)); secondaryContainer.setVisibility(View.GONE); } -- cgit v1.2.3 From 9675c980d2478000abe24ce5f4b062448dd88fc7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 1 Oct 2014 07:48:46 -0700 Subject: Fix title being switch to Dsub briefly on new fragment creation --- src/github/daneren2005/dsub/activity/SubsonicActivity.java | 10 ++++++++-- src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 2865ef8f..4d60dd77 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -372,8 +372,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte @Override public void setTitle(CharSequence title) { - getSupportActionBar().setTitle(title); - recreateSpinner(); + if(!title.equals(getSupportActionBar().getTitle())) { + getSupportActionBar().setTitle(title); + recreateSpinner(); + } } public void setSubtitle(CharSequence title) { getSupportActionBar().setSubtitle(title); @@ -653,6 +655,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } protected void recreateSpinner() { + if(currentFragment.getTitle() == null) { + return; + } + if(backStack.size() > 0) { spinnerAdapter.clear(); for(int i = 0; i < backStack.size(); i++) { diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index cf6f78b0..fe1153c0 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -96,7 +96,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR private int tag; protected SubsonicActivity context; - protected CharSequence title = "DSub"; + protected CharSequence title = null; protected CharSequence subtitle = null; protected View rootView; protected boolean primaryFragment = false; @@ -420,7 +420,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public void setPrimaryFragment(boolean primary) { primaryFragment = primary; if(primary) { - if(context != null) { + if(context != null && title != null) { context.setTitle(title); context.setSubtitle(subtitle); } -- cgit v1.2.3 From e34688b0366f9ac17e8c9c55877d83d4acd7fb0d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 1 Oct 2014 14:35:59 -0700 Subject: Reduce work done in main thread to mitigate choppy fragment transition --- .../dsub/fragments/SelectDirectoryFragment.java | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 824d4f33..cc38ad69 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -615,22 +615,21 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter protected Pair doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(context); MusicDirectory dir = load(musicService); - boolean valid = musicService.isLicenseValid(context, this); - return new Pair(dir, valid); + licenseValid = musicService.isLicenseValid(context, this); + + albums = dir.getChildren(true, false); + if(largeAlbums) { + entries = dir.getChildren(false, true); + } else { + entries = dir.getChildren(); + } + + return new Pair(dir, licenseValid); } @Override protected void done(Pair result) { - if(largeAlbums) { - albums = result.getFirst().getChildren(true, false); - entries = result.getFirst().getChildren(false, true); - } else { - albums = result.getFirst().getChildren(true, false); - entries = result.getFirst().getChildren(); - } - licenseValid = result.getSecond(); - finishLoading(); - + finishLoading(); currentTask = null; } } @@ -646,7 +645,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } else { showHeader = false; if(!"root".equals(id) && (entries.size() == 0 || !largeAlbums && albums.size() == entries.size())) { - hideButtons = true; + hideButtons = true; } } @@ -699,7 +698,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if(validData) { entryList.setVisibility(View.VISIBLE); } - context.supportInvalidateOptionsMenu(); + context.supportInvalidateOptionsMenu(); if(lookupEntry != null) { for(int i = 0; i < entries.size(); i++) { @@ -711,12 +710,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } } - Bundle args = getArguments(); - boolean playAll = args.getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); - if (playAll && !restoredInstance) { - playAll(args.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); - } - } + Bundle args = getArguments(); + boolean playAll = args.getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); + if (playAll && !restoredInstance) { + playAll(args.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); + } + } private void setupAlbumList() { albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() { -- cgit v1.2.3 From cecd46ae801d86d8251b5ed04df63a34c9dd660a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 3 Oct 2014 14:50:42 -0700 Subject: Only trigger UpdateView update when actually resuming fragment --- src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 66900b55..f2f81073 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -110,6 +110,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected boolean artist = false; protected boolean artistOverride = false; protected SwipeRefreshLayout refreshLayout; + protected boolean firstRun; public SubsonicFragment() { super(); @@ -126,6 +127,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR title = name; } } + firstRun = true; } @Override @@ -137,7 +139,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR @Override public void onResume() { super.onResume(); - UpdateView.triggerUpdate(); + if(firstRun) { + firstRun = false; + } else { + UpdateView.triggerUpdate(); + } } @Override -- cgit v1.2.3 From 72f9f2bf4f431b790490fe1ddb8820c478a66801 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 7 Oct 2014 19:23:39 -0700 Subject: Temporarily disable tablet transitions --- src/github/daneren2005/dsub/activity/SubsonicActivity.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 4d60dd77..16f731d3 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -560,7 +560,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte // Move old right to left if there is a backstack already SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1); if(replaceCurrent) { - trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); + // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); } trans.remove(newLeftFragment); @@ -568,7 +568,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(!replaceCurrent) { SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2); oldLeftFragment.setSecondaryFragment(false); - trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); + // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); trans.hide(oldLeftFragment); // Make sure remove is finished before adding @@ -576,7 +576,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); - trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); + // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); trans.add(R.id.fragment_container, newLeftFragment, newLeftFragment.getSupportTag() + ""); } else { backStack.remove(backStack.size() - 1); @@ -611,12 +611,12 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); // Remove old right fragment - trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); + // trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.remove(oldFrag); // Only switch places if there is a backstack, otherwise primary container is correct if(backStack.size() > 0) { - trans.setCustomAnimations(0, 0, 0, 0); + // trans.setCustomAnimations(0, 0, 0, 0); // Add current left fragment to right side trans.remove(currentFragment); @@ -625,14 +625,14 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); - trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); + // trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + ""); SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1); newLeftFragment.setSecondaryFragment(true); trans.show(newLeftFragment); } else { - secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right)); + // secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right)); secondaryContainer.setVisibility(View.GONE); } -- cgit v1.2.3