Converted Lyrics activity to fragment
This commit is contained in:
parent
73f246b60e
commit
4d6f75031a
5 changed files with 113 additions and 125 deletions
|
@ -111,7 +111,7 @@
|
|||
<activity android:name=".activities.SettingsActivity" />
|
||||
<activity android:name=".activities.tageditor.AlbumTagEditorActivity" />
|
||||
<activity android:name=".activities.tageditor.SongTagEditorActivity" />
|
||||
<activity android:name=".activities.LyricsActivity" />
|
||||
<activity android:name=".fragments.LyricsActivity" />
|
||||
<activity android:name=".activities.SupportDevelopmentActivity" />
|
||||
<activity android:name=".activities.LicenseActivity" />
|
||||
<activity android:name=".activities.PurchaseActivity" />
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* See the GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
package code.name.monkey.retromusic.activities
|
||||
package code.name.monkey.retromusic.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
|
@ -20,13 +20,13 @@ import android.view.*
|
|||
import androidx.core.view.ViewCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
||||
import code.name.monkey.retromusic.activities.tageditor.WriteTagsAsyncTask
|
||||
import code.name.monkey.retromusic.databinding.ActivityLyricsBinding
|
||||
import code.name.monkey.retromusic.databinding.FragmentLyricsBinding
|
||||
import code.name.monkey.retromusic.databinding.FragmentNormalLyricsBinding
|
||||
import code.name.monkey.retromusic.databinding.FragmentSyncedLyricsBinding
|
||||
import code.name.monkey.retromusic.extensions.accentColor
|
||||
|
@ -53,12 +53,13 @@ import org.jaudiotagger.tag.FieldKey
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class LyricsActivity : AbsMusicServiceActivity() {
|
||||
class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
|
||||
|
||||
private lateinit var binding: ActivityLyricsBinding
|
||||
private var _binding: FragmentLyricsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private lateinit var song: Song
|
||||
|
||||
private val lyricsSectionsAdapter = LyricsSectionsAdapter(this)
|
||||
private lateinit var lyricsSectionsAdapter: LyricsSectionsAdapter
|
||||
|
||||
private val googleSearchLrcUrl: String
|
||||
get() {
|
||||
|
@ -80,20 +81,18 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
private fun buildContainerTransform(): MaterialContainerTransform {
|
||||
val transform = MaterialContainerTransform()
|
||||
transform.setAllContainerColors(
|
||||
MaterialColors.getColor(findViewById(R.id.container), R.attr.colorSurface)
|
||||
MaterialColors.getColor(requireView().findViewById(R.id.container), R.attr.colorSurface)
|
||||
)
|
||||
transform.addTarget(R.id.container)
|
||||
transform.duration = 300
|
||||
return transform
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityLyricsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
lyricsSectionsAdapter = LyricsSectionsAdapter(requireActivity())
|
||||
_binding = FragmentLyricsBinding.bind(view)
|
||||
ViewCompat.setTransitionName(binding.container, "lyrics")
|
||||
setStatusbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
|
||||
setupWakelock()
|
||||
|
||||
|
@ -101,12 +100,10 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
binding.tabLyrics.setBackgroundColor(surfaceColor())
|
||||
binding.container.setBackgroundColor(surfaceColor())
|
||||
ToolbarContentTintHelper.colorBackButton(binding.toolbar)
|
||||
setSupportActionBar(binding.toolbar)
|
||||
setupViews()
|
||||
|
||||
updateTitleSong()
|
||||
}
|
||||
|
||||
|
||||
private fun setupViews() {
|
||||
binding.lyricsPager.adapter = lyricsSectionsAdapter
|
||||
TabLayoutMediator(binding.tabLyrics, binding.lyricsPager) { tab, position ->
|
||||
|
@ -118,7 +115,7 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
}.attach()
|
||||
// lyricsPager.isUserInputEnabled = false
|
||||
|
||||
binding.tabLyrics.setSelectedTabIndicatorColor(ThemeStore.accentColor(this))
|
||||
binding.tabLyrics.setSelectedTabIndicatorColor(ThemeStore.accentColor(requireContext()))
|
||||
binding.tabLyrics.setTabTextColors(textColorSecondary(), accentColor())
|
||||
}
|
||||
|
||||
|
@ -140,22 +137,22 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
}
|
||||
|
||||
private fun setupWakelock() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_search, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_search, menu)
|
||||
return super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
finish()
|
||||
findNavController().navigateUp()
|
||||
return true
|
||||
}
|
||||
if (item.itemId == R.id.action_search) {
|
||||
RetroUtil.openUrl(
|
||||
this, when (binding.lyricsPager.currentItem) {
|
||||
requireActivity(), when (binding.lyricsPager.currentItem) {
|
||||
0 -> syairSearchLrcUrl
|
||||
1 -> googleSearchLrcUrl
|
||||
else -> googleSearchLrcUrl
|
||||
|
@ -184,7 +181,7 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
e.printStackTrace()
|
||||
}
|
||||
|
||||
MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
title(res = R.string.edit_normal_lyrics)
|
||||
input(
|
||||
hintRes = R.string.paste_lyrics_here,
|
||||
|
@ -193,7 +190,7 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
) { _, input ->
|
||||
val fieldKeyValueMap = EnumMap<FieldKey, String>(FieldKey::class.java)
|
||||
fieldKeyValueMap[FieldKey.LYRICS] = input.toString()
|
||||
WriteTagsAsyncTask(this@LyricsActivity).execute(
|
||||
WriteTagsAsyncTask(requireActivity()).execute(
|
||||
LoadingInfo(
|
||||
listOf(song.data), fieldKeyValueMap, null
|
||||
)
|
||||
|
@ -216,7 +213,7 @@ class LyricsActivity : AbsMusicServiceActivity() {
|
|||
}
|
||||
val content: String = LyricUtil.getStringFromLrc(lrcFile)
|
||||
|
||||
MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
title(res = R.string.edit_synced_lyrics)
|
||||
input(
|
||||
hintRes = R.string.paste_timeframe_lyrics_here,
|
|
@ -11,100 +11,88 @@
|
|||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
package code.name.monkey.retromusic.util
|
||||
|
||||
package code.name.monkey.retromusic.util;
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.audiofx.AudioEffect
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.navigation.findNavController
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.*
|
||||
import code.name.monkey.retromusic.activities.bugreport.BugReportActivity
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.audioSessionId
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityOptions;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.audiofx.AudioEffect;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.activities.DriveModeActivity;
|
||||
import code.name.monkey.retromusic.activities.LicenseActivity;
|
||||
import code.name.monkey.retromusic.activities.LyricsActivity;
|
||||
import code.name.monkey.retromusic.activities.PlayingQueueActivity;
|
||||
import code.name.monkey.retromusic.activities.PurchaseActivity;
|
||||
import code.name.monkey.retromusic.activities.SupportDevelopmentActivity;
|
||||
import code.name.monkey.retromusic.activities.WhatsNewActivity;
|
||||
import code.name.monkey.retromusic.activities.bugreport.BugReportActivity;
|
||||
import code.name.monkey.retromusic.fragments.UserInfoFragment;
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
|
||||
|
||||
public class NavigationUtil {
|
||||
|
||||
public static void bugReport(@NonNull Activity activity) {
|
||||
ActivityCompat.startActivity(activity, new Intent(activity, BugReportActivity.class), null);
|
||||
}
|
||||
|
||||
public static void goToLyrics(@NonNull Activity activity) {
|
||||
Intent intent = new Intent(activity, LyricsActivity.class);
|
||||
ActivityCompat.startActivity(activity, intent, null);
|
||||
}
|
||||
|
||||
public static void goToOpenSource(@NonNull Activity activity) {
|
||||
ActivityCompat.startActivity(activity, new Intent(activity, LicenseActivity.class), null);
|
||||
}
|
||||
|
||||
public static void goToPlayingQueue(@NonNull Activity activity) {
|
||||
Intent intent = new Intent(activity, PlayingQueueActivity.class);
|
||||
ActivityCompat.startActivity(activity, intent, null);
|
||||
}
|
||||
|
||||
public static void goToProVersion(@NonNull Context context) {
|
||||
ActivityCompat.startActivity(context, new Intent(context, PurchaseActivity.class), null);
|
||||
}
|
||||
|
||||
public static void goToSupportDevelopment(@NonNull Activity activity) {
|
||||
ActivityCompat.startActivity(
|
||||
activity, new Intent(activity, SupportDevelopmentActivity.class), null);
|
||||
}
|
||||
|
||||
public static void goToUserInfo(
|
||||
@NonNull Activity activity, @NonNull ActivityOptions activityOptions) {
|
||||
ActivityCompat.startActivity(
|
||||
activity, new Intent(activity, UserInfoFragment.class), activityOptions.toBundle());
|
||||
}
|
||||
|
||||
public static void gotoDriveMode(@NotNull final Activity activity) {
|
||||
ActivityCompat.startActivity(activity, new Intent(activity, DriveModeActivity.class), null);
|
||||
}
|
||||
|
||||
public static void gotoWhatNews(@NonNull Activity activity) {
|
||||
ActivityCompat.startActivity(activity, new Intent(activity, WhatsNewActivity.class), null);
|
||||
}
|
||||
|
||||
public static void openEqualizer(@NonNull final Activity activity) {
|
||||
stockEqalizer(activity);
|
||||
}
|
||||
|
||||
private static void stockEqalizer(@NonNull Activity activity) {
|
||||
final int sessionId = MusicPlayerRemote.INSTANCE.getAudioSessionId();
|
||||
if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
|
||||
Toast.makeText(
|
||||
activity, activity.getResources().getString(R.string.no_audio_ID), Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
try {
|
||||
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
|
||||
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
|
||||
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
|
||||
activity.startActivityForResult(effects, 0);
|
||||
} catch (@NonNull final ActivityNotFoundException notFound) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
activity.getResources().getString(R.string.no_equalizer),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
object NavigationUtil {
|
||||
fun bugReport(activity: Activity) {
|
||||
ActivityCompat.startActivity(
|
||||
activity,
|
||||
Intent(activity, BugReportActivity::class.java),
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun goToOpenSource(activity: Activity) {
|
||||
ActivityCompat.startActivity(activity, Intent(activity, LicenseActivity::class.java), null)
|
||||
}
|
||||
|
||||
fun goToLyrics(activity: Activity) {
|
||||
if (activity is MainActivity) {
|
||||
activity.collapsePanel()
|
||||
}
|
||||
activity.findNavController(R.id.fragment_container).navigate(R.id.lyrics_fragment)
|
||||
}
|
||||
|
||||
fun goToProVersion(context: Context) {
|
||||
ActivityCompat.startActivity(context, Intent(context, PurchaseActivity::class.java), null)
|
||||
}
|
||||
|
||||
fun goToSupportDevelopment(activity: Activity) {
|
||||
ActivityCompat.startActivity(
|
||||
activity, Intent(activity, SupportDevelopmentActivity::class.java), null
|
||||
)
|
||||
}
|
||||
|
||||
fun gotoDriveMode(activity: Activity) {
|
||||
ActivityCompat.startActivity(
|
||||
activity,
|
||||
Intent(activity, DriveModeActivity::class.java),
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
fun gotoWhatNews(activity: Activity) {
|
||||
ActivityCompat.startActivity(activity, Intent(activity, WhatsNewActivity::class.java), null)
|
||||
}
|
||||
|
||||
fun openEqualizer(activity: Activity) {
|
||||
stockEqalizer(activity)
|
||||
}
|
||||
|
||||
private fun stockEqalizer(activity: Activity) {
|
||||
val sessionId = audioSessionId
|
||||
if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
|
||||
Toast.makeText(
|
||||
activity, activity.resources.getString(R.string.no_audio_ID), Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
} else {
|
||||
try {
|
||||
val effects = Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL)
|
||||
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId)
|
||||
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC)
|
||||
activity.startActivityForResult(effects, 0)
|
||||
} catch (notFound: ActivityNotFoundException) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
activity.resources.getString(R.string.no_equalizer),
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,11 +7,10 @@
|
|||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.bottomappbar.BottomAppBar
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:padding="0dp"
|
||||
app:contentInsetLeft="0dp"
|
||||
app:contentInsetStart="0dp"
|
||||
|
@ -39,13 +38,13 @@
|
|||
tools:subtitle="@tools:sample/full_names"
|
||||
tools:title="@tools:sample/full_names" />
|
||||
|
||||
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="?attr/actionBarSize">
|
||||
android:layout_marginTop="?attr/actionBarSize">
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/lyricsPager"
|
|
@ -129,4 +129,8 @@
|
|||
<fragment
|
||||
android:id="@+id/playing_queue_fragment"
|
||||
android:name="code.name.monkey.retromusic.fragments.queue.PlayingQueueFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/lyrics_fragment"
|
||||
android:name="code.name.monkey.retromusic.fragments.LyricsFragment" />
|
||||
</navigation>
|
Loading…
Reference in a new issue