-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from Chooloo/ui
So many things I can't even remember, I'm bad with commits
- Loading branch information
Showing
85 changed files
with
1,595 additions
and
1,268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/CallActionsAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.