Skip to content

Commit

Permalink
[Modify] Fix can't build
Browse files Browse the repository at this point in the history
  • Loading branch information
daolq-2712 committed Jan 31, 2024
1 parent f0b4ea5 commit 514788e
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 5 additions & 12 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}

android {
namespace = "com.sun.structure_android"
namespace = "com.sun.android"
compileSdk = AppConfigs.compile_sdk_version

defaultConfig {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sun.structure_android">
package="com.sun.android">

<uses-permission android:name="android.permission.INTERNET" />

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/sun/android/AndroidApplication.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/sun/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/sun/android/base/BaseRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -23,7 +23,7 @@ abstract class BaseRepository : KoinComponent {

protected suspend fun <R> withResultContext(
context: CoroutineContext = dispatchersProvider.io(),
requestBlock: suspend CoroutineScope.() -> R
requestBlock: suspend CoroutineScope.() -> R,
): DataResult<R> = withContext(context) {
return@withContext try {
val response = requestBlock()
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/sun/android/base/BaseViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,6 +28,8 @@ open class BaseViewModel : ViewModel() {
getErrorResponse()?.let { errorResponse.value = it }
}
}

else -> {}
}
hideLoading(isShowLoading)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
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<TokenDataSource.Local> { TokenLocalImpl(get()) }

single<MovieDataSource.Remote> { MovieRemoteImpl(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sun.android.data.di
package com.sun.android.di

import android.app.Application
import com.google.gson.Gson
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}
17 changes: 10 additions & 7 deletions app/src/main/java/com/sun/android/ui/listmovie/MoviesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ class MoviesFragment : BaseFragment<MoviesFragmentBinding>(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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MoviesAdapter : RecyclerView.Adapter<MoviesAdapter.ViewHolder?>() {

class ViewHolder(
private val binding: ItemLayoutMovieBinding,
private val itemClickListener: OnItemRecyclerViewClickListener<Movie>?
itemClickListener: OnItemRecyclerViewClickListener<Movie>?
) : RecyclerView.ViewHolder(binding.root), View.OnClickListener {

private var movieData: Movie? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sun.android.utils
package com.sun.android.utils.extension

import android.content.Context
import android.widget.Toast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.sun.android.utils.livedata
import androidx.lifecycle.Observer

class SafeObserver<T>(private val notifier: (T) -> Unit) : Observer<T> {
override fun onChanged(t: T?) {
t?.let { notifier(t) }
override fun onChanged(t: T) {
notifier(t)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class SingleLiveData<T> : MutableLiveData<T>() {

@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {

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."
)
}

Expand Down
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 514788e

Please sign in to comment.