Cleanup with Kotlin extension functions
This commit is contained in:
parent
fc4f0396a4
commit
e0f345b616
37 changed files with 183 additions and 291 deletions
|
@ -2,8 +2,8 @@ package code.name.monkey.retromusic.util
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import java.io.File
|
||||
|
||||
object BackupUtil {
|
||||
|
@ -19,11 +19,9 @@ object BackupUtil {
|
|||
).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).setType("*/*")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Could not share this file.",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
context.showToast(
|
||||
"Could not share this file."
|
||||
)
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,13 @@ import android.provider.MediaStore
|
|||
import android.widget.Toast
|
||||
import androidx.core.content.edit
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
|
@ -53,7 +52,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
.into(object : SimpleTarget<Bitmap>() {
|
||||
override fun onLoadFailed(errorDrawable: Drawable?) {
|
||||
super.onLoadFailed(errorDrawable)
|
||||
Toast.makeText(App.getContext(), "Load Failed", Toast.LENGTH_LONG).show()
|
||||
App.getContext().showToast("Load Failed")
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
|
@ -70,13 +69,12 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
|
||||
var succesful = false
|
||||
try {
|
||||
val os = BufferedOutputStream(FileOutputStream(file))
|
||||
succesful = ImageUtil.resizeBitmap(resource, 2048)
|
||||
.compress(Bitmap.CompressFormat.JPEG, 100, os)
|
||||
os.close()
|
||||
file.outputStream().buffered().use { bos ->
|
||||
succesful = ImageUtil.resizeBitmap(resource, 2048)
|
||||
.compress(Bitmap.CompressFormat.JPEG, 100, bos)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Toast.makeText(App.getContext(), e.toString(), Toast.LENGTH_LONG)
|
||||
.show()
|
||||
App.getContext().showToast(e.toString(), Toast.LENGTH_LONG)
|
||||
}
|
||||
|
||||
if (succesful) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.os.Environment
|
|||
import android.provider.BaseColumns
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.content.contentValuesOf
|
||||
import androidx.core.net.toUri
|
||||
|
@ -20,6 +19,7 @@ import code.name.monkey.retromusic.db.PlaylistEntity
|
|||
import code.name.monkey.retromusic.db.SongEntity
|
||||
import code.name.monkey.retromusic.db.toSongEntity
|
||||
import code.name.monkey.retromusic.extensions.getLong
|
||||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.removeFromQueue
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
|
@ -58,11 +58,7 @@ object MusicUtil : KoinComponent {
|
|||
} catch (e: IllegalArgumentException) {
|
||||
// TODO the path is most likely not like /storage/emulated/0/... but something like /storage/28C7-75B0/...
|
||||
e.printStackTrace()
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Could not share this file, I'm aware of the issue.",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
context.showToast("Could not share this file, I'm aware of the issue.")
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
|
@ -456,12 +452,7 @@ object MusicUtil : KoinComponent {
|
|||
}
|
||||
activity.contentResolver.notifyChange("content://media".toUri(), null)
|
||||
activity.runOnUiThread {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
activity.getString(R.string.deleted_x_songs, songCount),
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
activity.showToast(activity.getString(R.string.deleted_x_songs, songCount))
|
||||
callback?.run()
|
||||
}
|
||||
|
||||
|
@ -519,11 +510,7 @@ object MusicUtil : KoinComponent {
|
|||
cursor.close()
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.deleted_x_songs, deletedCount),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
context.showToast(context.getString(R.string.deleted_x_songs, deletedCount))
|
||||
}
|
||||
|
||||
} catch (ignored: SecurityException) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.widget.Toast
|
|||
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.extensions.showToast
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.audioSessionId
|
||||
|
||||
object NavigationUtil {
|
||||
|
@ -68,10 +69,7 @@ object NavigationUtil {
|
|||
private fun stockEqualizer(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()
|
||||
activity.showToast(R.string.no_audio_ID, Toast.LENGTH_LONG)
|
||||
} else {
|
||||
try {
|
||||
val effects = Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL)
|
||||
|
@ -79,12 +77,7 @@ object NavigationUtil {
|
|||
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()
|
||||
activity.showToast(R.string.no_equalizer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -424,10 +424,11 @@ object PreferenceUtil {
|
|||
val position = sharedPreferences.getStringOrDefault(
|
||||
HOME_ARTIST_GRID_STYLE, "0"
|
||||
).toInt()
|
||||
val typedArray = App.getContext()
|
||||
.resources.obtainTypedArray(R.array.pref_home_grid_style_layout)
|
||||
val layoutRes = typedArray.getResourceId(position, 0)
|
||||
typedArray.recycle()
|
||||
val layoutRes =
|
||||
App.getContext().resources.obtainTypedArray(R.array.pref_home_grid_style_layout)
|
||||
.use {
|
||||
it.getResourceId(position, 0)
|
||||
}
|
||||
return if (layoutRes == 0) {
|
||||
R.layout.item_artist
|
||||
} else layoutRes
|
||||
|
@ -438,10 +439,10 @@ object PreferenceUtil {
|
|||
val position = sharedPreferences.getStringOrDefault(
|
||||
HOME_ALBUM_GRID_STYLE, "4"
|
||||
).toInt()
|
||||
val typedArray = App.getContext()
|
||||
.resources.obtainTypedArray(R.array.pref_home_grid_style_layout)
|
||||
val layoutRes = typedArray.getResourceId(position, 0)
|
||||
typedArray.recycle()
|
||||
val layoutRes = App.getContext()
|
||||
.resources.obtainTypedArray(R.array.pref_home_grid_style_layout).use {
|
||||
it.getResourceId(position, 0)
|
||||
}
|
||||
return if (layoutRes == 0) {
|
||||
R.layout.item_image
|
||||
} else layoutRes
|
||||
|
@ -582,7 +583,7 @@ object PreferenceUtil {
|
|||
4 -> VerticalFlipTransformation()
|
||||
5 -> HingeTransformation()
|
||||
6 -> VerticalStackTransformer()
|
||||
else -> ViewPager.PageTransformer { _, _ -> }
|
||||
else -> ViewPager.PageTransformer { _, _ -> }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ import android.content.Intent
|
|||
import android.provider.BaseColumns
|
||||
import android.provider.MediaStore
|
||||
import android.provider.Settings
|
||||
import android.widget.Toast
|
||||
import androidx.core.net.toUri
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.MusicUtil.getSongFileUri
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
@ -45,7 +45,7 @@ class RingtoneManager(val context: Context) {
|
|||
Settings.System.putString(resolver, Settings.System.RINGTONE, uri.toString())
|
||||
val message = context
|
||||
.getString(R.string.x_has_been_set_as_ringtone, cursorSong.getString(0))
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
context.showToast(message)
|
||||
}
|
||||
}
|
||||
} catch (ignored: SecurityException) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue