Skip to content

Commit

Permalink
Fixes and improvements:
Browse files Browse the repository at this point in the history
- Fixed icons list and filters not loading properly from drawable.xml
- Minor performance and reliability improvements for icons and requests load
  • Loading branch information
jahirfiquitiva committed Feb 9, 2018
1 parent 3503cf5 commit f0e4bec
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 128 deletions.
4 changes: 2 additions & 2 deletions app/src/main/res/values/blueprint_configs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
~ limitations under the License.
-->
<!--suppress CheckTagEmptyBody -->
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Icon Pack designer/owner e-mail -->
<string name="email">someone@email.com</string>

Expand Down Expand Up @@ -81,5 +81,5 @@
<string name="arctic_backend_host"></string>

<!-- Host must also be filled in first. An app API key from Arctic Request Manager. -->
<string name="arctic_backend_api_key"></string>
<string name="arctic_backend_api_key" tools:ignore="TypographyDashes"></string>
</resources>
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ ext.versions = [
targetSdk : 27,
buildTools : '27.0.3',
// Versions:
versionCode : 104,
versionName : '1.0.4',
versionCode : 105,
versionName : '1.0.5',
// Gradle Plugins
gradle : '3.0.1',
kotlin : '1.2.21',
libs : '2.0',
// Dependencies
kuper : '1.2.0',
kuper : '1.2.1',
materialDrawer: '6.0.6',
fabsMenu : '1.1.2',
counterFab : '1.0.3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ data class Icon(val name: String, @DrawableRes val icon: Int) : Comparable<Icon>
override fun compareTo(other: Icon): Int = this.name.compareTo(other.name)
}

data class IconsCategory(val title: String, val icons: ArrayList<Icon> = ArrayList())
data class IconsCategory(val title: String) {
val icons: ArrayList<Icon> = ArrayList()
fun setIcons(newIcons: ArrayList<Icon>) {
icons.clear()
icons.addAll(newIcons)
}

fun addIcon(icon: Icon) {
icons.add(icon)
}

fun hasIcons(): Boolean = icons.isNotEmpty()
}

@Suppress("ArrayInDataClass")
data class Launcher(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
package jahirfiquitiva.libs.blueprint.helpers.utils

import ca.allanwang.kau.logging.KauLogger
import jahirfiquitiva.libs.blueprint.BuildConfig

internal object BPLog : KauLogger("Quest", { BuildConfig.DEBUG })
internal object BPLog : KauLogger("Blueprint", { false })
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
package jahirfiquitiva.libs.blueprint.providers.viewmodels

import android.content.Context
import android.util.Log
import ca.allanwang.kau.utils.boolean
import jahirfiquitiva.libs.archhelpers.viewmodels.ListViewModel
import jahirfiquitiva.libs.blueprint.R
import jahirfiquitiva.libs.blueprint.data.models.Icon
import jahirfiquitiva.libs.blueprint.data.models.IconsCategory
import jahirfiquitiva.libs.blueprint.helpers.extensions.blueprintFormat
import jahirfiquitiva.libs.kauextensions.extensions.formatCorrectly
import jahirfiquitiva.libs.kauextensions.extensions.getAppName
import jahirfiquitiva.libs.kauextensions.extensions.getIconResource
import jahirfiquitiva.libs.kauextensions.extensions.stringArray
import org.xmlpull.v1.XmlPullParser

class IconsViewModel : ListViewModel<Context, IconsCategory>() {
override fun internalLoad(param: Context): ArrayList<IconsCategory> {
val categories: ArrayList<IconsCategory> = ArrayList()
if (param.boolean(R.bool.xml_drawable_enabled)) {
val list = ArrayList<IconsCategory>()
val parser = param.resources.getXml(R.xml.drawable)
try {
var event = parser.eventType
Expand All @@ -39,18 +41,29 @@ class IconsViewModel : ListViewModel<Context, IconsCategory>() {
when (event) {
XmlPullParser.START_TAG -> {
val tag = parser.name
if (tag == "category")
if (tag == "category") {
if (category != null && category.hasIcons()) {
categories.add(category)
}
category = IconsCategory(
parser.getAttributeValue(null, "title")
.formatCorrectly().blueprintFormat())
else if (tag == "item")
} else if (tag == "item") {
if (category != null) {
val iconName = parser.getAttributeValue(null, "drawable")
category.icons.add(
Icon(
iconName.formatCorrectly().blueprintFormat(),
iconName.getIconResource(param)))
val iconRes = iconName.getIconResource(param)
if (iconRes > 0) {
category.addIcon(
Icon(
iconName.formatCorrectly().blueprintFormat(),
iconRes))
} else {
Log.e(
param.getAppName(),
"Could NOT find icon with name '$iconName'")
}
}
}
}
}
event = parser.next()
Expand All @@ -59,17 +72,7 @@ class IconsViewModel : ListViewModel<Context, IconsCategory>() {
} finally {
parser?.close()
}
if (list.size > 0) {
val finalList = ArrayList<IconsCategory>()
list.forEach {
if (it.icons.size > 0) finalList.add(it)
}
list.clear()
list.addAll(finalList)
}
return list
} else {
val categories: ArrayList<IconsCategory> = ArrayList()
param.stringArray(R.array.icon_filters).forEach {
val icons = ArrayList<Icon>()
val list = ArrayList<String>()
Expand All @@ -80,9 +83,11 @@ class IconsViewModel : ListViewModel<Context, IconsCategory>() {
icons.add(
Icon(it.formatCorrectly().blueprintFormat(), it.getIconResource(param)))
}
categories.add(IconsCategory(it, ArrayList(icons.distinct().sorted())))
val category = IconsCategory(it)
category.setIcons(ArrayList(icons.distinct().sortedBy { it.name }))
categories.add(category)
}
return categories
}
return ArrayList(categories.distinct().sortedBy { it.title })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class RequestsViewModel : ViewModel() {
) {
IconRequest.start(context)
.withAppName(context.getString(R.string.app_name))
.withFooter("Blueprint version: ${BuildConfig.VERSION_NAME}")
.withFooter("Blueprint version: ${BuildConfig.LIB_VERSION}")
.withSubject(context.getString(R.string.request_title))
.toEmail(context.getString(R.string.email))
.withAPIHost(host.orEmpty())
Expand All @@ -158,7 +158,6 @@ class RequestsViewModel : ViewModel() {
context.getString(
R.string.request_save_location,
Environment.getExternalStorageDirectory())))
.generateAppFilterJson(false)
.debugMode(BuildConfig.DEBUG)
.filterXmlId(R.xml.appfilter)
.withTimeLimit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import android.support.annotation.IntRange
import android.support.annotation.WorkerThread
import android.support.annotation.XmlRes
import android.text.Html
import android.util.Log
import ca.allanwang.kau.utils.toBitmap
import com.afollestad.bridge.Bridge
import com.afollestad.bridge.Bridge.post
Expand All @@ -54,6 +55,7 @@ import jahirfiquitiva.libs.blueprint.quest.utils.saveAll
import jahirfiquitiva.libs.blueprint.quest.utils.saveIcon
import jahirfiquitiva.libs.blueprint.quest.utils.wipe
import jahirfiquitiva.libs.blueprint.quest.utils.zip
import jahirfiquitiva.libs.kauextensions.extensions.getAppName
import jahirfiquitiva.libs.kauextensions.extensions.getUri
import jahirfiquitiva.libs.kauextensions.extensions.hasContent
import jahirfiquitiva.libs.kauextensions.extensions.readBoolean
Expand All @@ -63,6 +65,8 @@ import jahirfiquitiva.libs.kauextensions.extensions.writeEnum
import org.json.JSONObject
import org.xmlpull.v1.XmlPullParser
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
import java.text.SimpleDateFormat
import java.util.ArrayList
import java.util.Date
Expand Down Expand Up @@ -257,7 +261,7 @@ class IconRequest private constructor() {

fun withAPIHost(host: String): Builder {
if (host.hasContent()) apiHost = host
return generateAppFilterJson(host.hasContent())
return generateAppFilterJson(apiHost.hasContent())
}

fun withAPIKey(key: String?): Builder {
Expand Down Expand Up @@ -310,7 +314,7 @@ class IconRequest private constructor() {
return this
}

fun generateAppFilterJson(generate: Boolean): Builder {
private fun generateAppFilterJson(generate: Boolean): Builder {
generateAppFilterJson = generate
return this
}
Expand Down Expand Up @@ -463,14 +467,20 @@ class IconRequest private constructor() {
}

fun loadApps(onProgress: (progress: Int) -> Unit = {}) {
if (builder?.isLoading == true) return
builder?.isLoading = true
if (apps.isNotEmpty()) {
builder?.callback?.onAppsLoaded(apps)
builder?.isLoading = false
return
}
Thread {
val filter = loadFilterApps() ?: return@Thread
BPLog.d { "Loading unthemed installed apps..." }
val filter = loadFilterApps() ?: return@Thread
apps.clear()
apps.addAll(builder?.context?.getInstalledApps(filter, onProgress).orEmpty())
builder?.isLoading = false
apps.let { builder?.callback?.onAppsLoaded(it) }
builder?.callback?.onAppsLoaded(apps)
}.start()
}

Expand Down Expand Up @@ -712,14 +722,13 @@ class IconRequest private constructor() {
.append("\t\t\t\"name\": \"$name\",\n")
.append("\t\t\t\"pkg\": \"${app.pckg}\",\n")
.append("\t\t\t\"componentInfo\": \"${app.code}\",\n")
.append("\t\t\t\"drawable\": \"$drawableName\",\n")
.append("\t\t\t\"drawable\": \"$drawableName\"")
.append("\t\t}")
}
appNames.add(iconName)
}

val date = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault())
.format(Date())
val date = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())

if (xmlSb != null) {
xmlSb.append("\n\n</resources>")
Expand Down Expand Up @@ -781,7 +790,6 @@ class IconRequest private constructor() {
onRequestProgress?.doOnError()
return@Thread
}

}

if (filesToZip.size == 0) {
Expand Down Expand Up @@ -836,7 +844,15 @@ class IconRequest private constructor() {

onRequestProgress?.doWhenReady()
} catch (e: Exception) {
BPLog.e { "Failed to send icons to the backend: ${e.message}" }
Log.e(
builder?.context?.getAppName() ?: "Blueprint",
"Failed to send icons to the backend: ${e.message}")
try {
val errors = StringWriter()
e.printStackTrace(PrintWriter(errors))
Log.e(builder?.context?.getAppName() ?: "Blueprint", errors.toString())
} catch (ignored: Exception) {
}
sendRequestViaEmail(zipFile, onRequestProgress)
}
} else {
Expand All @@ -845,8 +861,7 @@ class IconRequest private constructor() {
}.start()
} else {
builder?.context?.let {
builder?.callback?.onRequestLimited(
it, currentState, requestsLeft, millisToFinish)
builder?.callback?.onRequestLimited(it, currentState, requestsLeft, millisToFinish)
}
}
}
Expand Down
Loading

0 comments on commit f0e4bec

Please sign in to comment.