From 423cad016753a795e9cb75534d172f562e4326c1 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 13 Jun 2019 00:51:31 -0700 Subject: Update iconics to 4.x.x --- core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt index 8b40352..52ea57d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt @@ -16,11 +16,12 @@ package ca.allanwang.kau.utils import android.content.Context -import android.content.res.ColorStateList import android.graphics.Color import android.graphics.drawable.Drawable import androidx.annotation.ColorInt import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.colorInt +import com.mikepenz.iconics.sizeDp import com.mikepenz.iconics.typeface.IIcon /** @@ -33,8 +34,7 @@ fun IIcon.toDrawable( @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {} ): Drawable { - val state = ColorStateList.valueOf(color) - val icon = IconicsDrawable(c).icon(this).color(state) + val icon = IconicsDrawable(c).icon(this).colorInt(color) if (sizeDp > 0) icon.sizeDp(sizeDp) icon.builder() return icon -- cgit v1.2.3 From d94017e6f6df67e80604111028ea16f6c7f4e077 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 26 Jul 2019 14:53:29 -0700 Subject: Update versions and setup with google --- .gitignore | 4 +- .idea/codeStyles/Project.xml | 136 --------------------- .idea/vcs.xml | 6 - buildSrc/src/main/kotlin/kau/Versions.kt | 6 +- core-ui/src/main/res-public/values/public.xml | 4 +- .../ca/allanwang/kau/swipe/ViewDragHelper.java | 2 +- core/src/main/res-public/values/public.xml | 52 ++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 36 insertions(+), 176 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/vcs.xml (limited to 'core/src/main/kotlin') diff --git a/.gitignore b/.gitignore index ef20a58..f08bd63 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,6 @@ .idea/**/assetWizardSettings.xml .idea/**/caches .idea/modules.xml -.idea/modules \ No newline at end of file +.idea/modules +.idea/vcs.xml +.idea/codeStyles/Project.xml \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index be6976d..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt index 515f702..4deb3b7 100644 --- a/buildSrc/src/main/kotlin/kau/Versions.kt +++ b/buildSrc/src/main/kotlin/kau/Versions.kt @@ -24,10 +24,10 @@ object Versions { const val constraintLayout = "1.1.3" // https://kotlinlang.org/docs/reference/using-gradle.html - const val kotlin = "1.3.31" + const val kotlin = "1.3.41" // https://github.com/Kotlin/kotlinx.coroutines/releases - const val coroutines = "1.3.0-M1" + const val coroutines = "1.3.0-RC" // https://github.com/mikepenz/AboutLibraries/releases const val aboutLibraries = "6.2.3" @@ -71,7 +71,7 @@ object Versions { const val bugsnagPlugin="4.1.1" // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google - const val gradlePlugin = "3.4.1" + const val gradlePlugin = "3.5.0-rc01" // https://github.com/dcendents/android-maven-gradle-plugin/releases const val mavenPlugin = "2.1" // https://github.com/Triple-T/gradle-play-publisher/releases diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml index af7ce44..71657d6 100644 --- a/core-ui/src/main/res-public/values/public.xml +++ b/core-ui/src/main/res-public/values/public.xml @@ -1,8 +1,8 @@ - + - + diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java index ac7fb7e..f6e907a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java @@ -25,7 +25,7 @@ import static ca.allanwang.kau.swipe.SwipeBackHelperKt.SWIPE_EDGE_TOP; * of useful operations and state tracking for allowing a user to drag and reposition * views within their parent ViewGroup. *

- * This is an extension of {@link androidx.core.widget.ViewDragHelper} + * This is an extension of {@link androidx.customview.widget.ViewDragHelper} * Along with additional methods defined in {@link ViewDragHelperExtras} */ class ViewDragHelper implements ViewDragHelperExtras { diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index 9761199..0b050dc 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,20 +1,27 @@ - + + + + + + + + + + + + + + - + - - - - - - - - - + + + @@ -43,6 +50,13 @@ + + + + + + + @@ -98,21 +112,7 @@ + - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9fccf04..f1f2eac 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip -- cgit v1.2.3 From 63f6b70cc81ec9dc6e92b6521dfd78fa72fe70a5 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jul 2019 18:59:14 -0700 Subject: Fix compile errors --- .../ca/allanwang/kau/about/AboutPanelDelegate.kt | 8 +-- .../kotlin/ca/allanwang/kau/about/CutoutIItem.kt | 6 ++- .../kotlin/ca/allanwang/kau/about/LibraryIItem.kt | 4 +- android-lib.gradle | 1 + .../ca/allanwang/kau/permissions/Permissions.kt | 3 ++ .../kotlin/ca/allanwang/kau/utils/Kotterknife.kt | 6 +-- .../ca/allanwang/kau/adapters/AdapterUtils.kt | 7 +-- .../kau/adapters/FastItemThemedAdapter.kt | 34 ++++++------ .../kau/adapters/RepeatedClickListener.kt | 18 ++++--- .../allanwang/kau/kpref/activity/KPrefActivity.kt | 13 +++-- .../kau/kpref/activity/items/KPrefCheckbox.kt | 5 +- .../kau/kpref/activity/items/KPrefColorPicker.kt | 10 ++-- .../kau/kpref/activity/items/KPrefHeader.kt | 8 +-- .../kau/kpref/activity/items/KPrefItemBase.kt | 8 +-- .../kau/kpref/activity/items/KPrefItemCore.kt | 4 +- .../kau/kpref/activity/items/KPrefPlainText.kt | 3 +- .../kau/kpref/activity/items/KPrefSeekbar.kt | 11 ++-- .../kau/kpref/activity/items/KPrefSubItems.kt | 6 ++- .../kau/kpref/activity/items/KPrefText.kt | 8 +-- .../kau/kpref/activity/items/KPrefTimePicker.kt | 17 ++++-- .../allanwang/kau/mediapicker/BlurredImageView.kt | 33 ++++++------ .../allanwang/kau/mediapicker/MediaActionItem.kt | 4 ++ .../ca/allanwang/kau/mediapicker/MediaItem.kt | 2 +- .../ca/allanwang/kau/mediapicker/MediaItemBasic.kt | 21 ++++---- .../ca/allanwang/kau/mediapicker/MediaModel.kt | 2 + .../kau/mediapicker/MediaPickerActivityBase.kt | 30 ++++++++--- .../mediapicker/MediaPickerActivityOverlayBase.kt | 2 +- .../allanwang/kau/mediapicker/MediaPickerCore.kt | 63 ++++++++++++---------- sample/build.gradle | 1 + .../ca/allanwang/kau/sample/AdapterActivity.kt | 2 +- .../kotlin/ca/allanwang/kau/sample/AnimActivity.kt | 10 +++- .../kotlin/ca/allanwang/kau/sample/MainActivity.kt | 2 +- .../ca/allanwang/kau/sample/PermissionCheckbox.kt | 2 +- .../ca/allanwang/kau/searchview/SearchItem.kt | 4 +- .../ca/allanwang/kau/searchview/SearchView.kt | 48 ++++++++++++----- 35 files changed, 255 insertions(+), 151 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt index aae6cb0..512516d 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt @@ -48,7 +48,7 @@ interface AboutPanelContract { /** * Model list to be added to [adapter] */ - var items: List>? + var items: List> /** * The adapter, will be late initialized as it depends on configs */ @@ -90,7 +90,7 @@ interface AboutPanelContract { abstract class AboutPanelRecycler : AboutPanelContract { - override var items: List>? = null + override var items: List> = emptyList() override lateinit var adapter: FastItemThemedAdapter> @@ -116,7 +116,9 @@ abstract class AboutPanelRecycler : AboutPanelContract { } override fun addItems(activity: AboutActivityBase, position: Int) { - if (items == null) return + if (items.isEmpty()) { + return + } activity.pageStatus[position] = 2 postDelayed(300) { addItemsImpl(activity, position) } } diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt index b51c9c8..d51db46 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt @@ -27,11 +27,13 @@ import ca.allanwang.kau.ui.views.CutoutView * * Just a cutout item with some defaults in [R.layout.kau_iitem_cutout] */ -class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem( +class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem( R.layout.kau_iitem_cutout, ::ViewHolder, R.id.kau_item_cutout ), ThemableIItem by ThemableIItemDelegate() { - override fun isSelectable(): Boolean = false + override var isSelectable: Boolean + get() = false + set(_) {} override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt index 445d435..dcc0874 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -54,7 +54,9 @@ class LibraryIItem(val lib: Library) : KauIItem( } } - override fun isSelectable(): Boolean = false + override var isSelectable: Boolean + get() = false + set(_) {} override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) diff --git a/android-lib.gradle b/android-lib.gradle index 90ec6bf..486b4ed 100644 --- a/android-lib.gradle +++ b/android-lib.gradle @@ -59,6 +59,7 @@ android { packagingOptions { pickFirst 'META-INF/core_release.kotlin_module' pickFirst 'META-INF/library_release.kotlin_module' + pickFirst 'META-INF/library-core_release.kotlin_module' } compileOptions { diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt index 3c90b05..f649cc6 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package ca.allanwang.kau.permissions import android.Manifest @@ -76,6 +77,8 @@ const val PERMISSION_READ_CALL_LOG = Manifest.permission.READ_CALL_LOG const val PERMISSION_WRITE_CALL_LOG = Manifest.permission.WRITE_CALL_LOG const val PERMISSION_ADD_VOICEMAIL = Manifest.permission.ADD_VOICEMAIL const val PERMISSION_USE_SIP = Manifest.permission.USE_SIP +@Deprecated(level = DeprecationLevel.WARNING, message = "Permission is deprecated") +@Suppress("DEPRECATION") const val PERMISSION_PROCESS_OUTGOING_CALLS = Manifest.permission.PROCESS_OUTGOING_CALLS @RequiresApi(Build.VERSION_CODES.KITKAT_WATCH) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt index 8765c69..aaef160 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -116,11 +116,11 @@ private inline val Dialog.viewFinder: Dialog.(Int) -> View? private inline val DialogFragment.viewFinder: DialogFragment.(Int) -> View? get() = { dialog.findViewById(it) } private inline val SupportDialogFragment.viewFinder: SupportDialogFragment.(Int) -> View? - get() = { dialog.findViewById(it) } + get() = { dialog?.findViewById(it) } private inline val Fragment.viewFinder: Fragment.(Int) -> View? - get() = { view!!.findViewById(it) } + get() = { view?.findViewById(it) } private inline val SupportFragment.viewFinder: SupportFragment.(Int) -> View? - get() = { view!!.findViewById(it) } + get() = { view?.findViewById(it) } private inline val ViewHolder.viewFinder: ViewHolder.(Int) -> View? get() = { itemView.findViewById(it) } diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt index 42fe1a2..14fdc9d 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt @@ -31,14 +31,11 @@ import com.mikepenz.fastadapter.select.SelectExtension fun > fastAdapter(vararg adapter: IAdapter) = FastAdapter.with>(adapter.toList()) -inline fun , Item : IItem<*>> FastAdapter.getExtension(): T? = - getExtension(T::class.java) - /** * Returns selection size, or -1 if selection is disabled */ inline val > IAdapter.selectionSize: Int - get() = fastAdapter?.getExtension, Item>()?.selections?.size ?: -1 + get() = fastAdapter?.getExtension>()?.selections?.size ?: -1 inline val > IAdapter.selectedItems: Set - get() = fastAdapter?.getExtension, Item>()?.selectedItems ?: emptySet() + get() = fastAdapter?.getExtension>()?.selectedItems ?: emptySet() diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index 01ac0e5..e6d4b24 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -24,6 +24,7 @@ import androidx.annotation.RequiresApi import ca.allanwang.kau.ui.createSimpleRippleDrawable import ca.allanwang.kau.utils.adjustAlpha import com.mikepenz.fastadapter.IItem +import com.mikepenz.fastadapter.IItemAdapter import com.mikepenz.fastadapter.adapters.FastItemAdapter /** @@ -40,7 +41,11 @@ class FastItemThemedAdapter>( backgroundColor: Int? = null, accentColor: Int? = null ) : FastItemAdapter() { - constructor(colors: ThemableIItemColors) : this(colors.textColor, colors.backgroundColor, colors.accentColor) + constructor(colors: ThemableIItemColors) : this( + colors.textColor, + colors.backgroundColor, + colors.accentColor + ) var textColor: Int? = textColor set(value) { @@ -73,46 +78,41 @@ class FastItemThemedAdapter>( notifyAdapterDataSetChanged() } - override fun add(position: Int, items: List): FastItemAdapter { + override fun add(position: Int, items: List): IItemAdapter { injectTheme(items) return super.add(position, items) } - override fun add(position: Int, item: Item): FastItemAdapter { - injectTheme(item) - return super.add(position, item) + override fun add(position: Int, vararg items: Item): IItemAdapter { + injectTheme(items.toList()) + return super.add(position, *items) } - override fun add(item: Item): FastItemAdapter { - injectTheme(item) - return super.add(item) + override fun add(vararg items: Item): IItemAdapter { + injectTheme(items.toList()) + return super.add(*items) } - override fun add(items: List?): FastItemAdapter { + override fun add(items: List): IItemAdapter { injectTheme(items) return super.add(items) } - override fun set(items: List?): FastItemAdapter { + override fun set(items: List): IItemAdapter { injectTheme(items) return super.set(items) } - override fun set(position: Int, item: Item): FastItemAdapter { + override fun set(position: Int, item: Item): IItemAdapter { injectTheme(item) return super.set(position, item) } - override fun setNewList(items: List?, retainFilter: Boolean): FastItemAdapter { + override fun setNewList(items: List, retainFilter: Boolean): IItemAdapter { injectTheme(items) return super.setNewList(items, retainFilter) } - override fun setNewList(items: List?): FastItemAdapter { - injectTheme(items) - return super.setNewList(items) - } - private fun injectTheme(items: Collection?>?) { items?.forEach { injectTheme(it) } } diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt index 3e7d707..99c367b 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt @@ -17,10 +17,10 @@ package ca.allanwang.kau.adapters import android.view.View import androidx.annotation.IntRange +import com.mikepenz.fastadapter.ClickListener import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IAdapter import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.listeners.OnClickListener /** * Created by Allan Wang on 26/12/17. @@ -28,9 +28,11 @@ import com.mikepenz.fastadapter.listeners.OnClickListener fun > FastAdapter.withOnRepeatedClickListener( count: Int, duration: Long, - event: OnClickListener -) = - withOnClickListener(RepeatedClickListener(count, duration, event)) + event: ClickListener +): FastAdapter { + onClickListener = RepeatedClickListener(count, duration, event) + return this +} /** * Registers and skips each click until the designated [count] clicks are triggered, @@ -40,8 +42,8 @@ fun > FastAdapter.withOnRepeatedClickListener( private class RepeatedClickListener>( @IntRange(from = 1) val count: Int, @IntRange(from = 1) val duration: Long, - val event: OnClickListener -) : OnClickListener { + val event: ClickListener +) : ClickListener { init { if (count <= 0) @@ -53,7 +55,7 @@ private class RepeatedClickListener>( private var chain = 0 private var time = -1L - override fun onClick(v: View?, adapter: IAdapter, item: Item, position: Int): Boolean { + override fun invoke(v: View?, adapter: IAdapter, item: Item, position: Int): Boolean { val now = System.currentTimeMillis() if (time - now < duration) chain++ @@ -62,7 +64,7 @@ private class RepeatedClickListener>( time = now if (chain == count) { chain = 0 - event.onClick(v, adapter, item, position) + event(v, adapter, item, position) return true } return false diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt index b701a07..f11afde 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt @@ -32,6 +32,7 @@ import ca.allanwang.kau.utils.resolveColor import ca.allanwang.kau.utils.statusBarColor import ca.allanwang.kau.utils.withLinearAdapter import com.mikepenz.fastadapter.adapters.FastItemAdapter +import com.mikepenz.fastadapter.select.getSelectExtension import kotlinx.android.synthetic.main.kau_pref_activity.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -82,7 +83,8 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { toolbar.setNavigationOnClickListener { onBackPressed() } setDisplayShowTitleEnabled(false) } - window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + window.decorView.systemUiVisibility = + View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN statusBarColor = 0x30000000 kau_toolbar_ripple.set(resolveColor(R.attr.colorPrimary)) kau_ripple.set(resolveColor(android.R.attr.colorBackground)) @@ -92,8 +94,13 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { core.builder() globalOptions = GlobalOptions(core, this) kau_recycler.withLinearAdapter(adapter) - adapter.withSelectable(false) - .withOnClickListener { v, _, item, _ -> item.onClick(v!!); true } + adapter.apply { + getSelectExtension().isSelectable = true + onClickListener = { v, _, item, _ -> + item.onClick(v!!) + true + } + } showNextPrefs(R.string.kau_settings, onCreateKPrefs(savedInstanceState), true) } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt index 0f025a6..f4f4a65 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt @@ -34,7 +34,7 @@ open class KPrefCheckbox(builder: BaseContract) : KPrefItemBase) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) val checkbox = holder.bindInnerView(R.layout.kau_pref_checkbox) withAccentColor(checkbox::tint) @@ -42,5 +42,6 @@ open class KPrefCheckbox(builder: BaseContract) : KPrefItemBase(builder) { - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) if (builder.showPreview) { val preview = holder.bindInnerView(R.layout.kau_pref_color) @@ -63,7 +63,7 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas /** * Extension of the base contract and [ColorContract] along with a showPreview option */ - interface KPrefColorContract : KPrefItemBase.BaseContract, ColorContract { + interface KPrefColorContract : BaseContract, ColorContract { var showPreview: Boolean var dialogBuilder: MaterialDialog.() -> Unit } @@ -76,11 +76,13 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas titleId: Int, getter: () -> Int, setter: KPrefItemActions.(value: Int) -> Unit - ) : KPrefColorContract, KPrefItemBase.BaseContract by BaseBuilder(globalOptions, titleId, getter, setter), + ) : KPrefColorContract, + BaseContract by BaseBuilder(globalOptions, titleId, getter, setter), ColorContract by ColorBuilder() { override var showPreview: Boolean = true override var dialogBuilder: MaterialDialog.() -> Unit = {} } - override fun getType(): Int = R.id.kau_item_pref_color_picker + override val type: Int + get() = R.id.kau_item_pref_color_picker } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt index 7d73322..ca70b61 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt @@ -25,12 +25,14 @@ import ca.allanwang.kau.kpref.activity.R */ open class KPrefHeader(builder: CoreContract) : KPrefItemCore(builder) { - override fun getLayoutRes(): Int = R.layout.kau_pref_header + override val layoutRes: Int + get() = R.layout.kau_pref_header - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) withAccentColor(holder.title::setTextColor) } - override fun getType() = R.id.kau_item_pref_header + override val type: Int + get() = R.id.kau_item_pref_header } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt index c597b63..9197057 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt @@ -46,7 +46,7 @@ abstract class KPrefItemBase(protected val base: BaseContract) : KPrefItem } @CallSuper - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) _enabled = base.enabler() with(holder) { @@ -77,12 +77,14 @@ abstract class KPrefItemBase(protected val base: BaseContract) : KPrefItem super.unbindView(holder) holder.container?.apply { isEnabled = true - background = holder.itemView.context.resolveDrawable(android.R.attr.selectableItemBackground) + background = + holder.itemView.context.resolveDrawable(android.R.attr.selectableItemBackground) alpha = 1.0f } } - final override fun getLayoutRes(): Int = R.layout.kau_pref_core + final override val layoutRes: Int + get() = R.layout.kau_pref_core /** * Extension of the core contract diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt index 36bf670..79b7e82 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt @@ -48,7 +48,7 @@ import com.mikepenz.iconics.typeface.IIcon * Core class containing nothing but the view items */ -abstract class KPrefItemCore(val core: CoreContract) : AbstractItem(), KPrefItemActions by core, +abstract class KPrefItemCore(val core: CoreContract) : AbstractItem(), KPrefItemActions by core, ThemableIItem by ThemableIItemDelegate() { final override fun getViewHolder(v: View) = ViewHolder(v) @@ -70,7 +70,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) with(holder) { updateTitle() diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt index 6a0aaf5..7381a07 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt @@ -36,5 +36,6 @@ open class KPrefPlainText(open val builder: KPrefPlainTextBuilder) : KPrefItemBa titleId: Int ) : BaseContract by BaseBuilder(globalOptions, titleId, {}, {}) - override fun getType(): Int = R.id.kau_item_pref_plain_text + override val type: Int + get() = R.id.kau_item_pref_plain_text } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt index a582ec4..5de1f83 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt @@ -37,7 +37,7 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( override fun KClick.defaultOnClick() = Unit - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) val text = holder.bindInnerView(R.layout.kau_pref_seekbar_text) withTextColor(text::setTextColor) @@ -60,7 +60,8 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( }) } withAccentColor(seekbar::tint) - text.text = builder.toText(seekbar.progress.fromProgress) //set initial text in case no change occurs + text.text = + builder.toText(seekbar.progress.fromProgress) //set initial text in case no change occurs seekbar.progress = pref.toProgress seekbar.isEnabled = builder.enabler() } @@ -87,7 +88,8 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( titleId: Int, getter: () -> Int, setter: KPrefItemActions.(value: Int) -> Unit - ) : KPrefSeekbarContract, BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { + ) : KPrefSeekbarContract, + BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { override var min: Int = 0 @@ -118,5 +120,6 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( protected inline val Int.fromProgress: Int get() = this * increment + min - override fun getType(): Int = R.id.kau_item_pref_seekbar + override val type: Int + get() = R.id.kau_item_pref_seekbar } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt index 1fa528b..8474627 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt @@ -33,7 +33,8 @@ open class KPrefSubItems(open val builder: KPrefSubItemsContract) : KPrefItemCor builder.globalOptions.showNextPrefs(builder.titleFun(), builder.itemBuilder) } - override fun getLayoutRes(): Int = R.layout.kau_pref_core + override val layoutRes: Int + get() = R.layout.kau_pref_core /** * Extension of the base contract with an optional text getter @@ -51,5 +52,6 @@ open class KPrefSubItems(open val builder: KPrefSubItemsContract) : KPrefItemCor override val itemBuilder: KPrefAdapterBuilder.() -> Unit ) : KPrefSubItemsContract, CoreContract by CoreBuilder(globalOptions, titleId) - override fun getType(): Int = R.id.kau_item_pref_sub_item + override val type: Int + get() = R.id.kau_item_pref_sub_item } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt index 76c9e20..50f0c62 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt @@ -46,7 +46,7 @@ open class KPrefText(open val builder: KPrefTextContract) : KPrefItemBase< context.toast("No click function set") } - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) val textView = holder.bindInnerView(R.layout.kau_pref_text) withTextColor(textView::setTextColor) @@ -68,9 +68,11 @@ open class KPrefText(open val builder: KPrefTextContract) : KPrefItemBase< titleId: Int, getter: () -> T, setter: KPrefItemActions.(value: T) -> Unit - ) : KPrefTextContract, BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { + ) : KPrefTextContract, + BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { override var textGetter: (T) -> String? = { it?.toString() } } - override fun getType(): Int = R.id.kau_item_pref_text + override val type: Int + get() = R.id.kau_item_pref_text } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt index f50397c..318b630 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt @@ -33,7 +33,8 @@ import java.util.Locale */ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText(builder) { - interface KPrefTimeContract : KPrefText.KPrefTextContract, TimePickerDialog.OnTimeSetListener { + interface KPrefTimeContract : KPrefText.KPrefTextContract, + TimePickerDialog.OnTimeSetListener { var use24HourFormat: Boolean } @@ -50,7 +51,8 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText< titleId: Int, getter: () -> Int, setter: KPrefItemActions.(value: Int) -> Unit - ) : KPrefTimeContract, BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { + ) : KPrefTimeContract, + BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { override var use24HourFormat: Boolean = false @@ -64,11 +66,18 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText< if (use24HourFormat) String.format(Locale.CANADA, "%d:%02d", hour, min) else - String.format(Locale.CANADA, "%d:%02d %s", hour % 12, min, if (hour >= 12) "PM" else "AM") + String.format( + Locale.CANADA, + "%d:%02d %s", + hour % 12, + min, + if (hour >= 12) "PM" else "AM" + ) } } - override fun getType(): Int = R.id.kau_item_pref_time_picker + override val type: Int + get() = R.id.kau_item_pref_time_picker } private val Int.splitTime: Pair diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt index 739bf47..e430dff 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt @@ -28,7 +28,7 @@ import ca.allanwang.kau.utils.scaleXY import ca.allanwang.kau.utils.setBackgroundColorRes import ca.allanwang.kau.utils.setIcon import ca.allanwang.kau.utils.visible -import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import jp.wasabeef.blurry.internal.BlurFactor import jp.wasabeef.blurry.internal.BlurTask import kotlinx.android.synthetic.main.kau_blurred_imageview.view.* @@ -48,7 +48,9 @@ class BlurredImageView @JvmOverloads constructor( defStyleAttr: Int = 0 ) : FrameLayout(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() { - private var blurred = false + var isBlurred = false + private set + val imageBase: ImageView get() = image_base init { @@ -69,20 +71,19 @@ class BlurredImageView @JvmOverloads constructor( image_foreground.clearAnimation() } - private fun View.scaleAnimate(scale: Float) = animate().scaleXY(scale).setDuration(ANIMATION_DURATION) - private fun View.alphaAnimate(alpha: Float) = animate().alpha(alpha).setDuration(ANIMATION_DURATION) + private fun View.scaleAnimate(scale: Float) = + animate().scaleXY(scale).setDuration(ANIMATION_DURATION) - fun isBlurred(): Boolean { - return blurred - } + private fun View.alphaAnimate(alpha: Float) = + animate().alpha(alpha).setDuration(ANIMATION_DURATION) /** * Applies a blur and fills the blur image asynchronously * When ready, scales the image down and shows the blur & foreground */ fun blur() { - if (blurred) return - blurred = true + if (isBlurred) return + isBlurred = true val factor = BlurFactor() factor.width = width factor.height = height @@ -100,7 +101,7 @@ class BlurredImageView @JvmOverloads constructor( * is still asynchronous and takes time */ fun blurInstantly() { - blurred = true + isBlurred = true clearAnimation() val factor = BlurFactor() factor.width = width @@ -117,8 +118,8 @@ class BlurredImageView @JvmOverloads constructor( * Animate view back to original state and remove drawable when finished */ fun removeBlur() { - if (!blurred) return - blurred = false + if (!isBlurred) return + isBlurred = false scaleAnimate(1.0f).start() image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start() image_foreground.alphaAnimate(0f).start() @@ -128,7 +129,7 @@ class BlurredImageView @JvmOverloads constructor( * Clear all animations and unblur the image */ fun removeBlurInstantly() { - blurred = false + isBlurred = false clearAnimation() scaleX = 1.0f scaleX = 1.0f @@ -143,9 +144,9 @@ class BlurredImageView @JvmOverloads constructor( * @return true if new state is blurred; false otherwise */ fun toggleBlur(): Boolean { - if (blurred) removeBlur() + if (isBlurred) removeBlur() else blur() - return blurred + return isBlurred } /** @@ -162,7 +163,7 @@ class BlurredImageView @JvmOverloads constructor( */ fun fullReset() { reset() - fullAction({ it.visible().background = null }) + fullAction { it.visible().background = null } image_foreground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay) image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE) } diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt index 55b448e..552bf0f 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt @@ -42,6 +42,10 @@ class MediaActionItem( R.id.kau_item_media_action ) { + override var isSelectable: Boolean + get() = false + set(_) {} + override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) holder.image.apply { 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 5d47590..88a304f 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt @@ -52,7 +52,7 @@ class MediaItem(val data: MediaModel) : override var isSelectable: Boolean get() = !failedToLoad - set(value) {} + set(_) {} override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) 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 73647b8..873289f 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt @@ -27,29 +27,32 @@ import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.select.getSelectExtension /** * 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") fun bindEvents(activity: Activity, fastAdapter: FastAdapter) { - fastAdapter.withSelectable(false) - //add image data and return right away - .withOnClickListener { _, _, item, _ -> - activity.finish(arrayListOf(item.data)) - true - } + fastAdapter.getSelectExtension().isSelectable = true + //add image data and return right away + fastAdapter.onClickListener = { _, _, item, _ -> + activity.finish(arrayListOf(item.data)) + true + } } } - override fun isSelectable(): Boolean = false + override var isSelectable: Boolean + get() = false + set(_) {} - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) glide(holder.itemView) .load(data.data) 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 edd6199..1ba8041 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt @@ -85,6 +85,8 @@ data class MediaModel( } companion object CREATOR : Parcelable.Creator { + @Suppress("DEPRECATION") + // TODO verify data deprecation val projection = arrayOf( MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.MIME_TYPE, diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt index 5e5d1ed..c7cff55 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt @@ -26,7 +26,9 @@ import ca.allanwang.kau.utils.setIcon import ca.allanwang.kau.utils.toDrawable import ca.allanwang.kau.utils.toast import com.google.android.material.appbar.AppBarLayout -import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.fastadapter.ISelectionListener +import com.mikepenz.fastadapter.select.selectExtension +import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import kotlinx.android.synthetic.main.kau_activity_image_picker.* /** @@ -46,21 +48,37 @@ abstract class MediaPickerActivityBase( setContentView(R.layout.kau_activity_image_picker) - kau_selection_count.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null) + kau_selection_count.setCompoundDrawables( + null, + null, + GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), + null + ) setSupportActionBar(kau_toolbar) supportActionBar?.apply { setDisplayHomeAsUpEnabled(true) setDisplayShowHomeEnabled(true) - setHomeAsUpIndicator(GoogleMaterial.Icon.gmd_close.toDrawable(this@MediaPickerActivityBase, 18)) + setHomeAsUpIndicator( + GoogleMaterial.Icon.gmd_close.toDrawable( + this@MediaPickerActivityBase, + 18 + ) + ) } kau_toolbar.setNavigationOnClickListener { onBackPressed() } initializeRecycler(kau_recyclerview) - MediaItem.bindEvents(adapter.fastAdapter) - adapter.fastAdapter.withSelectionListener { _, _ -> - kau_selection_count.text = adapter.selectionSize.toString() + adapter.fastAdapter!!.let { + MediaItem.bindEvents(it) + it.selectExtension { + selectionListener = object : ISelectionListener { + override fun onSelectionChanged(item: MediaItem?, selected: Boolean) { + kau_selection_count.text = adapter.selectionSize.toString() + } + } + } } kau_fab.apply { diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt index a7ee63d..df47688 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt @@ -39,7 +39,7 @@ abstract class MediaPickerActivityOverlayBase( super.onCreate(savedInstanceState) setContentView(R.layout.kau_activity_image_picker_overlay) initializeRecycler(kau_recyclerview) - MediaItemBasic.bindEvents(this, adapter.fastAdapter) + MediaItemBasic.bindEvents(this, adapter.fastAdapter!!) kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top) kau_draggable.setOnClickListener { finishAfterTransition() } 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 c928e04..116f511 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -46,13 +46,10 @@ import com.bumptech.glide.Glide import com.bumptech.glide.RequestManager import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.adapters.ItemAdapter -import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.colorInt -import com.mikepenz.iconics.paddingPx -import com.mikepenz.iconics.sizePx +import com.mikepenz.iconics.dsl.ExperimentalIconicsDSL +import com.mikepenz.iconics.dsl.iconicsDrawable import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial -import com.mikepenz.iconics.utils.toIconicsColor import kotlinx.coroutines.CancellationException import java.io.File @@ -91,16 +88,19 @@ abstract class MediaPickerCore>( /** * Create error tile for a given item */ + @ExperimentalIconicsDSL fun getErrorDrawable(context: Context) = getIconDrawable(context, GoogleMaterial.Icon.gmd_error, accentColor) + @ExperimentalIconicsDSL fun getIconDrawable(context: Context, iicon: IIcon, color: Int): Drawable { - val sizePx = MediaPickerCore.computeViewSize(context) - return IconicsDrawable(context, iicon) - .sizePx(sizePx) - .backgroundColor(color.toIconicsColor()) - .paddingPx(sizePx / 3) - .colorInt(Color.WHITE) + val sizePx = computeViewSize(context) + return context.iconicsDrawable(iicon) { + size = sizePx(sizePx) + backgroundColor = colorInt(color) + padding = sizePx(sizePx / 3) + this.color = colorInt(Color.WHITE) + } } var accentColor: Int = 0xff666666.toInt() @@ -110,12 +110,12 @@ abstract class MediaPickerCore>( * This is used for both single and multiple photo picks */ fun onMediaPickerResult(resultCode: Int, data: Intent?): List { - if (resultCode != Activity.RESULT_OK || data == null || !data.hasExtra( - MEDIA_PICKER_RESULT - ) - ) + if (resultCode != Activity.RESULT_OK || + data?.hasExtra(MEDIA_PICKER_RESULT) != true + ) { return emptyList() - return data.getParcelableArrayListExtra(MEDIA_PICKER_RESULT) + } + return data.getParcelableArrayListExtra(MEDIA_PICKER_RESULT) ?: emptyList() } /** @@ -278,8 +278,8 @@ abstract class MediaPickerCore>( override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (resultCode != RESULT_OK) { - if (tempPath != null) { - val f = File(tempPath) + tempPath?.let { + val f = File(it) if (f.exists()) f.delete() tempPath = null } @@ -295,14 +295,18 @@ abstract class MediaPickerCore>( private fun onCameraResult(data: Intent?) { val f: File - if (tempPath != null) { - f = File(tempPath) - tempPath = null - } else if (data?.data != null) { - f = File(data.data!!.path) - } else { - KL.d { "Media camera no file found" } - return + val tempPath = tempPath + val dataPath = data?.data?.path + when { + tempPath != null -> { + f = File(tempPath) + this.tempPath = null + } + dataPath != null -> f = File(dataPath) + else -> { + KL.d { "Media camera no file found" } + return + } } if (f.exists()) { KL.v { "Media camera path found: ${f.absolutePath}" } @@ -315,9 +319,10 @@ abstract class MediaPickerCore>( private fun onPickerResult(data: Intent?) { val items = mutableListOf() - if (data?.data != null) { - KL.v { "Media picker data uri: ${data.data!!.path}" } - items.add(data.data!!) + val _data = data?.data + if (_data != null) { + KL.v { "Media picker data uri: ${_data.path}" } + items.add(_data) } else if (data != null) { val clip = data.clipData if (clip != null) { diff --git a/sample/build.gradle b/sample/build.gradle index cacd21f..1441cf0 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -76,6 +76,7 @@ android { packagingOptions { pickFirst 'META-INF/core_release.kotlin_module' pickFirst 'META-INF/library_release.kotlin_module' + pickFirst 'META-INF/library-core_release.kotlin_module' } compileOptions { diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt index 8c35c77..2fedbeb 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt @@ -22,7 +22,7 @@ import ca.allanwang.kau.ui.activities.ElasticRecyclerActivity import ca.allanwang.kau.utils.toast import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.adapters.ItemAdapter -import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial /** * Created by Allan Wang on 2017-07-17. diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt index aaa6143..f6d5ccc 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt @@ -43,14 +43,20 @@ class AnimActivity : KauBaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val adapter = FastItemAdapter() - setContentView(fullLinearRecycler(adapter).apply { setBackgroundColor(KPrefSample.bgColor.withAlpha(255)) }) + setContentView(fullLinearRecycler(adapter).apply { + setBackgroundColor( + KPrefSample.bgColor.withAlpha( + 255 + ) + ) + }) adapter.add(listOf( PERMISSION_ACCESS_COARSE_LOCATION, PERMISSION_ACCESS_FINE_LOCATION, PERMISSION_CAMERA ).map { PermissionCheckbox(it) }) - adapter.withOnClickListener { _, _, item, _ -> + adapter.onClickListener = { _, _, item, _ -> KL.d { "Perm Click" } kauRequestPermissions(item.permission) { granted, _ -> toast("${item.permission} enabled: $granted") diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index f4a09cf..11d19e5 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -39,7 +39,7 @@ import ca.allanwang.kau.utils.toast import ca.allanwang.kau.utils.withSceneTransitionAnimation import ca.allanwang.kau.xml.showChangelog import com.afollestad.materialdialogs.input.input -import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial class MainActivity : KPrefActivity() { diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt index 025179d..7cf6cc1 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt @@ -25,7 +25,7 @@ import ca.allanwang.kau.utils.hasPermission /** * Created by Allan Wang on 2017-07-03. */ -class PermissionCheckbox(val permission: String) : KauIItem( +class PermissionCheckbox(val permission: String) : KauIItem( R.layout.permission_checkbox, { ViewHolder(it) }) { override fun bindView(holder: ViewHolder, payloads: MutableList) { diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt index 7747d81..7bf01b3 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -32,7 +32,7 @@ import ca.allanwang.kau.utils.setIcon import ca.allanwang.kau.utils.setRippleBackground import ca.allanwang.kau.utils.visible import com.mikepenz.iconics.typeface.IIcon -import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial /** * Created by Allan Wang on 2017-06-23. @@ -47,7 +47,7 @@ class SearchItem( val description: String? = null, val iicon: IIcon? = GoogleMaterial.Icon.gmd_search, val image: Drawable? = null -) : KauIItem( +) : KauIItem( R.layout.kau_search_iitem, { ViewHolder(it) }, R.id.kau_item_search diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index 18eb675..da06ec4 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -63,8 +63,9 @@ import ca.allanwang.kau.utils.toDrawable import ca.allanwang.kau.utils.visible import ca.allanwang.kau.utils.withLinearAdapter import com.mikepenz.fastadapter.adapters.FastItemAdapter +import com.mikepenz.fastadapter.select.selectExtension import com.mikepenz.iconics.typeface.IIcon -import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import kotlinx.android.synthetic.main.kau_search_view.view.* /** @@ -255,7 +256,11 @@ class SearchView @JvmOverloads constructor( val list = if (value.isEmpty() && configs.noResultsFound != INVALID_ID) listOf(SearchItem("", context.string(configs.noResultsFound), iicon = null)) else value - if (configs.highlightQueryText && value.isNotEmpty()) list.forEach { it.withHighlights(kau_search_edit_text.text?.toString()) } + if (configs.highlightQueryText && value.isNotEmpty()) list.forEach { + it.withHighlights( + kau_search_edit_text.text?.toString() + ) + } cardTransition() adapter.setNewList(list) } @@ -297,7 +302,8 @@ class SearchView @JvmOverloads constructor( View.inflate(context, R.layout.kau_search_view, this) z = 99f kau_search_nav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() } - kau_search_clear.setSearchIcon(configs.clearIcon).setOnClickListener { kau_search_edit_text.text?.clear() } + kau_search_clear.setSearchIcon(configs.clearIcon) + .setOnClickListener { kau_search_edit_text.text?.clear() } tintForeground(configs.foregroundColor) tintBackground(configs.backgroundColor) with(kau_search_recycler) { @@ -312,11 +318,18 @@ class SearchView @JvmOverloads constructor( itemAnimator = null } with(adapter) { - withSelectable(true) - withOnClickListener { _, _, item, position -> - if (item.key.isNotBlank()) configs.onItemClick(position, item.key, item.content, this@SearchView); true + selectExtension { + isSelectable = true + } + onClickListener = { _, _, item, position -> + if (item.key.isNotBlank()) configs.onItemClick( + position, + item.key, + item.content, + this@SearchView + ); true } - withOnLongClickListener { _, _, item, position -> + onLongClickListener = { _, _, item, position -> if (item.key.isNotBlank()) configs.onItemLongClick( position, item.key, @@ -420,7 +433,8 @@ class SearchView @JvmOverloads constructor( menuX = (locations[0] + view.width / 2) menuHalfHeight = view.height / 2 menuY = (locations[1] + menuHalfHeight) - kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener { + kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object : + ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { view.viewTreeObserver.removeOnPreDrawListener(this) kau_search_cardview.setMarginTop(menuY - kau_search_cardview.height / 2) @@ -474,7 +488,11 @@ class SearchView @JvmOverloads constructor( configs.openListener?.invoke(this@SearchView) kau_search_shadow.fadeIn() kau_search_edit_text.showKeyboard() - kau_search_cardview.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) { + kau_search_cardview.circularReveal( + menuX, + menuHalfHeight, + duration = configs.revealDuration + ) { cardTransition() kau_search_recycler.visible() } @@ -487,7 +505,9 @@ class SearchView @JvmOverloads constructor( kau_search_shadow.fadeOut(duration = configs.transitionDuration) cardTransition { addEndListener { - kau_search_cardview.circularHide(menuX, menuHalfHeight, duration = configs.revealDuration, + kau_search_cardview.circularHide(menuX, + menuHalfHeight, + duration = configs.revealDuration, onFinish = { configs.closeListener?.invoke(this@SearchView) if (configs.shouldClearOnClose) kau_search_edit_text.text?.clear() @@ -512,7 +532,8 @@ fun Activity.bindSearchView( @IdRes id: Int, @ColorInt menuIconColor: Int = Color.WHITE, config: Configs.() -> Unit = {} -): SearchView = findViewById(android.R.id.content).bindSearchView(menu, id, menuIconColor, config) +): SearchView = + findViewById(android.R.id.content).bindSearchView(menu, id, menuIconColor, config) /** * Bind searchView to a menu item; call this in [Activity.onCreateOptionsMenu] @@ -528,7 +549,10 @@ fun ViewGroup.bindSearchView( ): SearchView { val searchView = SearchView(context) searchView.layoutParams = - FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) + FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT + ) addView(searchView) searchView.bind(menu, id, menuIconColor, config) return searchView -- cgit v1.2.3 From a99e5885a8e67c2609b3c23dff069189c2e62dab Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jul 2019 19:45:53 -0700 Subject: Apply spotless --- .../kotlin/ca/allanwang/kau/about/AboutActivityBase.kt | 1 - .../kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt | 1 - .../src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt | 1 - .../main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt | 1 - .../kau/ui/widgets/ElasticDragDismissFrameLayout.kt | 1 - .../main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt | 17 ++++++++++++++++- .../ca/allanwang/kau/kpref/KPrefSingleDelegate.kt | 2 +- .../kotlin/ca/allanwang/kau/permissions/Permissions.kt | 3 +-- .../kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt | 2 -- .../ca/allanwang/kau/adapters/FastItemThemedAdapter.kt | 2 -- .../ca/allanwang/kau/adapters/RepeatedClickListener.kt | 1 - .../main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt | 1 - .../ca/allanwang/kau/mediapicker/MediaPickerCore.kt | 1 - .../kotlin/ca/allanwang/kau/sample/AboutActivity.kt | 1 - 14 files changed, 18 insertions(+), 17 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt index d346090..452d28c 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -34,7 +34,6 @@ import ca.allanwang.kau.utils.dimenPixelSize import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem import kotlinx.android.synthetic.main.kau_activity_about.* /** diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt index 24f1c48..ba7330c 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt @@ -35,7 +35,6 @@ import ca.allanwang.kau.utils.withMarginDecoration import ca.allanwang.kau.xml.kauParseFaq import com.mikepenz.aboutlibraries.Libs import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt index 0a570f8..977b7ff 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt @@ -31,7 +31,6 @@ import ca.allanwang.kau.utils.setPaddingLeft import ca.allanwang.kau.xml.FaqItem import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.fastadapter.select.getSelectExtension diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt index 8f93422..275945b 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -30,7 +30,6 @@ import ca.allanwang.kau.utils.visible import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.select.getSelectExtension /** diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt index 2cf005a..52672fa 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt @@ -29,7 +29,6 @@ import ca.allanwang.kau.logging.KL import ca.allanwang.kau.ui.R import ca.allanwang.kau.utils.AnimHolder import ca.allanwang.kau.utils.dimen -import ca.allanwang.kau.utils.dpToPx import ca.allanwang.kau.utils.isNavBarOnBottom import ca.allanwang.kau.utils.navigationBarColor import ca.allanwang.kau.utils.scaleXY diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt index 4dd3012..8f6d0c5 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 Allan Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package ca.allanwang.kau.kpref interface KPrefBuilder { @@ -72,4 +87,4 @@ object KPrefBuilderInMemory : KPrefBuilder { KPrefDelegateInMemory(key, fallback, this, postSetter) override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateInMemory(key, this) -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt index ef59e78..ae1f855 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt @@ -110,4 +110,4 @@ class KPrefSingleDelegateInMemory internal constructor( override fun isInitialized(): Boolean = _value != null override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet." -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt index f649cc6..ee4f5ef 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018 Allan Wang + * Copyright 2019 Allan Wang * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package ca.allanwang.kau.permissions import android.Manifest diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt index 59832ed..655b355 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt @@ -18,8 +18,6 @@ package ca.allanwang.kau.adapters import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.IAdapter -import com.mikepenz.fastadapter.IAdapterExtension -import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.select.SelectExtension /** diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index e3f43ca..5531f59 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -24,8 +24,6 @@ import androidx.annotation.RequiresApi import ca.allanwang.kau.ui.createSimpleRippleDrawable import ca.allanwang.kau.utils.adjustAlpha import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.IItemAdapter import com.mikepenz.fastadapter.adapters.FastItemAdapter /** diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt index 3aca18b..1eba2e0 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt @@ -21,7 +21,6 @@ import com.mikepenz.fastadapter.ClickListener import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.IAdapter -import com.mikepenz.fastadapter.IItem /** * Created by Allan Wang on 26/12/17. diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt index 040559c..1a2e6cb 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt @@ -35,7 +35,6 @@ import ca.allanwang.kau.utils.toDrawable import ca.allanwang.kau.utils.visible import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.iconics.typeface.IIcon 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 47933eb..d21b33f 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -45,7 +45,6 @@ import ca.allanwang.kau.utils.toast import com.bumptech.glide.Glide import com.bumptech.glide.RequestManager import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.iconics.dsl.ExperimentalIconicsDSL import com.mikepenz.iconics.dsl.iconicsDrawable diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt index 89fa2c4..ffe769a 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt @@ -19,7 +19,6 @@ import ca.allanwang.kau.about.AboutActivityBase import ca.allanwang.kau.adapters.FastItemThemedAdapter import ca.allanwang.kau.iitems.CardIItem import com.mikepenz.fastadapter.GenericItem -import com.mikepenz.fastadapter.IItem /** * Created by Allan Wang on 2017-06-27. -- cgit v1.2.3 From d6f213563be35b183f81e20e95d925dbd65e4694 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jul 2019 20:14:05 -0700 Subject: Add braces to non assignment if statements --- .../ca/allanwang/kau/about/AboutActivityBase.kt | 8 ++- .../kotlin/ca/allanwang/kau/about/LibraryIItem.kt | 5 +- .../kau/ui/activities/ElasticRecyclerActivity.kt | 4 +- .../ui/widgets/ElasticDragDismissFrameLayout.kt | 4 +- .../kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 3 +- .../main/kotlin/ca/allanwang/kau/kotlin/Streams.kt | 11 ++-- .../kotlin/ca/allanwang/kau/logging/KauLogger.kt | 15 ++++-- .../ca/allanwang/kau/swipe/SwipeBackLayout.kt | 25 +++++---- .../kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt | 8 ++- .../kau/ui/views/CollapsibleViewDelegate.kt | 38 ++++++++++---- .../allanwang/kau/ui/views/MeasureSpecDelegate.kt | 20 +++++--- .../ca/allanwang/kau/ui/views/RippleCanvas.kt | 3 +- .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 4 +- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 31 +++++++---- .../kotlin/ca/allanwang/kau/utils/ViewUtils.kt | 22 +++++--- .../main/kotlin/ca/allanwang/kau/xml/Changelog.kt | 10 ++-- .../kau/adapters/FastItemThemedAdapter.kt | 4 +- .../kau/mediapicker/MediaPickerActivityBase.kt | 5 +- .../allanwang/kau/mediapicker/MediaPickerCore.kt | 5 +- .../ca/allanwang/kau/searchview/SearchItem.kt | 15 ++++-- .../ca/allanwang/kau/searchview/SearchView.kt | 60 ++++++++++++++-------- 21 files changed, 202 insertions(+), 98 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt index 452d28c..f7eddb9 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -69,7 +69,9 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde val panels: List by lazy { val defaultPanels = mutableListOf(AboutPanelMain(), AboutPanelLibs()) - if (configs.faqXmlRes != INVALID_ID) defaultPanels.add(AboutPanelFaqs()) + if (configs.faqXmlRes != INVALID_ID) { + defaultPanels.add(AboutPanelFaqs()) + } defaultPanels } @@ -78,7 +80,9 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde setContentView(R.layout.kau_activity_about) pageStatus = IntArray(panels.size) pageStatus[0] = 2 //the first page is instantly visible - if (configs.textColor != null) about_indicator.setColour(configs.textColor!!) + if (configs.textColor != null) { + about_indicator.setColour(configs.textColor!!) + } with(about_pager) { adapter = AboutPagerAdapter() pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal) diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt index 275945b..cd53f55 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -43,13 +43,14 @@ class LibraryIItem(val lib: Library) : KauIItem( fun bindEvents(fastAdapter: FastAdapter) { fastAdapter.getSelectExtension().isSelectable = true fastAdapter.onClickListener = { v, _, item, _ -> - if (item !is LibraryIItem) + if (item !is LibraryIItem) { false - else + } else { with(item.lib) { v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) true } + } } } } diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt index aff4d1c..3e7254f 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt @@ -53,7 +53,9 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.kau_elastic_recycler_activity) setSupportActionBar(kau_toolbar) - if (!onCreate(savedInstanceState, configs)) return + if (!onCreate(savedInstanceState, configs)) { + return + } kau_draggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { override fun onDragDismissed() { diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt index 52672fa..6095a32 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt @@ -204,7 +204,9 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor( } translationY = dragTo - if (shouldScale) scaleXY = 1 - (1 - dragDismissScale) * dragFraction + if (shouldScale) { + scaleXY = 1 - (1 - dragDismissScale) * dragFraction + } // if we've reversed direction and gone past the settle point then clear the flags to // allow the list to get the scroll events & reset any transforms 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 78661b1..5ae8376 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -104,8 +104,9 @@ class EmailBuilder(val email: String, val subject: String) { if (packages.isNotEmpty()) { emailBuilder.append("\n") packages.forEach { - if (context.isAppInstalled(it.packageName)) + if (context.isAppInstalled(it.packageName)) { emailBuilder.append(String.format("\n%s is installed", it.appName)) + } } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt index 65d15a7..582b0cd 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt @@ -26,8 +26,11 @@ package ca.allanwang.kau.kotlin */ inline fun > C.kauRemoveIf(filter: (item: T) -> Boolean): C { val iter = iterator() - while (iter.hasNext()) - if (filter(iter.next())) iter.remove() + while (iter.hasNext()) { + if (filter(iter.next())) { + iter.remove() + } + } return this } @@ -38,7 +41,9 @@ inline fun > C.kauRemoveIf(filter: (item: T) -> Boolea inline fun Iterator.firstOrNull(predicate: (T) -> Boolean): T? { while (hasNext()) { val data = next() - if (predicate(data)) return data + if (predicate(data)) { + return data + } } return null } diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt index 4562b00..9410c4c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt @@ -64,16 +64,18 @@ open class KauLogger( } inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) { - if (shouldLog(priority)) + if (shouldLog(priority)) { logImpl(priority, message()?.toString(), t) + } } open fun logImpl(priority: Int, message: String?, t: Throwable?) { val msg = message ?: "null" - if (t != null) + if (t != null) { Log.e(tag, msg, t) - else + } else { Log.println(priority, tag, msg) + } } /** @@ -113,8 +115,11 @@ class KauLoggerExtension(val tag: String, val logger: KauLogger) { inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) = logger.log(priority, { val msg = message()?.toString() - if (msg == null) null - else "$tag: $msg" + if (msg == null) { + null + } else { + "$tag: $msg" + } }, t) inline fun checkThread(id: Int) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt index 1f564ce..0fb0046 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -52,7 +52,9 @@ internal class SwipeBackLayout @JvmOverloads constructor( */ override var scrollThreshold = DEFAULT_SCROLL_THRESHOLD set(value) { - if (value >= 1.0f || value <= 0f) throw IllegalArgumentException("Threshold value should be between 0.0 and 1.0") + if (value >= 1.0f || value <= 0f) { + throw IllegalArgumentException("Threshold value should be between 0.0 and 1.0") + } field = value } @@ -130,8 +132,9 @@ internal class SwipeBackLayout @JvmOverloads constructor( * We will verify that only one axis is used at a time */ set(value) { - if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT)) + if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT)) { throw IllegalArgumentException("Edge flag is not valid; use one of the SWIPE_EDGE_* values") + } field = value horizontal = edgeFlag == SWIPE_EDGE_LEFT || edgeFlag == SWIPE_EDGE_RIGHT dragHelper.setEdgeTrackingEnabled(value) @@ -197,8 +200,9 @@ internal class SwipeBackLayout @JvmOverloads constructor( val iter = listeners.iterator() while (iter.hasNext()) { val l = iter.next().get() - if (l == null || l == listener) + if (l == null || l == listener) { iter.remove() + } } } @@ -210,10 +214,11 @@ internal class SwipeBackLayout @JvmOverloads constructor( val iter = listeners.iterator() while (iter.hasNext()) { val l = iter.next().get() - if (l == null) + if (l == null) { iter.remove() - else if (l == listener) + } else if (l == listener) { return true + } } return false } @@ -239,12 +244,14 @@ internal class SwipeBackLayout @JvmOverloads constructor( } override fun onInterceptTouchEvent(event: MotionEvent): Boolean { - if (!swipeEnabled || disallowIntercept) return false - try { - return dragHelper.shouldInterceptTouchEvent(event) - } catch (e: Exception) { + if (!swipeEnabled || disallowIntercept) { return false } + return try { + dragHelper.shouldInterceptTouchEvent(event) + } catch (e: Exception) { + false + } } @SuppressLint("ClickableViewAccessibility") diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt index a46e6c5..bb4cd88 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt @@ -94,7 +94,9 @@ class ProgressAnimator private constructor() : ValueAnimator() { * @return [condition] */ private fun ProgressAction.runIf(condition: Boolean, progress: Float): Boolean { - if (condition) this(progress) + if (condition) { + this(progress) + } return condition } @@ -170,7 +172,9 @@ class ProgressAnimator private constructor() : ValueAnimator() { fun withDisposableEndAction(action: ProgressDisposableRunnable) = endActions.add(action) fun reset() { - if (isRunning) cancel() + if (isRunning) { + cancel() + } animators.clear() startActions.clear() cancelActions.clear() diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt index b2a0d27..4631aec 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt @@ -62,15 +62,22 @@ class CollapsibleViewDelegate : CollapsibleView { override var expansion = 0f set(value) { - if (value == field) return + if (value == field) { + return + } var v = value - if (v > 1) v = 1f - else if (v < 0) v = 0f + if (v > 1) { + v = 1f + } else if (v < 0) { + v = 0f + } stateHolder = - if (v == 0f) KAU_COLLAPSED - else if (v == 1f) KAU_EXPANDED - else if (v - field < 0) KAU_COLLAPSING - else KAU_EXPANDING + when { + v == 0f -> KAU_COLLAPSED + v == 1f -> KAU_EXPANDED + v - field < 0 -> KAU_COLLAPSING + else -> KAU_EXPANDING + } field = v view?.goneIf(state == KAU_COLLAPSED) view?.requestLayout() @@ -89,8 +96,11 @@ class CollapsibleViewDelegate : CollapsibleView { override fun resetCollapsibleAnimation() { animator?.cancel() animator = null - if (stateHolder == KAU_COLLAPSING) stateHolder = KAU_COLLAPSED - else if (stateHolder == KAU_EXPANDING) stateHolder = KAU_EXPANDED + if (stateHolder == KAU_COLLAPSING) { + stateHolder = KAU_COLLAPSED + } else if (stateHolder == KAU_EXPANDING) { + stateHolder = KAU_EXPANDED + } } override fun getCollapsibleDimension(): Pair { @@ -116,8 +126,14 @@ class CollapsibleViewDelegate : CollapsibleView { override fun collapse(animate: Boolean) = setExpanded(false, animate) override fun setExpanded(expand: Boolean) = setExpanded(expand, true) override fun setExpanded(expand: Boolean, animate: Boolean) { - if (expand == expanded) return //state already matches + if (expand == expanded) { + return //state already matches + } val target = if (expand) 1f else 0f - if (animate) animateSize(target) else expansion = target + if (animate) { + animateSize(target) + } else { + expansion = target + } } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt index 6481306..8800c2d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt @@ -95,7 +95,9 @@ class MeasureSpecDelegate : MeasureSpecContract { private val parentFrame = Rect() override fun initAttrs(context: Context, attrs: AttributeSet?) { - if (attrs == null) return + if (attrs == null) { + return + } val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MeasureSpecDelegate) relativeWidth = styledAttrs.getFloat(R.styleable.MeasureSpecDelegate_relativeWidth, relativeWidth) relativeHeight = styledAttrs.getFloat(R.styleable.MeasureSpecDelegate_relativeHeight, relativeHeight) @@ -114,20 +116,24 @@ class MeasureSpecDelegate : MeasureSpecContract { var width = View.MeasureSpec.getSize(widthMeasureSpec).toFloat() var height = View.MeasureSpec.getSize(heightMeasureSpec).toFloat() //first cycle - relative to parent - if (relativeHeightToParent > 0) + if (relativeHeightToParent > 0) { height = relativeHeightToParent * parentFrame.height() - if (relativeWidthToParent > 0) + } + if (relativeWidthToParent > 0) { width = relativeWidthToParent * parentFrame.width() + } //second cycle - relative to each other - if (relativeHeight > 0) + if (relativeHeight > 0) { height = relativeHeight * width - else if (relativeWidth > 0) + } else if (relativeWidth > 0) { width = relativeWidth * height + } //third cycle - relative to each other - if (postRelativeHeight > 0) + if (postRelativeHeight > 0) { height = postRelativeHeight * width - else if (postRelativeWidth > 0) + } else if (postRelativeWidth > 0) { width = postRelativeWidth * height + } return Pair(width.measureSpec, height.measureSpec) } diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt index 176b9ea..a972447 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt @@ -102,11 +102,12 @@ class RippleCanvas @JvmOverloads constructor( ripple.radius = animation.animatedValue as Float invalidate() } - if (callback != null) + if (callback != null) { animator.addListener(object : AnimatorListenerAdapter() { override fun onAnimationCancel(animation: Animator?) = callback() override fun onAnimationEnd(animation: Animator?) = callback() }) + } animator.start() } diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index 21141f1..3b593a6 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -125,7 +125,9 @@ inline var Activity.statusBarColor: Int get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK @SuppressLint("NewApi") set(value) { - if (buildIsLollipopAndUp) window.statusBarColor = value + if (buildIsLollipopAndUp) { + window.statusBarColor = value + } } inline var Activity.statusBarLight: Boolean 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 d002fb8..2f552ed 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -80,22 +80,27 @@ inline fun Context.startActivity( intentBuilder: Intent.() -> Unit = {} ) { val intent = Intent(this, clazz) - if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + if (clearStack) { + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + } intent.intentBuilder() val bundle = Bundle() bundle.bundleBuilder() - startActivity(intent, if (bundle.isEmpty) null else bundle) - if (clearStack && this is Activity) finish() + startActivity(intent, bundle.takeIf { !it.isEmpty }) + if (clearStack && this is Activity) { + finish() + } } fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes)) fun Context.startPlayStoreLink(packageId: String) { val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId")) - if (intent.resolveActivity(packageManager) != null) + if (intent.resolveActivity(packageManager) != null) { startActivity(intent) - else + } else { toast("Cannot resolve play store", log = true) + } } /** @@ -105,10 +110,11 @@ 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)) - if (browserIntent.resolveActivity(packageManager) != null) + if (browserIntent.resolveActivity(packageManager) != null) { startActivity(browserIntent) - else + } else { toast("Cannot resolve browser", log = true) + } } fun Context.startLink(@StringRes url: Int) = startLink(string(url)) @@ -240,19 +246,22 @@ fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || Con fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showToast: Boolean = true) { val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipboard.setPrimaryClip(ClipData.newPlainText(label, text ?: "")) - if (showToast) toast(R.string.kau_text_copied) + if (showToast) { + toast(R.string.kau_text_copied) + } } fun Context.shareText(text: String?) { - if (text == null) return toast("Share text is null") + text ?: return toast("Share text is null") val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, text) val chooserIntent = Intent.createChooser(intent, string(R.string.kau_share)) - if (chooserIntent.resolveActivity(packageManager) != null) + if (chooserIntent.resolveActivity(packageManager) != null) { startActivity(chooserIntent) - else + } else { toast("Cannot resolve activity to share text", log = true) + } } /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index 186d125..e4ec19c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -105,7 +105,7 @@ fun ImageView.setIcon( @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {} ) { - if (icon == null) return + icon ?: return setImageDrawable(icon.toDrawable(context, sizeDp = sizeDp, color = color, builder = builder)) } @@ -274,7 +274,9 @@ fun Context.fullLinearRecycler(rvAdapter: RecyclerView.Adapter<*>? = null, confi layoutManager = LinearLayoutManager(this@fullLinearRecycler) layoutParams = RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT) - if (rvAdapter != null) adapter = rvAdapter + if (rvAdapter != null) { + adapter = rvAdapter + } configs() } @@ -296,8 +298,9 @@ inline fun T.fadeScaleTransition( minScale: Float = 0.7f, crossinline action: T.() -> Unit ) { - if (!isVisible) action() - else { + if (!isVisible) { + action() + } else { var transitioned = false ValueAnimator.ofFloat(1.0f, 0.0f, 1.0f).apply { this.duration = duration @@ -323,12 +326,17 @@ fun FloatingActionButton.hideOnDownwardsScroll(recycler: RecyclerView) { recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { - if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) show() + if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) { + show() + } } override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - if (dy > 0 && isShown) hide() - else if (dy < 0 && isHidden) show() + if (dy > 0 && isShown) { + hide() + } else if (dy < 0 && isHidden) { + show() + } } }) } diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt index 9adcbf4..0872b68 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt @@ -84,8 +84,9 @@ internal fun parse(context: Context, @XmlRes xmlRes: Int): List var eventType = parser.eventType while (eventType != XmlPullParser.END_DOCUMENT) { - if (eventType == XmlPullParser.START_TAG) + if (eventType == XmlPullParser.START_TAG) { ChangelogType.values.any { it.add(parser, items) } + } eventType = parser.next() } } @@ -104,9 +105,12 @@ internal enum class ChangelogType(val tag: String, val attr: String, @LayoutRes * Returns true if tag matches; false otherwise */ fun add(parser: XmlResourceParser, list: MutableList>): Boolean { - if (parser.name != tag) return false - if (parser.getAttributeValue(null, attr).isNotBlank()) + if (parser.name != tag) { + return false + } + if (parser.getAttributeValue(null, attr).isNotBlank()) { list.add(Pair(parser.getAttributeValue(null, attr), this)) + } return true } } diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index 5531f59..c5ce61f 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -79,7 +79,9 @@ class FastItemThemedAdapter( } fun themeChanged() { - if (adapterItemCount == 0) return + if (adapterItemCount == 0) { + return + } injectTheme(adapterItems) notifyAdapterDataSetChanged() } diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt index c7cff55..ad83d8a 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt @@ -110,11 +110,12 @@ abstract class MediaPickerActivityBase( */ private fun setToolbarScrollable(scrollable: Boolean) { val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams - if (scrollable) + if (scrollable) { params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL - else + } else { params.scrollFlags = 0 + } } override fun onLoadFinished(loader: Loader, data: Cursor?) { 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 d21b33f..cc6df81 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -147,9 +147,8 @@ abstract class MediaPickerCore( recycler.apply { val manager = object : GridLayoutManager(context, computeColumnCount(context)) { override fun getExtraLayoutSpace(state: RecyclerView.State?): Int { - return if (mediaType != MediaType.VIDEO) extraSpace else super.getExtraLayoutSpace( - state - ) + return if (mediaType != MediaType.VIDEO) extraSpace + else super.getExtraLayoutSpace(state) } } setItemViewCacheSize(CACHE_SIZE) diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt index 7bf01b3..78d8782 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -66,7 +66,9 @@ class SearchItem( internal fun withHighlights(subText: String?) { subText ?: return val index = content.indexOf(subText, ignoreCase = true) - if (index == -1) return + if (index == -1) { + return + } styledContent = SpannableStringBuilder(content) styledContent!!.setSpan( StyleSpan(Typeface.BOLD), @@ -81,12 +83,17 @@ class SearchItem( holder.title.setTextColor(foregroundColor) holder.desc.setTextColor(foregroundColor.adjustAlpha(0.6f)) - if (image != null) holder.icon.setImageDrawable(image) - else holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor) + if (image != null) { + holder.icon.setImageDrawable(image) + } else { + holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor) + } holder.container.setRippleBackground(foregroundColor, backgroundColor) holder.title.text = styledContent ?: content - if (description?.isNotBlank() == true) holder.desc.visible().text = description + if (description?.isNotBlank() == true) { + holder.desc.visible().text = description + } } override fun unbindView(holder: ViewHolder) { diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index da06ec4..a552a01 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -234,10 +234,14 @@ class SearchView @JvmOverloads constructor( } val icons = mutableListOf(navIcon to kau_search_nav, clearIcon to kau_search_clear) val extra = extraIcon - if (extra != null) icons.add(extra.first to kau_search_extra) + if (extra != null) { + icons.add(extra.first to kau_search_extra) + } icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) } - if (extra != null) kau_search_extra.setOnClickListener(extra.second) + if (extra != null) { + kau_search_extra.setOnClickListener(extra.second) + } kau_search_divider.invisibleIf(!withDivider) kau_search_edit_text.hint = context.string(hintTextRes, hintText) textCallback.terminate() @@ -312,7 +316,9 @@ class SearchView @JvmOverloads constructor( addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) - if (newState == RecyclerView.SCROLL_STATE_DRAGGING) hideKeyboard() + if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { + hideKeyboard() + } } }) itemAnimator = null @@ -330,12 +336,15 @@ class SearchView @JvmOverloads constructor( ); true } onLongClickListener = { _, _, item, position -> - if (item.key.isNotBlank()) configs.onItemLongClick( - position, - item.key, - item.content, - this@SearchView - ); true + if (item.key.isNotBlank()) { + configs.onItemLongClick( + position, + item.key, + item.content, + this@SearchView + ) + } + true } } kau_search_edit_text.addTextChangedListener(object : TextWatcher { @@ -346,20 +355,21 @@ class SearchView @JvmOverloads constructor( override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { val text = s.toString().trim() textCallback.cancel() - if (text.isNotEmpty()) + if (text.isNotEmpty()) { textCallback(text, this@SearchView) - else if (!configs.textClearedCallback(this@SearchView)) + } else if (!configs.textClearedCallback(this@SearchView)) { clearResults() + } } }) kau_search_edit_text.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH) { - if (configs.searchCallback( - kau_search_edit_text.text?.toString() - ?: "", this - ) - ) revealClose() - else kau_search_edit_text.hideKeyboard() + val query = kau_search_edit_text.text?.toString() ?: "" + if (configs.searchCallback(query, this)) { + revealClose() + } else { + kau_search_edit_text.hideKeyboard() + } return@setOnEditorActionListener true } false @@ -427,7 +437,9 @@ class SearchView @JvmOverloads constructor( private fun configureCoords(item: MenuItem?) { item ?: return - if (parent !is ViewGroup) return + if (parent !is ViewGroup) { + return + } val view = parentViewGroup.findViewById(item.itemId) ?: return view.getLocationInWindow(locations) menuX = (locations[0] + view.width / 2) @@ -477,7 +489,9 @@ class SearchView @JvmOverloads constructor( } fun revealOpen() { - if (parent == null || isOpen) return + if (parent == null || isOpen) { + return + } context.runOnUiThread { /** * The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0 @@ -500,7 +514,9 @@ class SearchView @JvmOverloads constructor( } fun revealClose() { - if (parent == null || !isOpen) return + if (parent == null || !isOpen) { + return + } context.runOnUiThread { kau_search_shadow.fadeOut(duration = configs.transitionDuration) cardTransition { @@ -510,7 +526,9 @@ class SearchView @JvmOverloads constructor( duration = configs.revealDuration, onFinish = { configs.closeListener?.invoke(this@SearchView) - if (configs.shouldClearOnClose) kau_search_edit_text.text?.clear() + if (configs.shouldClearOnClose) { + kau_search_edit_text.text?.clear() + } }) } } -- cgit v1.2.3 From 0bab0561f071fca253b75fbcdae453dbd8790cab Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jul 2019 21:10:18 -0700 Subject: Fix imports --- core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt | 15 +++++++-------- fastadapter/build.gradle | 1 + .../ca/allanwang/kau/mediapicker/MediaPickerCore.kt | 3 --- sample/build.gradle | 1 - searchview/build.gradle | 1 - 5 files changed, 8 insertions(+), 13 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt index 52ea57d..dc7b214 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt @@ -20,8 +20,7 @@ import android.graphics.Color import android.graphics.drawable.Drawable import androidx.annotation.ColorInt import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.colorInt -import com.mikepenz.iconics.sizeDp +import com.mikepenz.iconics.dsl.iconicsDrawable import com.mikepenz.iconics.typeface.IIcon /** @@ -33,9 +32,9 @@ fun IIcon.toDrawable( sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {} -): Drawable { - val icon = IconicsDrawable(c).icon(this).colorInt(color) - if (sizeDp > 0) icon.sizeDp(sizeDp) - icon.builder() - return icon -} +): Drawable = c.iconicsDrawable(this) { + this.color = colorInt(color) + if (sizeDp > 0) { + size = sizeDp(sizeDp) + } +}.apply(builder) diff --git a/fastadapter/build.gradle b/fastadapter/build.gradle index 8472801..ff58fe8 100644 --- a/fastadapter/build.gradle +++ b/fastadapter/build.gradle @@ -10,6 +10,7 @@ dependencies { api project(':adapter') api Dependencies.fastAdapter + api Dependencies.fastAdapter("utils") } apply from: '../artifacts.gradle' 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 d21b33f..dceb1df 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -46,7 +46,6 @@ import com.bumptech.glide.Glide import com.bumptech.glide.RequestManager import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.adapters.ItemAdapter -import com.mikepenz.iconics.dsl.ExperimentalIconicsDSL import com.mikepenz.iconics.dsl.iconicsDrawable import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial @@ -88,11 +87,9 @@ abstract class MediaPickerCore( /** * Create error tile for a given item */ - @ExperimentalIconicsDSL fun getErrorDrawable(context: Context) = getIconDrawable(context, GoogleMaterial.Icon.gmd_error, accentColor) - @ExperimentalIconicsDSL fun getIconDrawable(context: Context, iicon: IIcon, color: Int): Drawable { val sizePx = computeViewSize(context) return context.iconicsDrawable(iicon) { diff --git a/sample/build.gradle b/sample/build.gradle index 9a3473d..ab98695 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -129,7 +129,6 @@ dependencies { implementation project(':mediapicker') implementation Dependencies.materialDialog("input") - implementation Dependencies.fastAdapter("utils") testImplementation Dependencies.kotlinTest testImplementation Dependencies.junit diff --git a/searchview/build.gradle b/searchview/build.gradle index e1d878f..64a88b3 100644 --- a/searchview/build.gradle +++ b/searchview/build.gradle @@ -7,7 +7,6 @@ apply from: '../android-lib.gradle' dependencies { implementation project(':core-ui') implementation project(':fastadapter') - implementation Dependencies.fastAdapter('utils') } apply from: '../artifacts.gradle' -- cgit v1.2.3 From 5aefeee08f68777dd07a16bd42a7d2392db6bbc9 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 15 Aug 2019 16:04:14 -0700 Subject: Apply spotless --- .../main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt | 8 ++++---- about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt | 2 +- .../src/main/kotlin/ca/allanwang/kau/ui/widgets/TextSlider.kt | 2 +- .../src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 2 +- .../kotlin/ca/allanwang/kau/permissions/PermissionManager.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt | 8 ++++---- .../ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt | 2 +- .../kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt | 6 +++--- core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 6 +++--- core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt | 4 ++-- core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt | 2 +- core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt | 8 ++++---- core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt | 4 ++-- .../kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt | 2 +- .../kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt | 4 ++-- .../ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt | 2 +- .../ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt | 2 +- .../main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt | 2 +- .../kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt | 6 +++--- sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt | 2 +- .../main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt | 2 +- .../src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt | 10 +++++----- 27 files changed, 49 insertions(+), 49 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt index 452d28c..d17c3ec 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -77,7 +77,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde super.onCreate(savedInstanceState) setContentView(R.layout.kau_activity_about) pageStatus = IntArray(panels.size) - pageStatus[0] = 2 //the first page is instantly visible + pageStatus[0] = 2 // the first page is instantly visible if (configs.textColor != null) about_indicator.setColour(configs.textColor!!) with(about_pager) { adapter = AboutPagerAdapter() @@ -107,14 +107,14 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde var libPageTitle: String? = null set(value) { field = value - libPageTitleRes = INVALID_ID //reset res so we don't use our default + libPageTitleRes = INVALID_ID // reset res so we don't use our default } var faqXmlRes: Int = INVALID_ID var faqPageTitleRes: Int = R.string.kau_about_faq_intro var faqPageTitle: String? = null set(value) { field = value - faqPageTitleRes = INVALID_ID //reset res so we don't use our default + faqPageTitleRes = INVALID_ID // reset res so we don't use our default } /** * Whether new lines should be included @@ -186,7 +186,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde } override fun onDestroy() { - AnimHolder.decelerateInterpolator.invalidate() //clear the reference to the interpolators we've used + AnimHolder.decelerateInterpolator.invalidate() // clear the reference to the interpolators we've used super.onDestroy() } } diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt index d51db46..d92f6a7 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt @@ -47,7 +47,7 @@ class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem MIN_FLING_VELOCITY) || (edgeFlag == SWIPE_EDGE_RIGHT && xvel < -MIN_FLING_VELOCITY) || (edgeFlag == SWIPE_EDGE_TOP && yvel > MIN_FLING_VELOCITY) || @@ -400,7 +400,7 @@ internal class SwipeBackLayout @JvmOverloads constructor( ) result = exitCaptureOffsets(edgeFlag, releasedChild) } else { - //threshold met; fling to designated side + // threshold met; fling to designated side result = exitCaptureOffsets(edgeFlag, releasedChild) } dragHelper.settleCapturedViewAt(result.first, result.second) diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt index b2a0d27..b00d951 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt @@ -116,7 +116,7 @@ class CollapsibleViewDelegate : CollapsibleView { override fun collapse(animate: Boolean) = setExpanded(false, animate) override fun setExpanded(expand: Boolean) = setExpanded(expand, true) override fun setExpanded(expand: Boolean, animate: Boolean) { - if (expand == expanded) return //state already matches + if (expand == expanded) return // state already matches val target = if (expand) 1f else 0f if (animate) animateSize(target) else expansion = target } diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt index 6481306..61e6f30 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt @@ -113,17 +113,17 @@ class MeasureSpecDelegate : MeasureSpecContract { view.parentViewGroup.getWindowVisibleDisplayFrame(parentFrame) var width = View.MeasureSpec.getSize(widthMeasureSpec).toFloat() var height = View.MeasureSpec.getSize(heightMeasureSpec).toFloat() - //first cycle - relative to parent + // first cycle - relative to parent if (relativeHeightToParent > 0) height = relativeHeightToParent * parentFrame.height() if (relativeWidthToParent > 0) width = relativeWidthToParent * parentFrame.width() - //second cycle - relative to each other + // second cycle - relative to each other if (relativeHeight > 0) height = relativeHeight * width else if (relativeWidth > 0) width = relativeWidth * height - //third cycle - relative to each other + // third cycle - relative to each other if (postRelativeHeight > 0) height = postRelativeHeight * width else if (postRelativeWidth > 0) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index 21141f1..fe210b2 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -85,7 +85,7 @@ inline fun Activity.restart(intentBuilder: Intent.() -> Unit = {}) { i.putExtras(oldExtras) i.intentBuilder() startActivity(i) - overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_fade_out) //No transitions + overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_fade_out) // No transitions finish() overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_fade_out) } diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt index 3de0297..ab7b341 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -157,7 +157,7 @@ fun String.toColor(): Int { return Color.parseColor(toParse) } -//Get ColorStateList +// Get ColorStateList fun Context.colorStateList(@ColorInt color: Int): ColorStateList { val disabledColor = color.adjustAlpha(0.3f) return ColorStateList( 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 d002fb8..62e5716 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -113,7 +113,7 @@ fun Context.startLink(vararg url: String?) { fun Context.startLink(@StringRes url: Int) = startLink(string(url)) -//Toast helpers +// Toast helpers inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = context.toast(id, duration, log) @@ -130,7 +130,7 @@ inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: B const val INVALID_ID = 0 -//Resource retrievers +// Resource retrievers inline fun Context.string(@StringRes id: Int): String = getString(id) inline fun Context.string(@StringRes id: Int, fallback: String?): String? = @@ -161,7 +161,7 @@ inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(th inline fun Context.plural(@PluralsRes id: Int, quantity: Number) = resources.getQuantityString(id, quantity.toInt(), quantity.toInt()) -//Attr retrievers +// Attr retrievers fun Context.resolveColor(@AttrRes attr: Int, @ColorInt fallback: Int = 0): Int { val a = theme.obtainStyledAttributes(intArrayOf(attr)) try { diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt index aaef160..fac9421 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -246,7 +246,7 @@ private fun requiredResettable(ids: IntArray, finder: T.(Int) -> V private fun optionalResettable(ids: IntArray, finder: T.(Int) -> View?) = LazyResettable { t: T, _ -> ids.map { t.finder(it) as V? }.filterNotNull() } -//Like Kotterknife's lazy delegate but is resettable +// Like Kotterknife's lazy delegate but is resettable private class LazyResettable(initializer: (T, KProperty<*>) -> V) : Lazy(initializer) { override fun getValue(thisRef: T, property: KProperty<*>): V { KotterknifeRegistry.register(thisRef!!, this) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt index 4055847..0bd534e 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt @@ -54,13 +54,13 @@ fun Context.isAppEnabled(packageName: String): Boolean { @KauUtils fun Context.showAppInfo(packageName: String) { try { - //Open the specific App Info page: + // Open the specific App Info page: val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) intent.data = Uri.parse("package:$packageName") startActivity(intent) } catch (e: ActivityNotFoundException) { e.printStackTrace() - //Open the generic Apps page: + // Open the generic Apps page: val intent = Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS) startActivity(intent) } diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt index 73d7d6c..afde735 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt @@ -43,7 +43,7 @@ fun Context.kauParseFaq( resources.getXml(xmlRes).use { parser: XmlResourceParser -> var eventType = parser.eventType var question: Spanned? = null - var flag = -1 //-1, 0, 1 -> invalid, question, answer + var flag = -1 // -1, 0, 1 -> invalid, question, answer while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { flag = when (parser.name) { diff --git a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt index c406901..d43901f 100644 --- a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt +++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt @@ -50,16 +50,16 @@ class DebounceTest { fun multipleDebounces() { var i = 0 val debounce = debounce(20) { i += it } - debounce(1) //ignore -> i = 0 + debounce(1) // ignore -> i = 0 Thread.sleep(10) assertEquals(0, i) - debounce(2) //accept -> i = 2 + debounce(2) // accept -> i = 2 Thread.sleep(30) assertEquals(2, i) - debounce(4) //ignore -> i = 2 + debounce(4) // ignore -> i = 2 Thread.sleep(10) assertEquals(2, i) - debounce(8) //accept -> i = 10 + debounce(8) // accept -> i = 10 Thread.sleep(30) assertEquals(10, i) } diff --git a/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt b/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt index 4dc4a34..e3d4e5b 100644 --- a/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt +++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt @@ -47,10 +47,10 @@ class StreamsTest { items.add(3, thePotato) assertEquals(result.size + 1, items.size, "Invalid list addition") assertEquals(2, items.filter { it.id == 9 }.size, "Invalid number of potatoes with id 9") - items.kauRemoveIf { it === thePotato } //removal by reference + items.kauRemoveIf { it === thePotato } // removal by reference assertEquals(result.size, items.size, "Invalid list size after removal") assertEquals(result, items) - items.kauRemoveIf { it == thePotato } //removal by equality + items.kauRemoveIf { it == thePotato } // removal by equality assertEquals(result.size - 1, items.size, "Invalid list removal based on equality") } } diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index 5531f59..be98ffa 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -159,7 +159,7 @@ class ThemableIItemDelegate : ThemableIItem, ThemableIItemColors by ThemableIIte override fun bindBackgroundRipple(vararg views: View?) { val background = backgroundColor ?: return val foreground = accentColor ?: textColor ?: backgroundColor - ?: return //default to normal background + ?: return // default to normal background val ripple = createSimpleRippleDrawable(foreground, background) views.forEach { it?.background = ripple } } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt index f11afde..800a355 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt @@ -74,7 +74,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { @SuppressLint("NewApi") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - //setup layout + // setup layout setContentView(R.layout.kau_pref_activity) setSupportActionBar(toolbar) supportActionBar?.apply { @@ -88,7 +88,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { statusBarColor = 0x30000000 kau_toolbar_ripple.set(resolveColor(R.attr.colorPrimary)) kau_ripple.set(resolveColor(android.R.attr.colorBackground)) - //setup prefs + // setup prefs val core = CoreAttributeBuilder() val builder = kPrefCoreAttributes() core.builder() diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt index f4f4a65..a867d06 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt @@ -39,7 +39,7 @@ open class KPrefCheckbox(builder: BaseContract) : KPrefItemBase(R.layout.kau_pref_checkbox) withAccentColor(checkbox::tint) checkbox.isChecked = pref - checkbox.jumpDrawablesToCurrentState() //Cancel the animation + checkbox.jumpDrawablesToCurrentState() // Cancel the animation } override val type: Int diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt index 5de1f83..9abdf09 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt @@ -61,7 +61,7 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( } withAccentColor(seekbar::tint) text.text = - builder.toText(seekbar.progress.fromProgress) //set initial text in case no change occurs + builder.toText(seekbar.progress.fromProgress) // set initial text in case no change occurs seekbar.progress = pref.toProgress seekbar.isEnabled = builder.enabler() } 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 873289f..e801848 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt @@ -40,7 +40,7 @@ class MediaItemBasic(val data: MediaModel) : @SuppressLint("NewApi") fun bindEvents(activity: Activity, fastAdapter: FastAdapter) { fastAdapter.getSelectExtension().isSelectable = true - //add image data and return right away + // add image data and return right away fastAdapter.onClickListener = { _, _, item, _ -> activity.finish(arrayListOf(item.data)) true 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 dceb1df..9b8bdfa 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -157,7 +157,7 @@ abstract class MediaPickerCore( } } - //Sort by descending date + // Sort by descending date var sortQuery = MediaStore.MediaColumns.DATE_MODIFIED + " DESC" override fun onCreateLoader(id: Int, args: Bundle?): Loader { @@ -264,8 +264,8 @@ abstract class MediaPickerCore( }.mapNotNull { DocumentsContract.getDocumentId(it).split(":").getOrNull(1) }.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 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 ) diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index 11d19e5..4fe941b 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -47,7 +47,7 @@ class MainActivity : KPrefActivity() { companion object { - //some of the most common english words for show + // some of the most common english words for show val wordBank: List by lazy { listOf( "the", "name", "of", "very", "to", "through", diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt index 7cf6cc1..68dde2a 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt @@ -33,7 +33,7 @@ class PermissionCheckbox(val permission: String) : KauIItem Unit = {}) { TransitionManager.beginDelayedTransition(kau_search_cardview, - //we are only using change bounds, as the recyclerview items may be animated as well, - //which causes a measure IllegalStateException + // we are only using change bounds, as the recyclerview items may be animated as well, + // which causes a measure IllegalStateException TransitionSet().addTransition(ChangeBounds()).apply { duration = configs.transitionDuration builder() -- cgit v1.2.3 From ff2a6237d1412b400644650f12389fefe73480c8 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 16 Aug 2019 00:26:22 -0700 Subject: Apply spotless --- about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt | 2 +- .../main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt index 5c3a00b..f02d073 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -79,7 +79,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde super.onCreate(savedInstanceState) setContentView(R.layout.kau_activity_about) pageStatus = IntArray(panels.size) - pageStatus[0] = 2 //the first page is instantly visible + pageStatus[0] = 2 // the first page is instantly visible if (configs.textColor != null) { about_indicator.setColour(configs.textColor!!) } diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt index 4631aec..2a057cb 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt @@ -127,7 +127,7 @@ class CollapsibleViewDelegate : CollapsibleView { override fun setExpanded(expand: Boolean) = setExpanded(expand, true) override fun setExpanded(expand: Boolean, animate: Boolean) { if (expand == expanded) { - return //state already matches + return // state already matches } val target = if (expand) 1f else 0f if (animate) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt index b1e442f..728ba7b 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt @@ -115,7 +115,7 @@ class MeasureSpecDelegate : MeasureSpecContract { view.parentViewGroup.getWindowVisibleDisplayFrame(parentFrame) var width = View.MeasureSpec.getSize(widthMeasureSpec).toFloat() var height = View.MeasureSpec.getSize(heightMeasureSpec).toFloat() - //first cycle - relative to parent + // first cycle - relative to parent if (relativeHeightToParent > 0) { height = relativeHeightToParent * parentFrame.height() } @@ -128,7 +128,7 @@ class MeasureSpecDelegate : MeasureSpecContract { } else if (relativeWidth > 0) { width = relativeWidth * height } - //third cycle - relative to each other + // third cycle - relative to each other if (postRelativeHeight > 0) { height = postRelativeHeight * width } else if (postRelativeWidth > 0) { -- cgit v1.2.3