ReadYou/app/src/main/java/me/ash/reader/MainActivity.kt

75 lines
2.4 KiB
Kotlin

package me.ash.reader
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.CompositionLocalProvider
import androidx.core.view.WindowCompat
import androidx.profileinstaller.ProfileInstallerInitializer
import coil.ImageLoader
import coil.compose.LocalImageLoader
import dagger.hilt.android.AndroidEntryPoint
import ie.equalit.ouinet.Ouinet
import ie.equalit.ouinet.Config
import me.ash.reader.data.dao.AccountDao
import me.ash.reader.data.model.preference.AccountSettingsProvider
import me.ash.reader.data.model.preference.LanguagesPreference
import me.ash.reader.data.model.preference.SettingsProvider
import me.ash.reader.ui.ext.languages
import me.ash.reader.ui.page.common.HomeEntry
import javax.inject.Inject
/**
* The Single-Activity Architecture.
*/
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private lateinit var ouinet: Ouinet
@Inject
lateinit var imageLoader: ImageLoader
@Inject
lateinit var accountDao: AccountDao
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
Log.i("RLog", "onCreate: ${ProfileInstallerInitializer().create(this)}")
// Set the language
LanguagesPreference.fromValue(languages).let {
if (it == LanguagesPreference.UseDeviceLanguages) return@let
it.setLocale(this)
}
// Enable OuiNet client
val config = Config.ConfigBuilder(this)
.setCacheType("bep5-http")
.setCacheHttpPubKey(BuildConfig.CACHE_PUB_KEY)
.setInjectorCredentials(BuildConfig.INJECTOR_CREDENTIALS)
.setInjectorTlsCert(BuildConfig.INJECTOR_TLS_CERT)
.setTlsCaCertStorePath("file:///android_asset/cacert.pem")
.setDisableOriginAccess(true)
//.setDisableProxyAccess(true)
//.setDisableInjectorAccess(true)
.build()
ouinet = Ouinet(this, config)
ouinet.start()
setContent {
CompositionLocalProvider(
LocalImageLoader provides imageLoader,
) {
AccountSettingsProvider(accountDao) {
SettingsProvider {
HomeEntry()
}
}
}
}
}
}