mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Make chosen background images persistent
- by saving the image Uri in SharedPreferences
This commit is contained in:
parent
0eecdff99f
commit
6c5df6189e
2 changed files with 19 additions and 2 deletions
|
@ -2,8 +2,10 @@ package com.finnmglas.launcher
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -51,8 +53,14 @@ class MainActivity : AppCompatActivity(),
|
|||
|
||||
currentTheme = getSavedTheme(this)
|
||||
|
||||
if (currentTheme == "custom" && background == null)
|
||||
if (currentTheme == "custom") {
|
||||
try {
|
||||
background = MediaStore.Images.Media.getBitmap(this.contentResolver, Uri.parse(sharedPref.getString("background_uri", "")))
|
||||
} catch (e: Exception) { }
|
||||
|
||||
if (background == null)
|
||||
currentTheme = saveTheme(this, "finn")
|
||||
}
|
||||
|
||||
setTheme(
|
||||
when (currentTheme) {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.finnmglas.launcher.settings
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
|
@ -92,6 +94,13 @@ class SettingsFragmentTheme : Fragment() {
|
|||
if (data == null) return
|
||||
|
||||
val imageUri = data.data
|
||||
|
||||
/* Save image Uri as string */
|
||||
val editor: SharedPreferences.Editor = context!!.getSharedPreferences(
|
||||
context!!.getString(R.string.preference_file_key), Context.MODE_PRIVATE).edit()
|
||||
editor.putString("background_uri", imageUri.toString())
|
||||
editor.apply()
|
||||
|
||||
background = MediaStore.Images.Media.getBitmap(this.context!!.contentResolver, imageUri)
|
||||
|
||||
saveTheme(this.context!!, "custom")
|
||||
|
|
Loading…
Add table
Reference in a new issue