From 5b91660d1122aa7271b0e71fed111e3c4d7893ed Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 5 Feb 2014 21:43:46 -0800 Subject: Completely retool fragment management to not rely on unique id's --- .../dsub/activity/DownloadActivity.java | 8 ++-- .../dsub/activity/SubsonicActivity.java | 43 ++++++++++++---------- .../dsub/activity/SubsonicFragmentActivity.java | 17 +++------ .../dsub/fragments/DownloadFragment.java | 6 +-- .../daneren2005/dsub/fragments/MainFragment.java | 6 +-- .../daneren2005/dsub/fragments/SearchFragment.java | 7 +--- .../dsub/fragments/SelectArtistFragment.java | 6 +-- .../dsub/fragments/SelectDirectoryFragment.java | 22 +---------- .../dsub/fragments/SelectGenreFragment.java | 3 +- .../dsub/fragments/SelectPlaylistFragment.java | 15 ++------ .../dsub/fragments/SelectPodcastsFragment.java | 11 +----- .../dsub/fragments/SelectShareFragment.java | 5 +-- .../dsub/fragments/SelectYearFragment.java | 2 +- .../dsub/fragments/SubsonicFragment.java | 34 +++-------------- 14 files changed, 56 insertions(+), 129 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/activity/DownloadActivity.java b/src/github/daneren2005/dsub/activity/DownloadActivity.java index e302d59e..fcdc69de 100644 --- a/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -20,12 +20,10 @@ package github.daneren2005.dsub.activity; import github.daneren2005.dsub.R; import android.os.Bundle; -import android.view.MenuItem; import android.view.MotionEvent; import github.daneren2005.dsub.fragments.DownloadFragment; import android.widget.EditText; -import android.content.Intent; import github.daneren2005.dsub.util.Constants; @@ -41,7 +39,7 @@ public class DownloadActivity extends SubsonicActivity { super.onCreate(savedInstanceState); setContentView(R.layout.download_activity); - if (findViewById(R.id.download_container) != null && savedInstanceState == null) { + if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) { currentFragment = new DownloadFragment(); if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) { Bundle args = new Bundle(); @@ -49,14 +47,14 @@ public class DownloadActivity extends SubsonicActivity { currentFragment.setArguments(args); } currentFragment.setPrimaryFragment(true); - getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit(); + getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit(); } } @Override public boolean onTouchEvent(MotionEvent me) { if(currentFragment != null) { - return ((DownloadFragment)currentFragment).getGestureDetector().onTouchEvent(me); + return currentFragment.getGestureDetector().onTouchEvent(me); } else { return false; } diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index b7e5eac8..d15f3d7b 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -30,11 +30,8 @@ import android.os.Environment; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; -import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.KeyEvent; @@ -54,7 +51,6 @@ import android.widget.ListView; import android.widget.Spinner; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.fragments.SearchFragment; import github.daneren2005.dsub.fragments.SubsonicFragment; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; @@ -66,10 +62,8 @@ import github.daneren2005.dsub.view.UpdateView; import java.io.File; import java.io.PrintWriter; -import java.util.AbstractList; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; public class SubsonicActivity extends ActionBarActivity implements OnItemSelectedListener { @@ -268,30 +262,34 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte currentFragment.setPrimaryFragment(true); currentFragment.setSupportTag(ids[0]); supportInvalidateOptionsMenu(); + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); for(int i = 1; i < size; i++) { SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i]); frag.setSupportTag(ids[i]); if(secondaryContainer != null) { frag.setPrimaryFragment(false, true); } + trans.hide(frag); backStack.add(frag); } + trans.commit(); // Current fragment is hidden in secondaryContainer - if(secondaryContainer == null && findViewById(currentFragment.getRootId()) == null) { - FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + if(secondaryContainer == null && !currentFragment.isVisible()) { + trans = getSupportFragmentManager().beginTransaction(); trans.remove(currentFragment); trans.commit(); getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); - trans.add(backStack.get(backStack.size() - 1).getRootId(), currentFragment, ids[0]); + trans.add(R.id.fragment_container, currentFragment, ids[0]); trans.commit(); } // Current fragment needs to be moved over to secondaryContainer else if(secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null && backStack.size() > 0) { - FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans = getSupportFragmentManager().beginTransaction(); trans.remove(currentFragment); + trans.show(backStack.get(backStack.size() - 1)); trans.commit(); getSupportFragmentManager().executePendingTransactions(); @@ -484,10 +482,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } } - public void replaceFragment(SubsonicFragment fragment, int id, int tag) { - replaceFragment(fragment, id, tag, false); + public void replaceFragment(SubsonicFragment fragment, int tag) { + replaceFragment(fragment, tag, false); } - public void replaceFragment(SubsonicFragment fragment, int id, int tag, boolean replaceCurrent) { + public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) { + SubsonicFragment oldFragment = currentFragment; if(currentFragment != null) { currentFragment.setPrimaryFragment(false, secondaryContainer != null); } @@ -499,7 +498,8 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(secondaryContainer == null) { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); - trans.add(id, fragment, tag + ""); + trans.hide(oldFragment); + trans.add(R.id.fragment_container, fragment, tag + ""); trans.commit(); } else { // Make sure secondary container is visible now @@ -517,14 +517,14 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(!replaceCurrent) { SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2); oldLeftFragment.setSecondaryFragment(false); - int leftId = oldLeftFragment.getRootId(); + trans.hide(oldLeftFragment); // Make sure remove is finished before adding trans.commit(); getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); - trans.add(leftId, newLeftFragment, newLeftFragment.getSupportTag() + ""); + trans.add(R.id.fragment_container, newLeftFragment, newLeftFragment.getSupportTag() + ""); } else { backStack.remove(backStack.size() - 1); } @@ -542,15 +542,16 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(currentFragment != null) { currentFragment.setPrimaryFragment(false); } - Fragment oldFrag = (Fragment)currentFragment; + Fragment oldFrag = currentFragment; - currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1); + currentFragment = backStack.remove(backStack.size() - 1); currentFragment.setPrimaryFragment(true, false); supportInvalidateOptionsMenu(); if(secondaryContainer == null) { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.remove(oldFrag); + trans.show(currentFragment); trans.commit(); } else { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); @@ -569,8 +570,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte trans = getSupportFragmentManager().beginTransaction(); trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + ""); - - backStack.get(backStack.size() - 1).setSecondaryFragment(true); + + SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1); + newLeftFragment.setSecondaryFragment(true); + trans.show(newLeftFragment); } else { secondaryContainer.setVisibility(View.GONE); } diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 38d84bef..c44f87fc 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -20,17 +20,14 @@ package github.daneren2005.dsub.activity; import android.accounts.Account; import android.accounts.AccountManager; -import android.app.AlertDialog; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.MenuItem; @@ -114,7 +111,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { if(getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) { SearchFragment fragment = new SearchFragment(); - replaceFragment(fragment, R.id.home_layout, fragment.getSupportTag()); + replaceFragment(fragment, fragment.getSupportTag()); } } @@ -238,7 +235,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { setIntent(intent); SearchFragment fragment = new SearchFragment(); - replaceFragment(fragment, currentFragment.getRootId(), fragment.getSupportTag()); + replaceFragment(fragment, fragment.getSupportTag()); } } else { setIntent(intent); @@ -263,7 +260,6 @@ public class SubsonicFragmentActivity extends SubsonicActivity { }; if(getIntent().hasExtra(Constants.INTENT_EXTRA_VIEW_ALBUM)) { - int fragmentID = currentFragment != null ? currentFragment.getRootId() : R.id.fragment_list_layout; if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID)) { SelectDirectoryFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); @@ -272,8 +268,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout, currentFragment.getSupportTag()); - fragmentID = fragment.setRootId(); + replaceFragment(fragment, currentFragment.getSupportTag()); } SubsonicFragment fragment = new SelectDirectoryFragment(); @@ -285,7 +280,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } fragment.setArguments(args); - replaceFragment(fragment, fragmentID, currentFragment.getSupportTag()); + replaceFragment(fragment, currentFragment.getSupportTag()); getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM); if("Artist".equals(getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE))) { lastSelectedPosition = 1; @@ -332,8 +327,8 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } @Override - public void replaceFragment(SubsonicFragment fragment, int id, int tag, boolean replaceCurrent) { - super.replaceFragment(fragment, id, tag, replaceCurrent); + public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) { + super.replaceFragment(fragment, tag, replaceCurrent); drawerToggle.setDrawerIndicatorEnabled(false); } @Override diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 86e2b94f..d7f58e88 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -11,10 +11,8 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; -import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; -import android.util.Log; import android.view.ContextMenu; import android.view.Display; import android.view.GestureDetector; @@ -352,7 +350,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe if(downloadService != null && downloadService.getEqualizerController() != null && downloadService.getEqualizerController().getEqualizer() != null) { SubsonicFragment fragment = new EqualizerFragment(); - replaceFragment(fragment, R.id.download_layout_container); + replaceFragment(fragment); setControlsVisible(true); } else { Util.toast(context, "Failed to start equalizer. Try restarting."); @@ -614,7 +612,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe args.putString(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle()); fragment.setArguments(args); - replaceFragment(fragment, R.id.download_layout_container); + replaceFragment(fragment); return true; case R.id.menu_remove: new SilentBackgroundTask(context) { diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index 65924685..1905e77a 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -221,10 +221,10 @@ public class MainFragment extends SubsonicFragment { private void showAlbumList(String type) { if("genres".equals(type)) { SubsonicFragment fragment = new SelectGenreFragment(); - replaceFragment(fragment, R.id.home_layout); + replaceFragment(fragment); } else if("years".equals(type)) { SubsonicFragment fragment = new SelectYearFragment(); - replaceFragment(fragment, R.id.home_layout); + replaceFragment(fragment); } else { SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); @@ -233,7 +233,7 @@ public class MainFragment extends SubsonicFragment { args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); fragment.setArguments(args); - replaceFragment(fragment, R.id.home_layout); + replaceFragment(fragment); } } diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java index 86f31041..5ef8c1dd 100644 --- a/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -1,14 +1,11 @@ package github.daneren2005.dsub.fragments; -import java.io.Serializable; import java.util.ArrayList; -import java.util.Dictionary; import java.util.List; import java.util.Arrays; import android.content.Intent; import android.os.Bundle; -import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -301,7 +298,7 @@ public class SearchFragment extends SubsonicFragment { args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) { @@ -314,7 +311,7 @@ public class SearchFragment extends SubsonicFragment { } fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) { diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 4f4449e1..5644c059 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -2,7 +2,6 @@ package github.daneren2005.dsub.fragments; import android.os.Build; import android.os.Bundle; -import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -22,11 +21,10 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistAdapter; -import java.io.File; + import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -178,7 +176,7 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } } diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 00bbd049..a132d847 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -48,7 +48,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); private DragSortListView entryList; - int rootId = -1; private View emptyView; private boolean hideButtons = false; private Boolean licenseValid; @@ -78,11 +77,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter public void onCreate(Bundle bundle) { super.onCreate(bundle); if(bundle != null) { - int tmp = bundle.getInt(Constants.FRAGMENT_ID, -1); - if(tmp > 0) { - rootId = tmp; - maximizeIdGenerator(tmp); - } entries = (List) bundle.getSerializable(Constants.FRAGMENT_LIST); restoredInstance = true; } @@ -91,17 +85,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(Constants.FRAGMENT_ID, rootId); outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) entries); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.select_album, container, false); - if(rootId == -1) { - rootId = getNewId(); - } - rootView.setId(rootId); entryList = (DragSortListView) rootView.findViewById(R.id.select_album_entries); entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); @@ -338,7 +327,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } fragment.setArguments(args); - replaceFragment(fragment, rootId, true); + replaceFragment(fragment, true); } else if (entry.isVideo()) { playVideo(entry); } else if(entry instanceof PodcastEpisode) { @@ -366,15 +355,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter load(refresh); } } - - @Override - public int getRootId() { - return rootId; - } - public int setRootId() { - rootId = getNewId(); - return rootId; - } private void load(boolean refresh) { if(refreshListing) { diff --git a/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java b/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java index fd0bbf4a..9cf505b3 100644 --- a/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java @@ -19,7 +19,6 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; -import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -67,6 +66,6 @@ public class SelectGenreFragment extends SelectListFragment { args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_EXTRA, genre.getName()); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } } diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index fb3a254a..0bf64be1 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -5,17 +5,14 @@ import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.ListView; + import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.Playlist; @@ -24,18 +21,14 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.OfflineException; import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SyncUtil; -import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.CacheCleaner; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.LoadingTask; -import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PlaylistAdapter; -import java.io.Serializable; import java.util.List; public class SelectPlaylistFragment extends SelectListFragment { @@ -94,7 +87,7 @@ public class SelectPlaylistFragment extends SelectListFragment { args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); break; case R.id.playlist_menu_play_shuffled: fragment = new SelectDirectoryFragment(); @@ -105,7 +98,7 @@ public class SelectPlaylistFragment extends SelectListFragment { args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); break; case R.id.playlist_menu_delete: deletePlaylist(playlist); @@ -156,7 +149,7 @@ public class SelectPlaylistFragment extends SelectListFragment { args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } private void deletePlaylist(final Playlist playlist) { diff --git a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index fde45b0f..820090ce 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -21,17 +21,11 @@ package github.daneren2005.dsub.fragments; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; -import android.util.Log; import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.ListView; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; @@ -42,15 +36,12 @@ import github.daneren2005.dsub.service.OfflineException; import github.daneren2005.dsub.service.ServerTooOldException; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SyncUtil; -import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.SilentBackgroundTask; -import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PodcastChannelAdapter; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -162,7 +153,7 @@ public class SelectPodcastsFragment extends SelectListFragment { args.putString(Constants.INTENT_EXTRA_NAME_PODCAST_DESCRIPTION, channel.getDescription()); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } } diff --git a/src/github/daneren2005/dsub/fragments/SelectShareFragment.java b/src/github/daneren2005/dsub/fragments/SelectShareFragment.java index 92d2d4b6..5fc50594 100644 --- a/src/github/daneren2005/dsub/fragments/SelectShareFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectShareFragment.java @@ -1,10 +1,8 @@ package github.daneren2005.dsub.fragments; import android.app.AlertDialog; -import android.app.DatePickerDialog; import android.content.DialogInterface; import android.os.Bundle; -import android.util.Log; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; @@ -15,7 +13,6 @@ import android.widget.CompoundButton; import android.widget.DatePicker; import android.widget.EditText; -import java.util.Calendar; import java.util.Date; import java.util.List; @@ -101,7 +98,7 @@ public class SelectShareFragment extends SelectListFragment { args.putSerializable(Constants.INTENT_EXTRA_NAME_SHARE, share); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } private void displayShareInfo(final Share share) { diff --git a/src/github/daneren2005/dsub/fragments/SelectYearFragment.java b/src/github/daneren2005/dsub/fragments/SelectYearFragment.java index ee60bf69..03d62307 100644 --- a/src/github/daneren2005/dsub/fragments/SelectYearFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectYearFragment.java @@ -73,6 +73,6 @@ public class SelectYearFragment extends SelectListFragment { args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_EXTRA, Integer.toString(decade)); fragment.setArguments(args); - replaceFragment(fragment, R.id.fragment_list_layout); + replaceFragment(fragment); } } diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index a9d62d0b..1669ad1f 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -28,7 +28,6 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.media.MediaMetadataRetriever; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; @@ -44,7 +43,6 @@ import android.widget.EditText; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; -import github.daneren2005.dsub.activity.SettingsActivity; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.activity.SubsonicFragmentActivity; import github.daneren2005.dsub.domain.Artist; @@ -68,7 +66,6 @@ import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.Util; import java.io.File; -import java.io.Serializable; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -77,11 +74,9 @@ import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; public class SubsonicFragment extends Fragment { private static final String TAG = SubsonicFragment.class.getSimpleName(); - private static final AtomicInteger nextGeneratedId = new AtomicInteger(1); private static int TAG_INC = 10; private int tag; @@ -354,30 +349,13 @@ public class SubsonicFragment extends Fragment { return true; } - public void replaceFragment(SubsonicFragment fragment, int id) { - replaceFragment(fragment, id, true); + public void replaceFragment(SubsonicFragment fragment) { + replaceFragment(fragment, true); } - public void replaceFragment(SubsonicFragment fragment, int id, boolean replaceCurrent) { - context.replaceFragment(fragment, id, fragment.getSupportTag(), secondaryFragment && replaceCurrent); - } - - protected int getNewId() { - for (;;) { - final int result = nextGeneratedId.get(); - // aapt-generated IDs have the high byte nonzero; clamp to the range under that. - int newValue = result + 1; - if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. - if (nextGeneratedId.compareAndSet(result, newValue)) { - return result; - } - } - } - protected void maximizeIdGenerator(int id) { - final int result = nextGeneratedId.get(); - if(id >= result) { - nextGeneratedId.set(id + 1); - } + public void replaceFragment(SubsonicFragment fragment, boolean replaceCurrent) { + context.replaceFragment(fragment, fragment.getSupportTag(), secondaryFragment && replaceCurrent); } + public int getRootId() { return rootView.getId(); } @@ -1137,7 +1115,7 @@ public class SubsonicFragment extends Fragment { args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); fragment.setArguments(args); - replaceFragment(fragment, getRootId(), true); + replaceFragment(fragment, true); } public void createShare(final List entries) { -- cgit v1.2.3