mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-22 22:11:27 +01:00
Remove function 'handlePickedImage'
Put the code in the `onActivityResult` function so that things get a little easier.
This commit is contained in:
parent
179448007f
commit
e8fa4f058d
1 changed files with 40 additions and 42 deletions
|
@ -45,11 +45,49 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
REQUEST_PERMISSION_STORAGE -> letUserPickImage()
|
REQUEST_PERMISSION_STORAGE -> letUserPickImage()
|
||||||
REQUEST_PICK_IMAGE -> handlePickedImage(resultCode, data)
|
REQUEST_PICK_IMAGE -> {
|
||||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
|
||||||
|
if (resultCode == AppCompatActivity.RESULT_OK && data != null) {
|
||||||
|
|
||||||
|
val imageUri = data.data
|
||||||
|
background = MediaStore.Images.Media.getBitmap(context!!.contentResolver, imageUri)
|
||||||
|
|
||||||
|
Palette.Builder(background!!).generate {
|
||||||
|
it?.let { palette ->
|
||||||
|
dominantColor = palette.getDominantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
|
||||||
|
vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
|
||||||
|
|
||||||
|
// never let dominantColor equal vibrantColor
|
||||||
|
if(dominantColor == vibrantColor) {
|
||||||
|
vibrantColor =
|
||||||
|
manipulateColor(
|
||||||
|
vibrantColor,
|
||||||
|
1.2F
|
||||||
|
)
|
||||||
|
dominantColor =
|
||||||
|
manipulateColor(
|
||||||
|
dominantColor,
|
||||||
|
0.8F
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save image Uri as string */
|
||||||
|
launcherPreferences.edit()
|
||||||
|
.putString(PREF_WALLPAPER, imageUri.toString())
|
||||||
|
.putInt(PREF_DOMINANT, dominantColor)
|
||||||
|
.putInt(PREF_VIBRANT, vibrantColor)
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
intendedSettingsPause = true
|
||||||
|
activity!!.recreate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,46 +108,6 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
||||||
startActivityForResult(intent, REQUEST_PICK_IMAGE)
|
startActivityForResult(intent, REQUEST_PICK_IMAGE)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handlePickedImage(resultCode: Int, data: Intent?) {
|
|
||||||
if (resultCode == AppCompatActivity.RESULT_OK) {
|
|
||||||
if (data == null) return
|
|
||||||
|
|
||||||
val imageUri = data.data
|
|
||||||
background = MediaStore.Images.Media.getBitmap(context!!.contentResolver, imageUri)
|
|
||||||
|
|
||||||
Palette.Builder(background!!).generate {
|
|
||||||
it?.let { palette ->
|
|
||||||
dominantColor = palette.getDominantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
|
|
||||||
vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
|
|
||||||
|
|
||||||
// never let dominantColor equal vibrantColor
|
|
||||||
if(dominantColor == vibrantColor) {
|
|
||||||
vibrantColor =
|
|
||||||
manipulateColor(
|
|
||||||
vibrantColor,
|
|
||||||
1.2F
|
|
||||||
)
|
|
||||||
dominantColor =
|
|
||||||
manipulateColor(
|
|
||||||
dominantColor,
|
|
||||||
0.8F
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save image Uri as string */
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putString(PREF_WALLPAPER, imageUri.toString())
|
|
||||||
.putInt(PREF_DOMINANT, dominantColor)
|
|
||||||
.putInt(PREF_VIBRANT, vibrantColor)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
intendedSettingsPause = true
|
|
||||||
activity!!.recreate()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTheme() {
|
override fun applyTheme() {
|
||||||
|
|
||||||
setSwitchColor(settings_launcher_switch_screen_timeout, vibrantColor)
|
setSwitchColor(settings_launcher_switch_screen_timeout, vibrantColor)
|
||||||
|
|
Loading…
Add table
Reference in a new issue