Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Nov 8, 2023
1 parent 06ffc79 commit ae8ca7b
Show file tree
Hide file tree
Showing 104 changed files with 600 additions and 307 deletions.
10 changes: 7 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.io.FileInputStream
import org.apache.commons.io.output.ByteArrayOutputStream
import org.jetbrains.kotlin.konan.properties.Properties
import java.io.FileInputStream

@Suppress("dsl_scope_violation")
plugins {
Expand All @@ -11,7 +11,6 @@ plugins {
alias(libs.plugins.firebase.appdistribution)
alias(libs.plugins.firebase.crashlytics)
alias(libs.plugins.palantir.git)
alias(libs.plugins.detekt)
id("movies-android-hilt")
}

Expand Down Expand Up @@ -148,15 +147,20 @@ android {
checkDependencies = true
lintConfig = file("${project.rootDir}/config/codestyle/lint.xml")
}

kapt {
correctErrorTypes = true
}
}

dependencies {
implementation(project(":core:analytics"))
implementation(project(":core:common"))
implementation(project(":core:domain"))
implementation(project(":core:interactor"))
implementation(project(":core:navigation"))
implementation(project(":core:notifications"))
implementation(project(":core:ui"))
implementation(project(":core:work"))

implementation(project(":feature:auth"))
implementation(project(":feature:account"))
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/kotlin/org/michaelbel/movies/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.workDataOf
import dagger.hilt.android.AndroidEntryPoint
import org.michaelbel.movies.work.AccountUpdateWorker
import org.michaelbel.movies.common.theme.AppTheme
import org.michaelbel.movies.work.MoviesDatabaseWorker
import org.michaelbel.movies.navigation.ktx.addOnDestinationChangedListener
import org.michaelbel.movies.ui.shortcuts.installShortcuts
import org.michaelbel.movies.ui.theme.MoviesTheme
Expand Down Expand Up @@ -50,5 +55,21 @@ internal class MainActivity: AppCompatActivity() {
)
}
}

prepopulateDatabase()
updateAccountDetails()
}

private fun prepopulateDatabase() {
val request = OneTimeWorkRequestBuilder<MoviesDatabaseWorker>()
.setInputData(workDataOf(MoviesDatabaseWorker.KEY_FILENAME to MainViewModel.MOVIES_DATA_FILENAME))
.build()
WorkManager.getInstance(this).enqueue(request)
}

private fun updateAccountDetails() {
val request = OneTimeWorkRequestBuilder<AccountUpdateWorker>()
.build()
WorkManager.getInstance(this).enqueue(request)
}
}
27 changes: 3 additions & 24 deletions app/src/main/kotlin/org/michaelbel/movies/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package org.michaelbel.movies
import android.app.Activity
import android.os.Bundle
import androidx.navigation.NavDestination
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.google.firebase.messaging.FirebaseMessaging
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
Expand All @@ -17,16 +15,12 @@ import org.michaelbel.movies.common.inappupdate.di.InAppUpdate
import org.michaelbel.movies.common.ktx.printlnDebug
import org.michaelbel.movies.common.theme.AppTheme
import org.michaelbel.movies.common.viewmodel.BaseViewModel
import org.michaelbel.movies.domain.workers.AccountUpdateWorker
import org.michaelbel.movies.domain.workers.MoviesDatabaseWorker
import org.michaelbel.movies.interactor.Interactor
import javax.inject.Inject

@HiltViewModel
internal class MainViewModel @Inject constructor(
private val interactor: Interactor,
private val inAppUpdate: InAppUpdate,
private val workManager: WorkManager,
private val analytics: MoviesAnalytics,
private val firebaseMessaging: FirebaseMessaging
): BaseViewModel() {
Expand All @@ -48,8 +42,6 @@ internal class MainViewModel @Inject constructor(
init {
fetchRemoteConfig()
fetchFirebaseMessagingToken()
prepopulateDatabase()
updateAccountDetails()
}

fun analyticsTrackDestination(destination: NavDestination, arguments: Bundle?) {
Expand All @@ -71,20 +63,7 @@ internal class MainViewModel @Inject constructor(
}
}

private fun prepopulateDatabase() {
val request = OneTimeWorkRequestBuilder<MoviesDatabaseWorker>()
.setInputData(workDataOf(MoviesDatabaseWorker.KEY_FILENAME to MOVIES_DATA_FILENAME))
.build()
workManager.enqueue(request)
}

private fun updateAccountDetails() {
val request = OneTimeWorkRequestBuilder<AccountUpdateWorker>()
.build()
workManager.enqueue(request)
}

private companion object {
private const val MOVIES_DATA_FILENAME = "movies.json"
companion object {
const val MOVIES_DATA_FILENAME = "movies.json"
}
}
1 change: 0 additions & 1 deletion benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id("com.android.test")
id("org.jetbrains.kotlin.android")
id("kotlin-android")
alias(libs.plugins.detekt)
}

android {
Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ plugins {

detekt {
config.setFrom("$projectDir/config/detekt/detekt.yml")
}

subprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
}
5 changes: 4 additions & 1 deletion core/analytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
plugins {
alias(libs.plugins.library)
alias(libs.plugins.kotlin)
alias(libs.plugins.detekt)
id("movies-android-hilt")
}

Expand Down Expand Up @@ -34,6 +33,10 @@ android {
checkDependencies = true
lintConfig = file("${project.rootDir}/config/codestyle/lint.xml")
}

kapt {
correctErrorTypes = true
}
}

dependencies {
Expand Down
9 changes: 7 additions & 2 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
plugins {
alias(libs.plugins.library)
alias(libs.plugins.kotlin)
alias(libs.plugins.detekt)
id("movies-android-hilt")
}

Expand Down Expand Up @@ -43,18 +42,24 @@ android {
checkDependencies = true
lintConfig = file("${project.rootDir}/config/codestyle/lint.xml")
}

kapt {
correctErrorTypes = true
}
}

dependencies {
implementation(project(":core:analytics"))
api(project(":core:entities"))
implementation(project(":core:network"))
api(libs.bundles.kotlin.coroutines)
api(libs.firebase.config.ktx)
api(libs.gms.play.services.base)
api(libs.play.core.ktx)
api(libs.androidx.activity.compose)
api(libs.androidx.core.ktx)
api(libs.androidx.paging.compose)
api(libs.androidx.work.runtime.ktx)
api(libs.androidx.hilt.work)
api(libs.bundles.lifecycle)
api(libs.timber)
implementation(libs.bundles.appcompat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.michaelbel.movies.common.usecase

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import org.michaelbel.movies.entities.Either
import org.michaelbel.movies.network.Either
import timber.log.Timber

abstract class UseCase<in P, R>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class AppVersionData(
val isDebug: Boolean
) {
companion object {
val None: AppVersionData = AppVersionData(
val Empty: AppVersionData = AppVersionData(
version = "",
code = 0L,
isDebug = false
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion core/entities/.gitignore

This file was deleted.

50 changes: 0 additions & 50 deletions core/entities/build.gradle.kts

This file was deleted.

2 changes: 0 additions & 2 deletions core/entities/src/main/AndroidManifest.xml

This file was deleted.

5 changes: 4 additions & 1 deletion core/interactor-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
plugins {
alias(libs.plugins.library)
alias(libs.plugins.kotlin)
alias(libs.plugins.detekt)
id("movies-android-hilt")
}

Expand Down Expand Up @@ -34,6 +33,10 @@ android {
checkDependencies = true
lintConfig = file("${project.rootDir}/config/codestyle/lint.xml")
}

kapt {
correctErrorTypes = true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.michaelbel.movies.interactor

import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import org.michaelbel.movies.common.dispatchers.MoviesDispatchers
import org.michaelbel.movies.persistence.database.entity.ImageDb
import org.michaelbel.movies.repository.ImageRepository

@Singleton
internal class ImageInteractorImpl @Inject constructor(
private val dispatchers: MoviesDispatchers,
private val imageRepository: ImageRepository
): ImageInteractor {

override fun imagesFlow(movieId: Int): Flow<List<ImageDb>> {
return imageRepository.imagesFlow(movieId)
}

override suspend fun images(movieId: Int) {
return withContext(dispatchers.io) {
imageRepository.images(movieId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import androidx.paging.PagingSource
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import org.michaelbel.movies.common.dispatchers.MoviesDispatchers
import org.michaelbel.movies.entities.Either
import org.michaelbel.movies.interactor.usecase.DelayUseCase
import org.michaelbel.movies.network.model.ImagesResponse
import org.michaelbel.movies.network.Either
import org.michaelbel.movies.network.model.MovieResponse
import org.michaelbel.movies.network.model.Result
import org.michaelbel.movies.persistence.database.entity.MovieDb
Expand All @@ -26,8 +24,8 @@ internal class MovieInteractorImpl @Inject constructor(
return movieRepository.moviesPagingSource(movieList)
}

override fun movieImage(movieId: Int): Flow<String> {
return movieRepository.movieImage(movieId)
override suspend fun backdropPosition(movieId: Int): Int {
return movieRepository.backdropPosition(movieId)
}

override suspend fun moviesResult(movieList: String, page: Int): Result<MovieResponse> {
Expand All @@ -46,12 +44,6 @@ internal class MovieInteractorImpl @Inject constructor(
}
}

override suspend fun movieImages(movieId: Int): ImagesResponse {
return withContext(dispatchers.io) {
movieRepository.movieImages(movieId)
}
}

override suspend fun removeAllMovies(movieList: String) {
return withContext(dispatchers.io) {
movieRepository.removeAllMovies(movieList)
Expand Down
Loading

0 comments on commit ae8ca7b

Please sign in to comment.