Code Cleanup

This commit is contained in:
Prathamesh More 2022-05-17 08:06:25 +05:30
parent 860fa9d8b4
commit 6779eb0e2b
5 changed files with 22 additions and 47 deletions

View file

@ -18,7 +18,6 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
@ -35,14 +34,14 @@ import code.name.monkey.retromusic.adapter.song.SongAdapter
import code.name.monkey.retromusic.fragments.home.HomeFragment import code.name.monkey.retromusic.fragments.home.HomeFragment
import code.name.monkey.retromusic.interfaces.IAlbumClickListener import code.name.monkey.retromusic.interfaces.IAlbumClickListener
import code.name.monkey.retromusic.interfaces.IArtistClickListener import code.name.monkey.retromusic.interfaces.IArtistClickListener
import code.name.monkey.retromusic.interfaces.IGenreClickListener import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.model.Home
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
class HomeAdapter( class HomeAdapter(private val activity: AppCompatActivity) :
private val activity: AppCompatActivity RecyclerView.Adapter<RecyclerView.ViewHolder>(), IArtistClickListener, IAlbumClickListener {
) : RecyclerView.Adapter<RecyclerView.ViewHolder>(), IArtistClickListener, IAlbumClickListener,
IGenreClickListener {
private var list = listOf<Home>() private var list = listOf<Home>()
@ -134,6 +133,7 @@ class HomeAdapter(
notifyDataSetChanged() notifyDataSetChanged()
} }
@Suppress("UNCHECKED_CAST")
private inner class AlbumViewHolder(view: View) : AbsHomeViewItem(view) { private inner class AlbumViewHolder(view: View) : AbsHomeViewItem(view) {
fun bindView(home: Home) { fun bindView(home: Home) {
title.setText(home.titleRes) title.setText(home.titleRes)
@ -144,6 +144,7 @@ class HomeAdapter(
} }
} }
@Suppress("UNCHECKED_CAST")
private inner class ArtistViewHolder(view: View) : AbsHomeViewItem(view) { private inner class ArtistViewHolder(view: View) : AbsHomeViewItem(view) {
fun bindView(home: Home) { fun bindView(home: Home) {
title.setText(home.titleRes) title.setText(home.titleRes)
@ -154,6 +155,7 @@ class HomeAdapter(
} }
} }
@Suppress("UNCHECKED_CAST")
private inner class PlaylistViewHolder(view: View) : AbsHomeViewItem(view) { private inner class PlaylistViewHolder(view: View) : AbsHomeViewItem(view) {
fun bindView(home: Home) { fun bindView(home: Home) {
title.setText(home.titleRes) title.setText(home.titleRes)
@ -172,7 +174,6 @@ class HomeAdapter(
open class AbsHomeViewItem(itemView: View) : RecyclerView.ViewHolder(itemView) { open class AbsHomeViewItem(itemView: View) : RecyclerView.ViewHolder(itemView) {
val recyclerView: RecyclerView = itemView.findViewById(R.id.recyclerView) val recyclerView: RecyclerView = itemView.findViewById(R.id.recyclerView)
val title: AppCompatTextView = itemView.findViewById(R.id.title) val title: AppCompatTextView = itemView.findViewById(R.id.title)
val arrow: ImageView = itemView.findViewById(R.id.arrow)
val clickableArea: ViewGroup = itemView.findViewById(R.id.clickable_area) val clickableArea: ViewGroup = itemView.findViewById(R.id.clickable_area)
} }
@ -209,16 +210,4 @@ class HomeAdapter(
) )
) )
} }
override fun onClickGenre(genre: Genre, view: View) {
activity.findNavController(R.id.fragment_container).navigate(
R.id.genreDetailsFragment,
bundleOf(EXTRA_GENRE to genre),
null,
FragmentNavigatorExtras(
view to "genre"
)
)
}
} }

View file

@ -185,7 +185,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
listSongs( listSongs(
requireContext(), requireContext(),
toList(file), listOf(file),
AUDIO_FILE_FILTER, AUDIO_FILE_FILTER,
fileComparator fileComparator
) { songs -> ) { songs ->
@ -226,7 +226,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
listSongs( listSongs(
requireContext(), requireContext(),
toList(file), listOf(file),
AUDIO_FILE_FILTER, AUDIO_FILE_FILTER,
fileComparator fileComparator
) { songs -> ) { songs ->
@ -264,7 +264,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
listSongs( listSongs(
requireContext(), requireContext(),
toList(mFile.parentFile), listOf(mFile.parentFile),
fileFilter, fileFilter,
fileComparator fileComparator
) { songs -> ) { songs ->
@ -501,12 +501,6 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
) )
} }
private fun toList(file: File): ArrayList<File> {
val files = ArrayList<File>(1)
files.add(file)
return files
}
private fun updateAdapter(files: List<File>) { private fun updateAdapter(files: List<File>) {
adapter?.swapDataSet(files) adapter?.swapDataSet(files)
val crumb = activeCrumb val crumb = activeCrumb
@ -578,7 +572,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
suspend fun listSongs( suspend fun listSongs(
context: Context, context: Context,
files: List<File>, files: List<File?>,
fileFilter: FileFilter, fileFilter: FileFilter,
fileComparator: Comparator<File>, fileComparator: Comparator<File>,
doOnSongsListed: (songs: List<Song>) -> Unit doOnSongsListed: (songs: List<Song>) -> Unit

View file

@ -15,26 +15,18 @@ import java.security.MessageDigest
@Suppress("Deprecation") @Suppress("Deprecation")
class BlurTransformation : BitmapTransformation { class BlurTransformation private constructor(builder: Builder) : BitmapTransformation() {
private var context: Context? = null private var context: Context? = null
private var blurRadius = 0f private var blurRadius = 0f
private var sampling = 0 private var sampling = 0
private fun init(builder: Builder) { init {
this.context = builder.context this.context = builder.context
this.blurRadius = builder.blurRadius this.blurRadius = builder.blurRadius
this.sampling = builder.sampling this.sampling = builder.sampling
} }
private constructor(builder: Builder) : super() {
init(builder)
}
private constructor(builder: Builder, bitmapPool: BitmapPool) : super() {
init(builder)
}
class Builder(val context: Context) { class Builder(val context: Context) {
private var bitmapPool: BitmapPool? = null private var bitmapPool: BitmapPool? = null
var blurRadius = DEFAULT_BLUR_RADIUS var blurRadius = DEFAULT_BLUR_RADIUS
@ -69,7 +61,7 @@ class BlurTransformation : BitmapTransformation {
fun build(): BlurTransformation { fun build(): BlurTransformation {
return if (bitmapPool != null) { return if (bitmapPool != null) {
BlurTransformation(this, bitmapPool!!) BlurTransformation(this)
} else BlurTransformation(this) } else BlurTransformation(this)
} }
} }
@ -78,7 +70,7 @@ class BlurTransformation : BitmapTransformation {
pool: BitmapPool, pool: BitmapPool,
toTransform: Bitmap, toTransform: Bitmap,
outWidth: Int, outWidth: Int,
outHeight: Int outHeight: Int,
): Bitmap { ): Bitmap {
val sampling = if (this.sampling == 0) { val sampling = if (this.sampling == 0) {
ImageUtil.calculateInSampleSize(toTransform.width, toTransform.height, 100) ImageUtil.calculateInSampleSize(toTransform.width, toTransform.height, 100)

View file

@ -434,10 +434,10 @@ object MusicPlayerRemote : KoinComponent {
if (songs == null || songs.isEmpty()) { if (songs == null || songs.isEmpty()) {
var songFile: File? = null var songFile: File? = null
if (uri.authority != null && uri.authority == "com.android.externalstorage.documents") { if (uri.authority != null && uri.authority == "com.android.externalstorage.documents") {
songFile = File( val path = uri.path?.split(":".toRegex(), 2)?.get(1)
getExternalStorageDirectory(), if (path != null) {
uri.path?.split(":".toRegex(), 2)?.get(1) songFile = File(getExternalStorageDirectory(), path)
) }
} }
if (songFile == null) { if (songFile == null) {
val path = getFilePathFromUri(context, uri) val path = getFilePathFromUri(context, uri)

View file

@ -49,7 +49,7 @@ fun headerInterceptor(context: Context): Interceptor {
fun provideOkHttp(context: Context, cache: Cache): OkHttpClient { fun provideOkHttp(context: Context, cache: Cache): OkHttpClient {
return OkHttpClient.Builder() return OkHttpClient.Builder()
.addNetworkInterceptor(logInterceptor()) .addNetworkInterceptor(logInterceptor())
//.addInterceptor(headerInterceptor(context)) .addInterceptor(headerInterceptor(context))
.connectTimeout(1, TimeUnit.SECONDS) .connectTimeout(1, TimeUnit.SECONDS)
.readTimeout(1, TimeUnit.SECONDS) .readTimeout(1, TimeUnit.SECONDS)
.cache(cache) .cache(cache)