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 --- .../ca/allanwang/kau/about/AboutActivityBase.kt | 27 ++++++++++--- .../kotlin/ca/allanwang/kau/about/AboutBinder.kt | 21 ++++++++-- .../ca/allanwang/kau/about/AboutPanelDelegate.kt | 41 +++++++++++++++----- .../ca/allanwang/kau/about/CollapsibleTextView.kt | 23 +++++++++-- .../kotlin/ca/allanwang/kau/about/CutoutIItem.kt | 22 +++++++++-- .../main/kotlin/ca/allanwang/kau/about/FaqIItem.kt | 41 +++++++++++++------- .../kotlin/ca/allanwang/kau/about/LibraryIItem.kt | 45 +++++++++++++++------- 7 files changed, 167 insertions(+), 53 deletions(-) (limited to 'about/src/main/kotlin/ca/allanwang') 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 9667f47..79077c5 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.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.about import android.graphics.drawable.Drawable @@ -32,7 +47,8 @@ import kotlinx.android.synthetic.main.kau_activity_about.* * Note that for the auto detection to work, the R fields must be excluded from Proguard * Manual lib listings and other extra modifications can be done so by overriding the open functions */ -abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilder: Configs.() -> Unit = {}) : KauBaseActivity(), ViewPager.OnPageChangeListener { +abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilder: Configs.() -> Unit = {}) : + KauBaseActivity(), ViewPager.OnPageChangeListener { val currentPage: Int get() = about_pager.currentItem @@ -73,7 +89,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde about_draggable_frame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { override fun onDragDismissed() { window.returnTransition = TransitionInflater.from(this@AboutActivityBase) - .inflateTransition(if (about_draggable_frame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top) + .inflateTransition(if (about_draggable_frame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top) panels[currentPage].recycler?.stopScroll() finishAfterTransition() } @@ -113,7 +129,6 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde * Feel free to add your own items to the adapter in here */ open fun postInflateMainPage(adapter: FastItemThemedAdapter>) { - } /** @@ -123,7 +138,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde * This is fetched asynchronously and you may override it to customize the list */ open fun getLibraries(libs: Libs): List = - libs.prepareLibraries(this, null, null, true, true, true)!! + libs.prepareLibraries(this, null, null, true, true, true)!! /* * ------------------------------------------------------------------- @@ -156,7 +171,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde */ private fun getPage(position: Int, parent: ViewGroup): View { if (views[position] == null) views[position] = panels[position] - .inflatePage(this@AboutActivityBase, parent, position) + .inflatePage(this@AboutActivityBase, parent, position) return views[position]!! } } @@ -174,4 +189,4 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde AnimHolder.decelerateInterpolator.invalidate() //clear the reference to the interpolators we've used super.onDestroy() } -} \ No newline at end of file +} diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutBinder.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutBinder.kt index c99f7c2..1183113 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutBinder.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutBinder.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.about import android.content.Context @@ -12,6 +27,6 @@ import ca.allanwang.kau.utils.withSceneTransitionAnimation * About activity launcher */ inline fun Context.kauLaunchAbout() = - startActivity(bundleBuilder = { - withSceneTransitionAnimation(this@kauLaunchAbout) - }) \ No newline at end of file + startActivity(bundleBuilder = { + withSceneTransitionAnimation(this@kauLaunchAbout) + }) 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 6698dba..35c1322 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt @@ -1,15 +1,37 @@ +/* + * 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.about -import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView import ca.allanwang.kau.adapters.FastItemThemedAdapter import ca.allanwang.kau.animators.FadeScaleAnimatorAdd import ca.allanwang.kau.animators.KauAnimator import ca.allanwang.kau.animators.NoAnimatorChange import ca.allanwang.kau.iitems.HeaderIItem -import ca.allanwang.kau.utils.* +import ca.allanwang.kau.utils.AnimHolder +import ca.allanwang.kau.utils.KAU_BOTTOM +import ca.allanwang.kau.utils.colorToForeground +import ca.allanwang.kau.utils.drawable +import ca.allanwang.kau.utils.fullLinearRecycler +import ca.allanwang.kau.utils.postDelayed +import ca.allanwang.kau.utils.string +import ca.allanwang.kau.utils.withMarginDecoration import ca.allanwang.kau.xml.kauParseFaq import com.mikepenz.aboutlibraries.Libs import com.mikepenz.fastadapter.IItem @@ -76,8 +98,8 @@ abstract class AboutPanelRecycler : AboutPanelContract { override fun onInflatingPage(activity: AboutActivityBase, recycler: RecyclerView, position: Int) { recycler.adapter = adapter recycler.itemAnimator = KauAnimator( - addAnimator = FadeScaleAnimatorAdd(scaleFactor = 0.7f, itemDelayFactor = 0.2f), - changeAnimator = NoAnimatorChange() + addAnimator = FadeScaleAnimatorAdd(scaleFactor = 0.7f, itemDelayFactor = 0.2f), + changeAnimator = NoAnimatorChange() ).apply { addDuration = 300; interpolator = AnimHolder.decelerateInterpolator(recycler.context) } } @@ -136,7 +158,6 @@ open class AboutPanelMain : AboutPanelRecycler() { } override fun addItemsImpl(activity: AboutActivityBase, position: Int) {} - } /** @@ -155,7 +176,8 @@ open class AboutPanelLibs : AboutPanelRecycler() { override fun loadItems(activity: AboutActivityBase, position: Int) { doAsync { with(activity) { - items = getLibraries(if (rClass == null) Libs(activity) else Libs(this, Libs.toStringArray(rClass.fields))) + items = + getLibraries(if (rClass == null) Libs(activity) else Libs(this, Libs.toStringArray(rClass.fields))) .map(::LibraryIItem) if (pageStatus[position] == 1) uiThread { addItems(activity, position) } @@ -166,7 +188,7 @@ open class AboutPanelLibs : AboutPanelRecycler() { override fun addItemsImpl(activity: AboutActivityBase, position: Int) { with(activity.configs) { adapter.add(HeaderIItem(text = libPageTitle, textRes = libPageTitleRes)) - .add(items) + .add(items) } } } @@ -191,8 +213,7 @@ open class AboutPanelFaqs : AboutPanelRecycler() { override fun addItemsImpl(activity: AboutActivityBase, position: Int) { with(activity.configs) { adapter.add(HeaderIItem(text = faqPageTitle, textRes = faqPageTitleRes)) - .add(items) + .add(items) } } - -} \ No newline at end of file +} diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/CollapsibleTextView.kt b/about/src/main/kotlin/ca/allanwang/kau/about/CollapsibleTextView.kt index 3dbb87e..c9b8b93 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/CollapsibleTextView.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/CollapsibleTextView.kt @@ -1,9 +1,24 @@ +/* + * 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.about import android.content.Context import android.content.res.Configuration -import androidx.appcompat.widget.AppCompatTextView import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView import ca.allanwang.kau.ui.views.CollapsibleView import ca.allanwang.kau.ui.views.CollapsibleViewDelegate @@ -12,7 +27,9 @@ import ca.allanwang.kau.ui.views.CollapsibleViewDelegate * */ class CollapsibleTextView @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : AppCompatTextView(context, attrs, defStyleAttr), CollapsibleView by CollapsibleViewDelegate() { init { @@ -29,4 +46,4 @@ class CollapsibleTextView @JvmOverloads constructor( val result = getCollapsibleDimension() setMeasuredDimension(result.first, result.second) } -} \ No newline at end of file +} 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 630a48e..b51c9c8 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.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.about -import androidx.recyclerview.widget.RecyclerView import android.view.View +import androidx.recyclerview.widget.RecyclerView import ca.allanwang.kau.adapters.ThemableIItem import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.iitems.KauIItem @@ -13,7 +28,7 @@ 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( - R.layout.kau_iitem_cutout, ::ViewHolder, R.id.kau_item_cutout + R.layout.kau_iitem_cutout, ::ViewHolder, R.id.kau_item_cutout ), ThemableIItem by ThemableIItemDelegate() { override fun isSelectable(): Boolean = false @@ -37,5 +52,4 @@ class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem( - R.layout.kau_iitem_faq, ::ViewHolder, R.id.kau_item_faq + R.layout.kau_iitem_faq, ::ViewHolder, R.id.kau_item_faq ), ThemableIItem by ThemableIItemDelegate() { companion object { fun bindEvents(fastAdapter: FastAdapter>) { fastAdapter.withSelectable(false) - .withEventHook(object : ClickEventHook>() { + .withEventHook(object : ClickEventHook>() { - override fun onBind(viewHolder: RecyclerView.ViewHolder): View? = (viewHolder as? ViewHolder)?.questionContainer + override fun onBind(viewHolder: RecyclerView.ViewHolder): View? = + (viewHolder as? ViewHolder)?.questionContainer - override fun onClick(v: View, position: Int, adapter: FastAdapter>, item: IItem<*, *>) { - if (item !is FaqIItem) return - item.isExpanded = !item.isExpanded - v.parentViewGroup.findViewById(R.id.faq_item_answer).setExpanded(item.isExpanded) - } - - }) + override fun onClick(v: View, position: Int, adapter: FastAdapter>, item: IItem<*, *>) { + if (item !is FaqIItem) return + item.isExpanded = !item.isExpanded + v.parentViewGroup.findViewById(R.id.faq_item_answer) + .setExpanded(item.isExpanded) + } + }) } } @@ -83,5 +99,4 @@ class FaqIItem(val content: FaqItem) : KauIItem( - R.layout.kau_iitem_library, ::ViewHolder, R.id.kau_item_library + R.layout.kau_iitem_library, ::ViewHolder, R.id.kau_item_library ), ThemableIItem by ThemableIItemDelegate() { companion object { fun bindEvents(fastAdapter: FastAdapter>) { fastAdapter.withSelectable(false) - .withOnClickListener { v, _, item, _ -> - if (item !is LibraryIItem) - false - else - with(item.lib) { - v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) - true - } - } + .withOnClickListener { v, _, item, _ -> + if (item !is LibraryIItem) + false + else + with(item.lib) { + v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) + true + } + } } } @@ -48,7 +63,10 @@ class LibraryIItem(val lib: Library) : KauIItem lib.libraryDescription - Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> Html.fromHtml(lib.libraryDescription, Html.FROM_HTML_MODE_LEGACY) + Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> Html.fromHtml( + lib.libraryDescription, + Html.FROM_HTML_MODE_LEGACY + ) else -> Html.fromHtml(lib.libraryDescription) } bottomDivider.gone() @@ -90,5 +108,4 @@ class LibraryIItem(val lib: Library) : KauIItem