From fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 24 Dec 2018 01:17:31 -0500 Subject: Enhancement/ktlint (#179) * Add spotless dependency * Apply ktlint * Add license headers --- .../kau/kpref/activity/items/KPrefCheckbox.kt | 20 ++++++-- .../kau/kpref/activity/items/KPrefColorPicker.kt | 29 ++++++++--- .../kau/kpref/activity/items/KPrefHeader.kt | 18 ++++++- .../kau/kpref/activity/items/KPrefItemBase.kt | 29 ++++++++--- .../kau/kpref/activity/items/KPrefItemCore.kt | 56 +++++++++++++++------- .../kau/kpref/activity/items/KPrefPlainText.kt | 22 +++++++-- .../kau/kpref/activity/items/KPrefSeekbar.kt | 26 +++++++--- .../kau/kpref/activity/items/KPrefSubItems.kt | 24 ++++++++-- .../kau/kpref/activity/items/KPrefText.kt | 26 +++++++--- .../kau/kpref/activity/items/KPrefTimePicker.kt | 29 +++++++---- 10 files changed, 215 insertions(+), 64 deletions(-) (limited to 'kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items') 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 0a7922e..0f025a6 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 @@ -1,7 +1,22 @@ +/* + * Copyright 2018 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.activity.items -import androidx.appcompat.widget.AppCompatCheckBox import android.widget.CheckBox +import androidx.appcompat.widget.AppCompatCheckBox import ca.allanwang.kau.kpref.activity.KClick import ca.allanwang.kau.kpref.activity.R import ca.allanwang.kau.utils.tint @@ -28,5 +43,4 @@ open class KPrefCheckbox(builder: BaseContract) : KPrefItemBase Int, - setter: (value: Int) -> Unit + class KPrefColorBuilder( + globalOptions: GlobalOptions, + titleId: Int, + getter: () -> Int, + setter: (value: Int) -> Unit ) : KPrefColorContract, BaseContract by BaseBuilder(globalOptions, titleId, getter, setter), - ColorContract by ColorBuilder() { + ColorContract by ColorBuilder() { override var showPreview: Boolean = true } override fun getType(): Int = R.id.kau_item_pref_color_picker - -} \ No newline at end of file +} 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 9b63a52..7d73322 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 @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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.activity.items import ca.allanwang.kau.kpref.activity.R @@ -18,5 +33,4 @@ open class KPrefHeader(builder: CoreContract) : KPrefItemCore(builder) { } override fun getType() = R.id.kau_item_pref_header - -} \ No newline at end of file +} 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 aa60fcd..6690574 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 @@ -1,7 +1,22 @@ +/* + * Copyright 2018 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.activity.items -import androidx.annotation.CallSuper import android.view.View +import androidx.annotation.CallSuper import ca.allanwang.kau.kpref.activity.GlobalOptions import ca.allanwang.kau.kpref.activity.KClick import ca.allanwang.kau.kpref.activity.R @@ -84,14 +99,14 @@ abstract class KPrefItemBase(protected val base: BaseContract) : KPrefItem /** * Default implementation of [BaseContract] */ - class BaseBuilder(globalOptions: GlobalOptions, - titleId: Int, - override val getter: () -> T, - override val setter: (value: T) -> Unit + class BaseBuilder( + globalOptions: GlobalOptions, + titleId: Int, + override val getter: () -> T, + override val setter: (value: T) -> Unit ) : CoreContract by CoreBuilder(globalOptions, titleId), BaseContract { override var enabler: () -> Boolean = { true } override var onClick: (KClick.() -> Unit)? = null override var onDisabledClick: (KClick.() -> Unit)? = null } - -} \ No newline at end of file +} 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 4e8ecbe..fc632ce 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 @@ -1,23 +1,43 @@ +/* + * Copyright 2018 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.activity.items import android.annotation.SuppressLint -import androidx.annotation.CallSuper -import androidx.annotation.IdRes -import androidx.annotation.LayoutRes -import androidx.annotation.StringRes -import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import androidx.annotation.CallSuper +import androidx.annotation.IdRes +import androidx.annotation.LayoutRes +import androidx.annotation.StringRes +import androidx.recyclerview.widget.RecyclerView import ca.allanwang.kau.adapters.ThemableIItem import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.kpref.activity.GlobalOptions import ca.allanwang.kau.kpref.activity.KPrefMarker import ca.allanwang.kau.kpref.activity.R -import ca.allanwang.kau.utils.* +import ca.allanwang.kau.utils.INVALID_ID +import ca.allanwang.kau.utils.adjustAlpha +import ca.allanwang.kau.utils.buildIsLollipopAndUp +import ca.allanwang.kau.utils.gone +import ca.allanwang.kau.utils.setIcon +import ca.allanwang.kau.utils.visible import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.iconics.typeface.IIcon @@ -28,7 +48,7 @@ import com.mikepenz.iconics.typeface.IIcon */ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem(), - ThemableIItem by ThemableIItemDelegate() { + ThemableIItem by ThemableIItemDelegate() { final override fun getViewHolder(v: View) = ViewHolder(v) @@ -69,13 +89,15 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem Unit) = - withColor(core.globalOptions.accentColor, action) + withColor(core.globalOptions.accentColor, action) protected inline fun withTextColor(action: (color: Int) -> Unit) = - withColor(core.globalOptions.textColor, action) + withColor(core.globalOptions.textColor, action) - protected inline fun withColor(noinline supplier: (() -> Int)?, - action: (color: Int) -> Unit) { + protected inline fun withColor( + noinline supplier: (() -> Int)?, + action: (color: Int) -> Unit + ) { val color = supplier?.invoke() ?: return action(color) } @@ -116,8 +138,10 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem bindInnerView(@LayoutRes id: Int, onFirstBind: (T) -> Unit): T { val innerFrame = this.innerFrame - ?: throw IllegalStateException("Cannot bind inner view when innerFrame does not exist") + ?: throw IllegalStateException("Cannot bind inner view when innerFrame does not exist") if (innerView !is T) { innerFrame.removeAllViews() LayoutInflater.from(innerFrame.context).inflate(id, innerFrame) @@ -162,7 +186,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem bindLowerView(@LayoutRes id: Int, onFirstBind: (T) -> Unit): T { val lowerFrame = this.lowerFrame - ?: throw IllegalStateException("Cannot bind inner view when lowerContent does not exist") + ?: throw IllegalStateException("Cannot bind inner view when lowerContent does not exist") if (lowerContent !is T) { lowerFrame.removeAllViews() LayoutInflater.from(lowerFrame.context).inflate(id, lowerFrame) @@ -173,4 +197,4 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem.defaultOnClick() = Unit class KPrefPlainTextBuilder( - globalOptions: GlobalOptions, - titleId: Int + globalOptions: GlobalOptions, + titleId: Int ) : BaseContract by BaseBuilder(globalOptions, titleId, {}, {}) override fun getType(): Int = R.id.kau_item_pref_plain_text - -} \ No newline at end of file +} 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 ce61e8f..e70a374 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 @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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.activity.items import android.widget.SeekBar @@ -67,10 +82,10 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( * Default implementation of [KPrefSeekbarContract] */ class KPrefSeekbarBuilder( - globalOptions: GlobalOptions, - titleId: Int, - getter: () -> Int, - setter: (value: Int) -> Unit + globalOptions: GlobalOptions, + titleId: Int, + getter: () -> Int, + setter: (value: Int) -> Unit ) : KPrefSeekbarContract, BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { override var min: Int = 0 @@ -103,5 +118,4 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase( get() = this * increment + min override fun getType(): Int = R.id.kau_item_pref_seekbar - -} \ No newline at end of file +} 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 6753142..1fa528b 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 @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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.activity.items import android.view.View @@ -31,11 +46,10 @@ open class KPrefSubItems(open val builder: KPrefSubItemsContract) : KPrefItemCor * Default implementation of [KPrefTextContract] */ class KPrefSubItemsBuilder( - globalOptions: GlobalOptions, - titleId: Int, - override val itemBuilder: KPrefAdapterBuilder.() -> Unit + globalOptions: GlobalOptions, + titleId: Int, + override val itemBuilder: KPrefAdapterBuilder.() -> Unit ) : KPrefSubItemsContract, CoreContract by CoreBuilder(globalOptions, titleId) override fun getType(): Int = R.id.kau_item_pref_sub_item - -} \ No newline at end of file +} 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 2ab911b..ac8416d 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 @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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.activity.items import android.widget.TextView @@ -48,14 +63,13 @@ open class KPrefText(open val builder: KPrefTextContract) : KPrefItemBase< * Default implementation of [KPrefTextContract] */ class KPrefTextBuilder( - globalOptions: GlobalOptions, - titleId: Int, - getter: () -> T, - setter: (value: T) -> Unit + globalOptions: GlobalOptions, + titleId: Int, + getter: () -> T, + setter: (value: T) -> Unit ) : 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 - -} \ No newline at end of file +} 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 f6fc40a..7242bbe 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 @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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.activity.items import android.app.TimePickerDialog @@ -5,7 +20,7 @@ import android.widget.TimePicker import ca.allanwang.kau.kpref.activity.GlobalOptions import ca.allanwang.kau.kpref.activity.KClick import ca.allanwang.kau.kpref.activity.R -import java.util.* +import java.util.Locale /** * Created by Allan Wang on 2017-06-14. @@ -30,10 +45,10 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText< * Default implementation of [KPrefTimeContract] */ class KPrefTimeBuilder( - globalOptions: GlobalOptions, - titleId: Int, - getter: () -> Int, - setter: (value: Int) -> Unit + globalOptions: GlobalOptions, + titleId: Int, + getter: () -> Int, + setter: (value: Int) -> Unit ) : KPrefTimeContract, BaseContract by BaseBuilder(globalOptions, titleId, getter, setter) { override var use24HourFormat: Boolean = false @@ -50,15 +65,13 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText< else 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 - } private val Int.splitTime: Pair get() = Pair(this / 100, this % 100) private val Pair.mergeTime: Int - get() = first * 100 + second \ No newline at end of file + get() = first * 100 + second -- cgit v1.2.3