Code Cleanup

This commit is contained in:
Prathamesh More 2022-04-13 00:03:27 +05:30
parent 818703c573
commit ad90694879
61 changed files with 236 additions and 495 deletions

View file

@ -22,11 +22,11 @@ import android.os.Bundle
import android.view.animation.LinearInterpolator
import android.widget.SeekBar
import androidx.lifecycle.lifecycleScope
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
import code.name.monkey.retromusic.databinding.ActivityDriveModeBinding
import code.name.monkey.retromusic.db.toSongEntity
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
import code.name.monkey.retromusic.glide.BlurTransformation
@ -66,7 +66,7 @@ class DriveModeActivity : AbsMusicServiceActivity(), Callback {
setUpMusicControllers()
progressViewUpdateHelper = MusicProgressViewUpdateHelper(this)
lastPlaybackControlsColor = ThemeStore.accentColor(this)
lastPlaybackControlsColor = accentColor()
binding.close.setOnClickListener {
onBackPressed()
}
@ -91,7 +91,6 @@ class DriveModeActivity : AbsMusicServiceActivity(), Callback {
private fun toggleFavorite(song: Song) {
lifecycleScope.launch(Dispatchers.IO) {
val playlist = repository.favoritePlaylist()
if (playlist != null) {
val songEntity = song.toSongEntity(playlist.playListId)
val isFavorite = repository.isSongFavorite(song.id)
if (isFavorite) {
@ -99,7 +98,6 @@ class DriveModeActivity : AbsMusicServiceActivity(), Callback {
} else {
repository.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
}
}
sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED))
}
}
@ -139,7 +137,6 @@ class DriveModeActivity : AbsMusicServiceActivity(), Callback {
}
private fun setUpPrevNext() {
binding.nextButton.setOnClickListener { MusicPlayerRemote.playNextSong() }
binding.previousButton.setOnClickListener { MusicPlayerRemote.back() }
}
@ -246,7 +243,8 @@ class DriveModeActivity : AbsMusicServiceActivity(), Callback {
GlideApp.with(this)
.load(RetroGlideExtension.getSongModel(song))
.songCoverOptions(song).transform(BlurTransformation.Builder(this).build())
.songCoverOptions(song)
.transform(BlurTransformation.Builder(this).build())
.into(binding.image)
}

View file

@ -16,12 +16,12 @@ package code.name.monkey.retromusic.activities
import android.graphics.Color
import android.os.Bundle
import android.view.MenuItem
import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
import code.name.monkey.appthemehelper.util.ColorUtil.lightenColor
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.activities.base.AbsThemeActivity
import code.name.monkey.retromusic.databinding.ActivityLicenseBinding
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.surfaceColor
import java.io.BufferedReader
@ -59,11 +59,11 @@ class LicenseActivity : AbsThemeActivity() {
"body { background-color: %s; color: %s; }", backgroundColor, contentColor
)
)
.replace("{link-color}", colorToCSS(accentColor(this)))
.replace("{link-color}", colorToCSS(accentColor()))
.replace(
"{link-color-active}",
colorToCSS(
lightenColor(accentColor(this))
lightenColor(accentColor())
)
)
binding.license.loadData(changeLog, "text/html", "UTF-8")

View file

@ -25,14 +25,10 @@ import androidx.annotation.RequiresApi
import androidx.core.net.toUri
import androidx.core.text.parseAsHtml
import androidx.core.view.isVisible
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
import code.name.monkey.retromusic.databinding.ActivityPermissionBinding
import code.name.monkey.retromusic.extensions.accentBackgroundColor
import code.name.monkey.retromusic.extensions.setStatusBarColorAuto
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.extensions.*
import code.name.monkey.retromusic.util.RingtoneManager
class PermissionActivity : AbsMusicServiceActivity() {
@ -75,9 +71,10 @@ class PermissionActivity : AbsMusicServiceActivity() {
}
private fun setupTitle() {
val color = ThemeStore.accentColor(this)
val color = accentColor()
val hexColor = String.format("#%06X", 0xFFFFFF and color)
val appName = "Hello there! <br>Welcome to <b>Retro <span style='color:$hexColor';>Music</span></b>"
val appName =
"Hello there! <br>Welcome to <b>Retro <span style='color:$hexColor';>Music</span></b>"
.parseAsHtml()
binding.appNameText.text = appName
}
@ -87,14 +84,13 @@ class PermissionActivity : AbsMusicServiceActivity() {
if (hasStoragePermission()) {
binding.storagePermission.checkImage.isVisible = true
binding.storagePermission.checkImage.imageTintList =
ColorStateList.valueOf(ThemeStore.accentColor(this))
ColorStateList.valueOf(accentColor())
}
if (hasAudioPermission()) {
binding.audioPermission.checkImage.isVisible = true
binding.audioPermission.checkImage.imageTintList =
ColorStateList.valueOf(ThemeStore.accentColor(this))
ColorStateList.valueOf(accentColor())
}
super.onResume()
}

View file

@ -28,6 +28,7 @@ import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.databinding.ActivityProVersionBinding
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.setLightStatusBar
import code.name.monkey.retromusic.extensions.setStatusBarColor
import com.anjlab.android.iab.v3.BillingProcessor
@ -61,7 +62,7 @@ class PurchaseActivity : AbsBaseActivity(), BillingProcessor.IBillingHandler {
billingProcessor.purchase(this@PurchaseActivity, PRO_VERSION_PRODUCT_ID)
}
binding.bannerContainer.backgroundTintList =
ColorStateList.valueOf(ThemeStore.accentColor(this))
ColorStateList.valueOf(accentColor())
}
private fun restorePurchase() {

View file

@ -28,6 +28,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.databinding.ActivityShareInstagramBinding
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.setLightStatusBar
import code.name.monkey.retromusic.extensions.setStatusBarColor
import code.name.monkey.retromusic.glide.GlideApp
@ -96,11 +97,11 @@ class ShareInstagramStory : AbsBaseActivity() {
binding.shareButton.setTextColor(
MaterialValueHelper.getPrimaryTextColor(
this,
ColorUtil.isColorLight(ThemeStore.accentColor(this))
ColorUtil.isColorLight(accentColor())
)
)
binding.shareButton.backgroundTintList =
ColorStateList.valueOf(ThemeStore.accentColor(this))
ColorStateList.valueOf(accentColor())
}
private fun setColors(colorLight: Boolean, color: Int) {

View file

@ -75,8 +75,8 @@ class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingH
setupToolbar()
billingProcessor = BillingProcessor(this, BuildConfig.GOOGLE_PLAY_LICENSING_KEY, this)
TintHelper.setTint(binding.progress, ThemeStore.accentColor(this))
binding.donation.setTextColor(ThemeStore.accentColor(this))
TintHelper.setTint(binding.progress, accentColor())
binding.donation.setTextColor(accentColor())
}
private fun setupToolbar() {

View file

@ -5,7 +5,6 @@ import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Bundle
import androidx.core.widget.NestedScrollView
import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
import code.name.monkey.appthemehelper.util.ColorUtil.isColorLight
import code.name.monkey.appthemehelper.util.ColorUtil.lightenColor
@ -14,12 +13,8 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.Constants
import code.name.monkey.retromusic.activities.base.AbsThemeActivity
import code.name.monkey.retromusic.databinding.ActivityWhatsNewBinding
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.extensions.*
import code.name.monkey.retromusic.util.PreferenceUtil.lastVersion
import code.name.monkey.retromusic.util.RetroUtil
import java.io.BufferedReader
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets
@ -45,13 +40,13 @@ class WhatsNewActivity : AbsThemeActivity() {
// Inject color values for WebView body background and links
val isDark = isWindowBackgroundDark(this)
val accentColor = accentColor(this)
val accentColor = accentColor()
val backgroundColor = colorToCSS(
surfaceColor(Color.parseColor(if (isDark) "#424242" else "#ffffff"))
)
val contentColor = colorToCSS(Color.parseColor(if (isDark) "#ffffff" else "#000000"))
val textColor = colorToCSS(Color.parseColor(if (isDark) "#60FFFFFF" else "#80000000"))
val accentColorString = colorToCSS(accentColor(this))
val accentColorString = colorToCSS(accentColor())
val cardBackgroundColor =
colorToCSS(Color.parseColor(if (isDark) "#353535" else "#ffffff"))
val accentTextColor = colorToCSS(
@ -64,11 +59,11 @@ class WhatsNewActivity : AbsThemeActivity() {
"{style-placeholder}",
"body { background-color: $backgroundColor; color: $contentColor; } li {color: $textColor;} h3 {color: $accentColorString;} .tag {background-color: $accentColorString; color: $accentTextColor; } div{background-color: $cardBackgroundColor;}"
)
.replace("{link-color}", colorToCSS(accentColor(this)))
.replace("{link-color}", colorToCSS(accentColor()))
.replace(
"{link-color-active}",
colorToCSS(
lightenColor(accentColor(this))
lightenColor(accentColor())
)
)
binding.webView.loadData(changeLog, "text/html", "UTF-8")
@ -79,10 +74,7 @@ class WhatsNewActivity : AbsThemeActivity() {
}
setChangelogRead(this)
binding.tgFab.setOnClickListener {
RetroUtil.openUrl(
this,
Constants.TELEGRAM_CHANGE_LOG
)
openUrl(Constants.TELEGRAM_CHANGE_LOG)
}
binding.tgFab.accentColor()
binding.tgFab.shrink()

View file

@ -29,9 +29,9 @@ import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.core.app.ActivityCompat
import androidx.core.content.getSystemService
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.accentColor
import com.google.android.material.snackbar.Snackbar
abstract class AbsBaseActivity : AbsThemeActivity() {
@ -126,14 +126,15 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
Snackbar.LENGTH_INDEFINITE
)
.setAction(R.string.action_grant) { requestPermissions() }
.setActionTextColor(ThemeStore.accentColor(this)).show()
.setActionTextColor(accentColor()).show()
} else {
// User has deny permission and checked never show permission dialog so you can redirect to Application settings page
Snackbar.make(
snackBarContainer,
permissionDeniedMessage!!,
Snackbar.LENGTH_INDEFINITE
).setAction(R.string.action_settings) {
)
.setAction(R.string.action_settings) {
val intent = Intent()
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
val uri = Uri.fromParts(
@ -143,7 +144,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
)
intent.data = uri
startActivity(intent)
}.setActionTextColor(ThemeStore.accentColor(this)).show()
}.setActionTextColor(accentColor()).show()
}
return
}
@ -156,6 +157,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
companion object {
const val PERMISSION_REQUEST = 100
}
// this lets keyboard close when clicked in backgroud
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN) {
@ -165,7 +167,10 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
v.getGlobalVisibleRect(outRect)
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
v.clearFocus()
getSystemService<InputMethodManager>()?.hideSoftInputFromWindow(v.windowToken, 0)
getSystemService<InputMethodManager>()?.hideSoftInputFromWindow(
v.windowToken,
0
)
}
}
}

View file

@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.ViewStub
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.cast.CastHelper
import code.name.monkey.retromusic.cast.RetroSessionManager
import code.name.monkey.retromusic.cast.RetroSessionManagerListener
import code.name.monkey.retromusic.cast.RetroWebServer
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import com.google.android.gms.cast.framework.CastContext
@ -22,7 +22,7 @@ abstract class AbsCastActivity : AbsSlidingMusicPanelActivity() {
private var playServicesAvailable: Boolean = false
private val sessionManagerListener by lazy {
object : RetroSessionManager {
object : RetroSessionManagerListener {
override fun onSessionStarting(castSession: CastSession) {
invalidateOptionsMenu()
webServer = RetroWebServer.getInstance(this@AbsCastActivity)
@ -88,7 +88,7 @@ abstract class AbsCastActivity : AbsSlidingMusicPanelActivity() {
}
private fun setupCast() {
sessionManager = CastContext.getSharedInstance(applicationContext).sessionManager
sessionManager = CastContext.getSharedInstance(this).sessionManager
}
override fun onResume() {
@ -104,10 +104,16 @@ abstract class AbsCastActivity : AbsSlidingMusicPanelActivity() {
super.onResume()
}
override fun onStop() {
super.onStop()
override fun onPause() {
super.onPause()
if (playServicesAvailable) {
sessionManager.removeSessionManagerListener(
sessionManagerListener,
CastSession::class.java
)
mCastSession = null
}
}
private fun songChanged(position: Int) {
loadCastQueue(position)

View file

@ -26,7 +26,6 @@ import androidx.annotation.StringRes
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.lifecycle.lifecycleScope
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
@ -38,6 +37,7 @@ import code.name.monkey.retromusic.activities.bugreport.model.github.ExtraInfo
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubLogin
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget
import code.name.monkey.retromusic.databinding.ActivityBugReportBinding
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
@ -87,7 +87,7 @@ open class BugReportActivity : AbsThemeActivity() {
}
private fun initViews() {
val accentColor = ThemeStore.accentColor(this)
val accentColor = accentColor()
setSupportActionBar(binding.toolbar)
ToolbarContentTintHelper.colorBackButton(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
@ -314,6 +314,7 @@ open class BugReportActivity : AbsThemeActivity() {
private const val STATUS_BAD_CREDENTIALS = 401
private const val STATUS_ISSUES_NOT_ENABLED = 410
private const val ISSUE_TRACKER_LINK = "https://github.com/RetroMusicPlayer/RetroMusicPlayer"
private const val ISSUE_TRACKER_LINK =
"https://github.com/RetroMusicPlayer/RetroMusicPlayer"
}
}

View file

@ -41,6 +41,7 @@ import code.name.monkey.retromusic.R.drawable
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.activities.saf.SAFGuideActivity
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.hideSoftKeyboard
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
import code.name.monkey.retromusic.model.ArtworkInfo
import code.name.monkey.retromusic.model.AudioTagInfo
@ -346,7 +347,7 @@ abstract class AbsTagEditorActivity<VB : ViewBinding> : AbsBaseActivity() {
fieldKeyValueMap: Map<FieldKey, String>,
artworkInfo: ArtworkInfo?
) {
RetroUtil.hideSoftKeyboard(this)
hideSoftKeyboard()
hideFab()
println(fieldKeyValueMap)

View file

@ -14,15 +14,14 @@
*/
package code.name.monkey.retromusic.adapter
import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.openUrl
import code.name.monkey.retromusic.model.Contributor
import code.name.monkey.retromusic.util.RetroUtil.openUrl
import code.name.monkey.retromusic.views.RetroShapeableImageView
import com.bumptech.glide.Glide
@ -65,7 +64,7 @@ class ContributorAdapter(
val contributor = contributors[position]
holder.bindData(contributor)
holder.itemView.setOnClickListener {
openUrl(it?.context as Activity, contributors[position].link)
it?.context?.openUrl(contributors[position].link)
}
}

View file

@ -91,9 +91,9 @@ open class AlbumAdapter(
// Check if imageContainer exists so we can have a smooth transition without
// CardView clipping, if it doesn't exist in current layout set transition name to image instead.
if (holder.imageContainer != null) {
holder.imageContainer!!.setTransitionName(album.id.toString())
holder.imageContainer?.transitionName = album.id.toString()
} else {
holder.image!!.setTransitionName(album.id.toString())
holder.image?.transitionName = album.id.toString()
}
loadAlbumCover(album, holder)
}

View file

@ -85,7 +85,6 @@ class AlbumCoverPagerAdapter(
class AlbumCoverFragment : Fragment() {
private lateinit var albumCover: ImageView
private var isColorReady: Boolean = false
private lateinit var color: MediaNotificationProcessor
private lateinit var song: Song
@ -106,8 +105,6 @@ class AlbumCoverPagerAdapter(
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(getLayoutWithPlayerTheme(), container, false)
view.setTransitionName("lyrics")
albumCover = view.findViewById(R.id.player_image)
view.setOnClickListener {
if (mainActivity.getBottomSheetBehavior().state == STATE_EXPANDED) {
showLyricsDialog()
@ -158,7 +155,7 @@ class AlbumCoverPagerAdapter(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
loadAlbumCover()
loadAlbumCover(albumCover = view.findViewById(R.id.player_image))
}
override fun onDestroyView() {
@ -166,7 +163,7 @@ class AlbumCoverPagerAdapter(
colorReceiver = null
}
private fun loadAlbumCover() {
private fun loadAlbumCover(albumCover: ImageView) {
GlideApp.with(this).asBitmapPalette().songCoverOptions(song)
//.checkIgnoreMediaStore()
.load(RetroGlideExtension.getSongModel(song))

View file

@ -92,9 +92,9 @@ class ArtistAdapter(
val transitionName =
if (albumArtistsOnly) artist.name else artist.id.toString()
if (holder.imageContainer != null) {
holder.imageContainer!!.setTransitionName(transitionName)
holder.imageContainer?.transitionName = transitionName
} else {
holder.image!!.setTransitionName(transitionName)
holder.image?.transitionName = transitionName
}
loadArtistImage(artist, holder)
}

View file

@ -163,7 +163,7 @@ class PlaylistAdapter(
if (isInQuickSelectMode) {
toggleChecked(layoutPosition)
} else {
itemView.setTransitionName("playlist")
itemView.transitionName = "playlist"
listener.onPlaylistClick(dataSet[layoutPosition], itemView)
}
}

View file

@ -1,3 +1,5 @@
@file:Suppress("unused")
package code.name.monkey.retromusic.cast
import android.content.Context

View file

@ -3,7 +3,7 @@ package code.name.monkey.retromusic.cast
import com.google.android.gms.cast.framework.CastSession
import com.google.android.gms.cast.framework.SessionManagerListener
interface RetroSessionManager : SessionManagerListener<CastSession> {
interface RetroSessionManagerListener : SessionManagerListener<CastSession> {
override fun onSessionResuming(p0: CastSession, p1: String) {
}

View file

@ -26,15 +26,9 @@ class RetroWebServer(val context: Context) : NanoHTTPD(SERVER_PORT) {
}
}
override fun serve(
uri: String?,
method: Method?,
headers: MutableMap<String, String>?,
parms: MutableMap<String, String>?,
files: MutableMap<String, String>?
): Response {
if (uri?.contains(PART_COVER_ART) == true) {
val albumId = parms?.get(PARAM_ID) ?: return errorResponse()
override fun serve(session: IHTTPSession?): Response {
if (session?.uri?.contains(PART_COVER_ART) == true) {
val albumId = session.parameters?.get(PARAM_ID)?.get(0) ?: return errorResponse()
val albumArtUri = MusicUtil.getMediaStoreAlbumCoverUri(albumId.toLong())
val fis: InputStream?
try {
@ -43,12 +37,12 @@ class RetroWebServer(val context: Context) : NanoHTTPD(SERVER_PORT) {
return errorResponse()
}
return newChunkedResponse(Status.OK, MIME_TYPE_IMAGE, fis)
} else if (uri?.contains(PART_SONG) == true) {
val songId = parms?.get(PARAM_ID) ?: return errorResponse()
} else if (session?.uri?.contains(PART_SONG) == true) {
val songId = session.parameters?.get(PARAM_ID)?.get(0) ?: return errorResponse()
val songUri = MusicUtil.getSongFileUri(songId.toLong())
val songPath = MusicUtil.getSongFilePath(context, songUri)
val song = File(songPath)
return serveFile(headers!!, song, MIME_TYPE_AUDIO)
return serveFile(session.headers!!, song, MIME_TYPE_AUDIO)
}
return newFixedLengthResponse(Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found")
}

View file

@ -16,7 +16,6 @@ package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.EXTRA_PLAYLIST_ID
@ -48,7 +47,7 @@ class RenamePlaylistDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val playlistEntity = extraNotNull<PlaylistEntity>(EXTRA_PLAYLIST_ID).value
val layout = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_playlist, null)
val layout = layoutInflater.inflate(R.layout.dialog_playlist, null)
val inputEditText: TextInputEditText = layout.findViewById(R.id.actionNewPlaylist)
val nameContainer: TextInputLayout = layout.findViewById(R.id.actionNewPlaylistContainer)
nameContainer.accentColor()

View file

@ -19,60 +19,51 @@ import android.content.Context
import android.os.Bundle
import android.text.Spanned
import android.util.Log
import android.view.LayoutInflater
import android.widget.TextView
import androidx.annotation.NonNull
import androidx.core.os.bundleOf
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.EXTRA_SONG
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.DialogFileDetailsBinding
import code.name.monkey.retromusic.extensions.colorButtons
import code.name.monkey.retromusic.extensions.materialDialog
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
import org.jaudiotagger.audio.AudioFileIO
import org.jaudiotagger.audio.exceptions.CannotReadException
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException
import org.jaudiotagger.tag.TagException
import java.io.File
import java.io.IOException
class SongDetailDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val context: Context = requireContext()
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_file_details, null)
val binding = DialogFileDetailsBinding.inflate(layoutInflater)
val song = requireArguments().getParcelable<Song>(EXTRA_SONG)
val fileName: TextView = dialogView.findViewById(R.id.fileName)
val filePath: TextView = dialogView.findViewById(R.id.filePath)
val fileSize: TextView = dialogView.findViewById(R.id.fileSize)
val dateModified: TextView = dialogView.findViewById(R.id.dateModified)
val fileFormat: TextView = dialogView.findViewById(R.id.fileFormat)
val trackLength: TextView = dialogView.findViewById(R.id.trackLength)
val bitRate: TextView = dialogView.findViewById(R.id.bitrate)
val samplingRate: TextView = dialogView.findViewById(R.id.samplingRate)
with(binding) {
fileName.text = makeTextWithTitle(context, R.string.label_file_name, "-")
filePath.text = makeTextWithTitle(context, R.string.label_file_path, "-")
fileSize.text = makeTextWithTitle(context, R.string.label_file_size, "-")
fileFormat.text = makeTextWithTitle(context, R.string.label_file_format, "-")
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, "-")
bitRate.text = makeTextWithTitle(context, R.string.label_bit_rate, "-")
bitrate.text = makeTextWithTitle(context, R.string.label_bit_rate, "-")
samplingRate.text = makeTextWithTitle(context, R.string.label_sampling_rate, "-")
}
if (song != null) {
val songFile = File(song.data)
if (songFile.exists()) {
fileName.text = makeTextWithTitle(context, R.string.label_file_name, songFile.name)
filePath.text =
binding.fileName.text =
makeTextWithTitle(context, R.string.label_file_name, songFile.name)
binding.filePath.text =
makeTextWithTitle(context, R.string.label_file_path, songFile.absolutePath)
dateModified.text = makeTextWithTitle(context, R.string.label_last_modified,
MusicUtil.getDateModifiedString(songFile.lastModified()))
binding.dateModified.text = makeTextWithTitle(
context, R.string.label_last_modified,
MusicUtil.getDateModifiedString(songFile.lastModified())
)
fileSize.text =
binding.fileSize.text =
makeTextWithTitle(
context,
R.string.label_file_size,
@ -82,56 +73,28 @@ class SongDetailDialog : DialogFragment() {
val audioFile = AudioFileIO.read(songFile)
val audioHeader = audioFile.audioHeader
fileFormat.text =
binding.fileFormat.text =
makeTextWithTitle(context, R.string.label_file_format, audioHeader.format)
trackLength.text = makeTextWithTitle(
binding.trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString((audioHeader.trackLength * 1000).toLong())
)
bitRate.text = makeTextWithTitle(
binding.bitrate.text = makeTextWithTitle(
context,
R.string.label_bit_rate,
audioHeader.bitRate + " kb/s"
)
samplingRate.text =
binding.samplingRate.text =
makeTextWithTitle(
context,
R.string.label_sampling_rate,
audioHeader.sampleRate + " Hz"
)
} catch (@NonNull e: CannotReadException) {
} catch (e: Exception) {
Log.e(TAG, "error while reading the song file", e)
// fallback
trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString(song.duration)
)
} catch (@NonNull e: IOException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString(song.duration)
)
} catch (@NonNull e: TagException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString(song.duration)
)
} catch (@NonNull e: ReadOnlyFileException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString(song.duration)
)
} catch (@NonNull e: InvalidAudioFrameException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(
binding.trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString(song.duration)
@ -139,8 +102,9 @@ class SongDetailDialog : DialogFragment() {
}
} else {
// fallback
fileName.text = makeTextWithTitle(context, R.string.label_file_name, song.title)
trackLength.text = makeTextWithTitle(
binding.fileName.text =
makeTextWithTitle(context, R.string.label_file_name, song.title)
binding.trackLength.text = makeTextWithTitle(
context,
R.string.label_track_length,
MusicUtil.getReadableDurationString(song.duration)
@ -149,7 +113,7 @@ class SongDetailDialog : DialogFragment() {
}
return materialDialog(R.string.action_details)
.setPositiveButton(android.R.string.ok, null)
.setView(dialogView)
.setView(binding.root)
.create()
.colorButtons()
}

View file

@ -6,7 +6,9 @@ import android.os.Build
import android.view.View
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import androidx.core.view.*
import androidx.fragment.app.FragmentActivity
import code.name.monkey.appthemehelper.util.ColorUtil
@ -222,3 +224,12 @@ fun AppCompatActivity.setStatusBarColorPreMarshmallow(color: Int) {
window.statusBarColor = ColorUtil.darkenColor(color)
}
}
fun AppCompatActivity.hideSoftKeyboard() {
val currentFocus: View? = currentFocus
if (currentFocus != null) {
val inputMethodManager =
getSystemService<InputMethodManager>()
inputMethodManager?.hideSoftInputFromWindow(currentFocus.windowToken, 0)
}
}

View file

@ -131,12 +131,12 @@ fun Slider.accent() {
fun Button.accentTextColor() {
if (materialYou) return
setTextColor(ThemeStore.accentColor(App.getContext()))
setTextColor(context.accentColor())
}
fun MaterialButton.accentBackgroundColor() {
if (materialYou) return
backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(App.getContext()))
backgroundTintList = ColorStateList.valueOf(context.accentColor())
}
fun MaterialButton.accentOutlineColor() {

View file

@ -1,10 +1,12 @@
package code.name.monkey.retromusic.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.net.toUri
import androidx.fragment.app.Fragment
import java.io.OutputStream
@ -30,3 +32,15 @@ fun Fragment.createNewFile(
}
startForResult.launch(intent)
}
fun Context.openUrl(url: String) {
val i = Intent(Intent.ACTION_VIEW)
i.data = url.toUri()
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(i)
}
fun Fragment.openUrl(url: String) {
requireContext().openUrl(url)
}

View file

@ -14,12 +14,10 @@
*/
package code.name.monkey.retromusic.fragments.about
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import androidx.core.app.ShareCompat
import androidx.core.net.toUri
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DefaultItemAnimator
@ -29,6 +27,7 @@ import code.name.monkey.retromusic.Constants
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.ContributorAdapter
import code.name.monkey.retromusic.databinding.FragmentAboutBinding
import code.name.monkey.retromusic.extensions.openUrl
import code.name.monkey.retromusic.fragments.LibraryViewModel
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.RetroUtil
@ -53,13 +52,6 @@ class AboutFragment : Fragment(R.layout.fragment_about), View.OnClickListener {
}
}
private fun openUrl(url: String) {
val i = Intent(Intent.ACTION_VIEW)
i.data = url.toUri()
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(i)
}
private fun setUpView() {
binding.aboutContent.cardRetroInfo.appGithub.setOnClickListener(this)
binding.aboutContent.cardRetroInfo.faqLink.setOnClickListener(this)

View file

@ -117,7 +117,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
mainActivity.setSupportActionBar(binding.toolbar)
binding.toolbar.title = " "
binding.albumCoverContainer.setTransitionName(arguments.extraAlbumId.toString())
binding.albumCoverContainer.transitionName = arguments.extraAlbumId.toString()
postponeEnterTransition()
detailsViewModel.getAlbum().observe(viewLifecycleOwner) {
requireView().doOnPreDraw {
@ -125,10 +125,10 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
}
albumArtistExists = !it.albumArtist.isNullOrEmpty()
showAlbum(it)
if (albumArtistExists) {
binding.artistImage.setTransitionName(album.albumArtist)
binding.artistImage.transitionName = if (albumArtistExists) {
album.albumArtist
} else {
binding.artistImage.setTransitionName(album.artistId.toString())
album.artistId.toString()
}
}
@ -308,7 +308,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
.load(
RetroGlideExtension.getArtistModel(
artist,
PreferenceUtil.isAllowedToDownloadMetadata()
PreferenceUtil.isAllowedToDownloadMetadata(requireContext())
)
)
.artistImageOptions(artist)

View file

@ -88,7 +88,7 @@ abstract class AbsArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragm
mainActivity.addMusicServiceEventListener(detailsViewModel)
mainActivity.setSupportActionBar(binding.toolbar)
binding.toolbar.title = null
binding.artistCoverContainer.setTransitionName((artistId ?: artistName).toString())
binding.artistCoverContainer.transitionName = (artistId ?: artistName).toString()
postponeEnterTransition()
detailsViewModel.getArtist().observe(viewLifecycleOwner) {
requireView().doOnPreDraw {
@ -146,7 +146,7 @@ abstract class AbsArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragm
}
this.artist = artist
loadArtistImage(artist)
if (RetroUtil.isAllowedToDownloadMetadata(requireContext())) {
if (PreferenceUtil.isAllowedToDownloadMetadata(requireContext())) {
loadBiography(artist.name)
}
binding.artistTitle.text = artist.name

View file

@ -1,7 +1,6 @@
package code.name.monkey.retromusic.fragments.backup
import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData

View file

@ -30,6 +30,7 @@ import androidx.core.view.isVisible
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.MusicSeekSkipTouchListener
import code.name.monkey.retromusic.fragments.other.VolumeFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -224,8 +225,7 @@ abstract class AbsPlayerControlsFragment(@LayoutRes layout: Int) : AbsMusicServi
}
childFragmentManager.executePendingTransactions()
}
volumeFragment =
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as? VolumeFragment
volumeFragment = whichFragment(R.id.volumeFragmentContainer)
}
override fun onResume() {

View file

@ -359,15 +359,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
val TAG: String = AbsPlayerFragment::class.java.simpleName
const val VISIBILITY_ANIM_DURATION: Long = 300
}
protected fun getUpNextAndQueueTime(): String {
val duration = MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.position)
return MusicUtil.buildInfoString(
resources.getString(R.string.up_next),
MusicUtil.getReadableDurationString(duration)
)
}
}
fun goToArtist(activity: Activity) {

View file

@ -56,7 +56,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_
setHasOptionsMenu(true)
mainActivity.addMusicServiceEventListener(detailsViewModel)
mainActivity.setSupportActionBar(binding.toolbar)
binding.container.setTransitionName("genre")
binding.container.transitionName = "genre"
genre = arguments.extraGenre
binding.toolbar.title = arguments.extraGenre.name
setupRecyclerView()

View file

@ -40,10 +40,7 @@ import code.name.monkey.retromusic.activities.tageditor.TagWriter
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
import code.name.monkey.retromusic.extensions.materialDialog
import code.name.monkey.retromusic.extensions.textColorSecondary
import code.name.monkey.retromusic.extensions.uri
import code.name.monkey.retromusic.extensions.*
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
@ -52,7 +49,6 @@ import code.name.monkey.retromusic.model.AudioTagInfo
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.FileUtils
import code.name.monkey.retromusic.util.LyricUtil
import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.UriUtil
import com.afollestad.materialdialogs.input.input
import com.google.android.material.color.MaterialColors
@ -149,7 +145,7 @@ class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
exitTransition = Fade()
lyricsSectionsAdapter = LyricsSectionsAdapter(requireActivity())
_binding = FragmentLyricsBinding.bind(view)
binding.container.setTransitionName("lyrics")
binding.container.transitionName = "lyrics"
setupWakelock()
setupViews()
@ -225,8 +221,7 @@ class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
return true
}
if (item.itemId == R.id.action_search) {
RetroUtil.openUrl(
requireActivity(), when (binding.lyricsPager.currentItem) {
openUrl(when (binding.lyricsPager.currentItem) {
0 -> syairSearchLrcUrl
1 -> googleSearchLrcUrl
else -> googleSearchLrcUrl

View file

@ -48,9 +48,9 @@ class AdaptiveFragment : AbsPlayerFragment(R.layout.fragment_adaptive_player) {
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as AdaptivePlaybackControlsFragment
whichFragment(R.id.playbackControlsFragment) as AdaptivePlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
whichFragment(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
playerAlbumCoverFragment.apply {
removeSlideEffect()
setCallbacks(this@AdaptiveFragment)

View file

@ -27,6 +27,7 @@ import code.name.monkey.retromusic.NEW_BLUR_AMOUNT
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentBlurBinding
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.glide.*
@ -62,10 +63,9 @@ class BlurPlayerFragment : AbsPlayerFragment(R.layout.fragment_blur),
}
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as BlurPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
playbackControlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -22,6 +22,7 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentCardPlayerBinding
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment
@ -87,10 +88,9 @@ class CardFragment : AbsPlayerFragment(R.layout.fragment_card_player) {
}
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
playbackControlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
playerAlbumCoverFragment.removeSlideEffect()
}
@ -117,14 +117,4 @@ class CardFragment : AbsPlayerFragment(R.layout.fragment_card_player) {
super.onDestroyView()
_binding = null
}
companion object {
fun newInstance(): PlayerFragment {
val args = Bundle()
val fragment = PlayerFragment()
fragment.arguments = args
return fragment
}
}
}

View file

@ -26,6 +26,7 @@ import code.name.monkey.retromusic.NEW_BLUR_AMOUNT
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentCardBlurPlayerBinding
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment
@ -98,8 +99,8 @@ class CardBlurFragment : AbsPlayerFragment(R.layout.fragment_card_blur_player),
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardBlurPlaybackControlsFragment
(childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment?)?.setCallbacks(
whichFragment(R.id.playbackControlsFragment) as CardBlurPlaybackControlsFragment
(whichFragment(R.id.playerAlbumCoverFragment) as? PlayerAlbumCoverFragment)?.setCallbacks(
this
)
}

View file

@ -35,10 +35,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.RetroBottomSheetBehavior
import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter
import code.name.monkey.retromusic.databinding.FragmentClassicPlayerBinding
import code.name.monkey.retromusic.extensions.getSongInfo
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.extensions.*
import code.name.monkey.retromusic.fragments.MusicSeekSkipTouchListener
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
@ -131,8 +128,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
hideVolumeIfAvailable()
setupRecyclerView()
val coverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment)
coverFragment.setCallbacks(this)
getQueuePanel().addBottomSheetCallback(bottomSheetCallbackList)
@ -174,7 +170,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
}
childFragmentManager.executePendingTransactions()
volumeFragment =
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as VolumeFragment?
whichFragment(R.id.volumeFragmentContainer) as VolumeFragment?
}
}
@ -368,7 +364,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
}
private fun setupPanel() {
if (!binding.playerContainer.isLaidOut() || binding.playerContainer.isLayoutRequested) {
if (!binding.playerContainer.isLaidOut || binding.playerContainer.isLayoutRequested) {
binding.playerContainer.addOnLayoutChangeListener(this)
return
}
@ -419,7 +415,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
}
fun setUpProgressSlider() {
private fun setUpProgressSlider() {
binding.playerControlsContainer.progressSlider.setOnSeekBarChangeListener(object :
SimpleOnSeekbarChangeListener() {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {

View file

@ -24,6 +24,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentColorPlayerBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -110,15 +111,14 @@ class ColorFragment : AbsPlayerFragment(R.layout.fragment_color_player) {
_binding = FragmentColorPlayerBinding.bind(view)
setUpSubFragments()
setUpPlayerToolbar()
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playbackControlsFragment)
playerAlbumCoverFragment.setCallbacks(this)
playerToolbar().drawAboveSystemBars()
}
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as ColorPlaybackControlsFragment
playbackControlsFragment = whichFragment(R.id.playbackControlsFragment)
}
private fun setUpPlayerToolbar() {

View file

@ -22,6 +22,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentFitBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -90,10 +91,9 @@ class FitFragment : AbsPlayerFragment(R.layout.fragment_fit) {
}
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FitPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
playbackControlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -27,6 +27,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentFlatPlayerBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -52,10 +53,9 @@ class FlatPlayerFragment : AbsPlayerFragment(R.layout.fragment_flat_player) {
private fun setUpSubFragments() {
controlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FlatPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
controlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -132,7 +132,7 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
}
private fun setupPanel() {
if (!binding.colorBackground.isLaidOut() || binding.colorBackground.isLayoutRequested) {
if (!binding.colorBackground.isLaidOut || binding.colorBackground.isLayoutRequested) {
binding.colorBackground.addOnLayoutChangeListener(this)
return
}
@ -309,7 +309,7 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
}
childFragmentManager.executePendingTransactions()
volumeFragment =
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as VolumeFragment?
whichFragment(R.id.volumeFragmentContainer) as VolumeFragment?
}
}

View file

@ -26,6 +26,7 @@ import code.name.monkey.retromusic.databinding.FragmentMaterialBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment
@ -134,10 +135,9 @@ class MaterialFragment : AbsPlayerFragment(R.layout.fragment_material) {
}
private fun setUpSubFragments() {
playbackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as MaterialControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
playbackControlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playbackControlsFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -27,10 +27,7 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.SNOWFALL
import code.name.monkey.retromusic.databinding.FragmentPlayerBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.isColorLight
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.extensions.*
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -141,10 +138,9 @@ class PlayerFragment : AbsPlayerFragment(R.layout.fragment_player),
}
private fun setUpSubFragments() {
controlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PlayerPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
controlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -58,10 +58,10 @@ class PeekPlayerFragment : AbsPlayerFragment(R.layout.fragment_peek_player) {
private fun setUpSubFragments() {
controlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PeekPlayerControlFragment
whichFragment(R.id.playbackControlsFragment) as PeekPlayerControlFragment
val coverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
whichFragment(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
coverFragment.setCallbacks(this)
}

View file

@ -22,6 +22,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentPlainPlayerBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.base.goToAlbum
import code.name.monkey.retromusic.fragments.base.goToArtist
@ -89,10 +90,9 @@ class PlainPlayerFragment : AbsPlayerFragment(R.layout.fragment_plain_player) {
}
private fun setUpSubFragments() {
plainPlaybackControlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PlainPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
plainPlaybackControlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -22,6 +22,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentSimplePlayerBinding
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.whichFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -56,11 +57,10 @@ class SimplePlayerFragment : AbsPlayerFragment(R.layout.fragment_simple_player)
}
private fun setUpSubFragments() {
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
controlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as SimplePlaybackControlsFragment
controlsFragment = whichFragment(R.id.playbackControlsFragment)
}
override fun onShow() {

View file

@ -29,10 +29,7 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentTinyPlayerBinding
import code.name.monkey.retromusic.extensions.drawAboveSystemBars
import code.name.monkey.retromusic.extensions.getSongInfo
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.extensions.*
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.base.goToAlbum
import code.name.monkey.retromusic.fragments.base.goToArtist
@ -153,10 +150,9 @@ class TinyPlayerFragment : AbsPlayerFragment(R.layout.fragment_tiny_player),
}
private fun setUpSubFragments() {
controlsFragment =
childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as TinyPlaybackControlsFragment
val playerAlbumCoverFragment =
childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment
controlsFragment = whichFragment(R.id.playbackControlsFragment)
val playerAlbumCoverFragment: PlayerAlbumCoverFragment =
whichFragment(R.id.playerAlbumCoverFragment)
playerAlbumCoverFragment.setCallbacks(this)
}

View file

@ -59,7 +59,7 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false)
setHasOptionsMenu(true)
mainActivity.setSupportActionBar(binding.toolbar)
binding.container.setTransitionName("playlist")
binding.container.transitionName = "playlist"
playlist = arguments.extraPlaylist
binding.toolbar.title = playlist.playlistEntity.playlistName
setUpRecyclerView()

View file

@ -42,7 +42,7 @@ class ArtistImageFetcher(
override fun loadData(priority: Priority, callback: DataFetcher.DataCallback<in InputStream>) {
try {
if (!MusicUtil.isArtistNameUnknown(model.artist.name) &&
PreferenceUtil.isAllowedToDownloadMetadata()
PreferenceUtil.isAllowedToDownloadMetadata(context)
) {
val artists = model.artist.name.split(",", "&")
response = deezerService.getArtistImage(artists[0])

View file

@ -139,8 +139,6 @@ object SearchQueryHelper : KoinComponent {
arrayOf(query.lowercase())
)
)
return if (songs.isNotEmpty()) {
songs
} else ArrayList()
return songs.ifEmpty { ArrayList() }
}
}

View file

@ -35,6 +35,8 @@ import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Scroller;
import androidx.core.content.res.ResourcesCompat;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;

View file

@ -1,86 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* 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.misc;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class LagTracker {
private static Map<String, Long> mMap;
private static LagTracker mSingleton;
private boolean mEnabled = true;
private LagTracker() {
mMap = new HashMap<>();
}
public static LagTracker get() {
if (mSingleton == null) {
mSingleton = new LagTracker();
}
return mSingleton;
}
private void print(String str, long j) {
long toMillis = TimeUnit.NANOSECONDS.toMillis(j);
Log.d(
"LagTracker",
"["
+ str
+ " completed in]: "
+ j
+ " ns ("
+ toMillis
+ "ms, "
+ TimeUnit.NANOSECONDS.toSeconds(j)
+ "s)");
}
public LagTracker disable() {
this.mEnabled = false;
return this;
}
public LagTracker enable() {
this.mEnabled = true;
return this;
}
public void end(String str) {
long nanoTime = System.nanoTime();
if (this.mEnabled) {
if (mMap.containsKey(str)) {
print(str, nanoTime - mMap.get(str));
mMap.remove(str);
return;
}
throw new IllegalStateException("No start time found for " + str);
} else if (!mMap.isEmpty()) {
mMap.clear();
}
}
public void start(String str) {
long nanoTime = System.nanoTime();
if (this.mEnabled) {
mMap.put(str, nanoTime);
} else if (!mMap.isEmpty()) {
mMap.clear();
}
}
}

View file

@ -25,9 +25,9 @@ import java.lang.reflect.Type
class LyricsConverterFactory : Converter.Factory() {
override fun responseBodyConverter(
type: Type?,
annotations: Array<Annotation>?,
retrofit: Retrofit?
type: Type,
annotations: Array<out Annotation>,
retrofit: Retrofit
): Converter<ResponseBody, *>? {
return if (String::class.java == type) {
Converter<ResponseBody, String> { value -> value.string() }
@ -35,10 +35,10 @@ class LyricsConverterFactory : Converter.Factory() {
}
override fun requestBodyConverter(
type: Type?,
parameterAnnotations: Array<Annotation>?,
methodAnnotations: Array<Annotation>?,
retrofit: Retrofit?
type: Type,
parameterAnnotations: Array<Annotation>,
methodAnnotations: Array<Annotation>,
retrofit: Retrofit
): Converter<*, RequestBody>? {
return if (String::class.java == type) {

View file

@ -392,7 +392,7 @@ class MusicService : MediaBrowserServiceCompat(),
wakeLock?.acquire(milli)
}
var pausedByZeroVolume = false
private var pausedByZeroVolume = false
override fun onAudioVolumeChanged(currentVolume: Int, maxVolume: Int) {
if (isPauseOnZeroVolume) {
if (isPlaying && currentVolume < 1) {

View file

@ -1,19 +0,0 @@
package code.name.monkey.retromusic.util
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
class ColorAnimUtil {
companion object {
fun createColorAnimator(
fromColor: Int,
toColor: Int,
mDuration: Long = 300
): ValueAnimator {
return ValueAnimator.ofInt(fromColor, toColor).apply {
setEvaluator(ArgbEvaluator())
duration = mDuration
}
}
}
}

View file

@ -1,80 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* 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;
import android.content.Context;
import android.graphics.Bitmap;
import java.io.File;
import java.io.IOException;
/**
* Created on : June 18, 2016 Author : zetbaitsu Name : Zetra GitHub : https://github.com/zetbaitsu
*/
public class Compressor {
// max width and height values of the compressed image is taken as 612x816
private int maxWidth = 612;
private int maxHeight = 816;
private Bitmap.CompressFormat compressFormat = Bitmap.CompressFormat.JPEG;
private int quality = 80;
private String destinationDirectoryPath;
public Compressor(Context context) {
destinationDirectoryPath = context.getCacheDir().getPath() + File.separator + "images";
}
public Compressor setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
return this;
}
public Compressor setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
return this;
}
public Compressor setCompressFormat(Bitmap.CompressFormat compressFormat) {
this.compressFormat = compressFormat;
return this;
}
public Compressor setQuality(int quality) {
this.quality = quality;
return this;
}
public Compressor setDestinationDirectoryPath(String destinationDirectoryPath) {
this.destinationDirectoryPath = destinationDirectoryPath;
return this;
}
public File compressToFile(File imageFile) throws IOException {
return compressToFile(imageFile, imageFile.getName());
}
public File compressToFile(File imageFile, String compressedFileName) throws IOException {
return ImageUtil.compressImage(
imageFile,
maxWidth,
maxHeight,
compressFormat,
quality,
destinationDirectoryPath + File.separator + compressedFileName);
}
public Bitmap compressToBitmap(File imageFile) throws IOException {
return ImageUtil.decodeSampledBitmapFromFile(imageFile, maxWidth, maxHeight);
}
}

View file

@ -24,13 +24,13 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;
import androidx.exifinterface.media.ExifInterface;
import java.io.File;
import java.io.FileOutputStream;

View file

@ -268,15 +268,14 @@ object MusicUtil : KoinComponent {
)
}
fun getSongFilePath(context: Context, uri: Uri): String? {
fun getSongFilePath(context: Context, uri: Uri): String {
val projection = arrayOf(MediaStore.MediaColumns.DATA)
return context.contentResolver.query(uri, projection, null, null, null)?.use {
context.contentResolver.query(uri, projection, null, null, null)?.use {
if (it.moveToFirst()) {
it.getString(0)
} else {
""
return it.getString(0)
}
}
return ""
}
fun getTotalDuration(songs: List<Song>): Long {

View file

@ -71,7 +71,7 @@ class PackageValidator(
/**
* Checks whether the caller attempting to connect to a [MediaBrowserServiceCompat] is known.
* See [MusicService.onGetRoot] for where this is utilized.
* See [MediaBrowserServiceCompat.onGetRoot] for where this is utilized.
*
* @param callingPackage The package name of the caller.
* @param callingUid The user id of the caller.

View file

@ -1,8 +1,8 @@
package code.name.monkey.retromusic.util
import android.content.Context
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.net.ConnectivityManager
import android.net.NetworkInfo
import androidx.core.content.edit
import androidx.core.content.getSystemService
import androidx.preference.PreferenceManager
@ -328,15 +328,12 @@ object PreferenceUtil {
val isLockScreen get() = sharedPreferences.getBoolean(LOCK_SCREEN, false)
fun isAllowedToDownloadMetadata(): Boolean {
fun isAllowedToDownloadMetadata(context: Context): Boolean {
return when (autoDownloadImagesPolicy) {
"always" -> true
"only_wifi" -> {
val connectivityManager = App.getContext().getSystemService<ConnectivityManager>()
var netInfo: NetworkInfo? = null
if (connectivityManager != null) {
netInfo = connectivityManager.activeNetworkInfo
}
val connectivityManager = context.getSystemService<ConnectivityManager>()
val netInfo = connectivityManager?.activeNetworkInfo
netInfo != null && netInfo.type == ConnectivityManager.TYPE_WIFI && netInfo.isConnectedOrConnecting
}
"never" -> false

View file

@ -195,13 +195,6 @@ public class RetroUtil {
>= 600;
}
public static void openUrl(@NonNull Activity context, @NonNull String str) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.setData(Uri.parse(str));
intent.setFlags(268435456);
context.startActivity(intent);
}
public static void setAllowDrawUnderNavigationBar(Window window) {
window.setNavigationBarColor(Color.TRANSPARENT);
window