From 26421aa428c669f4123fca7094fff0e1d90b5387 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 30 Aug 2017 12:13:38 -0400 Subject: fix/mediapicker (#50) * Bring all glide request managers to one instance * Switch to test implementation * Check if parent is null for searchview * Ensure open close runs on ui thread * Make glide contract internal * Update changelog * Update version Update changelog for previous prs --- .../kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt | 18 ++++++++++++++++++ .../kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt | 6 +++--- .../ca/allanwang/kau/mediapicker/MediaItemBasic.kt | 6 +++--- .../ca/allanwang/kau/mediapicker/MediaPickerCore.kt | 11 +++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt (limited to 'mediapicker/src/main') diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt new file mode 100644 index 0000000..8bb341c --- /dev/null +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt @@ -0,0 +1,18 @@ +package ca.allanwang.kau.mediapicker + +import android.view.View +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager + +/** + * Created by Allan Wang on 29/08/2017. + * + * Basic helper to fetch the [RequestManager] from the activity if it exists, before creating another one + */ +internal interface GlideContract { + fun glide(v: View): RequestManager +} + +internal class GlideDelegate : GlideContract { + override fun glide(v: View) = ((v.context as? MediaPickerCore<*>)?.glide ?: Glide.with(v))!! +} \ No newline at end of file diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt index b6f3721..0431465 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt @@ -16,7 +16,7 @@ import com.mikepenz.fastadapter.FastAdapter * Created by Allan Wang on 2017-07-04. */ class MediaItem(val data: MediaModel) - : KauIItem(R.layout.kau_iitem_image, { ViewHolder(it) }) { + : KauIItem(R.layout.kau_iitem_image, { ViewHolder(it) }), GlideContract by GlideDelegate() { private var failedToLoad = false @@ -38,7 +38,7 @@ class MediaItem(val data: MediaModel) override fun bindView(holder: ViewHolder, payloads: List?) { super.bindView(holder, payloads) - Glide.with(holder.itemView) + glide(holder.itemView) .load(data.data) .applyMediaOptions(holder.itemView.context) .listener(object : RequestListener { @@ -59,7 +59,7 @@ class MediaItem(val data: MediaModel) override fun unbindView(holder: ViewHolder) { super.unbindView(holder) - Glide.with(holder.itemView).clear(holder.container.imageBase) + glide(holder.itemView).clear(holder.container.imageBase) holder.container.removeBlurInstantly() failedToLoad = false } diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt index e546afb..2d6cefa 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt @@ -22,7 +22,7 @@ import com.mikepenz.fastadapter.FastAdapter * Created by Allan Wang on 2017-07-04. */ class MediaItemBasic(val data: MediaModel) - : KauIItem(R.layout.kau_iitem_image_basic, { ViewHolder(it) }) { + : KauIItem(R.layout.kau_iitem_image_basic, { ViewHolder(it) }), GlideContract by GlideDelegate() { companion object { @SuppressLint("NewApi") @@ -40,7 +40,7 @@ class MediaItemBasic(val data: MediaModel) override fun bindView(holder: ViewHolder, payloads: List?) { super.bindView(holder, payloads) - Glide.with(holder.itemView) + glide(holder.itemView) .load(data.data) .applyMediaOptions(holder.itemView.context) .listener(object : RequestListener { @@ -58,7 +58,7 @@ class MediaItemBasic(val data: MediaModel) override fun unbindView(holder: ViewHolder) { super.unbindView(holder) - Glide.with(holder.itemView).clear(holder.image) + glide(holder.itemView).clear(holder.image) } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt index eada173..d518b78 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -27,6 +27,7 @@ import ca.allanwang.kau.permissions.kauRequestPermissions import ca.allanwang.kau.utils.dimenPixelSize import ca.allanwang.kau.utils.toast import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.adapters.HeaderAdapter import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter @@ -103,6 +104,7 @@ abstract class MediaPickerCore>( const val CACHE_SIZE = 80 } + lateinit var glide: RequestManager private var hasPreloaded = false private var prefetcher: Future<*>? = null @@ -113,6 +115,11 @@ abstract class MediaPickerCore>( */ val extraSpace: Int by lazy { resources.displayMetrics.heightPixels } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + glide = Glide.with(this) + } + fun initializeRecycler(recycler: RecyclerView) { val adapterWrapper = HeaderAdapter() adapterWrapper.wrap(adapter) @@ -176,7 +183,7 @@ abstract class MediaPickerCore>( hasPreloaded = true prefetcher = doAsync { models.subList(0, Math.min(models.size, 50)).map { it.data }.forEach { - val target = Glide.with(this@MediaPickerCore).load(it) + val target = glide.load(it) .applyMediaOptions(this@MediaPickerCore) .submit() try { @@ -184,7 +191,7 @@ abstract class MediaPickerCore>( } catch (ignored: InterruptedException) { } catch (ignored: ExecutionException) { } finally { - Glide.with(this@MediaPickerCore).clear(target) + glide.clear(target) } } } -- cgit v1.2.3 From ff597a7ef456fcb37160fa7a46b45296098ca413 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 10 Oct 2017 16:44:54 -0400 Subject: fix/validate-document-uri (#80) * Check if id is document before retrieving * Add logging * Add null check for getString index 1 --- .../main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt | 2 +- .../kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'mediapicker/src/main') diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt index ae85558..26736d4 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt @@ -21,7 +21,7 @@ data class MediaModel( @Throws(SQLException::class) constructor(@NonNull cursor: Cursor) : this( cursor.getString(0), - cursor.getString(1), + cursor.getString(1) ?: "", cursor.getLong(2), cursor.getLong(3), cursor.getString(4) diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt index d518b78..ec5d2f0 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -153,8 +153,7 @@ abstract class MediaPickerCore>( * The adapter will be cleared on each successful call */ open fun loadItems() { - kauRequestPermissions(Manifest.permission.READ_EXTERNAL_STORAGE) { - granted, _ -> + kauRequestPermissions(Manifest.permission.READ_EXTERNAL_STORAGE) { granted, _ -> if (granted) { supportLoaderManager.initLoader(LOADER_ID, null, this) onStatusChange(true) @@ -191,7 +190,7 @@ abstract class MediaPickerCore>( } catch (ignored: InterruptedException) { } catch (ignored: ExecutionException) { } finally { - glide.clear(target) + glide.clear(target) } } } @@ -238,9 +237,13 @@ abstract class MediaPickerCore>( * See */ private fun ContentResolver.query(baseUri: Uri, uris: List, block: (cursor: Cursor) -> R) { - val ids = uris.map { + val ids = uris.filter { + val valid = DocumentsContract.isDocumentUri(this@MediaPickerCore, it) + if (!valid) KL.d("Non document uri: ${it.encodedPath}") + valid + }.mapNotNull { DocumentsContract.getDocumentId(it).split(":").getOrNull(1) - }.filterNotNull().joinToString(prefix = "(", separator = ",", postfix = ")") + }.joinToString(prefix = "(", separator = ",", postfix = ")") //? query replacements are done for one arg at a time //since we potentially have a list of ids, we'll just format the WHERE clause ourself query(baseUri, MediaModel.projection, "${BaseColumns._ID} IN $ids", null, sortQuery)?.use(block) -- cgit v1.2.3 From 3f1d6746fd7bcc8d01ef367455628d291d07f434 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 12 Oct 2017 11:30:40 -0400 Subject: Translations (#84) * Rename string files * Add translations to readme * Check job scheduler null check against travis lint * Remove bad spacing * Update badges * Use vector zenhub badge --- .gitignore | 1 + README.md | 10 +++++-- about/src/main/res/values/strings.xml | 5 ---- about/src/main/res/values/strings_about.xml | 23 +++------------- about/src/main/res/values/strings_about_kau.xml | 20 ++++++++++++++ colorpicker/src/main/res/values/strings.xml | 6 ----- .../src/main/res/values/strings_colorpicker.xml | 6 +++++ gradle.properties | 2 +- mediapicker/src/main/res/values/strings.xml | 14 ---------- .../src/main/res/values/strings_mediapicker.xml | 14 ++++++++++ sample/src/main/res/values/strings.xml | 31 ---------------------- sample/src/main/res/values/strings_sample.xml | 31 ++++++++++++++++++++++ 12 files changed, 85 insertions(+), 78 deletions(-) delete mode 100644 about/src/main/res/values/strings.xml create mode 100644 about/src/main/res/values/strings_about_kau.xml delete mode 100644 colorpicker/src/main/res/values/strings.xml create mode 100644 colorpicker/src/main/res/values/strings_colorpicker.xml delete mode 100644 mediapicker/src/main/res/values/strings.xml create mode 100644 mediapicker/src/main/res/values/strings_mediapicker.xml delete mode 100644 sample/src/main/res/values/strings.xml create mode 100644 sample/src/main/res/values/strings_sample.xml (limited to 'mediapicker/src/main') diff --git a/.gitignore b/.gitignore index 4ca0b81..6f35f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.iml /.idea .gradle +/crowdin.properties /local.properties .DS_Store /build diff --git a/README.md b/README.md index cf3215c..bc09b0f 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,9 @@ KAU is available on JitPack [![](https://jitpack.io/v/ca.allanwang/kau.svg)](https://jitpack.io/#ca.allanwang/kau) [![Build Status](https://travis-ci.org/AllanWang/KAU.svg?branch=master)](https://travis-ci.org/AllanWang/KAU) +[![Crowdin](https://d322cqt584bo4o.cloudfront.net/kotlin-android-utils/localized.svg)](https://crowdin.com/project/kotlin-android-utils) [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) -[![Stories in Ready](https://badge.waffle.io/AllanWang/KAU.png?label=ready&title=Ready)](https://waffle.io/AllanWang/KAU?utm_source=badge) +[![ZenHub](https://img.shields.io/badge/Shipping%20faster%20with-ZenHub-45529A.svg)](https://app.zenhub.com/workspace/o/allanwang/kau/boards) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/AllanWang/KAU/master/LICENSE) To apply, add the following to your root build.gradle: @@ -140,4 +141,9 @@ To resolve that, add `multiDexEnabled true` under your `app.gradle > android > d Likewise, it is highly recommended to use proguard to clean up your project upon release. All KAU components support proguard out of the box. -Some may have extra requirements for certain features, which will be detailed in their respective README. \ No newline at end of file +Some may have extra requirements for certain features, which will be detailed in their respective README. + +## Translations + +KAU depends on translations crowdsourced by the general public. +If you would like to contribute, please visit [here](https://crwd.in/kotlin-android-utils) diff --git a/about/src/main/res/values/strings.xml b/about/src/main/res/values/strings.xml deleted file mode 100644 index 164c0c8..0000000 --- a/about/src/main/res/values/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - This app would not be possible without the following great libraries. - FAQ - \ No newline at end of file diff --git a/about/src/main/res/values/strings_about.xml b/about/src/main/res/values/strings_about.xml index 592f9f4..164c0c8 100644 --- a/about/src/main/res/values/strings_about.xml +++ b/about/src/main/res/values/strings_about.xml @@ -1,20 +1,5 @@ - - - Allan Wang - https://www.allanwang.ca/dev/ - @string/kau_version_code - KAU - -
- KAU aims to make many common functions executable in one line. It adds numerous extensions to match Kotlin\'s DSL, - and supports completely customizable view groups that are usable in any app project. - ]]> -
- https://allanwang.github.io/KAU/ - true - https://github.com/AllanWang/KAU - ca.allanwang.kau - apache_2_0 + + + This app would not be possible without the following great libraries. + FAQ \ No newline at end of file diff --git a/about/src/main/res/values/strings_about_kau.xml b/about/src/main/res/values/strings_about_kau.xml new file mode 100644 index 0000000..592f9f4 --- /dev/null +++ b/about/src/main/res/values/strings_about_kau.xml @@ -0,0 +1,20 @@ + + + Allan Wang + https://www.allanwang.ca/dev/ + @string/kau_version_code + KAU + +
+ KAU aims to make many common functions executable in one line. It adds numerous extensions to match Kotlin\'s DSL, + and supports completely customizable view groups that are usable in any app project. + ]]> +
+ https://allanwang.github.io/KAU/ + true + https://github.com/AllanWang/KAU + ca.allanwang.kau + apache_2_0 +
\ No newline at end of file diff --git a/colorpicker/src/main/res/values/strings.xml b/colorpicker/src/main/res/values/strings.xml deleted file mode 100644 index 5a6f89b..0000000 --- a/colorpicker/src/main/res/values/strings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - Color Palette - Custom - Presets - diff --git a/colorpicker/src/main/res/values/strings_colorpicker.xml b/colorpicker/src/main/res/values/strings_colorpicker.xml new file mode 100644 index 0000000..5a6f89b --- /dev/null +++ b/colorpicker/src/main/res/values/strings_colorpicker.xml @@ -0,0 +1,6 @@ + + + Color Palette + Custom + Presets + diff --git a/gradle.properties b/gradle.properties index 4e690c7..9a45266 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ ANDROID_SUPPORT_LIBS=26.1.0 VERSION_NAME=3.4.3 -KOTLIN=1.1.4-3 +KOTLIN=1.1.51 ABOUT_LIBRARIES=5.9.7 ANKO=0.10.1 BLURRY=2.1.1 diff --git a/mediapicker/src/main/res/values/strings.xml b/mediapicker/src/main/res/values/strings.xml deleted file mode 100644 index 717e12b..0000000 --- a/mediapicker/src/main/res/values/strings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - No items found - No items have been selected - Blurrable ImageView - No items loaded - - No camera found - Please install a camera app and try again. - - Failed to create a temporary file. - - Select Media - \ No newline at end of file diff --git a/mediapicker/src/main/res/values/strings_mediapicker.xml b/mediapicker/src/main/res/values/strings_mediapicker.xml new file mode 100644 index 0000000..717e12b --- /dev/null +++ b/mediapicker/src/main/res/values/strings_mediapicker.xml @@ -0,0 +1,14 @@ + + + No items found + No items have been selected + Blurrable ImageView + No items loaded + + No camera found + Please install a camera app and try again. + + Failed to create a temporary file. + + Select Media + \ No newline at end of file diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml deleted file mode 100644 index 1e3361e..0000000 --- a/sample/src/main/res/values/strings.xml +++ /dev/null @@ -1,31 +0,0 @@ - - KAU - This is a header - This is a description - Checkbox 1 - Checkbox 2 - Checkbox 3 - I am dependent on checkbox 2 - Text Color - Accent Color - Background Color - This selector allows custom colors - This selector does not allow custom colors - This selector allows for custom colors with alpha values - Text Pref - Saves the text - Seekbar - Time Pref - AM PM version - 24h version - Sub Item Pref - Press this to view the next subset of preferences - your.email@here.com - Your subject - Swipe Showcase - Image Showcase - Video Overlay Showcase - Adapter Showcase - KAU (Kotlin Android Utils) is a collection of common extension functions and complex UIs that can be used in almost all apps. It is meant to implement the shared components, so you can focus on what makes your app unique. - Long Prefs - diff --git a/sample/src/main/res/values/strings_sample.xml b/sample/src/main/res/values/strings_sample.xml new file mode 100644 index 0000000..1e3361e --- /dev/null +++ b/sample/src/main/res/values/strings_sample.xml @@ -0,0 +1,31 @@ + + KAU + This is a header + This is a description + Checkbox 1 + Checkbox 2 + Checkbox 3 + I am dependent on checkbox 2 + Text Color + Accent Color + Background Color + This selector allows custom colors + This selector does not allow custom colors + This selector allows for custom colors with alpha values + Text Pref + Saves the text + Seekbar + Time Pref + AM PM version + 24h version + Sub Item Pref + Press this to view the next subset of preferences + your.email@here.com + Your subject + Swipe Showcase + Image Showcase + Video Overlay Showcase + Adapter Showcase + KAU (Kotlin Android Utils) is a collection of common extension functions and complex UIs that can be used in almost all apps. It is meant to implement the shared components, so you can focus on what makes your app unique. + Long Prefs + -- cgit v1.2.3