Skip to content

Commit

Permalink
some flags import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AkosPaha01 committed Jul 24, 2021
1 parent e6bc689 commit c33b7e2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
applicationId "de.dertyp7214.rboardthememanager"
minSdkVersion 26
targetSdkVersion 31
versionCode 324000
versionCode 324001
versionName "3.2.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.core.graphics.get
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import de.dertyp7214.rboardthememanager.R
Expand Down Expand Up @@ -157,7 +158,9 @@ class ThemeAdapter(
ImageView(context).let { view ->
view.setImageBitmap(themeDataClass.image ?: default)
view.colorFilter = themeDataClass.colorFilter
val color = ColorUtils.dominantColor(view.drawable.getBitmap())
val color = view.drawable.getBitmap().let {
it[0, it.height / 2]
}
Pair(color, ColorUtils.isColorLight(color))
}
}, { colorCache[index] = it })
Expand All @@ -171,7 +174,9 @@ class ThemeAdapter(
} ?: ImageView(context).let { view ->
view.setImageBitmap(dataClass.image ?: default)
view.colorFilter = dataClass.colorFilter
val color = ColorUtils.dominantColor(view.drawable.getBitmap())
val color = view.drawable.getBitmap().let {
it[0, it.height / 2]
}
colorCache[position] = Pair(color, ColorUtils.isColorLight(color))
color
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/de/dertyp7214/rboardthememanager/core/Intent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.dertyp7214.rboardthememanager.core

import android.content.Intent

@Suppress("UNCHECKED_CAST")
inline fun <reified T> Intent.getArrayExtra(name: String): Array<T> {
return try {
getSerializableExtra(name) as Array<T>
} catch (e: Exception) {
arrayOf()
}
}

fun Intent.putExtra(name: String, value: Map<*, *>) = putExtra(name, value.toList().toTypedArray())
fun <K, V> Intent.getMapExtra(name: String): Map<K, V> = getArrayExtra<Pair<K, V>>(name).toMap()
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import de.dertyp7214.rboardthememanager.R
import de.dertyp7214.rboardthememanager.adapter.ShareFlagsAdapter
import de.dertyp7214.rboardthememanager.components.SearchBar
import de.dertyp7214.rboardthememanager.core.getMapExtra
import de.dertyp7214.rboardthememanager.core.setXmlValue
import de.dertyp7214.rboardthememanager.core.share
import de.dertyp7214.rboardthememanager.databinding.ActivityShareFlagsBinding
Expand All @@ -22,9 +23,7 @@ import java.io.File

class ShareFlags : AppCompatActivity() {

companion object {
var flags: Map<String, Any> = mapOf()
}
private var flags: Map<String, Any> = mapOf()

private lateinit var binding: ActivityShareFlagsBinding
private lateinit var adapter: ShareFlagsAdapter
Expand Down Expand Up @@ -61,7 +60,8 @@ class ShareFlags : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
title = getString(titleRes, 0)

if (!import) flags = Flags.flagValues
flags = if (!import) Flags.flagValues
else intent.getMapExtra("flags")
val orig = ArrayList(flags.map { it.key })
val flagKeys = ArrayList(orig)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ class AppStartUp(private val activity: AppCompatActivity) {
this,
R.string.repo_added,
Toast.LENGTH_SHORT
)
.show()
).show()
}
}
}
Expand All @@ -232,15 +231,18 @@ class AppStartUp(private val activity: AppCompatActivity) {
}
finishAndRemoveTask()
}
isReady = true
val dialog = openLoadingDialog(R.string.processing_flags)
doAsync({
File(cacheDir, "flags.rboard").apply {
delete()
data.writeToFile(activity, this)
}.readXML()
}) {
ShareFlags.flags = it
dialog.dismiss()
ShareFlags::class.java.start(this, resultLauncher) {
putExtra("import", true)
putExtra("flags", it)
}
}
}
Expand All @@ -266,12 +268,9 @@ class AppStartUp(private val activity: AppCompatActivity) {
} else listOf()
}
}) {
resultLauncher.launch(
Intent(
this,
InstallPackActivity::class.java
).putStringArrayListExtra("themes", ArrayList(it))
)
InstallPackActivity::class.java.start(this, resultLauncher) {
putStringArrayListExtra("themes", ArrayList(it))
}
}
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import java.io.BufferedInputStream
import java.net.URL
import java.util.*
import android.content.res.Configuration
import androidx.core.graphics.get
import kotlin.collections.ArrayList

@SuppressLint("SdCardPath")
Expand Down Expand Up @@ -307,7 +308,7 @@ object ThemeUtils {
).decodeBitmap()
} catch (e: Exception) {
null
})?: BitmapFactory.decodeStream(
}) ?: BitmapFactory.decodeStream(
BufferedInputStream(
context.resources.openRawResource(
R.raw.system_auto
Expand Down Expand Up @@ -341,7 +342,9 @@ object ThemeUtils {
themeIcon.setImageBitmap(theme.image ?: defaultImage)
themeIcon.colorFilter = theme.colorFilter

val color = ColorUtils.dominantColor(themeIcon.drawable.getBitmap())
val color = themeIcon.drawable.getBitmap().let {
it[0, it.height / 2]
}
val isDark = ColorUtils.isColorLight(color)

if (gradient != null) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<string name="not_rooted">Your device is not rooted</string>
<string name="channel_name">Push Notifications</string>
<string name="default_notification_channel_id">push_channel</string>
<string name="channel_description">For updates and informations.</string>
<string name="channel_description">For updates and information.</string>
<string name="channel_name_download">Download Notifications</string>
<string name="download_notification_channel_id">download_channel</string>
<string name="channel_description_download">For download notifications</string>
Expand Down Expand Up @@ -127,7 +127,7 @@
<string name="show_system_theme_long">Show system themes in themes section</string>
<string name="speedup_process">Speedup process</string>
<string name="key">Key</string>
<string name="unreleased">This app is unreleased, some features may not work. Please dont report any errors to the main group.</string>
<string name="unreleased">This app is unreleased, some features may not work. Please don\'t report any errors to the main group.</string>
<string name="notice">Notice</string>
<string name="install_module">Existing themes path found, do you still want to install the module?</string>
<string name="module">Install module</string>
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun May 30 15:50:17 CEST 2021
#Sat Jul 24 15:50:55 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit c33b7e2

Please sign in to comment.