diff options
author | Allan Wang <me@allanwang.ca> | 2017-09-23 15:14:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-23 15:14:12 -0400 |
commit | a647df3c32b77eff3e6ba8a78799dc7eb42ba11c (patch) | |
tree | e15593d81626e0ab4e3443c0d2bdd3b21162c083 | |
parent | f3e7098e52f8caa86be7922f5b07eade6f36cc57 (diff) | |
download | kau-a647df3c32b77eff3e6ba8a78799dc7eb42ba11c.tar.gz kau-a647df3c32b77eff3e6ba8a78799dc7eb42ba11c.tar.bz2 kau-a647df3c32b77eff3e6ba8a78799dc7eb42ba11c.zip |
v3.4.1 (#63)
* Check browser intent before launching (#54)
* Update changelog
* fix/misc (#55)
* Add kapt plugin
* Fix kau vector
* Debug lintRelease
* Revert debug
* Update dependencies
* Check context finishing state before showing dialog (#61)
* Keep copy of shared pref rather than application context (#60)
* Keep copy of shared pref rather than application context
* Add back preference name
* Add resolver checks (#62)
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 6 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 48 | ||||
-rw-r--r-- | core/src/main/res-public/values/strings_commons.xml | 2 | ||||
-rw-r--r-- | core/src/main/res/values/strings.xml | 4 | ||||
-rw-r--r-- | docs/Changelog.md | 1 | ||||
-rw-r--r-- | gradle.properties | 6 | ||||
-rw-r--r-- | mediapicker/build.gradle | 1 | ||||
-rw-r--r-- | sample/src/main/res/drawable/kau.xml | 4 |
9 files changed, 53 insertions, 36 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index 88a0945..8c6acff 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -13,6 +13,7 @@ import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.installerPackageName import ca.allanwang.kau.utils.isAppInstalled import ca.allanwang.kau.utils.string +import ca.allanwang.kau.utils.toast /** @@ -76,7 +77,10 @@ class EmailBuilder(val email: String, val subject: String) { emailBuilder.append("\n").append(footer) intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()) - context.startActivity(Intent.createChooser(intent, context.resources.getString(R.string.kau_send_via))) + if (intent.resolveActivity(context.packageManager) != null) + context.startActivity(Intent.createChooser(intent, context.resources.getString(R.string.kau_send_via))) + else + context.toast("Cannot resolve email activity", log = true) } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt index be16c7c..fbb8c7d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt @@ -3,6 +3,7 @@ package ca.allanwang.kau.kpref import android.content.Context import android.content.SharedPreferences import ca.allanwang.kau.kotlin.ILazyResettable +import ca.allanwang.kau.logging.KL /** * Created by Allan Wang on 2017-06-07. @@ -22,15 +23,13 @@ import ca.allanwang.kau.kotlin.ILazyResettable */ open class KPref { - lateinit private var c: Context - lateinit internal var PREFERENCE_NAME: String - private var initialized = false + lateinit var PREFERENCE_NAME: String + lateinit var sp: SharedPreferences fun initialize(c: Context, preferenceName: String) { - if (initialized) throw KPrefException("KPref object $preferenceName has already been initialized; please only do so once") - initialized = true - this.c = c.applicationContext PREFERENCE_NAME = preferenceName + sp = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) + KL.d("Shared Preference $preferenceName has been initialized") val toDelete = deleteKeys() if (toDelete.isNotEmpty()) { val edit = sp.edit() @@ -39,12 +38,6 @@ open class KPref { } } - //todo hide this - val sp: SharedPreferences by lazy { - if (!initialized) throw KPrefException("KPref object has not yet been initialized; please initialize it with a context and preference name") - c.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE) - } - internal val prefMap: MutableMap<String, ILazyResettable<*>> = mutableMapOf() fun reset() { diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index d561c8a..a72c7dd 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -77,7 +77,11 @@ fun Context.startActivitySlideOut(clazz: Class<out Activity>, clearStack: Boolea fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes)) fun Context.startPlayStoreLink(packageId: String) { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId"))) + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId")) + if (intent.resolveActivity(packageManager) != null) + startActivity(intent) + else + toast("Cannot resolve play store", log = true) } /** @@ -87,22 +91,24 @@ fun Context.startPlayStoreLink(packageId: String) { fun Context.startLink(vararg url: String?) { val link = url.firstOrNull { !it.isNullOrBlank() } ?: return val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(link)) - startActivity(browserIntent) + if (browserIntent.resolveActivity(packageManager) != null) + startActivity(browserIntent) + else + toast("Cannot resolve browser", log = true) } -fun Context.startLink(@StringRes url: Int) { - val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(string(url))) - startActivity(browserIntent) -} +fun Context.startLink(@StringRes url: Int) = startLink(string(url)) //Toast helpers -inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = context.toast(id, duration) +inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = context.toast(id, duration, log) + +inline fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = toast(this.string(id), duration, log) -inline fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = toast(this.string(id), duration) +inline fun View.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = context.toast(text, duration, log) -inline fun View.toast(text: String, duration: Int = Toast.LENGTH_LONG) = context.toast(text, duration) -inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG) { +inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) { Toast.makeText(this, text, duration).show() + if (log) KL.i("Toast: $text") } //Resource retrievers @@ -163,6 +169,10 @@ fun Context.resolveString(@AttrRes attr: Int, fallback: String = ""): String { inline fun Context.materialDialog(action: MaterialDialog.Builder.() -> Unit): MaterialDialog { val builder = MaterialDialog.Builder(this) builder.action() + if (isFinishing) { + KL.d("Material Dialog triggered from finishing context; did not show") + return builder.build() + } return builder.show() } @@ -192,9 +202,21 @@ fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showTo } fun Context.shareText(text: String?) { - if (text == null) return toast(R.string.kau_text_is_null) + if (text == null) return toast("Share text is null") val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(intent, string(R.string.kau_share))) -}
\ No newline at end of file + val chooserIntent = Intent.createChooser(intent, string(R.string.kau_share)) + if (chooserIntent.resolveActivity(packageManager) != null) + startActivity(chooserIntent) + else + toast("Cannot resolve activity to share text", log = true) +} + +/** + * Check if given context is finishing. + * This is a wrapper to check if it's both an activity and finishing + * As of now, it is only checked when tied to an activity + */ +inline val Context.isFinishing: Boolean + get() = (this as? Activity)?.isFinishing ?: false
\ No newline at end of file diff --git a/core/src/main/res-public/values/strings_commons.xml b/core/src/main/res-public/values/strings_commons.xml index d236021..6bea9a6 100644 --- a/core/src/main/res-public/values/strings_commons.xml +++ b/core/src/main/res-public/values/strings_commons.xml @@ -38,7 +38,7 @@ Most resources are verbatim and x represents a formatted item <string name="kau_no">No</string> <string name="kau_no_results_found">No Results Found</string> <string name="kau_none">None</string> - <string name="kau_ok">@android:string/ok</string> + <string name="kau_ok">OK</string> <string name="kau_play_store">Play Store</string> <string name="kau_rate">Rate</string> <string name="kau_report_bug">Report A Bug</string> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml deleted file mode 100644 index d8b2993..0000000 --- a/core/src/main/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string name="kau_text_is_null">Text is null</string> -</resources>
\ No newline at end of file diff --git a/docs/Changelog.md b/docs/Changelog.md index aa37c4d..4165fbb 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,6 +6,7 @@ * :searchview: Ensure reveals are called on the UI thread * :searchview: Check that searchview has a parent before checking card state * :mediapicker: Reuse request manager from activity +* :kpref-activity: Add bounds to text item ## v3.3.2 * :kpref-activity: Add visibility toggle to Core contract. Items can override this to show/hide given preferences based on boolean callbacks. diff --git a/gradle.properties b/gradle.properties index 9a1177d..08fad4d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,18 +21,18 @@ CORE_MIN_SDK=19 MIN_SDK=21 TARGET_SDK=26 BUILD_TOOLS=26.0.1 -ANDROID_SUPPORT_LIBS=26.0.1 +ANDROID_SUPPORT_LIBS=26.1.0 VERSION_NAME=3.4.0 -KOTLIN=1.1.4-2 +KOTLIN=1.1.4-3 ABOUT_LIBRARIES=5.9.7 ANKO=0.10.1 BLURRY=2.1.1 CONSTRAINT_LAYOUT=1.1.0-beta1 FAST_ADAPTER=2.6.3 FAST_ADAPTER_COMMONS=2.6.3 -GLIDE=4.0.0 +GLIDE=4.1.1 ICONICS=2.9.3 IICON_GOOGLE=3.0.1.1 MATERIAL_DIALOG=0.9.4.7 diff --git a/mediapicker/build.gradle b/mediapicker/build.gradle index eff6a77..0f90f7b 100644 --- a/mediapicker/build.gradle +++ b/mediapicker/build.gradle @@ -1,6 +1,7 @@ ext.kauSubModuleMinSdk = project.CORE_MIN_SDK apply from: '../android-lib.gradle' +apply plugin: 'kotlin-kapt' dependencies { implementation project(':core-ui') diff --git a/sample/src/main/res/drawable/kau.xml b/sample/src/main/res/drawable/kau.xml index b0a7be8..47612e0 100644 --- a/sample/src/main/res/drawable/kau.xml +++ b/sample/src/main/res/drawable/kau.xml @@ -8,11 +8,11 @@ <path android:fillColor="#00a9ff" android:fillType="evenOdd" - android:pathData="M42.8336 42.7538l19-42.75 31.67656 57H57.0836zM0 .08894h27L0 28.6213z" /> + android:pathData="M42.8336 42.7538l19-42.75 31.67656 57H57.0836zM0 0.08894h27L0 28.6213z" /> <path android:fillColor="#ff8900" android:fillType="evenOdd" - android:pathData="M28.5 .0038 H57l-57 57v-26.882z" /> + android:pathData="M28.5 0.0038 H57l-57 57v-26.882z" /> <path android:fillColor="#00a9ff" android:fillType="evenOdd" |