Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37d8c453 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Implement ViewBinding

parent 582a8238
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ buildscript {
    ext.mockito_version = '2.18.3'
    ext.moshi_version = '1.8.0'
    ext.okhttp3_version = '4.1.0'
    ext.realm_version = '5.8.0'
    ext.realm_version = '6.1.0'
    ext.realm_adapters_version = '3.1.0'
    ext.rxandroid_version = '2.0.1'
    ext.rxdogtag_version = '0.2.0'
@@ -42,7 +42,7 @@ buildscript {
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'io.fabric.tools:gradle:1.29.0'
+2 −2
Original line number Diff line number Diff line
#Tue Dec 03 23:30:52 EST 2019
#Tue Mar 03 19:56:50 EST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
+4 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
apply plugin: 'com.android.application'
apply plugin: 'realm-android' // Realm needs to be before Kotlin or the build will fail
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
@@ -70,6 +69,10 @@ android {
        noAnalytics { dimension "analytics" }
    }

    viewBinding {
        enabled = true
    }

    if (System.getenv("CI") == "true") {
        signingConfigs.release.storeFile = file("../keystore")
        signingConfigs.release.storePassword = System.getenv("keystore_password")
@@ -78,10 +81,6 @@ android {
    }
}

androidExtensions {
    experimental = true
}

configurations {
    noAnalyticsDebug
    noAnalyticsRelease
+21 −24
Original line number Diff line number Diff line
@@ -20,26 +20,26 @@ package com.moez.QKSMS.common

import android.content.Context
import android.content.res.ColorStateList
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.ArrayRes
import androidx.recyclerview.widget.RecyclerView
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.databinding.MenuListItemBinding
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.menu_list_item.*
import kotlinx.android.synthetic.main.menu_list_item.view.*
import javax.inject.Inject

data class MenuItem(val title: String, val actionId: Int)

class MenuItemAdapter @Inject constructor(private val context: Context, private val colors: Colors) : QkAdapter<MenuItem>() {
class MenuItemAdapter @Inject constructor(
    private val context: Context,
    private val colors: Colors
) : QkAdapter<MenuItem, MenuListItemBinding>() {

    val menuItemClicks: Subject<Int> = PublishSubject.create()

@@ -47,13 +47,13 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private

    var selectedItem: Int? = null
        set(value) {
            val old = data.map { it.actionId }.indexOfFirst { it == field }
            val new = data.map { it.actionId }.indexOfFirst { it == value }
            val old = data.map { it.actionId }.indexOfFirst { it == field }.takeIf { it != -1 }
            val new = data.map { it.actionId }.indexOfFirst { it == value }.takeIf { it != -1 }

            field = value

            old.let { notifyItemChanged(it) }
            new.let { notifyItemChanged(it) }
            old?.let(::notifyItemChanged)
            new?.let(::notifyItemChanged)
        }

    fun setData(@ArrayRes titles: Int, @ArrayRes values: Int = -1) {
@@ -63,31 +63,28 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private
                .mapIndexed { index, title -> MenuItem(title, valueInts?.getOrNull(index) ?: index) }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
        val layoutInflater = LayoutInflater.from(parent.context)
        val view = layoutInflater.inflate(R.layout.menu_list_item, parent, false)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<MenuListItemBinding> {
        return QkViewHolder(parent, MenuListItemBinding::inflate).apply {
            val states = arrayOf(
                    intArrayOf(android.R.attr.state_activated),
                    intArrayOf(-android.R.attr.state_activated))

            val text = parent.context.resolveThemeColor(android.R.attr.textColorTertiary)
        view.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text))
            binding.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text))

        return QkViewHolder(view).apply {
            view.setOnClickListener {
            binding.root.setOnClickListener {
                val menuItem = getItem(adapterPosition)
                menuItemClicks.onNext(menuItem.actionId)
            }
        }
    }

    override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
    override fun onBindViewHolder(holder: QkViewHolder<MenuListItemBinding>, position: Int) {
        val menuItem = getItem(position)

        holder.title.text = menuItem.title
        holder.check.isActivated = (menuItem.actionId == selectedItem)
        holder.check.setVisible(selectedItem != null)
        holder.binding.title.text = menuItem.title
        holder.binding.check.isActivated = (menuItem.actionId == selectedItem)
        holder.binding.check.setVisible(selectedItem != null)
    }

    override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.moez.QKSMS.common.base

import androidx.annotation.CallSuper
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import io.reactivex.Flowable
import io.reactivex.disposables.Disposable

@@ -27,7 +28,7 @@ import io.reactivex.disposables.Disposable
 * Base RecyclerView.Adapter that provides some convenience when creating a new Adapter, such as
 * data list handing and item animations
 */
abstract class FlowableAdapter<T> : QkAdapter<T>() {
abstract class FlowableAdapter<T, Binding: ViewBinding> : QkAdapter<T, Binding>() {

    var flowable: Flowable<List<T>>? = null
        set(value) {
Loading