Skip to content

Commit

Permalink
Merge pull request #504 from Chooloo/ui
Browse files Browse the repository at this point in the history
So many things I can't even remember,  I'm bad with commits
  • Loading branch information
roeiedri authored Feb 24, 2023
2 parents 7bdcabf + 9e746f9 commit 565821e
Show file tree
Hide file tree
Showing 85 changed files with 1,595 additions and 1,268 deletions.
26 changes: 18 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.10'
ext {
sdkVersion = 33
minSdkVersion = 25
hiltVersion = "2.44"
kotlinVersion = "1.8.0"
coreKtxVersion = "1.9.0"
appCompatVersion = "1.6.0"
}

repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://jitpack.io" }
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.1'
classpath "com.android.tools.build:gradle:7.4.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.44.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}
}

plugins {
id 'com.google.dagger.hilt.android' version '2.44' apply false
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://jitpack.io" }
}
}

tasks.register('clean') {
tasks.register("clean") {
delete rootProject.buildDir
}
104 changes: 48 additions & 56 deletions chooloolib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,96 +1,88 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'org.jetbrains.kotlin.android'
id "com.android.library"
id "kotlin-android"
id "kotlin-kapt"
id 'com.google.dagger.hilt.android'
id "org.jetbrains.kotlin.android"
}

android {
compileSdk 31
namespace "com.chooloo.www.chooloolib"
compileSdk rootProject.ext.sdkVersion

defaultConfig {

minSdk 25
targetSdk 33

targetSdk rootProject.ext.sdkVersion
minSdk rootProject.ext.minSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}

dataBinding {
//noinspection DataBindingWithoutKapt
enabled = true
}

buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_18
targetCompatibility JavaVersion.VERSION_18
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

hilt {
enableAggregatingTask true
jvmTarget = JavaVersion.VERSION_18.toString()
}

kapt {
correctErrorTypes true
}
namespace 'com.chooloo.www.chooloolib'
kotlin { jvmToolchain(18) }
dataBinding { enabled true }
kapt { correctErrorTypes true }
buildFeatures { viewBinding true }
buildFeatures { viewBinding true }
hilt { enableAggregatingTask true }
}

dependencies {
implementation 'androidx.core:core-ktx:+'
kapt(
'com.google.dagger:hilt-compiler:2.38.1',
'androidx.hilt:hilt-compiler:1.0.0-alpha01'
"androidx.hilt:hilt-compiler:1.0.0-alpha01",
"com.google.dagger:hilt-compiler:${rootProject.ext.hiltVersion}"
)

testImplementation(
'junit:junit:',
'androidx.room:room-testing:2.2.6'
"junit:junit:",
"androidx.room:room-testing:2.2.6"
)

androidTestImplementation(
'androidx.test:runner:1.3.0',
'androidx.test.ext:junit:1.1.3',
"androidx.test:runner:1.3.0",
"androidx.test.ext:junit:1.1.3",
"androidx.compose.ui:ui-test-junit4:1.0.4",
'androidx.test.espresso:espresso-core:3.4.0'
"androidx.test.espresso:espresso-core:3.4.0"
)

implementation(
'com.squareup.picasso:picasso:2.5.2',
'androidx.core:core-ktx:1.7.0',
'dev.sasikanth:colorsheet:1.0.1',
'androidx.appcompat:appcompat:1.4.1',
'io.reactivex.rxjava2:rxjava:2.1.16',
'androidx.preference:preference:1.1.1',
'androidx.fragment:fragment-ktx:1.1.0',
'androidx.activity:activity-ktx:1.1.0',
'io.github.l4digital:fastscroll:2.0.1',
'io.reactivex.rxjava2:rxandroid:2.0.1',
'com.google.dagger:hilt-android:2.38.1',
'com.google.android.material:material:1.6.0',
'com.github.abdularis:circularimageview:1.5',
'com.daimajia.androidanimations:library:2.4@aar',
'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1',
'com.pushtorefresh.storio3:content-resolver:3.0.0',
'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1',
// ktx
"androidx.fragment:fragment-ktx:1.5.5",
"androidx.activity:activity-ktx:1.6.1",
"androidx.preference:preference-ktx:1.2.0",
"androidx.navigation:navigation-ui-ktx:2.5.3",
"androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1",
"androidx.navigation:navigation-fragment-ktx:2.5.3",
"androidx.core:core-ktx:${rootProject.ext.coreKtxVersion}",

"androidx.compose.ui:ui:1.3.3",
"dev.sasikanth:colorsheet:1.0.1",
"com.squareup.picasso:picasso:2.5.2",
"io.reactivex.rxjava2:rxjava:2.1.16",
"androidx.preference:preference:1.1.1",
"io.github.l4digital:fastscroll:2.0.1",
"io.reactivex.rxjava2:rxandroid:2.0.1",
"com.google.android.material:material:1.6.0",
"com.github.abdularis:circularimageview:1.5",
"com.daimajia.androidanimations:library:2.4@aar",
"com.pushtorefresh.storio3:content-resolver:3.0.0",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4",
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9",
"com.google.dagger:hilt-android:${rootProject.ext.hiltVersion}",
"androidx.appcompat:appcompat:${rootProject.ext.appCompatVersion}",
)
}
9 changes: 7 additions & 2 deletions chooloolib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
android:name=".ui.call.CallActivity"
android:configChanges="screenSize|keyboardHidden"
android:excludeFromRecents="true"
android:exported="false"
android:exported="true"
android:noHistory="true"
android:screenOrientation="unspecified"
android:showOnLockScreen="true" />
android:showOnLockScreen="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".ui.permissions.PermissionRequestActivity"
android:screenOrientation="unspecified" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class AccountsAdapter @Inject constructor(
animations: AnimationsInteractor,
private val strings: StringsInteractor
) : ListAdapter<RawContactAccount>(animations) {
override fun onBindListItem(listItemHolder: ListItemHolder, item: RawContactAccount) {
override fun onBindListItem(
listItemHolder: ListItemHolder,
item: RawContactAccount,
position: Int
) {
listItemHolder.apply {
captionText = null
isImageVisible = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.chooloo.www.chooloolib.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.recyclerview.widget.RecyclerView
import com.chooloo.www.chooloolib.databinding.CallActionBinding
import com.chooloo.www.chooloolib.ui.callactions.CallAction

class CallActionsAdapter : RecyclerView.Adapter<CallActionsAdapter.ViewHolder>() {
private var _callActions: MutableList<CallAction> = mutableListOf()
private var _onCallActionClickListener: (CallAction) -> Unit = {}


override fun getItemCount() = _callActions.size

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
ViewHolder(CallActionBinding.inflate(LayoutInflater.from(parent.context), parent, false))

override fun onBindViewHolder(holder: ViewHolder, position: Int) =
holder.bind(_callActions[position], _onCallActionClickListener::invoke)


private fun getCallAction(@StringRes idRes: Int): CallAction? {
val index = _callActions.indexOfFirst { it.idRes == idRes }
if (index == -1) return null
return _callActions[index]
}

private fun changeCallAction(@StringRes idRes: Int, change: (CallAction) -> Unit) {
val index = _callActions.indexOfFirst { it.idRes == idRes }
if (index == -1) return
change.invoke(_callActions[index])
notifyItemChanged(index)
}

fun isCallActionEnabled(@StringRes idRes: Int) = getCallAction(idRes)?.isEnabled ?: false

fun isCallActionActivated(@StringRes idRes: Int) = getCallAction(idRes)?.isActivated ?: false

fun setCallActionEnabled(@StringRes idRes: Int, isEnabled: Boolean) {
changeCallAction(idRes) { it.isEnabled = isEnabled }
}

fun setCallActionActivated(@StringRes idRes: Int, isActivated: Boolean) {
changeCallAction(idRes) { it.isActivated = isActivated }
}

fun setCallActionIcon(@StringRes idRes: Int, @DrawableRes iconRes: Int) {
changeCallAction(idRes) { it.tempIconRes = iconRes }
}

fun addCallActions(callActions: List<CallAction>) {
for (callAction in callActions) {
if (_callActions.contains(callAction)) continue
_callActions.add(callAction)
notifyItemChanged(_callActions.indexOf(callAction))
}
}

fun removeCallActions(callActions: List<CallAction>) {
for (callAction in callActions) {
if (!_callActions.contains(callAction)) continue
val removedIndex = _callActions.indexOf(callAction)
_callActions.remove(callAction)
notifyItemRemoved(removedIndex)
}
}

fun setOnCallActionClickListener(onCallActionClickListener: (CallAction) -> Unit = {}) {
_onCallActionClickListener = onCallActionClickListener
}


class ViewHolder(private val binding: CallActionBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bind(callAction: CallAction, onClickListener: (CallAction) -> Unit = {}) {
binding.callActionRoot.apply {
setDefaultIcon(callAction.tempIconRes ?: callAction.iconRes)
callAction.checkedIconRes?.let(::setCheckedIcon)
isEnabled = callAction.isEnabled
isActivated = callAction.isActivated
setOnClickListener { onClickListener.invoke(callAction) }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CallItemsAdapter @Inject constructor(
private val phonesInteractor: PhonesInteractor,
@MainScope private val mainScope: CoroutineScope,
) : ListAdapter<Call>(animationsInteractor) {
override fun onBindListItem(listItemHolder: ListItemHolder, item: Call) {
override fun onBindListItem(listItemHolder: ListItemHolder, item: Call, position: Int) {
listItemHolder.apply {
ioScope.launch {
val account = phonesInteractor.lookupAccount(item.number)
Expand Down Expand Up @@ -48,7 +48,7 @@ class CallItemsAdapter @Inject constructor(

setLeftButtonIcon(R.drawable.call_split)
setRightButtonIcon(R.drawable.call_end)
setRightButtonIconTint(R.color.negative_foreground)
setRightButtonIconTint(R.color.negative)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.chooloo.www.chooloolib.adapter
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chooloo.www.chooloolib.data.model.ListData
import com.chooloo.www.chooloolib.databinding.ListItemBinding
import com.chooloo.www.chooloolib.interactor.animation.AnimationsInteractor
import com.chooloo.www.chooloolib.data.model.ListData
import com.chooloo.www.chooloolib.ui.widgets.listitemholder.ChoiceItemHolder
import com.chooloo.www.chooloolib.ui.widgets.listitemholder.ListItemHolder
import javax.inject.Inject
Expand All @@ -15,6 +15,7 @@ class ChoicesAdapter @Inject constructor(
animations: AnimationsInteractor,
) : ListAdapter<String>(animations) {
private var _selectedIndex: Int? = null
private var _onChoiceSelectedListener: (String) -> Boolean = { true }

var selectedIndex: Int?
get() = _selectedIndex
Expand All @@ -26,14 +27,23 @@ class ChoicesAdapter @Inject constructor(
ListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)

override fun onBindListItem(listItemHolder: ListItemHolder, item: String) {
listItemHolder.titleText = item
selectedIndex?.let {
if (items[it] == item) {
listItemHolder.setSelected()
override fun onBindListItem(listItemHolder: ListItemHolder, item: String, position: Int) {
listItemHolder.apply {
titleText = item
(this as ChoiceItemHolder).setSelected(selectedIndex == position)
setOnClickListener {
if (_onChoiceSelectedListener.invoke(item)) {
selectedIndex?.let(::notifyItemChanged)
selectedIndex = position
notifyItemChanged(position)
}
}
}
}

override fun convertDataToListData(items: List<String>) = ListData(items)

fun setOnChoiceSelectedListener(onChoiceSelectedListener: (String) -> Boolean) {
_onChoiceSelectedListener = onChoiceSelectedListener
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ open class ContactsAdapter @Inject constructor(
}


override fun onBindListItem(listItemHolder: ListItemHolder, item: ContactAccount) {
override fun onBindListItem(
listItemHolder: ListItemHolder,
item: ContactAccount,
position: Int
) {
listItemHolder.apply {
titleText = item.name
imageInitials = item.name?.initials()
Expand Down
Loading

0 comments on commit 565821e

Please sign in to comment.