From 514788e0ef2f88f7f3a7508c28bed8e5c1c2cee1 Mon Sep 17 00:00:00 2001 From: "le.quang.dao" Date: Wed, 31 Jan 2024 16:45:48 +0700 Subject: [PATCH] [Modify] Fix can't build --- .editorconfig | 2 +- .idea/deploymentTargetDropDown.xml | 17 +++++------------ app/build.gradle.kts | 6 ++---- app/src/main/AndroidManifest.xml | 2 +- .../java/com/sun/android/AndroidApplication.kt | 8 ++++---- .../main/java/com/sun/android/MainActivity.kt | 1 - .../com/sun/android/base/BaseRepository.kt | 6 +++--- .../java/com/sun/android/base/BaseViewModel.kt | 3 ++- .../data/repository/MovieRepositoryImpl.kt | 2 +- .../local/api/sharedpref/SharedPrefsImpl.kt | 4 ++++ .../remote/api/middleware/InterceptorImpl.kt | 1 - .../android/{data => }/di/DataSourceModule.kt | 4 ++-- .../sun/android/{data => }/di/NetWorkModule.kt | 18 +++++++++--------- .../android/{data => }/di/RepositoryModule.kt | 2 +- .../android/ui/detail/MovieDetailViewModel.kt | 7 +++---- .../sun/android/ui/listmovie/MoviesFragment.kt | 17 ++++++++++------- .../ui/listmovie/adapter/MoviesAdapter.kt | 2 +- .../utils/extension/ContextExtension.kt | 2 +- .../sun/android/utils/livedata/SafeObserver.kt | 4 ++-- .../android/utils/livedata/SingleLiveData.kt | 5 ++--- buildSrc/src/main/kotlin/Config.kt | 4 +--- config/detekt/detekt.yml | 2 +- gradle.properties | 1 + 23 files changed, 57 insertions(+), 63 deletions(-) rename app/src/main/java/com/sun/android/{data => }/di/DataSourceModule.kt (85%) rename app/src/main/java/com/sun/android/{data => }/di/NetWorkModule.kt (84%) rename app/src/main/java/com/sun/android/{data => }/di/RepositoryModule.kt (96%) diff --git a/.editorconfig b/.editorconfig index 0cfa3bb..7137309 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,4 +2,4 @@ indent_size=4 insert_final_newline=true max_line_length=120 -disabled_rules=no-wildcard-imports,experimental:annotation, import-ordering +disabled_rules=no-wildcard-imports,experimental:annotation, import-ordering, trailing-comma-on-declaration-site, wrapping, experimental:property-naming, experimental:function-signature diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index c2412a2..0c0c338 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,17 +1,10 @@ - - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1c24fcb..99d7ae7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,7 +10,7 @@ buildscript { } android { - namespace = "com.sun.structure_android" + namespace = "com.sun.android" compileSdk = AppConfigs.compile_sdk_version defaultConfig { @@ -103,7 +103,6 @@ dependencies { implementation(Deps.navigation_ui_ktx) //Lifecycle - implementation(Deps.lifecycle_extension) implementation(Deps.lifecycle_livedata_ktx) implementation(Deps.lifecycle_viewmodel_ktx) implementation(Deps.lifecycle_runtime) @@ -120,8 +119,7 @@ dependencies { implementation(Deps.okhttp_logging_interceptor) //Koin - implementation(Deps.koin_ext) - implementation(Deps.koin_viewmodel) + implementation(Deps.koin) //Glide implementation(Deps.glide_runtime) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9b9b8a2..768ea14 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.sun.android"> diff --git a/app/src/main/java/com/sun/android/AndroidApplication.kt b/app/src/main/java/com/sun/android/AndroidApplication.kt index d6e0c98..2c13e8d 100644 --- a/app/src/main/java/com/sun/android/AndroidApplication.kt +++ b/app/src/main/java/com/sun/android/AndroidApplication.kt @@ -1,9 +1,9 @@ package com.sun.android import android.app.Application -import com.sun.android.data.di.DataSourceModule -import com.sun.android.data.di.NetworkModule -import com.sun.android.data.di.RepositoryModule +import com.sun.android.di.dataSourceModule +import com.sun.android.di.NetworkModule +import com.sun.android.di.RepositoryModule import com.sun.android.di.AppModule import com.sun.android.di.ViewModelModule import org.koin.android.ext.koin.androidContext @@ -12,7 +12,7 @@ import org.koin.core.context.startKoin class AndroidApplication : Application() { - private val rootModule = listOf(AppModule, NetworkModule, DataSourceModule, RepositoryModule, ViewModelModule) + private val rootModule = listOf(AppModule, NetworkModule, dataSourceModule, RepositoryModule, ViewModelModule) override fun onCreate() { super.onCreate() diff --git a/app/src/main/java/com/sun/android/MainActivity.kt b/app/src/main/java/com/sun/android/MainActivity.kt index 49d5b92..81e021a 100644 --- a/app/src/main/java/com/sun/android/MainActivity.kt +++ b/app/src/main/java/com/sun/android/MainActivity.kt @@ -2,7 +2,6 @@ package com.sun.android import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import com.sun.structure_android.R class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/sun/android/base/BaseRepository.kt b/app/src/main/java/com/sun/android/base/BaseRepository.kt index 1e986ef..f860844 100644 --- a/app/src/main/java/com/sun/android/base/BaseRepository.kt +++ b/app/src/main/java/com/sun/android/base/BaseRepository.kt @@ -5,8 +5,8 @@ import com.sun.android.utils.dispatchers.BaseDispatcherProvider import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext -import org.koin.core.KoinComponent -import org.koin.core.get +import org.koin.core.component.KoinComponent +import org.koin.core.component.get abstract class BaseRepository : KoinComponent { @@ -23,7 +23,7 @@ abstract class BaseRepository : KoinComponent { protected suspend fun withResultContext( context: CoroutineContext = dispatchersProvider.io(), - requestBlock: suspend CoroutineScope.() -> R + requestBlock: suspend CoroutineScope.() -> R, ): DataResult = withContext(context) { return@withContext try { val response = requestBlock() diff --git a/app/src/main/java/com/sun/android/base/BaseViewModel.kt b/app/src/main/java/com/sun/android/base/BaseViewModel.kt index fa81712..d5b1871 100644 --- a/app/src/main/java/com/sun/android/base/BaseViewModel.kt +++ b/app/src/main/java/com/sun/android/base/BaseViewModel.kt @@ -19,7 +19,6 @@ open class BaseViewModel : ViewModel() { onError: (Exception) -> Unit = {}, isShowLoading: Boolean = true ) = viewModelScope.launch { - showLoading(isShowLoading) when (val asynchronousTasks = onRequest(this)) { is DataResult.Success -> onSuccess(asynchronousTasks.data) @@ -29,6 +28,8 @@ open class BaseViewModel : ViewModel() { getErrorResponse()?.let { errorResponse.value = it } } } + + else -> {} } hideLoading(isShowLoading) } diff --git a/app/src/main/java/com/sun/android/data/repository/MovieRepositoryImpl.kt b/app/src/main/java/com/sun/android/data/repository/MovieRepositoryImpl.kt index 483d9eb..d9d1d21 100644 --- a/app/src/main/java/com/sun/android/data/repository/MovieRepositoryImpl.kt +++ b/app/src/main/java/com/sun/android/data/repository/MovieRepositoryImpl.kt @@ -5,7 +5,7 @@ import com.sun.android.data.MovieRepository import com.sun.android.data.source.MovieDataSource class MovieRepositoryImpl constructor( - private val remote: MovieDataSource.Remote + private val remote: MovieDataSource.Remote, ) : BaseRepository(), MovieRepository { override suspend fun getMovies() = withResultContext { diff --git a/app/src/main/java/com/sun/android/data/source/local/api/sharedpref/SharedPrefsImpl.kt b/app/src/main/java/com/sun/android/data/source/local/api/sharedpref/SharedPrefsImpl.kt index 5e5c83a..51f0ec2 100644 --- a/app/src/main/java/com/sun/android/data/source/local/api/sharedpref/SharedPrefsImpl.kt +++ b/app/src/main/java/com/sun/android/data/source/local/api/sharedpref/SharedPrefsImpl.kt @@ -43,15 +43,19 @@ class SharedPrefsImpl(context: Context, private val gson: Gson) : SharedPrefsApi Boolean::class.java -> java.lang.Boolean.valueOf( sharedPreferences.getBoolean(key, default as? Boolean ?: false) ) as? T + Float::class.java -> java.lang.Float.valueOf( sharedPreferences.getFloat(key, default as? Float ?: 0f) ) as? T + Int::class.java -> Integer.valueOf( sharedPreferences.getInt(key, default as? Int ?: 0) ) as? T + Long::class.java -> java.lang.Long.valueOf( sharedPreferences.getLong(key, default as? Long ?: 0L) ) as? T + else -> gson.fromJson(sharedPreferences.getString(key, default as? String), type) } diff --git a/app/src/main/java/com/sun/android/data/source/remote/api/middleware/InterceptorImpl.kt b/app/src/main/java/com/sun/android/data/source/remote/api/middleware/InterceptorImpl.kt index 9fc447d..d287dd4 100644 --- a/app/src/main/java/com/sun/android/data/source/remote/api/middleware/InterceptorImpl.kt +++ b/app/src/main/java/com/sun/android/data/source/remote/api/middleware/InterceptorImpl.kt @@ -23,7 +23,6 @@ class InterceptorImpl( var response = chain.proceed(request) if (!isRefreshToken && response.code == HttpURLConnection.HTTP_UNAUTHORIZED) { - tokenRepository.getToken()?.let { token -> val newRequest = initNewRequest(request, token) response.close() diff --git a/app/src/main/java/com/sun/android/data/di/DataSourceModule.kt b/app/src/main/java/com/sun/android/di/DataSourceModule.kt similarity index 85% rename from app/src/main/java/com/sun/android/data/di/DataSourceModule.kt rename to app/src/main/java/com/sun/android/di/DataSourceModule.kt index 72ec159..a6cfafd 100644 --- a/app/src/main/java/com/sun/android/data/di/DataSourceModule.kt +++ b/app/src/main/java/com/sun/android/di/DataSourceModule.kt @@ -1,4 +1,4 @@ -package com.sun.android.data.di +package com.sun.android.di import com.sun.android.data.source.MovieDataSource import com.sun.android.data.source.TokenDataSource @@ -6,7 +6,7 @@ import com.sun.android.data.source.local.TokenLocalImpl import com.sun.android.data.source.remote.MovieRemoteImpl import org.koin.dsl.module -val DataSourceModule = module { +val dataSourceModule = module { single { TokenLocalImpl(get()) } single { MovieRemoteImpl(get()) } diff --git a/app/src/main/java/com/sun/android/data/di/NetWorkModule.kt b/app/src/main/java/com/sun/android/di/NetWorkModule.kt similarity index 84% rename from app/src/main/java/com/sun/android/data/di/NetWorkModule.kt rename to app/src/main/java/com/sun/android/di/NetWorkModule.kt index 8d88e70..21550c7 100644 --- a/app/src/main/java/com/sun/android/data/di/NetWorkModule.kt +++ b/app/src/main/java/com/sun/android/di/NetWorkModule.kt @@ -1,4 +1,4 @@ -package com.sun.android.data.di +package com.sun.android.di import android.app.Application import com.google.gson.Gson @@ -42,13 +42,16 @@ fun provideOkHttpClient(cache: Cache, interceptor: Interceptor): OkHttpClient { httpClientBuilder.addInterceptor(interceptor) httpClientBuilder.readTimeout( - NetWorkInstant.READ_TIMEOUT, TimeUnit.SECONDS + NetWorkInstant.READ_TIMEOUT, + TimeUnit.SECONDS ) httpClientBuilder.writeTimeout( - NetWorkInstant.WRITE_TIMEOUT, TimeUnit.SECONDS + NetWorkInstant.WRITE_TIMEOUT, + TimeUnit.SECONDS ) httpClientBuilder.connectTimeout( - NetWorkInstant.CONNECT_TIMEOUT, TimeUnit.SECONDS + NetWorkInstant.CONNECT_TIMEOUT, + TimeUnit.SECONDS ) if (BuildConfig.DEBUG) { @@ -61,11 +64,8 @@ fun provideOkHttpClient(cache: Cache, interceptor: Interceptor): OkHttpClient { } fun provideRetrofit(gson: Gson, okHttpClient: OkHttpClient): Retrofit { - return Retrofit.Builder() - .baseUrl(BuildConfig.BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .client(okHttpClient) - .build() + return Retrofit.Builder().baseUrl(BuildConfig.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)) + .client(okHttpClient).build() } fun provideApiService(retrofit: Retrofit): ApiService { diff --git a/app/src/main/java/com/sun/android/data/di/RepositoryModule.kt b/app/src/main/java/com/sun/android/di/RepositoryModule.kt similarity index 96% rename from app/src/main/java/com/sun/android/data/di/RepositoryModule.kt rename to app/src/main/java/com/sun/android/di/RepositoryModule.kt index 730438b..e495b70 100644 --- a/app/src/main/java/com/sun/android/data/di/RepositoryModule.kt +++ b/app/src/main/java/com/sun/android/di/RepositoryModule.kt @@ -1,4 +1,4 @@ -package com.sun.android.data.di +package com.sun.android.di import com.sun.android.data.MovieRepository import com.sun.android.data.TokenRepository diff --git a/app/src/main/java/com/sun/android/ui/detail/MovieDetailViewModel.kt b/app/src/main/java/com/sun/android/ui/detail/MovieDetailViewModel.kt index 496a7d3..ab38080 100644 --- a/app/src/main/java/com/sun/android/ui/detail/MovieDetailViewModel.kt +++ b/app/src/main/java/com/sun/android/ui/detail/MovieDetailViewModel.kt @@ -11,9 +11,8 @@ class MovieDetailViewModel(private val movieRepository: MovieRepository) : BaseV fun requestMovieDetails(movieId: Int) { launchTaskSync(onRequest = { movieRepository.getDetailMovies(movieId) - }, - onSuccess = { - movie.value = it - }) + }, onSuccess = { + movie.value = it + }) } } diff --git a/app/src/main/java/com/sun/android/ui/listmovie/MoviesFragment.kt b/app/src/main/java/com/sun/android/ui/listmovie/MoviesFragment.kt index a763d2f..23cc54f 100644 --- a/app/src/main/java/com/sun/android/ui/listmovie/MoviesFragment.kt +++ b/app/src/main/java/com/sun/android/ui/listmovie/MoviesFragment.kt @@ -31,14 +31,17 @@ class MoviesFragment : BaseFragment(MoviesFragmentBinding } override fun bindData() { - viewModel.movies.observe(this, Observer { movies -> - mMovieAdapter.updateData(movies) - }) + viewModel.movies.observe( + this, + Observer { movies -> + mMovieAdapter.updateData(movies) + }, + ) } - override fun onItemClick(item: Movie?) { - item.notNull { - addFragment(R.id.layoutContainer, DetailFragment.newInstance(it.id), true) - } + override fun onItemClick(item: Movie?) { + item.notNull { + addFragment(R.id.layoutContainer, DetailFragment.newInstance(it.id), true) + } } } diff --git a/app/src/main/java/com/sun/android/ui/listmovie/adapter/MoviesAdapter.kt b/app/src/main/java/com/sun/android/ui/listmovie/adapter/MoviesAdapter.kt index 77485eb..13c5dfd 100644 --- a/app/src/main/java/com/sun/android/ui/listmovie/adapter/MoviesAdapter.kt +++ b/app/src/main/java/com/sun/android/ui/listmovie/adapter/MoviesAdapter.kt @@ -44,7 +44,7 @@ class MoviesAdapter : RecyclerView.Adapter() { class ViewHolder( private val binding: ItemLayoutMovieBinding, - private val itemClickListener: OnItemRecyclerViewClickListener? + itemClickListener: OnItemRecyclerViewClickListener? ) : RecyclerView.ViewHolder(binding.root), View.OnClickListener { private var movieData: Movie? = null diff --git a/app/src/main/java/com/sun/android/utils/extension/ContextExtension.kt b/app/src/main/java/com/sun/android/utils/extension/ContextExtension.kt index f62e856..f290f71 100644 --- a/app/src/main/java/com/sun/android/utils/extension/ContextExtension.kt +++ b/app/src/main/java/com/sun/android/utils/extension/ContextExtension.kt @@ -1,4 +1,4 @@ -package com.sun.android.utils +package com.sun.android.utils.extension import android.content.Context import android.widget.Toast diff --git a/app/src/main/java/com/sun/android/utils/livedata/SafeObserver.kt b/app/src/main/java/com/sun/android/utils/livedata/SafeObserver.kt index bc9f93b..e16d7bd 100644 --- a/app/src/main/java/com/sun/android/utils/livedata/SafeObserver.kt +++ b/app/src/main/java/com/sun/android/utils/livedata/SafeObserver.kt @@ -3,7 +3,7 @@ package com.sun.android.utils.livedata import androidx.lifecycle.Observer class SafeObserver(private val notifier: (T) -> Unit) : Observer { - override fun onChanged(t: T?) { - t?.let { notifier(t) } + override fun onChanged(t: T) { + notifier(t) } } diff --git a/app/src/main/java/com/sun/android/utils/livedata/SingleLiveData.kt b/app/src/main/java/com/sun/android/utils/livedata/SingleLiveData.kt index d66906f..47b183d 100644 --- a/app/src/main/java/com/sun/android/utils/livedata/SingleLiveData.kt +++ b/app/src/main/java/com/sun/android/utils/livedata/SingleLiveData.kt @@ -41,11 +41,10 @@ class SingleLiveData : MutableLiveData() { @MainThread override fun observe(owner: LifecycleOwner, observer: Observer) { - if (hasActiveObservers()) { Log.d( - "", "Multiple observers registered but only one will be " + - "notified of changes." + "", + "Multiple observers registered but only one will be notified of changes." ) } diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index f5ce165..ee8ddda 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -65,7 +65,6 @@ object Deps { const val navigation_ui_ktx = "androidx.navigation:navigation-ui-ktx:${Versions.navigation}" // Lifecycle - const val lifecycle_extension = "androidx.lifecycle:lifecycle-extensions:${Versions.lifecycle}" const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:${Versions.lifecycle}" const val lifecycle_viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycle}" const val lifecycle_runtime = "androidx.lifecycle:lifecycle-runtime:${Versions.lifecycle}" @@ -88,8 +87,7 @@ object Deps { const val glide_compiler = "com.github.bumptech.glide:compiler:${Versions.glide}" // Koin - const val koin_ext = "org.koin:koin-androidx-ext:${Versions.koin}" - const val koin_viewmodel = "org.koin:koin-androidx-viewmodel:${Versions.koin}" + const val koin = "io.insert-koin:koin-android:${Versions.koin}" // Testing const val junit = "junit:junit:${Versions.jUnit}" diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 91fe123..59fb9ac 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -282,7 +282,7 @@ exceptions: active: true TooGenericExceptionCaught: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/base/BaseRepository.kt','**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] exceptionNames: - 'ArrayIndexOutOfBoundsException' - 'Error' diff --git a/gradle.properties b/gradle.properties index a0404d9..0820ba1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,5 +19,6 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official +android.defaults.buildfeatures.buildconfig=true # TODO - config run for MacOS, Other OS should update this line to run org.gradle.java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home