Fix crash while rotating device

main
Hemanth S 2020-08-13 23:18:49 +05:30
parent e159b1a32a
commit 1c08487939
19 changed files with 44 additions and 66 deletions

View File

@ -24,9 +24,13 @@ import java.util.*
open class AbsMusicServiceFragment(@LayoutRes layout: Int) : Fragment(layout),
MusicServiceEventListener {
val navOptions by lazy {
navOptions {
launchSingleTop = true
popUpTo(R.id.action_home) {
inclusive = false
}
launchSingleTop = false
anim {
enter = R.anim.retro_fragment_open_enter
exit = R.anim.retro_fragment_open_exit
@ -35,6 +39,7 @@ open class AbsMusicServiceFragment(@LayoutRes layout: Int) : Fragment(layout),
}
}
}
var playerActivity: AbsMusicServiceActivity? = null
private set

View File

@ -87,7 +87,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements
FileUtil.fileIsMimeType(file, "audio/*", MimeTypeMap.getSingleton()) ||
FileUtil.fileIsMimeType(file, "application/opus", MimeTypeMap.getSingleton()) ||
FileUtil.fileIsMimeType(file, "application/ogg", MimeTypeMap.getSingleton()));
public static final String PATH = "path";
private static final String CRUMBS = "crumbs";
private static final int LOADER_ID = 5;
private SongFileAdapter adapter;
@ -128,18 +128,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
return startFolder;
}
public static FoldersFragment newInstance(File directory) {
FoldersFragment frag = new FoldersFragment();
Bundle b = new Bundle();
b.putSerializable(PATH, directory);
frag.setArguments(b);
return frag;
}
public static FoldersFragment newInstance(Context context) {
return newInstance(PreferenceUtil.INSTANCE.getStartDirectory());
}
private static File tryGetCanonicalFile(File file) {
try {
return file.getCanonicalFile();
@ -174,7 +162,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements
if (savedInstanceState == null) {
//noinspection ConstantConditions
setCrumb(new BreadCrumbLayout.Crumb(FileUtil.safeGetCanonicalFile((File) requireArguments().getSerializable(PATH))), true);
setCrumb(new BreadCrumbLayout.Crumb(FileUtil.safeGetCanonicalFile(PreferenceUtil.INSTANCE.getStartDirectory())), true);
} else {
breadCrumbs.restoreFromStateWrapper(savedInstanceState.getParcelable(CRUMBS));
getLoaderManager().initLoader(LOADER_ID, null, this);

View File

@ -5,19 +5,17 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.NavigationUI
import code.name.monkey.appthemehelper.common.ATHToolbarActivity.getToolbarBackgroundColor
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.findNavController
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
import code.name.monkey.retromusic.fragments.folder.FoldersFragment
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.appbar.AppBarLayout
import kotlinx.android.synthetic.main.fragment_library.*
class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
@ -36,26 +34,7 @@ class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
private fun setupNavigationController() {
val navController = findNavController(R.id.fragment_container)
mainActivity.getBottomNavigationView().setOnNavigationItemSelectedListener {
var handled = false
if (navController.graph.findNode(it.itemId) != null) {
navController.navigate(it.itemId, null, navOptions)
handled = true
}
when (it.itemId) {
R.id.action_folder -> navController.navigate(
R.id.action_folder,
Bundle().apply {
putSerializable(
FoldersFragment.PATH,
PreferenceUtil.startDirectory
)
},
navOptions
)
}
return@setOnNavigationItemSelectedListener handled
}
NavigationUI.setupWithNavController(mainActivity.getBottomNavigationView(), navController)
}
override fun onPrepareOptionsMenu(menu: Menu) {

View File

@ -52,7 +52,7 @@ class PlayerPlaybackControlsFragment :
showBonceAnimation(playPauseButton)
}
title.isSelected = true
text.isSelected = true
}
override fun setColor(color: MediaNotificationProcessor) {

View File

@ -15,7 +15,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="8dp"
android:textAllCaps="true"
android:textAllCaps="false"
android:textAppearance="@style/TextViewNormal"
android:textColor="#fff"
tools:ignore="RtlSymmetry,UnusedAttribute"
tools:text="Storage"

View File

@ -42,7 +42,7 @@
</FrameLayout>
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -52,7 +52,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/statusBarContainer" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.blur.BlurPlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"

View File

@ -31,7 +31,7 @@
</FrameLayout>
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -41,7 +41,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/statusBarContainer" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.color.ColorPlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -22,7 +22,7 @@
android:layout_height="wrap_content"
android:layout_weight="1">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="match_parent"
@ -37,7 +37,7 @@
android:layout_height="wrap_content"
android:layout_weight="0">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.fit.FitPlaybackControlsFragment"
android:layout_width="match_parent"

View File

@ -43,7 +43,7 @@
app:navigationIcon="@drawable/ic_keyboard_arrow_down_black" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -55,7 +55,7 @@
tools:layout="@layout/fragment_album_flat_cover" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.flat.FlatPlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -8,7 +8,7 @@
android:focusable="true">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -31,7 +31,7 @@
app:layout_constraintTop_toTopOf="parent" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.full.FullPlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:paddingBottom="48dp">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"

View File

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"

View File

@ -47,7 +47,7 @@
</FrameLayout>
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="72dp"
@ -114,7 +114,7 @@
app:layout_constraintTop_toBottomOf="@+id/text"
tools:text="@tools:sample/lorem/random" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.peak.PeakPlayerControlFragment"
android:layout_width="match_parent"

View File

@ -61,7 +61,7 @@
tools:text="Text" />
</LinearLayout>
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -71,7 +71,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleContainer" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.plain.PlainPlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -32,7 +32,7 @@
</FrameLayout>
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -43,7 +43,7 @@
app:layout_constraintHeight_percent="0.5" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.normal.PlayerPlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -9,7 +9,6 @@
android:orientation="vertical"
tools:ignore="MissingPrefix">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/songCurrentProgress"
android:layout_width="wrap_content"
@ -85,10 +84,16 @@
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="@style/TextViewBody1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constrainedWidth="true"

View File

@ -25,7 +25,7 @@
</FrameLayout>
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
@ -35,7 +35,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/statusBarContainer" />
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.simple.SimplePlaybackControlsFragment"
android:layout_width="0dp"

View File

@ -7,7 +7,7 @@
android:clickable="true"
android:focusable="true">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="wrap_content"
@ -105,7 +105,7 @@
app:layout_constraintBottom_toTopOf="@id/toolbarContainer"
app:layout_constraintEnd_toEndOf="parent">
<androidx.fragment.app.FragmentContainerView
<fragment
android:id="@+id/playbackControlsFragment"
android:name="code.name.monkey.retromusic.fragments.player.tiny.TinyPlaybackControlsFragment"
android:layout_width="match_parent"