Skip to content

Commit

Permalink
chore: migrate app module to latest support-arch
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed May 21, 2024
1 parent d34ee52 commit 05be72e
Show file tree
Hide file tree
Showing 38 changed files with 145 additions and 154 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/android-spotless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- '*'

env:
CI: "true"

jobs:
android-spotless:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/android-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- develop

env:
CI: "true"

jobs:
android-unit-test:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/gradle-dokka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches: [ develop ]

env:
CI: "true"

jobs:
gradle-dokka:
runs-on: ubuntu-latest
Expand Down
18 changes: 18 additions & 0 deletions .idea/appInsightsSettings.xml

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

4 changes: 4 additions & 0 deletions .idea/modules.xml

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

18 changes: 17 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ dependencies {
implementation(libs.androidx.recycler.view)

implementation(libs.androidx.lifecycle.livedata.core)
implementation(libs.androidx.lifecycle.livedata.core.ktx)
implementation(libs.androidx.lifecycle.livedata)
implementation(libs.androidx.lifecycle.livedata.ktx)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.lifecycle.extensions)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.runtime.ktx)

implementation(libs.androidx.paging.common)
Expand All @@ -53,17 +57,29 @@ dependencies {
kapt(libs.androidx.room.compiler)

implementation(libs.anitrend.arch.ui)
implementation(libs.anitrend.arch.ext)
implementation(libs.anitrend.arch.extension)
implementation(libs.anitrend.arch.analytics)
implementation(libs.anitrend.arch.core)
implementation(libs.anitrend.arch.data)
implementation(libs.anitrend.arch.theme)
implementation(libs.anitrend.arch.domain)
implementation(libs.anitrend.arch.recycler)
implementation(libs.anitrend.arch.request)
implementation(libs.anitrend.arch.paging.legacy)
implementation(libs.anitrend.arch.recycler.paging.legacy)

implementation(libs.anitrend.emojify)
implementation(libs.anitrend.emojify.contract)
implementation(libs.anitrend.emojify.kotlinx)

implementation(libs.coil)
implementation(libs.coil.gif)

implementation(libs.square.retrofit)
implementation(libs.square.okhttp)
implementation(libs.square.okhttp.logger)


implementation(libs.timber)

releaseImplementation(libs.chuncker.release)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ inline fun FragmentManager.commit(
return fragmentTag
}

Timber.tag(javaClass.simpleName).v("FragmentItem model is null")
Timber.v("FragmentItem model is null")
return null
}

Expand All @@ -70,7 +70,6 @@ fun SupportImageView.using(
): Disposable {
return load(imageUrl) {
placeholder(placeHolder)
transition(CrossfadeTransition(350))
transformations(transformations.toList())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.anitrend.retrofit.graphql.core.helpers.logger

import org.koin.core.logger.KOIN_TAG
import org.koin.core.logger.Level
import org.koin.core.logger.Logger
import org.koin.core.logger.MESSAGE
Expand All @@ -12,13 +11,13 @@ import timber.log.Timber
internal class KoinLogger(
logLevel: Level
) : Logger(logLevel) {

override fun log(level: Level, msg: MESSAGE) {
override fun display(level: Level, msg: MESSAGE) {
when (level) {
Level.DEBUG -> Timber.tag(KOIN_TAG).d(msg)
Level.INFO -> Timber.tag(KOIN_TAG).i(msg)
Level.ERROR -> Timber.tag(KOIN_TAG).e(msg)
Level.NONE -> Timber.tag(KOIN_TAG).v(msg)
Level.DEBUG -> Timber.d(msg)
Level.INFO -> Timber.i(msg)
Level.ERROR -> Timber.e(msg)
Level.NONE -> {}
Level.WARNING -> Timber.w(msg)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class UncaughtExceptionHandler(
* @param throwable the exception
*/
override fun uncaughtException(thread: Thread, throwable: Throwable) {
Timber.tag(thread.name).e(throwable)
Timber.e(throwable)
exceptionHandler?.uncaughtException(thread, throwable)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package co.anitrend.retrofit.graphql.core.koin

import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.P
import co.anitrend.arch.extension.dispatchers.SupportDispatchers
import co.anitrend.retrofit.graphql.core.settings.Settings
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.decode.GifDecoder
import coil.decode.ImageDecoderDecoder
import coil.util.CoilUtils
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.android.ext.koin.androidApplication
Expand Down Expand Up @@ -41,27 +37,18 @@ private val coilModules = module {
}
)
.cache(
CoilUtils.createDefaultCache(
androidApplication()
)
Cache(androidApplication().cacheDir, 50 * 1024 * 1024)
).build()
}
factory<ImageLoaderFactory> {
object : ImageLoaderFactory {
override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(androidContext())
.crossfade(true)
.allowHardware(true)
.bitmapPoolPercentage(0.35)
.okHttpClient {
get(named("coilOkHttp"))
}
.componentRegistry {
if (SDK_INT >= P) add(ImageDecoderDecoder())
else add(GifDecoder())
}
.build()
}
ImageLoaderFactory {
ImageLoader.Builder(androidContext())
.crossfade(true)
.allowHardware(true)
.okHttpClient {
get(named("coilOkHttp"))
}
.build()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class SampleActivity : SupportActivity() {
* Can be used to configure custom theme styling as desired
*/
override fun configureActivity() {
setupKoinFragmentFactory(koinLifecycleScope)
setupKoinFragmentFactory()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val systemUiOptions = window.decorView.systemUiVisibility
when (AppCompatDelegate.getDefaultNightMode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal object RetrofitProvider {
when (endpointType) {
EndpointType.BUCKET,
EndpointType.GITHUB -> {
Timber.tag(moduleTag).d("""
Timber.d("""
Adding request interceptors for endpoint: ${endpointType.name}
""".trimIndent()
)
Expand Down Expand Up @@ -66,13 +66,13 @@ internal object RetrofitProvider {
fun provideRetrofit(endpointType: EndpointType, scope: Scope): Retrofit {
val reference = retrofitCache.get(endpointType)
return if (reference != null) {
Timber.tag(moduleTag).d(
Timber.d(
"Using cached retrofit instance for endpoint: ${endpointType.name}"
)
reference
}
else {
Timber.tag(moduleTag).d(
Timber.d(
"Creating new retrofit instance for endpoint: ${endpointType.name}"
)
val retrofit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class OfflineControllerPolicy<D> private constructor() : ControllerStra
block()
pagingRequestHelper.recordSuccess()
}.exceptionOrNull()?.also { e ->
Timber.tag(moduleTag).e(e)
Timber.e(e)
pagingRequestHelper.recordFailure(e)
}
}
Expand All @@ -64,7 +64,7 @@ internal class OfflineControllerPolicy<D> private constructor() : ControllerStra
networkState.postValue(NetworkState.Success)
result
}.getOrElse {
Timber.tag(moduleTag).e(it)
Timber.e(it)
networkState.postValue(
NetworkState.Error(
heading = it.cause?.message ?: "Unexpected error encountered",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class OnlineControllerPolicy<D> private constructor(
pagingRequestHelper.recordSuccess()
}.exceptionOrNull()?.also { e ->
e.printStackTrace()
Timber.tag(moduleTag).e(e)
Timber.e(e)
pagingRequestHelper.recordFailure(e)
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ internal class OnlineControllerPolicy<D> private constructor(
networkState.postValue(NetworkState.Success)
result
}.getOrElse {
Timber.tag(moduleTag).e(it)
Timber.e(it)
networkState.postValue(
NetworkState.Error(
heading = it.cause?.message ?: "Unexpected error encountered \uD83E\uDD2D",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal abstract class GraphQLMapper<S, D> : SupportResponseMapper<S, D>() {
* Simple logger for empty response
*/
protected fun onEmptyResponse() {
Timber.tag(moduleTag).v(
Timber.v(
"onResponseDatabaseInsert -> mappedData is empty"
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.anitrend.retrofit.graphql.domain.usecases

import co.anitrend.arch.domain.common.IUseCase
import co.anitrend.arch.domain.common.IUserInterfaceState
import co.anitrend.arch.domain.state.UiState
import co.anitrend.retrofit.graphql.domain.repositories.BucketRepository

abstract class BucketUseCase<R: IUserInterfaceState<*>>(
abstract class BucketUseCase<R: UiState<*>>(
protected val repository: BucketRepository<R>
) : IUseCase {
operator fun invoke() =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.anitrend.retrofit.graphql.domain.usecases

import co.anitrend.arch.domain.common.IUseCase
import co.anitrend.arch.domain.common.IUserInterfaceState
import co.anitrend.arch.domain.state.UiState
import co.anitrend.retrofit.graphql.domain.repositories.MarketPlaceRepository

abstract class MarketPlaceUseCase<R: IUserInterfaceState<*>>(
abstract class MarketPlaceUseCase<R: UiState<*>>(
protected val repository: MarketPlaceRepository<R>
) : IUseCase {
operator fun invoke() =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package co.anitrend.retrofit.graphql.domain.usecases

import co.anitrend.arch.domain.common.IUseCase
import co.anitrend.arch.domain.common.IUserInterfaceState
import co.anitrend.arch.domain.state.UiState
import co.anitrend.retrofit.graphql.domain.models.common.IGraphQuery
import co.anitrend.retrofit.graphql.domain.repositories.UploadRepository

abstract class UploadUseCase<R: IUserInterfaceState<*>>(
abstract class UploadUseCase<R: UiState<*>>(
protected val repository: UploadRepository<R>
) : IUseCase {
operator fun invoke(mutation: IGraphQuery) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.anitrend.retrofit.graphql.domain.usecases

import co.anitrend.arch.domain.common.IUseCase
import co.anitrend.arch.domain.common.IUserInterfaceState
import co.anitrend.arch.domain.state.UiState
import co.anitrend.retrofit.graphql.domain.repositories.UserRepository

abstract class UserUseCase<R: IUserInterfaceState<*>>(
abstract class UserUseCase<R: UiState<*>>(
protected val repository: UserRepository<R>
) : IUseCase {
operator fun invoke() =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package co.anitrend.retrofit.graphql.sample

import androidx.startup.AppInitializer
import co.anitrend.retrofit.graphql.core.SampleApp
import co.anitrend.retrofit.graphql.core.helpers.runtime.UncaughtExceptionHandler
import io.wax911.emojify.EmojiManager
import io.wax911.emojify.initializer.EmojiInitializer
import io.wax911.emojify.serializer.kotlinx.KotlinxDeserializer

class App : SampleApp() {

/**
* Emoji manager instance
*/
override val emojiManager: EmojiManager by lazy {
AppInitializer.getInstance(this)
.initializeComponent(EmojiInitializer::class.java)
EmojiManager.create(this, serializer = KotlinxDeserializer())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.content.Context
import androidx.startup.Initializer
import coil.Coil
import coil.ImageLoaderFactory
import org.koin.core.KoinComponent
import org.koin.core.get
import org.koin.core.component.KoinComponent
import org.koin.core.component.get

internal class CoilInitializer : Initializer<Unit> {

Expand All @@ -17,8 +17,7 @@ internal class CoilInitializer : Initializer<Unit> {
override fun create(context: Context) {
// I could just have koin component declared on the class level
val component = object : KoinComponent {}
val factory =
component.get<ImageLoaderFactory>()
val factory = component.get<ImageLoaderFactory>()
Coil.setImageLoader(factory)
}

Expand Down
Loading

0 comments on commit 05be72e

Please sign in to comment.