Skip to content

Commit

Permalink
feat: F-Droid flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Feb 6, 2024
1 parent 21f5d50 commit c0f3fed
Show file tree
Hide file tree
Showing 37 changed files with 218 additions and 97 deletions.
32 changes: 23 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
id 'kotlin-android'
id 'kotlinx-serialization'
id 'org.jetbrains.kotlin.android'
id 'com.google.devtools.ksp'

}

def gitCommitHash = providers.exec {
Expand All @@ -22,15 +19,31 @@ android {
targetSdk 34
versionCode ((System.currentTimeMillis() / 60000).toInteger())
versionName "2.1.0"
versionCode 210
signingConfig signingConfigs.debug
}

flavorDimensions "store"
productFlavors {
fdroid {
// F-Droid specific configuration
dimension "store"
versionNameSuffix "-fdroid"
}
google {
// Google Play specific configuration
dimension "store"
isDefault true
}
}

buildTypes {
alpha {
applicationIdSuffix ".beta" // keep as the same application by popular request
applicationIdSuffix ".beta" // keep as beta by popular request
versionNameSuffix "-alpha01"
manifestPlaceholders = [icon_placeholder: "@mipmap/ic_launcher_alpha", icon_placeholder_round: "@mipmap/ic_launcher_alpha_round"]
debuggable System.getenv("CI") == null
isDefault true
}
debug {
applicationIdSuffix ".beta"
Expand All @@ -46,6 +59,7 @@ android {
}
buildFeatures {
viewBinding true
buildConfig true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
Expand All @@ -59,6 +73,11 @@ android {
}

dependencies {

// FireBase
googleImplementation platform('com.google.firebase:firebase-bom:32.2.3')
googleImplementation 'com.google.firebase:firebase-analytics-ktx:21.5.0'
googleImplementation 'com.google.firebase:firebase-crashlytics-ktx:18.6.1'
// Core
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.browser:browser:1.7.0'
Expand All @@ -84,11 +103,6 @@ dependencies {
implementation "com.github.bumptech.glide:okhttp3-integration:$glide_version"
implementation 'jp.wasabeef:glide-transformations:4.3.0'

// FireBase
implementation platform('com.google.firebase:firebase-bom:32.2.3')
implementation 'com.google.firebase:firebase-analytics-ktx:21.5.0'
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.6.1'

// Exoplayer
ext.exo_version = '1.2.1'
implementation "androidx.media3:media3-exoplayer:$exo_version"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ani.dantotsu.connections.crashlytics

class CrashlyticsFactory {
companion object {
fun createCrashlytics(): CrashlyticsInterface {
return CrashlyticsStub()
}
}
}
9 changes: 9 additions & 0 deletions app/src/fdroid/java/ani/dantotsu/others/AppUpdater.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ani.dantotsu.others

import androidx.fragment.app.FragmentActivity

object AppUpdater {
suspend fun check(activity: FragmentActivity, post: Boolean = false) {
//no-op
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ani.dantotsu.connections.crashlytics

class CrashlyticsFactory {
companion object {
fun createCrashlytics(): CrashlyticsInterface {
return FirebaseCrashlytics()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ani.dantotsu.connections.crashlytics

import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase

class FirebaseCrashlytics : CrashlyticsInterface {
override fun logException(e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(e)
}

override fun log(message: String) {
FirebaseCrashlytics.getInstance().log(message)
}

override fun setUserId(id: String) {
Firebase.crashlytics.setUserId(id)
}

override fun setCustomKey(key: String, value: String) {
FirebaseCrashlytics.getInstance().setCustomKey(key, value)
}

override fun setCrashlyticsCollectionEnabled(enabled: Boolean) {
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(enabled)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ object AppUpdater {
return true
}

fun openApk(context: Context, uri: Uri) {
private fun openApk(context: Context, uri: Uri) {
try {
uri.path?.let {
val contentUri = FileProvider.getUriForFile(
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/ani/dantotsu/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
import ani.dantotsu.aniyomi.anime.custom.AppModule
import ani.dantotsu.aniyomi.anime.custom.PreferenceModule
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.others.DisabledReports
import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.parsers.MangaSources
Expand All @@ -17,9 +18,6 @@ import ani.dantotsu.settings.SettingsActivity
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefManager
import com.google.android.material.color.DynamicColors
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
Expand Down Expand Up @@ -55,28 +53,32 @@ class App : MultiDexApplication() {
super.onCreate()

PrefManager.init(this)
Injekt.importModule(AppModule(this))
Injekt.importModule(PreferenceModule(this))

val crashlytics = Injekt.get<CrashlyticsInterface>()

val useMaterialYou: Boolean = PrefManager.getVal(PrefName.UseMaterialYou)
if (useMaterialYou) {
DynamicColors.applyToActivitiesIfAvailable(this)
//TODO: HarmonizedColors
}
registerActivityLifecycleCallbacks(mFTActivityLifecycleCallbacks)

Firebase.crashlytics.setCrashlyticsCollectionEnabled(!DisabledReports)
crashlytics.setCrashlyticsCollectionEnabled(!DisabledReports)
(PrefManager.getVal(PrefName.SharedUserID) as Boolean).let {
if (!it) return@let
val dUsername = PrefManager.getVal(PrefName.DiscordUserName, null as String?)
val aUsername = PrefManager.getVal(PrefName.AnilistUserName, null as String?)
if (dUsername != null || aUsername != null) {
Firebase.crashlytics.setUserId("$dUsername - $aUsername")
if (dUsername != null) {
crashlytics.setCustomKey("dUsername", dUsername)
}
if (aUsername != null) {
crashlytics.setCustomKey("aUsername", aUsername)
}
}
FirebaseCrashlytics.getInstance()
.setCustomKey("device Info", SettingsActivity.getDeviceInfo())
crashlytics.setCustomKey("device Info", SettingsActivity.getDeviceInfo())


Injekt.importModule(AppModule(this))
Injekt.importModule(PreferenceModule(this))

initializeNetwork(baseContext)

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.BuildConfig.APPLICATION_ID
import ani.dantotsu.connections.anilist.Genre
import ani.dantotsu.connections.anilist.api.FuzzyDate
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.databinding.ItemCountDownBinding
import ani.dantotsu.media.Media
import ani.dantotsu.parsers.ShowResponse
Expand All @@ -61,11 +62,12 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.internal.ViewUtils
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.gson.Gson
import eu.kanade.tachiyomi.data.notification.Notifications
import kotlinx.coroutines.*
import nl.joery.animatedbottombar.AnimatedBottomBar
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.*
import java.lang.Runnable
import java.lang.reflect.Field
Expand Down Expand Up @@ -872,7 +874,7 @@ fun snackString(s: String?, activity: Activity? = null, clipboard: String? = nul
}
} catch (e: Exception) {
logger(e.stackTraceToString())
FirebaseCrashlytics.getInstance().recordException(e)
Injekt.get<CrashlyticsInterface>().logException(e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import androidx.annotation.OptIn
import androidx.core.content.ContextCompat
import androidx.media3.common.util.UnstableApi
import androidx.media3.database.StandaloneDatabaseProvider
import ani.dantotsu.BuildConfig
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.connections.crashlytics.CrashlyticsStub
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.media.manga.MangaCache
import ani.dantotsu.parsers.novel.NovelExtensionManager
Expand Down Expand Up @@ -53,6 +56,10 @@ class AppModule(val app: Application) : InjektModule {

addSingletonFactory { StandaloneDatabaseProvider(app) }

addSingletonFactory<CrashlyticsInterface> {
ani.dantotsu.connections.crashlytics.CrashlyticsFactory.createCrashlytics()
}

addSingletonFactory { MangaCache() }

ContextCompat.getMainExecutor(app).execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import ani.dantotsu.BuildConfig
import ani.dantotsu.R
import ani.dantotsu.connections.discord.Discord
import ani.dantotsu.connections.mal.MAL
Expand Down Expand Up @@ -100,7 +101,9 @@ class AnilistHomeViewModel : ViewModel() {
Anilist.getSavedToken()
MAL.getSavedToken(context)
Discord.getSavedToken(context)
if (PrefManager.getVal(PrefName.CheckUpdate)) AppUpdater.check(context)
if (!BuildConfig.FLAVOR.contains("fdroid")) {
if (PrefManager.getVal(PrefName.CheckUpdate)) AppUpdater.check(context)
}
genres.postValue(Anilist.query.getGenresAndTags(context))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ani.dantotsu.connections.crashlytics

interface CrashlyticsInterface {
fun logException(e: Throwable)
fun log(message: String)
fun setUserId(id: String)
fun setCustomKey(key: String, value: String)
fun setCrashlyticsCollectionEnabled(enabled: Boolean)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ani.dantotsu.connections.crashlytics

class CrashlyticsStub : CrashlyticsInterface {
override fun logException(e: Throwable) {
//no-op
}

override fun log(message: String) {
//no-op
}

override fun setUserId(id: String) {
//no-op
}

override fun setCustomKey(key: String, value: String) {
//no-op
}

override fun setCrashlyticsCollectionEnabled(enabled: Boolean) {
//no-op
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.media3.exoplayer.offline.DownloadManager
import androidx.media3.exoplayer.offline.DownloadService
import ani.dantotsu.FileUrl
import ani.dantotsu.R
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.currActivity
import ani.dantotsu.download.DownloadedType
import ani.dantotsu.download.DownloadsManager
Expand All @@ -34,7 +35,6 @@ import ani.dantotsu.parsers.Subtitle
import ani.dantotsu.parsers.Video
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.snackString
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.gson.GsonBuilder
import com.google.gson.InstanceCreator
import eu.kanade.tachiyomi.animesource.model.SAnime
Expand Down Expand Up @@ -277,7 +277,7 @@ class AnimeDownloaderService : Service() {
DownloadedType.Type.ANIME,
)
)
FirebaseCrashlytics.getInstance().recordException(
Injekt.get<CrashlyticsInterface>().logException(
Exception(
"Anime Download failed:" +
" ${download.failureReason}" +
Expand Down Expand Up @@ -333,7 +333,7 @@ class AnimeDownloaderService : Service() {
logger("Exception while downloading file: ${e.message}")
snackString("Exception while downloading file: ${e.message}")
e.printStackTrace()
FirebaseCrashlytics.getInstance().recordException(e)
Injekt.get<CrashlyticsInterface>().logException(e)
}
broadcastDownloadFailed(task.episode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.fragment.app.Fragment
import androidx.media3.common.util.UnstableApi
import ani.dantotsu.R
import ani.dantotsu.bottomBar
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.currActivity
import ani.dantotsu.currContext
import ani.dantotsu.download.DownloadedType
Expand All @@ -44,7 +45,6 @@ import ani.dantotsu.snackString
import com.google.android.material.card.MaterialCardView
import com.google.android.material.imageview.ShapeableImageView
import com.google.android.material.textfield.TextInputLayout
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.gson.GsonBuilder
import com.google.gson.InstanceCreator
import eu.kanade.tachiyomi.animesource.model.SAnime
Expand Down Expand Up @@ -318,7 +318,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
} catch (e: Exception) {
logger("Error loading media.json: ${e.message}")
logger(e.printStackTrace())
FirebaseCrashlytics.getInstance().recordException(e)
Injekt.get<CrashlyticsInterface>().logException(e)
null
}
}
Expand Down Expand Up @@ -374,7 +374,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
} catch (e: Exception) {
logger("Error loading media.json: ${e.message}")
logger(e.printStackTrace())
FirebaseCrashlytics.getInstance().recordException(e)
Injekt.get<CrashlyticsInterface>().logException(e)
return OfflineAnimeModel(
"unknown",
"0",
Expand Down
Loading

0 comments on commit c0f3fed

Please sign in to comment.