My initial commit
Removed Google play dependencies
This commit is contained in:
parent
fd582fff69
commit
301ac10570
430 changed files with 2210 additions and 3137 deletions
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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 io.github.muntashirakon.music.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import io.github.muntashirakon.music.R
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
|
||||
fun AppCompatActivity.applyToolbar(toolbar: MaterialToolbar) {
|
||||
toolbar.setBackgroundColor(surfaceColor())
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||
setSupportActionBar(toolbar)
|
||||
}
|
||||
|
||||
fun FragmentActivity?.addFragment(
|
||||
@IdRes idRes: Int = R.id.container,
|
||||
fragment: Fragment,
|
||||
tag: String? = null,
|
||||
addToBackStack: Boolean = false
|
||||
) {
|
||||
val compatActivity = this as? AppCompatActivity ?: return
|
||||
compatActivity.supportFragmentManager.beginTransaction()
|
||||
.apply {
|
||||
add(fragment, tag)
|
||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
if (addToBackStack) {
|
||||
addToBackStack(null)
|
||||
}
|
||||
commitNow()
|
||||
}
|
||||
}
|
||||
|
||||
fun AppCompatActivity.replaceFragment(
|
||||
@IdRes id: Int = R.id.container,
|
||||
fragment: Fragment,
|
||||
tag: String? = null,
|
||||
addToBackStack: Boolean = false
|
||||
) {
|
||||
val compatActivity = this ?: return
|
||||
compatActivity.supportFragmentManager.beginTransaction()
|
||||
.apply {
|
||||
replace(id, fragment, tag)
|
||||
if (addToBackStack) {
|
||||
addToBackStack(null)
|
||||
}
|
||||
commit()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Activity.extra(key: String, default: T? = null) = lazy {
|
||||
val value = intent?.extras?.get(key)
|
||||
if (value is T) value else default
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Activity.extraNotNull(key: String, default: T? = null) = lazy {
|
||||
val value = intent?.extras?.get(key)
|
||||
requireNotNull(if (value is T) value else default) { key }
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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 io.github.muntashirakon.music.extensions
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.widget.CheckBox
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.Fragment
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import io.github.muntashirakon.music.R
|
||||
|
||||
fun Int.ripAlpha(): Int {
|
||||
return ColorUtil.stripAlpha(this)
|
||||
}
|
||||
|
||||
fun Dialog.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
|
||||
fun Toolbar.backgroundTintList() {
|
||||
val surfaceColor = ATHUtil.resolveColor(context, R.attr.colorSurface, Color.BLACK)
|
||||
val colorStateList = ColorStateList.valueOf(surfaceColor)
|
||||
backgroundTintList = colorStateList
|
||||
}
|
||||
|
||||
fun Context.accentColor() = ThemeStore.accentColor(this)
|
||||
|
||||
fun Fragment.accentColor() = ThemeStore.accentColor(requireContext())
|
||||
|
||||
fun Context.surfaceColor() = resolveColor(R.attr.colorSurface, Color.WHITE)
|
||||
|
||||
fun Fragment.surfaceColor() = resolveColor(R.attr.colorSurface, Color.WHITE)
|
||||
|
||||
fun Context.textColorSecondary() = resolveColor(android.R.attr.textColorSecondary)
|
||||
|
||||
fun Fragment.textColorSecondary() = resolveColor(android.R.attr.textColorSecondary)
|
||||
|
||||
fun Context.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
|
||||
|
||||
fun Fragment.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
|
||||
|
||||
fun Context.textColorPrimary() = resolveColor(android.R.attr.textColorPrimary)
|
||||
|
||||
fun Fragment.textColorPrimary() = resolveColor(android.R.attr.textColorPrimary)
|
||||
|
||||
fun Context.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
||||
ATHUtil.resolveColor(this, attr, fallBackColor)
|
||||
|
||||
fun Fragment.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
||||
ATHUtil.resolveColor(requireContext(), attr, fallBackColor)
|
||||
|
||||
fun Dialog.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
||||
ATHUtil.resolveColor(context, attr, fallBackColor)
|
||||
|
||||
|
||||
fun CheckBox.addAccentColor() {
|
||||
buttonTintList = ColorStateList.valueOf(ThemeStore.accentColor(context))
|
||||
}
|
||||
|
||||
fun SeekBar.addAccentColor() {
|
||||
val colorState = ColorStateList.valueOf(ThemeStore.accentColor(context))
|
||||
progressTintList = colorState
|
||||
thumbTintList = colorState
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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 io.github.muntashirakon.music.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.AdaptiveIconDrawable
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import androidx.annotation.DimenRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import io.github.muntashirakon.music.R
|
||||
|
||||
fun Context.scaledDrawableResources(
|
||||
@DrawableRes id: Int,
|
||||
@DimenRes width: Int,
|
||||
@DimenRes height: Int
|
||||
): Drawable {
|
||||
val w = resources.getDimension(width).toInt()
|
||||
val h = resources.getDimension(height).toInt()
|
||||
return scaledDrawable(id, w, h)
|
||||
}
|
||||
|
||||
fun Context.scaledDrawable(@DrawableRes id: Int, width: Int, height: Int): Drawable {
|
||||
val bmp = BitmapFactory.decodeResource(resources, id)
|
||||
val bmpScaled = Bitmap.createScaledBitmap(bmp, width, height, false)
|
||||
return BitmapDrawable(resources, bmpScaled)
|
||||
}
|
||||
|
||||
fun Drawable.getBitmapDrawable(): Bitmap {
|
||||
val bmp = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bmp)
|
||||
draw(canvas)
|
||||
return bmp
|
||||
}
|
||||
|
||||
fun getAdaptiveIconDrawable(context: Context): Drawable {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
AdaptiveIconDrawable(
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_launcher_background),
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)
|
||||
)
|
||||
} else {
|
||||
ContextCompat.getDrawable(context, R.drawable.color_circle_gradient)!!
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package io.github.muntashirakon.music.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.PowerManager
|
||||
import androidx.annotation.IntegerRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import io.github.muntashirakon.music.util.PreferenceUtil
|
||||
|
||||
fun Fragment.getIntRes(@IntegerRes int: Int): Int {
|
||||
return resources.getInteger(int)
|
||||
}
|
||||
|
||||
fun Context.getIntRes(@IntegerRes int: Int): Int {
|
||||
return resources.getInteger(int)
|
||||
}
|
||||
|
||||
val Context.generalThemeValue
|
||||
get() = PreferenceUtil.getGeneralThemeValue(isSystemDarkModeEnabled())
|
||||
|
||||
|
||||
fun Context.isSystemDarkModeEnabled(): Boolean {
|
||||
val isBatterySaverEnabled =
|
||||
(getSystemService(Context.POWER_SERVICE) as PowerManager?)?.isPowerSaveMode ?: false
|
||||
val isDarkModeEnabled =
|
||||
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
return isBatterySaverEnabled or isDarkModeEnabled
|
||||
}
|
||||
|
||||
|
||||
inline fun <reified T : Any> Fragment.extra(key: String, default: T? = null) = lazy {
|
||||
val value = arguments?.get(key)
|
||||
if (value is T) value else default
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Fragment.extraNotNull(key: String, default: T? = null) = lazy {
|
||||
val value = arguments?.get(key)
|
||||
requireNotNull(if (value is T) value else default) { key }
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package io.github.muntashirakon.music.extensions
|
||||
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.palette.graphics.Palette
|
||||
|
||||
|
||||
fun getSuitableColorFor(palette: Palette, i: Int, i2: Int): Int {
|
||||
val dominantSwatch = palette.dominantSwatch
|
||||
if (dominantSwatch != null) {
|
||||
if (hasEnoughContrast(i, dominantSwatch.rgb)) {
|
||||
return dominantSwatch.rgb
|
||||
}
|
||||
}
|
||||
val vibrantSwatch = palette.vibrantSwatch
|
||||
if (vibrantSwatch != null) {
|
||||
if (hasEnoughContrast(i, vibrantSwatch.rgb)) {
|
||||
return vibrantSwatch.rgb
|
||||
}
|
||||
}
|
||||
val darkVibrantSwatch = palette.darkVibrantSwatch
|
||||
if (darkVibrantSwatch != null) {
|
||||
if (hasEnoughContrast(i, darkVibrantSwatch.rgb)) {
|
||||
return darkVibrantSwatch.rgb
|
||||
}
|
||||
}
|
||||
val lightVibrantSwatch = palette.lightVibrantSwatch
|
||||
if (lightVibrantSwatch != null) {
|
||||
if (hasEnoughContrast(i, lightVibrantSwatch.rgb)) {
|
||||
return lightVibrantSwatch.rgb
|
||||
}
|
||||
}
|
||||
val darkMutedSwatch = palette.darkMutedSwatch
|
||||
if (darkMutedSwatch != null) {
|
||||
if (hasEnoughContrast(i, darkMutedSwatch.rgb)) {
|
||||
return darkMutedSwatch.rgb
|
||||
}
|
||||
}
|
||||
val lightMutedSwatch = palette.lightMutedSwatch
|
||||
if (lightMutedSwatch != null) {
|
||||
if (hasEnoughContrast(i, lightMutedSwatch.rgb)) {
|
||||
return lightMutedSwatch.rgb
|
||||
}
|
||||
}
|
||||
val mutedSwatch = palette.mutedSwatch
|
||||
if (mutedSwatch != null) {
|
||||
if (hasEnoughContrast(i, mutedSwatch.rgb)) {
|
||||
return mutedSwatch.rgb
|
||||
}
|
||||
}
|
||||
return i2
|
||||
}
|
||||
|
||||
fun hasEnoughContrast(i: Int, i2: Int): Boolean {
|
||||
return ColorUtils.calculateContrast(i2, i) >= 2.toDouble()
|
||||
}
|
||||
|
||||
fun hasEnoughLuminance(i: Int): Boolean {
|
||||
return ColorUtils.calculateLuminance(i) >= 0.4f.toDouble()
|
||||
}
|
||||
|
||||
fun isBlack(fArr: FloatArray): Boolean {
|
||||
return fArr[2] <= 0.035f
|
||||
}
|
||||
|
||||
fun isNearRedLine(fArr: FloatArray): Boolean {
|
||||
val f = fArr[0]
|
||||
return f >= 10.0f && f <= 37.0f && fArr[1] <= 0.82f
|
||||
}
|
||||
|
||||
fun isDark(@ColorInt i: Int): Boolean {
|
||||
return ColorUtils.calculateLuminance(i) < 0.5
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package io.github.muntashirakon.music.extensions
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
fun SharedPreferences.getStringOrDefault(key: String, default: String): String {
|
||||
return getString(key, default) ?: default
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 io.github.muntashirakon.music.extensions
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.LayoutRes
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.TintHelper
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : View> ViewGroup.inflate(@LayoutRes layout: Int): T {
|
||||
return LayoutInflater.from(context).inflate(layout, this, false) as T
|
||||
}
|
||||
|
||||
fun View.show() {
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
fun View.hide() {
|
||||
visibility = View.GONE
|
||||
}
|
||||
|
||||
fun View.hidden() {
|
||||
visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
fun View.showOrHide(show: Boolean) = if (show) show() else hide()
|
||||
|
||||
fun EditText.appHandleColor(): EditText {
|
||||
TintHelper.colorHandles(this, ThemeStore.accentColor(context))
|
||||
return this
|
||||
}
|
||||
|
||||
fun SeekBar.applyColor(@ColorInt color: Int) {
|
||||
thumbTintList = ColorStateList.valueOf(color)
|
||||
progressTintList = ColorStateList.valueOf(color)
|
||||
progressBackgroundTintList = ColorStateList.valueOf(color)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue