diff options
Diffstat (limited to 'about')
6 files changed, 82 insertions, 50 deletions
diff --git a/about/build.gradle b/about/build.gradle index b970530..274ef5c 100644 --- a/about/build.gradle +++ b/about/build.gradle @@ -1,3 +1,5 @@ +import kau.Dependencies + apply from: '../android-lib.gradle' android { @@ -10,7 +12,7 @@ dependencies { implementation project(':core-ui') implementation project(':fastadapter') - api kau.Dependencies.aboutLibraries + api Dependencies.aboutLibraries } apply from: '../artifacts.gradle' 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 79077c5..7ba7811 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -33,7 +33,7 @@ import ca.allanwang.kau.utils.INVALID_ID import ca.allanwang.kau.utils.dimenPixelSize import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.entity.Library -import com.mikepenz.fastadapter.IItem +import com.mikepenz.fastadapter.GenericItem import kotlinx.android.synthetic.main.kau_activity_about.* /** @@ -47,7 +47,10 @@ 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 = {}) : +abstract class AboutActivityBase( + val rClass: Class<*>?, + private val configBuilder: Configs.() -> Unit = {} +) : KauBaseActivity(), ViewPager.OnPageChangeListener { val currentPage: Int @@ -69,7 +72,9 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde val panels: List<AboutPanelContract> by lazy { val defaultPanels = mutableListOf(AboutPanelMain(), AboutPanelLibs()) - if (configs.faqXmlRes != INVALID_ID) defaultPanels.add(AboutPanelFaqs()) + if (configs.faqXmlRes != INVALID_ID) { + defaultPanels.add(AboutPanelFaqs()) + } defaultPanels } @@ -77,8 +82,10 @@ 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 - if (configs.textColor != null) about_indicator.setColour(configs.textColor!!) + pageStatus[0] = 2 // the first page is instantly visible + if (configs.textColor != null) { + about_indicator.setColour(configs.textColor!!) + } with(about_pager) { adapter = AboutPagerAdapter() pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal) @@ -86,7 +93,8 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde addOnPageChangeListener(this@AboutActivityBase) } about_indicator.setViewPager(about_pager) - about_draggable_frame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { + 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) @@ -107,14 +115,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 @@ -128,7 +136,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde * Open hook called just before the main page view is returned * Feel free to add your own items to the adapter in here */ - open fun postInflateMainPage(adapter: FastItemThemedAdapter<IItem<*, *>>) { + open fun postInflateMainPage(adapter: FastItemThemedAdapter<GenericItem>) { } /** @@ -138,7 +146,14 @@ 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<Library> = - libs.prepareLibraries(this, null, null, true, true, true)!! + libs.prepareLibraries( + this, + null, + null, + true, + true, + true + ) /* * ------------------------------------------------------------------- @@ -178,7 +193,8 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde override fun onPageScrollStateChanged(state: Int) = Unit - override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) = Unit + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) = + Unit override fun onPageSelected(position: Int) { if (pageStatus[position] == 0) pageStatus[position] = 1 // mark as seen if previously null @@ -186,7 +202,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/AboutPanelDelegate.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt index a5d9c17..ba7330c 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt @@ -34,7 +34,7 @@ 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 +import com.mikepenz.fastadapter.GenericItem import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -48,11 +48,11 @@ interface AboutPanelContract { /** * Model list to be added to [adapter] */ - var items: List<IItem<*, *>>? + var items: List<GenericItem> /** * The adapter, will be late initialized as it depends on configs */ - var adapter: FastItemThemedAdapter<IItem<*, *>> + var adapter: FastItemThemedAdapter<GenericItem> /** * Reference to the recyclerview, will be used to stop scrolling upon exit */ @@ -90,9 +90,9 @@ interface AboutPanelContract { abstract class AboutPanelRecycler : AboutPanelContract { - override var items: List<IItem<*, *>>? = null + override var items: List<GenericItem> = emptyList() - override lateinit var adapter: FastItemThemedAdapter<IItem<*, *>> + override lateinit var adapter: FastItemThemedAdapter<GenericItem> override var recycler: RecyclerView? = null @@ -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..d92f6a7 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<CutoutIItem, CutoutIItem.ViewHolder>( +class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem.ViewHolder>( 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<Any>) { super.bindView(holder, payloads) @@ -45,7 +47,7 @@ class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem super.unbindView(holder) with(holder) { cutout.drawable = null - cutout.text = "Text" //back to default + cutout.text = "Text" // back to default } } 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 755ac81..977b7ff 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt @@ -30,31 +30,37 @@ import ca.allanwang.kau.utils.parentViewGroup import ca.allanwang.kau.utils.setPaddingLeft import ca.allanwang.kau.xml.FaqItem import com.mikepenz.fastadapter.FastAdapter -import com.mikepenz.fastadapter.IItem +import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.listeners.ClickEventHook +import com.mikepenz.fastadapter.select.getSelectExtension /** * Created by Allan Wang on 2017-08-02. */ -class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolder>( +class FaqIItem(val content: FaqItem) : KauIItem<FaqIItem.ViewHolder>( R.layout.kau_iitem_faq, ::ViewHolder, R.id.kau_item_faq ), ThemableIItem by ThemableIItemDelegate() { companion object { - fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) { - fastAdapter.withSelectable(false) - .withEventHook(object : ClickEventHook<IItem<*, *>>() { + fun bindEvents(fastAdapter: FastAdapter<GenericItem>) { + fastAdapter.getSelectExtension().isSelectable = true + fastAdapter.addEventHook(object : ClickEventHook<GenericItem>() { - 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<IItem<*, *>>, item: IItem<*, *>) { - if (item !is FaqIItem) return - item.isExpanded = !item.isExpanded - v.parentViewGroup.findViewById<CollapsibleTextView>(R.id.faq_item_answer) - .setExpanded(item.isExpanded) - } - }) + override fun onClick( + v: View, + position: Int, + fastAdapter: FastAdapter<GenericItem>, + item: GenericItem + ) { + if (item !is FaqIItem) return + item.isExpanded = !item.isExpanded + v.parentViewGroup.findViewById<CollapsibleTextView>(R.id.faq_item_answer) + .setExpanded(item.isExpanded) + } + }) } } @@ -69,7 +75,7 @@ class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolde answer.setExpanded(isExpanded, false) if (accentColor != null) answer.setLinkTextColor(accentColor!!) answer.text = content.answer - answer.post { answer.setPaddingLeft(16.dpToPx + number.width) } + answer.post { answer.setPaddingLeft(16.dpToPx + number.width) } // TODO not performant at all; and doesn't align across all items bindTextColor(number, question) bindTextColorSecondary(answer) val bg2 = backgroundColor?.colorToForeground(0.1f) 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 33aac09..cd53f55 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -29,31 +29,35 @@ import ca.allanwang.kau.utils.startLink import ca.allanwang.kau.utils.visible import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.fastadapter.FastAdapter -import com.mikepenz.fastadapter.IItem +import com.mikepenz.fastadapter.GenericItem +import com.mikepenz.fastadapter.select.getSelectExtension /** * Created by Allan Wang on 2017-06-27. */ -class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem, LibraryIItem.ViewHolder>( +class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem.ViewHolder>( R.layout.kau_iitem_library, ::ViewHolder, R.id.kau_item_library ), ThemableIItem by ThemableIItemDelegate() { companion object { - fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) { - fastAdapter.withSelectable(false) - .withOnClickListener { v, _, item, _ -> - if (item !is LibraryIItem) - false - else - with(item.lib) { - v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) - true - } + fun bindEvents(fastAdapter: FastAdapter<GenericItem>) { + fastAdapter.getSelectExtension().isSelectable = true + fastAdapter.onClickListener = { v, _, item, _ -> + if (item !is LibraryIItem) { + false + } else { + with(item.lib) { + v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) + true + } } + } } } - override fun isSelectable(): Boolean = false + override var isSelectable: Boolean + get() = false + set(_) {} override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) { super.bindView(holder, payloads) |