Skip to content

Commit

Permalink
Review wallpaper props restoring
Browse files Browse the repository at this point in the history
Signed-off-by: enricocid <[email protected]>
  • Loading branch information
enricocid committed Aug 10, 2019
1 parent b19ecf5 commit dbe78bb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 50 deletions.
2 changes: 1 addition & 1 deletion project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 15
versionName "1.3.2"
versionName "1.3.2.1"
}

// Configure only for each module that uses Java 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ const val SET_LIVE_WALLPAPER = 2

class SetWallpaperActivity : AppCompatActivity() {

private var mBackgroundColor = mTempPreferences.tempBackgroundColor
private var sUserIsSeeking = false
private var mScaleFactor = mTempPreferences.tempScale

private lateinit var mVectorView: VectorView

Expand Down Expand Up @@ -89,8 +87,10 @@ class SetWallpaperActivity : AppCompatActivity() {
//method to check if accent theme has changed on resume
private fun checkSystemAccent(): Boolean {

val isBackgroundAccented = mVectorifyPreferences.isBackgroundAccented
val isVectorAccented = mVectorifyPreferences.isVectorAccented
val isBackgroundAccented =
mTempPreferences.isBackgroundAccentSet && !mTempPreferences.isBackgroundColorChanged || mVectorifyPreferences.isBackgroundAccented && !mTempPreferences.isBackgroundColorChanged
val isVectorAccented =
mTempPreferences.isVectorAccentSet && !mTempPreferences.isVectorColorChanged || mVectorifyPreferences.isVectorAccented && !mTempPreferences.isVectorColorChanged

return if (!isBackgroundAccented && !isVectorAccented) {
false
Expand All @@ -99,35 +99,38 @@ class SetWallpaperActivity : AppCompatActivity() {
val systemAccentColor = Utils.getSystemAccentColor(this)

//if changed, update it!
if (systemAccentColor != mVectorifyPreferences.backgroundColor || systemAccentColor != mVectorifyPreferences.vectorColor) {
if (systemAccentColor != mTempPreferences.tempBackgroundColor || systemAccentColor != mTempPreferences.tempVectorColor) {

//update cards colors
if (isBackgroundAccented) {
mBackgroundColor = systemAccentColor
mTempPreferences.tempBackgroundColor = systemAccentColor
mVectorView.updateBackgroundColor(systemAccentColor)
setToolbarAndSeekbarColors()
}
if (isVectorAccented) mVectorView.updateVectorColor(systemAccentColor)
if (isVectorAccented) {
mTempPreferences.tempVectorColor = systemAccentColor
mVectorView.updateVectorColor(systemAccentColor)
}
}
return true
}
}

private fun setToolbarAndSeekbarColors() {

if (Utils.isColorDark(mBackgroundColor)) toolbar.context.setTheme(R.style.ToolbarStyle_Dark)
if (Utils.isColorDark(mTempPreferences.tempBackgroundColor)) toolbar.context.setTheme(R.style.ToolbarStyle_Dark)
else toolbar.context.setTheme(R.style.ToolbarStyle)

//determine if background color is dark or light and select
//the appropriate color for UI widgets
val widgetColors = Utils.getSecondaryColor(mBackgroundColor)
val widgetColors = Utils.getSecondaryColor(mTempPreferences.tempBackgroundColor)

toolbar.setBackgroundColor(mBackgroundColor)
toolbar.setBackgroundColor(mTempPreferences.tempBackgroundColor)
toolbar.setTitleTextColor(widgetColors)
toolbar.setNavigationIcon(R.drawable.ic_back)

//set seekbar colors
seekbar_card.setCardBackgroundColor(mBackgroundColor)
seekbar_card.setCardBackgroundColor(mTempPreferences.tempBackgroundColor)
seek_size.progressTintList = ColorStateList.valueOf(widgetColors)
seek_size.thumbTintList = ColorStateList.valueOf(widgetColors)
seek_size.progressBackgroundTintList = ColorStateList.valueOf(widgetColors)
Expand Down Expand Up @@ -167,7 +170,7 @@ class SetWallpaperActivity : AppCompatActivity() {
}

if (mTempPreferences.isScaleChanged) {
mVectorifyPreferences.scale = mScaleFactor
mVectorifyPreferences.scale = mTempPreferences.tempScale
mTempPreferences.isScaleChanged = false
}

Expand All @@ -186,8 +189,6 @@ class SetWallpaperActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

mBackgroundColor = mTempPreferences.tempBackgroundColor

//set ui theme and immersive mode
setTheme(mVectorifyPreferences.theme)
hideSystemUI()
Expand Down Expand Up @@ -227,16 +228,15 @@ class SetWallpaperActivity : AppCompatActivity() {
override fun onStopTrackingTouch(seekBar: SeekBar?) {
sUserIsSeeking = false
mTempPreferences.isScaleChanged = true
mScaleFactor = userProgress.toFloat() / 100
mTempPreferences.tempScale = mScaleFactor
mTempPreferences.tempScale = userProgress.toFloat() / 100
}
})

//restore saved scale value
seek_size.progress = (mScaleFactor * 100).toInt()
seek_size.progress = (mTempPreferences.tempScale * 100).toInt()

//set scale text
scale_text.text = Utils.getDecimalFormattedString(mScaleFactor)
scale_text.text = Utils.getDecimalFormattedString(mTempPreferences.tempScale)
}

override fun onWindowFocusChanged(hasFocus: Boolean) {
Expand Down
61 changes: 34 additions & 27 deletions project/app/src/main/java/com/iven/vectorify/VectorifyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class VectorifyActivity : AppCompatActivity() {

private var mTheme = R.style.AppTheme

private var mBackgroundColor = mVectorifyPreferences.backgroundColor
private var mVectorColor = mVectorifyPreferences.vectorColor
private var mVector = mVectorifyPreferences.vector

private lateinit var mFab: FloatingActionButton
private lateinit var mVectorFrame: ImageView
private lateinit var mBackgroundSystemAccentGrabber: Chip
private lateinit var mVectorSystemAccentGrabber: Chip

private var mBackgroundColor = Color.BLACK
private var mVectorColor = Color.WHITE
private var mVector = R.drawable.android

override fun onResume() {
super.onResume()
//check if accent theme has changed
Expand All @@ -58,10 +58,10 @@ class VectorifyActivity : AppCompatActivity() {

setContentView(R.layout.vectorify_activity)

//set temp preferecens to match preferences
mTempPreferences.tempBackgroundColor = mBackgroundColor
mTempPreferences.tempVectorColor = mVectorColor
mTempPreferences.tempVector = mVector
//get wallpaper shit
mBackgroundColor = mVectorifyPreferences.backgroundColor
mVectorColor = mVectorifyPreferences.vectorColor
mVector = mVectorifyPreferences.vector

//get system accent grabbers
mBackgroundSystemAccentGrabber = background_system_accent
Expand Down Expand Up @@ -129,14 +129,14 @@ class VectorifyActivity : AppCompatActivity() {
vectorsAdapter.onVectorClick = { vector ->

if (mVector != vector) {
runOnUiThread { mVectorFrame.setImageResource(vector!!) }
mVector = vector!!
mTempPreferences.isVectorChanged = true
mTempPreferences.tempVector = mVector
runOnUiThread { mVectorFrame.setImageResource(mVector) }
mTempPreferences.isVectorChanged = true
}
}

vectors_rv.scrollToPosition(vectorsAdapter.getVectorPosition(mVector))
vectors_rv.scrollToPosition(vectorsAdapter.getVectorPosition(mVectorifyPreferences.vector))

//set vector frame height
vectors_rv.afterMeasured {
Expand All @@ -153,8 +153,13 @@ class VectorifyActivity : AppCompatActivity() {
private fun setVectorFrameColors() {
mVectorFrame.setImageResource(mVector)
mVectorFrame.setBackgroundColor(mBackgroundColor)
if (mBackgroundColor == mVectorColor) {
if (Utils.isColorDark(mVectorColor)) mVectorFrame.setColorFilter(Utils.lightenColor(mVectorColor, 0.20F))
if (checkIfColorsEquals()) {
if (Utils.isColorDark(mVectorColor)) mVectorFrame.setColorFilter(
Utils.lightenColor(
mVectorColor,
0.20F
)
)
else mVectorFrame.setColorFilter(Utils.darkenColor(mVectorColor, 0.20F))
} else {
mVectorFrame.setColorFilter(mVectorColor)
Expand All @@ -167,7 +172,7 @@ class VectorifyActivity : AppCompatActivity() {
mTempPreferences.tempBackgroundColor = mBackgroundColor

//if system accent has changed update preferences on resume with the new accent
if (isSystemAccentChanged) mVectorifyPreferences.backgroundColor = mBackgroundColor
if (isSystemAccentChanged) mVectorifyPreferences.backgroundColor = color

//update shit colors
runOnUiThread {
Expand All @@ -179,7 +184,7 @@ class VectorifyActivity : AppCompatActivity() {
mFab.backgroundTintList = ColorStateList.valueOf(color)

//check if colors are the same so we enable stroke to make vector visible
val fabDrawableColor = if (checkIfColorsEquals()) textColor else mVectorColor
val fabDrawableColor = if (checkIfColorsEquals()) textColor else mTempPreferences.tempVectorColor
mFab.drawable.setTint(fabDrawableColor)

setVectorFrameColors()
Expand All @@ -192,7 +197,7 @@ class VectorifyActivity : AppCompatActivity() {
mTempPreferences.tempVectorColor = mVectorColor

//if system accent has changed update preferences on resume with the new accent
if (isSystemAccentChanged) mVectorifyPreferences.vectorColor = mVectorColor
if (isSystemAccentChanged) mVectorifyPreferences.vectorColor = color

//update shit colors
runOnUiThread {
Expand Down Expand Up @@ -247,29 +252,29 @@ class VectorifyActivity : AppCompatActivity() {
when (key) {
getString(R.string.background_color_key) -> {
//update the color only if it really changed
if (mBackgroundColor != color) {
mVectorifyPreferences.isBackgroundAccented = false
if (mTempPreferences.tempBackgroundColor != color) {
mTempPreferences.isBackgroundAccentSet = false
mTempPreferences.isBackgroundColorChanged = true
setBackgroundColorForUI(color, false)
}
}
else -> {
//update the color only if it really changed
if (mVectorColor != color) {
mVectorifyPreferences.isVectorAccented = false
if (mTempPreferences.tempVectorColor != color) {
mTempPreferences.isVectorAccentSet = false
mTempPreferences.isVectorColorChanged = true
setVectorColorForUI(color, false)
}
}
}
}
positiveButton(android.R.string.ok)
positiveButton()
}
}

private fun setBackgroundAndVectorColorsChanged() {
mVectorifyPreferences.isBackgroundAccented = false
mVectorifyPreferences.isVectorAccented = false
mTempPreferences.isBackgroundAccentSet = false
mTempPreferences.isVectorAccentSet = false
mTempPreferences.isBackgroundColorChanged = true
mTempPreferences.isVectorColorChanged = true
}
Expand Down Expand Up @@ -297,7 +302,7 @@ class VectorifyActivity : AppCompatActivity() {

//check if background and vector colors are equals
private fun checkIfColorsEquals(): Boolean {
return mBackgroundColor == mVectorColor
return mTempPreferences.tempBackgroundColor == mTempPreferences.tempVectorColor
}

//returns formatted hex string
Expand All @@ -308,8 +313,10 @@ class VectorifyActivity : AppCompatActivity() {
//method to check if accent theme has changed on resume
private fun checkSystemAccent(): Boolean {

val isBackgroundAccented = mVectorifyPreferences.isBackgroundAccented
val isVectorAccented = mVectorifyPreferences.isVectorAccented
val isBackgroundAccented =
mTempPreferences.isBackgroundAccentSet && !mTempPreferences.isBackgroundColorChanged || mVectorifyPreferences.isBackgroundAccented && !mTempPreferences.isBackgroundColorChanged
val isVectorAccented =
mTempPreferences.isVectorAccentSet && !mTempPreferences.isVectorColorChanged || mVectorifyPreferences.isVectorAccented && !mTempPreferences.isVectorColorChanged

return if (!isBackgroundAccented && !isVectorAccented) {
false
Expand All @@ -318,7 +325,7 @@ class VectorifyActivity : AppCompatActivity() {
val systemAccentColor = Utils.getSystemAccentColor(this)

//if changed, update it!
if (systemAccentColor != mVectorifyPreferences.backgroundColor || systemAccentColor != mVectorifyPreferences.vectorColor) {
if (systemAccentColor != mTempPreferences.tempBackgroundColor || systemAccentColor != mTempPreferences.tempVectorColor) {

//update cards colors
if (isBackgroundAccented) setBackgroundColorForUI(systemAccentColor, true)
Expand Down
7 changes: 7 additions & 0 deletions project/app/src/main/java/com/iven/vectorify/VectorifyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class VectorifyApp : Application() {
prefs = VectorifyPreferences(applicationContext)
tempPrefs = TempPreferences()

tempPrefs.tempBackgroundColor = prefs.backgroundColor
tempPrefs.tempVectorColor = prefs.vectorColor
tempPrefs.tempVector = prefs.vector
tempPrefs.isBackgroundAccentSet = prefs.isBackgroundAccented
tempPrefs.isVectorAccentSet = prefs.isVectorAccented
tempPrefs.tempScale = prefs.scale

//retrieve display specifications
val window = applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val d = DisplayMetrics()
Expand Down
14 changes: 10 additions & 4 deletions project/app/src/main/java/com/iven/vectorify/VectorifyDaHomeLP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class VectorifyDaHomeLP : WallpaperService() {
mBackgroundColor = mVectorifyPreferences.backgroundColor
mDrawableColor = mVectorifyPreferences.vectorColor
mScaleFactor = mVectorifyPreferences.scale

checkSystemAccent()
}

private fun checkSystemAccent() {
Expand All @@ -44,9 +46,14 @@ class VectorifyDaHomeLP : WallpaperService() {
if (isBackgroundAccented || isDrawableAccented) {
//change only if system accent has changed
val systemAccentColor = Utils.getSystemAccentColor(this)
if (isBackgroundAccented && mBackgroundColor != systemAccentColor) mBackgroundColor =
systemAccentColor
if (isDrawableAccented && mDrawableColor != systemAccentColor) mDrawableColor = systemAccentColor
if (isBackgroundAccented && mBackgroundColor != systemAccentColor) {
mBackgroundColor = systemAccentColor
mVectorifyPreferences.backgroundColor = systemAccentColor
}
if (isDrawableAccented && mDrawableColor != systemAccentColor) {
mDrawableColor = systemAccentColor
mVectorifyPreferences.vectorColor = systemAccentColor
}
}
}

Expand All @@ -60,7 +67,6 @@ class VectorifyDaHomeLP : WallpaperService() {
sVisible = visible
if (visible) {
updatePaintProps()
checkSystemAccent()
handler.post(drawRunner)
} else {
handler.removeCallbacks(drawRunner)
Expand Down

0 comments on commit dbe78bb

Please sign in to comment.