Skip to content

Commit

Permalink
Modulatization (#34)
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
julieminer authored Aug 14, 2024
1 parent 5f8db60 commit ee2deda
Show file tree
Hide file tree
Showing 240 changed files with 3,017 additions and 669 deletions.
64 changes: 18 additions & 46 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0-RC'
id 'org.jetbrains.kotlin.plugin.serialization'
id 'org.jetbrains.kotlin.plugin.compose' version '2.0.0'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
Expand Down Expand Up @@ -64,55 +64,27 @@ tasks.register('generateVersionTxt') {
}

dependencies {

implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.3'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.8.3"

implementation 'androidx.activity:activity-compose:1.9.0'
implementation "androidx.compose.ui:ui:1.6.8"
implementation "androidx.compose.ui:ui-tooling-preview:1.6.8"
implementation "androidx.compose.runtime:runtime-livedata:1.6.8"

implementation 'androidx.compose.material3:material3:1.2.1'
implementation "androidx.compose.material:material-icons-extended:1.6.8"
implementation 'com.google.firebase:firebase-crashlytics-ktx:19.0.2'
implementation 'com.google.firebase:firebase-analytics-ktx:22.0.2'
testImplementation 'junit:junit:4.13.2'

debugImplementation "androidx.compose.ui:ui-tooling:1.6.8"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.6.8"

implementation "io.insert-koin:koin-android:3.3.0"
implementation "io.insert-koin:koin-androidx-compose:3.3.0"

implementation "io.ktor:ktor-client-cio:2.1.3"
implementation "io.insert-koin:koin-ktor:3.2.2"
implementation "io.ktor:ktor-client-content-negotiation:2.1.3"
implementation "io.ktor:ktor-client-logging:2.1.3"
implementation "io.ktor:ktor-serialization-kotlinx-json:2.1.3"

implementation 'io.coil-kt:coil-compose:2.2.2'

implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.4.0"
implementation "androidx.datastore:datastore-preferences:1.1.1"

implementation "androidx.work:work-runtime-ktx:2.9.0"

implementation 'com.google.accompanist:accompanist-swiperefresh:0.27.0'

implementation "androidx.lifecycle:lifecycle-process:2.8.3"
implementation "androidx.lifecycle:lifecycle-common:2.8.3"

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:33.1.1')

// Add the dependency for the Realtime Database library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-database-ktx'

implementation project(":core")
implementation project(":core-ui")
implementation project(":lib-app-events")
implementation project(":lib-logging")
implementation project(":lib-notifications")
implementation project(":lib-navigation")
implementation project(":lib-database")
implementation project(":lib-chapter-cache")
implementation project(":lib-app-context")
implementation project(":lib-di")
implementation project(":lib-networking")
implementation project(":data-core-manga")
implementation project(":data-core-manga-ui")
implementation project(':data-manga')
implementation project(':data-at-home')
implementation project(':data-app-data')
implementation project(':data-user')
implementation project(':feature-authentication')
implementation project(':lib-chapter-cache')
implementation project(':feature-native-chapter-viewer')
implementation project(':feature-webview-chapter-viewer')
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
android:value="" />
</activity>

<activity android:name=".ui.scenes.chapter_reader.web_chapter_reader.WebViewActivity" />
<activity android:name=".ui.scenes.chapter_reader.native_chapter_reader.ChapterActivity" />
<activity android:name="com.melonhead.feature_webview_chapter_viewer.WebViewActivity" />
<activity android:name="com.melonhead.feature_native_chapter_viewer.ChapterActivity" />
</application>

</manifest>
45 changes: 20 additions & 25 deletions app/src/main/java/com/melonhead/mangadexfollower/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import androidx.lifecycle.ProcessLifecycleOwner
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import com.melonhead.lib_chapter_cache.di.ChapterCacheModule
import com.melonhead.lib_database.di.DBModule
import com.melonhead.mangadexfollower.di.appModule
import com.melonhead.lib_app_context.AppContext
import com.melonhead.lib_app_events.AppEventsRepository
import com.melonhead.lib_app_events.events.AppLifecycleEvent
import com.melonhead.lib_app_events.events.AuthenticationEvent
import com.melonhead.lib_logging.Clog
import com.melonhead.lib_networking.di.NetworkingModule
import com.melonhead.mangadexfollower.repositories.AuthRepository
import com.melonhead.mangadexfollower.repositories.MangaRepository
import com.melonhead.mangadexfollower.services.AppDataService
import com.melonhead.lib_networking.extensions.error401Callback
import com.melonhead.mangadexfollower.di.AppModule
import com.melonhead.mangadexfollower.work_manager.RefreshWorker
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand All @@ -26,13 +23,9 @@ import kotlin.time.Duration.Companion.minutes
import kotlin.time.toJavaDuration

class App: Application() {
private val mangaRepository: MangaRepository by inject()
private val authRepository: AuthRepository by inject()
private val externalScope: CoroutineScope by inject()
private val appDataService: AppDataService by inject()
private val appEventsRepository: AppEventsRepository by inject()
private val appNavigationMap: AppNavigationMap by inject()

var inForeground = false
private set
override fun onCreate() {
super.onCreate()

Expand All @@ -44,22 +37,27 @@ class App: Application() {
// Reference Android context
androidContext(this@App)
// Load modules
modules(DBModule)
modules(NetworkingModule)
modules(ChapterCacheModule)
modules(appModule)
modules(AppModule)
}

// force navigation initialization
appNavigationMap

error401Callback = {
appEventsRepository.postEvent(AuthenticationEvent.RefreshToken(logoutOnFail = true))
}

ProcessLifecycleOwner.get().lifecycle.addObserver(object: DefaultLifecycleObserver {
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
inForeground = true
externalScope.launch { mangaRepository.forceRefresh() }
AppContext.isInForeground = true
appEventsRepository.postEvent(AppLifecycleEvent.AppForegrounded)
}

override fun onStop(owner: LifecycleOwner) {
super.onStop(owner)
inForeground = false
AppContext.isInForeground = false
appEventsRepository.postEvent(AppLifecycleEvent.AppBackgrounded)
Clog.i("onStop: Creating background task")
val refreshWorkRequest = PeriodicWorkRequestBuilder<RefreshWorker>(15.minutes.toJavaDuration()).build()
WorkManager.getInstance(this@App).enqueueUniquePeriodicWork("refresh-task", ExistingPeriodicWorkPolicy.KEEP, refreshWorkRequest)
Expand All @@ -69,8 +67,5 @@ class App: Application() {

companion object {
private lateinit var instance: App
suspend fun authFailed() {
instance.authRepository.refreshToken(logoutOnFail = true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.melonhead.mangadexfollower

import com.melonhead.feature_authentication.navigation.LoginScreenResolver
import com.melonhead.feature_native_chapter_viewer.NativeChapterViewerActivityResolver
import com.melonhead.feature_webview_chapter_viewer.WebViewChapterViewerActivityResolver
import com.melonhead.lib_navigation.keys.ActivityKey
import com.melonhead.lib_navigation.keys.ScreenKey
import com.melonhead.lib_navigation.resolvers.ResolverMap
import com.melonhead.mangadexfollower.navigation.MainActivityResolver

class AppNavigationMap(
resolverMap: ResolverMap,

mainActivityResolver: MainActivityResolver,
nativeChapterViewerActivityResolver: NativeChapterViewerActivityResolver,
webViewActivityResolver: WebViewChapterViewerActivityResolver,

loginScreenResolver: LoginScreenResolver,
) {
init {
// activities
resolverMap.registerResolver(ActivityKey.WebViewActivity::class.java, webViewActivityResolver)
resolverMap.registerResolver(ActivityKey.ChapterActivity::class.java, nativeChapterViewerActivityResolver)
resolverMap.registerResolver(ActivityKey.MainActivity::class.java, mainActivityResolver)

// screens
resolverMap.registerResolver(ScreenKey.LoginScreen::class.java, loginScreenResolver)
}
}
61 changes: 18 additions & 43 deletions app/src/main/java/com/melonhead/mangadexfollower/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,56 +1,31 @@
package com.melonhead.mangadexfollower.di

import com.melonhead.mangadexfollower.repositories.AuthRepository
import com.melonhead.mangadexfollower.repositories.MangaRepository
import com.melonhead.mangadexfollower.services.*
import com.melonhead.mangadexfollower.ui.viewmodels.ChapterViewModel
import com.melonhead.data_app_data.di.AppDataServiceModule
import com.melonhead.feature_authentication.di.FeatureAuthenticationModule
import com.melonhead.feature_native_chapter_viewer.di.FeatureNativeChapterViewerModule
import com.melonhead.feature_webview_chapter_viewer.di.FeatureWebViewChapterViewerModule
import com.melonhead.lib_app_events.di.LibAppEventsModule
import com.melonhead.lib_navigation.di.LibNavigationModule
import com.melonhead.mangadexfollower.AppNavigationMap
import com.melonhead.mangadexfollower.navigation.MainActivityResolver
import com.melonhead.mangadexfollower.ui.viewmodels.MainViewModel
import com.melonhead.mangadexfollower.ui.viewmodels.WebViewViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val appModule = module {
single<AppDataService> {
AppDataServiceImpl(get(), get())
}
val AppModule = module {
includes(LibAppEventsModule)
includes(LibNavigationModule)

single<LoginService> {
LoginServiceImpl(get())
}
includes(AppDataServiceModule)

single<UserService> {
UserServiceImpl(get())
}

single<MangaService> {
MangaServiceImpl(get())
}

single<AtHomeService> {
AtHomeServiceImpl(get())
}

factory { CoroutineScope(Dispatchers.IO) }

single {
MangaRepository(get(), get(), get(), get(), get(), get(), get(), get(), get())
}

single(createdAtStart = true) {
AuthRepository(get(), get(), get(), get(), get())
}

viewModel {
MainViewModel(get(), get(), get())
}
includes(FeatureAuthenticationModule)
includes(FeatureNativeChapterViewerModule)
includes(FeatureWebViewChapterViewerModule)

viewModel {
WebViewViewModel(get())
MainViewModel(get(), get(), get(), get(), get())
}

viewModel {
ChapterViewModel(get(), get())
}
single(createdAtStart = true) { MainActivityResolver() }
single(createdAtStart = true) { AppNavigationMap(get(), get(), get(), get(), get()) }
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.melonhead.mangadexfollower.navigation

import android.content.Context
import android.content.Intent
import com.melonhead.lib_navigation.keys.ActivityKey
import com.melonhead.lib_navigation.resolvers.ActivityResolver
import com.melonhead.mangadexfollower.ui.scenes.MainActivity

class MainActivityResolver: ActivityResolver<ActivityKey.MainActivity> {
override fun intentForKey(context: Context, key: ActivityKey.MainActivity): Intent {
return Intent(context, MainActivity::class.java)
}
}
Loading

0 comments on commit ee2deda

Please sign in to comment.