Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ztimms73 committed Apr 17, 2023
1 parent d1e7375 commit cbc8ce7
Show file tree
Hide file tree
Showing 30 changed files with 292 additions and 110 deletions.
72 changes: 41 additions & 31 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream
import java.text.SimpleDateFormat
import java.util.Date
import java.util.TimeZone
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.application")
Expand Down Expand Up @@ -42,7 +42,7 @@ android {
buildConfigField("String", "DATABASE_VERSION", "\"3.0\"")

// Please disable ACRA or use your own instance in forked versions of the project
buildConfigField("String", "ACRA_URI", "\"https://acra.rumblur.space/report\"")
buildConfigField("String", "ACRA_URI", "\"https://acra.kotatsu.app/report\"")
buildConfigField("String", "ACRA_AUTH_LOGIN", acraAuthLogin)
buildConfigField("String", "ACRA_AUTH_PASSWORD", acraAuthPassword)

Expand Down Expand Up @@ -108,22 +108,24 @@ android {
dimension = "default"
}
create("dev") {
resConfigs("xxhdpi")
resourceConfigurations += setOf("xxhdpi")
dimension = "default"
}
}

packagingOptions {
resources.excludes.addAll(listOf(
"META-INF/DEPENDENCIES",
"LICENSE.txt",
"META-INF/LICENSE",
"META-INF/LICENSE.txt",
"META-INF/README.md",
"META-INF/NOTICE",
"META-INF/*.kotlin_module",
"META-INF/*.version",
))
resources.excludes.addAll(
listOf(
"META-INF/DEPENDENCIES",
"LICENSE.txt",
"META-INF/LICENSE",
"META-INF/LICENSE.txt",
"META-INF/README.md",
"META-INF/NOTICE",
"META-INF/*.kotlin_module",
"META-INF/*.version"
)
)
}

dependenciesInfo {
Expand Down Expand Up @@ -166,7 +168,7 @@ dependencies {
// AndroidX libraries
implementation("androidx.annotation:annotation:1.4.0-alpha02")
implementation("androidx.appcompat:appcompat:1.6.0")
implementation("androidx.browser:browser:1.4.0")
implementation("androidx.browser:browser:1.5.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
implementation("androidx.core:core-ktx:1.9.0")
Expand All @@ -182,12 +184,16 @@ dependencies {
// Data serialization (JSON, protobuf)
val kotlinSerializationVersion = "1.3.3"
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinSerializationVersion")
implementation(
"org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinSerializationVersion"
)

// Job scheduling
implementation("androidx.work:work-runtime-ktx:2.7.1")
implementation("com.google.guava:guava:31.1-android")
implementation("com.github.Koitharu.pausing-coroutine-dispatcher:pausing-coroutine-dispatcher:5213d53420")
implementation(
"com.github.Koitharu.pausing-coroutine-dispatcher:pausing-coroutine-dispatcher:5213d53420"
)

// Network
implementation("com.squareup.retrofit2:retrofit:2.9.0")
Expand Down Expand Up @@ -218,12 +224,16 @@ dependencies {
val flowbindingVersion = "1.2.0"
implementation("io.github.reactivecircus.flowbinding:flowbinding-android:$flowbindingVersion")
implementation("io.github.reactivecircus.flowbinding:flowbinding-appcompat:$flowbindingVersion")
implementation("io.github.reactivecircus.flowbinding:flowbinding-recyclerview:$flowbindingVersion")
implementation("io.github.reactivecircus.flowbinding:flowbinding-swiperefreshlayout:$flowbindingVersion")
implementation(
"io.github.reactivecircus.flowbinding:flowbinding-recyclerview:$flowbindingVersion"
)
implementation(
"io.github.reactivecircus.flowbinding:flowbinding-swiperefreshlayout:$flowbindingVersion"
)
implementation("io.github.reactivecircus.flowbinding:flowbinding-viewpager:$flowbindingVersion")

// UI libraries
implementation("com.google.android.material:material:1.7.0-alpha01")
implementation("com.google.android.material:material:1.8.0")
implementation("com.github.arkon.FlexibleAdapter:flexible-adapter:c8013533")
implementation("com.github.arkon.FlexibleAdapter:flexible-adapter-ui:c8013533")
implementation("dev.chrisbanes.insetter:insetter:0.6.1")
Expand Down Expand Up @@ -252,7 +262,7 @@ dependencies {
implementation("com.github.tachiyomiorg:conductor-support-preference:$conductorVersion")

// Crash reports/analytics
implementation("ch.acra:acra-http:5.9.6")
implementation("ch.acra:acra-http:5.9.7")

implementation("org.jsoup:jsoup:1.15.3")

Expand All @@ -271,15 +281,15 @@ tasks {
// See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers)
withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlin.Experimental",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.ExperimentalStdlibApi",
"-opt-in=kotlinx.coroutines.FlowPreview",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=coil.annotation.ExperimentalCoilApi",
"-Xjvm-default=enable",
"-opt-in=kotlin.Experimental",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.ExperimentalStdlibApi",
"-opt-in=kotlinx.coroutines.FlowPreview",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=coil.annotation.ExperimentalCoilApi",
"-Xjvm-default=enable"
)
}

Expand Down Expand Up @@ -322,4 +332,4 @@ fun runCommand(command: String): String {
standardOutput = byteOut
}
return String(byteOut.toByteArray()).trim()
}
}
19 changes: 9 additions & 10 deletions app/src/main/java/org/xtimms/ridebus/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ open class App : Application(), DefaultLifecycleObserver {

MapKitFactory.setApiKey("397822a9-4d94-49cb-b402-d419ed3d5355")

preferences.themeMode()
.asImmediateFlow {
AppCompatDelegate.setDefaultNightMode(
when (it) {
PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO
PreferenceValues.ThemeMode.dark -> AppCompatDelegate.MODE_NIGHT_YES
PreferenceValues.ThemeMode.system -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
preferences.themeMode().asImmediateFlow {
AppCompatDelegate.setDefaultNightMode(
when (it) {
PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO
PreferenceValues.ThemeMode.dark -> AppCompatDelegate.MODE_NIGHT_YES
PreferenceValues.ThemeMode.system -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}.launchIn(ProcessLifecycleOwner.get().lifecycleScope)

if (!LogcatLogger.isInstalled && preferences.verboseLogging()) {
LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE))
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/xtimms/ridebus/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import kotlinx.serialization.json.Json
import org.xtimms.ridebus.data.database.RideBusDatabase
import org.xtimms.ridebus.data.preference.PreferencesHelper
import org.xtimms.ridebus.network.NetworkHelper
import uy.kohesive.injekt.api.*
import uy.kohesive.injekt.api.InjektModule
import uy.kohesive.injekt.api.InjektRegistrar
import uy.kohesive.injekt.api.addSingleton
import uy.kohesive.injekt.api.addSingletonFactory
import uy.kohesive.injekt.api.get

class AppModule(val app: Application) : InjektModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ object PreferenceKeys {
const val reducedMotion = "reduced_motion"

const val verboseLogging = "verbose_logging"

const val city = "pref_city_key"
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PreferencesHelper(val context: Context) {
if (context.applicationContext.isTablet()) ALWAYS else NEVER
)

fun city() = flowPrefs.getString("pref_city_key", "-1")
fun city() = flowPrefs.getString(Keys.city, "0")

fun themeDarkAmoled() = flowPrefs.getBoolean("pref_theme_dark_amoled_key", false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ class DatabaseUpdateChecker {
private val networkService: NetworkHelper by injectLazy()
private val preferences: PreferencesHelper by injectLazy()

suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): DatabaseUpdateResult {
if (isUserPrompt.not() && Date().time < preferences.lastDatabaseCheck().get() + TimeUnit.DAYS.toMillis(1)) {
suspend fun checkForUpdate(
context: Context,
isUserPrompt: Boolean = false
): DatabaseUpdateResult {
if (isUserPrompt.not() && Date().time < preferences.lastDatabaseCheck()
.get() + TimeUnit.DAYS.toMillis(1)
) {
return DatabaseUpdateResult.NoNewUpdate
}

Expand All @@ -29,15 +34,21 @@ class DatabaseUpdateChecker {
.parseAs<GithubDatabase>()
.let {
preferences.lastDatabaseCheck().set(Date().time)
if (SemanticVersioning.isNewVersion(it.version, preferences.databaseVersion().get())) {
if (SemanticVersioning.isNewVersion(
it.version,
preferences.databaseVersion().get()
)
) {
DatabaseUpdateResult.NewUpdate(it)
} else {
DatabaseUpdateResult.NoNewUpdate
}
}

when (result) {
is DatabaseUpdateResult.NewUpdate -> DatabaseUpdateNotifier(context).promptUpdate(result.update)
is DatabaseUpdateResult.NewUpdate -> DatabaseUpdateNotifier(context).promptUpdate(
result.update
)
else -> {}
}
result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Intent
import android.os.IBinder
import android.os.PowerManager
import androidx.core.content.ContextCompat
import java.io.File
import logcat.LogPriority
import org.xtimms.ridebus.BuildConfig
import org.xtimms.ridebus.R
Expand All @@ -25,7 +26,6 @@ import org.xtimms.ridebus.util.system.acquireWakeLock
import org.xtimms.ridebus.util.system.isServiceRunning
import org.xtimms.ridebus.util.system.logcat
import uy.kohesive.injekt.injectLazy
import java.io.File

class DatabaseUpdateService : Service() {

Expand Down Expand Up @@ -104,7 +104,7 @@ class DatabaseUpdateService : Service() {
try {
val databasePath = database.openHelper.writableDatabase.path.replace("ridebus.db", "")
val oldDatabaseFile = withIOContext { File(databasePath, "ridebus.db") }
val databaseFile = withIOContext { File(databasePath, "ridebus_new.db") }
val databaseFile = withIOContext { File(databasePath, "update.db") }

if (response.isSuccessful) {
if (database.isOpen) {
Expand Down Expand Up @@ -132,9 +132,12 @@ class DatabaseUpdateService : Service() {

companion object {

internal const val EXTRA_DOWNLOAD_URL = "${BuildConfig.APPLICATION_ID}.DatabaseUpdaterService.DOWNLOAD_URL"
internal const val EXTRA_DOWNLOAD_TITLE = "${BuildConfig.APPLICATION_ID}.DatabaseUpdaterService.DOWNLOAD_TITLE"
internal const val EXTRA_DOWNLOAD_VERSION = "${BuildConfig.APPLICATION_ID}.DatabaseUpdaterService.DOWNLOAD_VERSION"
internal const val EXTRA_DOWNLOAD_URL =
"${BuildConfig.APPLICATION_ID}.DatabaseUpdaterService.DOWNLOAD_URL"
internal const val EXTRA_DOWNLOAD_TITLE =
"${BuildConfig.APPLICATION_ID}.DatabaseUpdaterService.DOWNLOAD_TITLE"
internal const val EXTRA_DOWNLOAD_VERSION =
"${BuildConfig.APPLICATION_ID}.DatabaseUpdaterService.DOWNLOAD_VERSION"

private fun isRunning(context: Context): Boolean =
context.isServiceRunning(DatabaseUpdateService::class.java)
Expand All @@ -155,12 +158,21 @@ class DatabaseUpdateService : Service() {
}
}

internal fun downloadDatabasePendingService(context: Context, url: String, version: String): PendingIntent {
internal fun downloadDatabasePendingService(
context: Context,
url: String,
version: String
): PendingIntent {
val intent = Intent(context, DatabaseUpdateService::class.java).apply {
putExtra(EXTRA_DOWNLOAD_URL, url)
putExtra(EXTRA_DOWNLOAD_VERSION, version)
}
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getService(
context,
0,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}
}
}
15 changes: 12 additions & 3 deletions app/src/main/java/org/xtimms/ridebus/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.Router
import com.google.android.material.navigation.NavigationBarView
import dev.chrisbanes.insetter.applyInsetter
import kotlin.collections.set
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import logcat.LogPriority
Expand All @@ -46,6 +47,7 @@ import org.xtimms.ridebus.ui.base.activity.BaseActivity
import org.xtimms.ridebus.ui.base.controller.*
import org.xtimms.ridebus.ui.favourite.FavouritesController
import org.xtimms.ridebus.ui.main.welcome.WelcomeDialogController
import org.xtimms.ridebus.ui.more.CriticalDatabaseUpdateDialogController
import org.xtimms.ridebus.ui.more.MoreController
import org.xtimms.ridebus.ui.more.NewScheduleDialogController
import org.xtimms.ridebus.ui.more.NewUpdateDialogController
Expand All @@ -62,7 +64,6 @@ import org.xtimms.ridebus.util.system.isTablet
import org.xtimms.ridebus.util.system.logcat
import org.xtimms.ridebus.util.system.toast
import org.xtimms.ridebus.util.view.setNavigationBarTransparentCompat
import kotlin.collections.set

class MainActivity : BaseActivity() {

Expand Down Expand Up @@ -330,7 +331,11 @@ class MainActivity : BaseActivity() {
private fun handleIntentAction(intent: Intent): Boolean {
val notificationId = intent.getIntExtra("notificationId", -1)
if (notificationId > -1) {
NotificationReceiver.dismissNotification(applicationContext, notificationId, intent.getIntExtra("groupId", 0))
NotificationReceiver.dismissNotification(
applicationContext,
notificationId,
intent.getIntExtra("groupId", 0)
)
}

isHandlingShortcut = true
Expand Down Expand Up @@ -495,7 +500,11 @@ class MainActivity : BaseActivity() {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1)
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
1
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundl
.replace("""---(\R|.)*Checksums(\R|.)*""".toRegex(), "")
val info = Markwon.create(activity!!).toMarkdown(releaseBody)

return MaterialAlertDialogBuilder(activity!!, materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
return MaterialAlertDialogBuilder(
activity!!,
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
)
.setTitle(R.string.update_check_notification_update_available)
.setMessage(info)
.setIcon(R.drawable.ic_update)
Expand Down Expand Up @@ -88,7 +91,10 @@ class NewScheduleDialogController(bundle: Bundle? = null) : DialogController(bun
append(infoBody)
}

return MaterialAlertDialogBuilder(activity!!, materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
return MaterialAlertDialogBuilder(
activity!!,
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
)
.setTitle(R.string.update_check_notification_database_update_available)
.setMessage(message)
.setIcon(R.drawable.ic_database_update)
Expand All @@ -103,7 +109,10 @@ class NewScheduleDialogController(bundle: Bundle? = null) : DialogController(bun
.setNeutralButton(R.string.action_postpone) { _, _ ->
dialog?.dismiss()
applicationContext?.let { context ->
NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_DATABASE_UPDATER)
NotificationReceiver.dismissNotificationPendingBroadcast(
context,
Notifications.ID_DATABASE_UPDATER
)
}
}
.create()
Expand Down
Loading

0 comments on commit cbc8ce7

Please sign in to comment.