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.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
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.interfaces.IAlbumClickListener
import code.name.monkey.retromusic.interfaces.IArtistClickListener
import code.name.monkey.retromusic.interfaces.IGenreClickListener
import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.model.Album
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
class HomeAdapter(
private val activity: AppCompatActivity
) : RecyclerView.Adapter<RecyclerView.ViewHolder>(), IArtistClickListener, IAlbumClickListener,
IGenreClickListener {
class HomeAdapter(private val activity: AppCompatActivity) :
RecyclerView.Adapter<RecyclerView.ViewHolder>(), IArtistClickListener, IAlbumClickListener {
private var list = listOf<Home>()
@ -134,6 +133,7 @@ class HomeAdapter(
notifyDataSetChanged()
}
@Suppress("UNCHECKED_CAST")
private inner class AlbumViewHolder(view: View) : AbsHomeViewItem(view) {
fun bindView(home: Home) {
title.setText(home.titleRes)
@ -144,6 +144,7 @@ class HomeAdapter(
}
}
@Suppress("UNCHECKED_CAST")
private inner class ArtistViewHolder(view: View) : AbsHomeViewItem(view) {
fun bindView(home: Home) {
title.setText(home.titleRes)
@ -154,6 +155,7 @@ class HomeAdapter(
}
}
@Suppress("UNCHECKED_CAST")
private inner class PlaylistViewHolder(view: View) : AbsHomeViewItem(view) {
fun bindView(home: Home) {
title.setText(home.titleRes)
@ -172,7 +174,6 @@ class HomeAdapter(
open class AbsHomeViewItem(itemView: View) : RecyclerView.ViewHolder(itemView) {
val recyclerView: RecyclerView = itemView.findViewById(R.id.recyclerView)
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)
}
@ -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) {
listSongs(
requireContext(),
toList(file),
listOf(file),
AUDIO_FILE_FILTER,
fileComparator
) { songs ->
@ -226,7 +226,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
lifecycleScope.launch(Dispatchers.IO) {
listSongs(
requireContext(),
toList(file),
listOf(file),
AUDIO_FILE_FILTER,
fileComparator
) { songs ->
@ -264,7 +264,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
lifecycleScope.launch(Dispatchers.IO) {
listSongs(
requireContext(),
toList(mFile.parentFile),
listOf(mFile.parentFile),
fileFilter,
fileComparator
) { 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>) {
adapter?.swapDataSet(files)
val crumb = activeCrumb
@ -578,7 +572,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
suspend fun listSongs(
context: Context,
files: List<File>,
files: List<File?>,
fileFilter: FileFilter,
fileComparator: Comparator<File>,
doOnSongsListed: (songs: List<Song>) -> Unit

View file

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

View file

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

View file

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