Working towards single activity design

This commit is contained in:
Hemanth S 2020-08-11 23:59:44 +05:30
parent 31534769a8
commit 3ebf777d7b
87 changed files with 1908 additions and 2423 deletions

View file

@ -22,13 +22,16 @@ import android.widget.Button
import android.widget.CheckBox
import android.widget.SeekBar
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
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 code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
fun Int.ripAlpha(): Int {
return ColorUtil.stripAlpha(this)
@ -83,4 +86,20 @@ fun SeekBar.addAccentColor() {
fun Button.accentTextColor() {
setTextColor(ThemeStore.accentColor(App.getContext()))
}
fun SeekBar.applyColor(@ColorInt color: Int) {
thumbTintList = ColorStateList.valueOf(color)
progressTintList = ColorStateList.valueOf(color)
progressBackgroundTintList = ColorStateList.valueOf(color)
}
fun ExtendedFloatingActionButton.accentColor() {
val color = ThemeStore.accentColor(context)
val textColor = MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))
val colorStateList = ColorStateList.valueOf(color)
val textColorStateList = ColorStateList.valueOf(textColor)
backgroundTintList = colorStateList
setTextColor(textColorStateList)
iconTint = textColorStateList
}

View file

@ -0,0 +1,20 @@
package code.name.monkey.retromusic.extensions
import android.app.Activity
import androidx.annotation.DimenRes
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
fun AppCompatActivity.dimToPixel(@DimenRes dimenRes: Int): Int {
return resources.getDimensionPixelSize(dimenRes)
}
fun Activity.dipToPix(dpInFloat: Float): Float {
val scale = resources.displayMetrics.density
return dpInFloat * scale + 0.5f
}
fun Fragment.dipToPix(dpInFloat: Float): Float {
val scale = resources.displayMetrics.density
return dpInFloat * scale + 0.5f
}

View file

@ -3,7 +3,10 @@ package code.name.monkey.retromusic.extensions
import android.content.Context
import android.content.res.Configuration
import android.os.PowerManager
import android.widget.Toast
import androidx.annotation.IdRes
import androidx.annotation.IntegerRes
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
@ -53,3 +56,17 @@ fun AppCompatActivity.currentFragment(navHostId: Int): Fragment? {
navHostFragment.targetFragment
return navHostFragment?.childFragmentManager?.fragments?.first()
}
@Suppress("UNCHECKED_CAST")
fun <T> AppCompatActivity.whichFragment(@IdRes id: Int): T {
return supportFragmentManager.findFragmentById(id) as T
}
fun Fragment.showToast(@StringRes stringRes: Int) {
showToast(getString(stringRes))
}
fun Fragment.showToast(message: String) {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
}

View file

@ -4,17 +4,22 @@ import androidx.annotation.IdRes
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
fun Fragment.navigate(@IdRes id: Int) = findNavController().navigate(id)
fun Fragment.navController(@IdRes id: Int): NavController {
fun Fragment.findNavController(@IdRes id: Int): NavController {
val fragment = childFragmentManager.findFragmentById(id) as NavHostFragment
return fragment.navController
}
fun AppCompatActivity.navController(@IdRes id: Int): NavController {
fun Fragment.findActivityNavController(@IdRes id: Int): NavController {
return requireActivity().findNavController(id)
}
fun AppCompatActivity.findNavController(@IdRes id: Int): NavController {
val fragment = supportFragmentManager.findFragmentById(id) as NavHostFragment
return fragment.navController
}

View file

@ -48,9 +48,3 @@ 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)
}