-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into main
- Loading branch information
Showing
24 changed files
with
446 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mx.rockstar.mytemplate | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class MainApp : Application() { | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/kotlin/com/mx/rockstar/mytemplate/binding/ViewBinding.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,29 @@ | ||
package com.mx.rockstar.mytemplate.binding | ||
|
||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.databinding.BindingAdapter | ||
import com.skydoves.whatif.whatIf | ||
import com.skydoves.whatif.whatIfNotNullOrEmpty | ||
|
||
object ViewBinding { | ||
|
||
@JvmStatic | ||
@BindingAdapter("toast") | ||
fun bindToast(view: View, text: String?) { | ||
text.whatIfNotNullOrEmpty { message -> | ||
Toast.makeText(view.context, message, Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("gone") | ||
fun bindGone(view: View, shouldBeGone: Boolean) { | ||
view.visibility = if (shouldBeGone) { | ||
View.GONE | ||
} else { | ||
View.VISIBLE | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/kotlin/com/mx/rockstar/mytemplate/ui/main/MainActivity.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,32 @@ | ||
package com.mx.rockstar.mytemplate.ui.main | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.annotation.VisibleForTesting | ||
import com.mx.rockstar.mytemplate.R | ||
import com.mx.rockstar.mytemplate.databinding.LayoutMainBinding | ||
import com.skydoves.bindables.BindingActivity | ||
import com.skydoves.transformationlayout.onTransformationStartContainer | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class MainActivity : BindingActivity<LayoutMainBinding>(R.layout.layout_main) { | ||
|
||
@get:VisibleForTesting | ||
internal val viewModel: MainViewModel by viewModels() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
onTransformationStartContainer() | ||
super.onCreate(savedInstanceState) | ||
binding { | ||
vm = viewModel | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
binding.button.setOnClickListener { | ||
viewModel.updateMessage() | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/kotlin/com/mx/rockstar/mytemplate/ui/main/MainViewModel.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,52 @@ | ||
package com.mx.rockstar.mytemplate.ui.main | ||
|
||
import androidx.databinding.Bindable | ||
import androidx.lifecycle.viewModelScope | ||
import com.mx.rockstar.mytemplate.core.data.repository.MainRepository | ||
import com.skydoves.bindables.BindingViewModel | ||
import com.skydoves.bindables.asBindingProperty | ||
import com.skydoves.bindables.bindingProperty | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MainViewModel @Inject constructor( | ||
private val mainRepository: MainRepository | ||
) : BindingViewModel() { | ||
|
||
@get:Bindable | ||
var isLoading: Boolean by bindingProperty(false) | ||
private set | ||
|
||
@get:Bindable | ||
var message: String? by bindingProperty(null) | ||
private set | ||
|
||
private val fetchingIndex: MutableStateFlow<Int> = MutableStateFlow(0) | ||
private val listFlow = fetchingIndex.flatMapLatest { page -> | ||
mainRepository.fetchData( | ||
page = page, | ||
onStart = { isLoading = true }, | ||
onComplete = { isLoading = false }, | ||
onError = { message = it } | ||
) | ||
} | ||
|
||
@get:Bindable | ||
val response: String by listFlow.asBindingProperty(viewModelScope, "") | ||
|
||
init { | ||
Timber.d("init MainViewModel") | ||
} | ||
|
||
fun updateMessage() { | ||
if (!isLoading) { | ||
message = "" | ||
fetchingIndex.value++ | ||
} | ||
} | ||
|
||
} |
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,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<data> | ||
<variable | ||
name="vm" | ||
type="com.mx.rockstar.mytemplate.ui.main.MainViewModel" /> | ||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
android:gravity="center" | ||
app:gone="@{vm.loading}" | ||
android:text="@{vm.response}" | ||
app:toast="@{vm.message}" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/button" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:text="@android:string/ok" | ||
android:layout_margin="16dp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent"/> | ||
|
||
<ProgressBar | ||
android:id="@+id/progressBar" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:gone="@{!vm.loading}" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</layout> |
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 @@ | ||
/build |
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,43 @@ | ||
import com.mx.rockstar.mytemplate.Configuration | ||
|
||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
id(libs.plugins.android.library.get().pluginId) | ||
id(libs.plugins.kotlin.android.get().pluginId) | ||
id(libs.plugins.kotlin.kapt.get().pluginId) | ||
} | ||
|
||
android { | ||
compileSdk = Configuration.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = Configuration.minSdk | ||
targetSdk = Configuration.targetSdk | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":core-model")) | ||
implementation(project(":core-network")) | ||
//implementation(project(":core-database")) | ||
testImplementation(project(":core-test")) | ||
|
||
// coroutines | ||
implementation(libs.coroutines) | ||
testImplementation(libs.coroutines) | ||
testImplementation(libs.coroutines.test) | ||
|
||
// network | ||
implementation(libs.sandwich) | ||
|
||
// di | ||
implementation(libs.hilt.android) | ||
kapt(libs.hilt.compiler) | ||
|
||
// unit test | ||
testImplementation(libs.junit) | ||
testImplementation(libs.turbine) | ||
testImplementation(libs.androidx.test.core) | ||
testImplementation(libs.mockito.kotlin) | ||
testImplementation(libs.mockito.inline) | ||
} |
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.mx.rockstar.mytemplate.core.data"/> |
17 changes: 17 additions & 0 deletions
17
core-data/src/main/kotlin/com/mx/rockstar/mytemplate/core/data/di/DataModule.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,17 @@ | ||
package com.mx.rockstar.mytemplate.core.data.di | ||
|
||
import com.mx.rockstar.mytemplate.core.data.repository.MainRepository | ||
import com.mx.rockstar.mytemplate.core.data.repository.MainRepositoryImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal interface DataModule { | ||
|
||
@Binds | ||
fun bindsMainRepository(mainRepositoryImpl: MainRepositoryImpl): MainRepository | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
core-data/src/main/kotlin/com/mx/rockstar/mytemplate/core/data/repository/MainRepository.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,16 @@ | ||
package com.mx.rockstar.mytemplate.core.data.repository | ||
|
||
import androidx.annotation.WorkerThread | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface MainRepository { | ||
|
||
@WorkerThread | ||
fun fetchData( | ||
page: Int, | ||
onStart: () -> Unit, | ||
onComplete: () -> Unit, | ||
onError: (String?) -> Unit | ||
): Flow<String> | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ata/src/main/kotlin/com/mx/rockstar/mytemplate/core/data/repository/MainRepositoryImpl.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,29 @@ | ||
package com.mx.rockstar.mytemplate.core.data.repository | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import androidx.annotation.WorkerThread | ||
import com.mx.rockstar.mytemplate.core.network.AppDispatcher | ||
import com.mx.rockstar.mytemplate.core.network.Dispatcher | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.* | ||
import javax.inject.Inject | ||
|
||
@VisibleForTesting | ||
class MainRepositoryImpl @Inject constructor( | ||
@Dispatcher(AppDispatcher.IO) private val ioDispatcher: CoroutineDispatcher | ||
) : MainRepository { | ||
|
||
@WorkerThread | ||
override fun fetchData( | ||
page: Int, | ||
onStart: () -> Unit, | ||
onComplete: () -> Unit, | ||
onError: (String?) -> Unit | ||
): Flow<String> = flow { | ||
kotlinx.coroutines.delay(1000) | ||
if (page == 0) emit("Comenzamos...") | ||
else if (page <= 10) emit("Flujo #${page} Terminando") | ||
else onError("Ya son Muchas...") | ||
}.onStart { onStart() }.onCompletion { onComplete() }.flowOn(ioDispatcher) | ||
|
||
} |
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 @@ | ||
/build |
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,27 @@ | ||
import com.mx.rockstar.mytemplate.Configuration | ||
|
||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
id(libs.plugins.android.library.get().pluginId) | ||
id(libs.plugins.kotlin.android.get().pluginId) | ||
id(libs.plugins.kotlin.parcelize.get().pluginId) | ||
id(libs.plugins.ksp.get().pluginId) version libs.versions.ksp.get() | ||
} | ||
|
||
android { | ||
compileSdk = Configuration.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = Configuration.minSdk | ||
targetSdk = Configuration.targetSdk | ||
} | ||
} | ||
|
||
dependencies { | ||
// json parsing | ||
implementation(libs.moshi) | ||
ksp(libs.moshi.codegen) | ||
|
||
// logger | ||
api(libs.timber) | ||
} |
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.mx.rockstar.mytemplate.core.model"/> |
5 changes: 5 additions & 0 deletions
5
core-model/src/main/kotlin/com/mx/rockstar/mytemplate/core/model/DataModel.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,5 @@ | ||
package com.mx.rockstar.mytemplate.core.model | ||
|
||
data class DataModel( | ||
var message: String? = null | ||
) |
Oops, something went wrong.