Skip to content

Commit

Permalink
refactor: re-write preset writer/reader & notification handling
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Mar 9, 2023
1 parent 127f18f commit c256340
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 229 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,12 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.3.0-rc01")
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-fragment:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
implementation("androidx.preference:preference-ktx:1.2.0")
implementation("androidx.preference:preference:1.2.0")
implementation("androidx.databinding:databinding-runtime:7.4.2")
implementation("androidx.work:work-runtime-ktx:2.8.0")

// Material
implementation("com.google.android.material:material:1.9.0-alpha02")

// Dependency injection
Expand Down Expand Up @@ -217,6 +218,9 @@ dependencies {
implementation("dev.rikka.shizuku:api:${AndroidConfig.shizukuVersion}")
implementation("dev.rikka.shizuku:provider:${AndroidConfig.shizukuVersion}")

// Used for backup feature; check if this can be removed later
implementation("com.github.tachiyomiorg:unifile:17bec43")

// Root APIs
"rootImplementation"("com.github.topjohnwu.libsu:core:5.0.4")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang
dumpFile.delete()
}

Notifications.createChannels(this)

val appModule = module {
single { DumpManager(androidContext()) }
single { UpdateManager(androidContext()) }
Expand Down
114 changes: 114 additions & 0 deletions app/src/main/java/me/timschneeberger/rootlessjamesdsp/Notifications.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package me.timschneeberger.rootlessjamesdsp

import android.content.Context
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.NotificationManagerCompat.IMPORTANCE_DEFAULT
import androidx.core.app.NotificationManagerCompat.IMPORTANCE_HIGH
import androidx.core.app.NotificationManagerCompat.IMPORTANCE_LOW
import androidx.core.app.NotificationManagerCompat.IMPORTANCE_NONE
import me.timschneeberger.rootlessjamesdsp.utils.extensions.buildNotificationChannel
import me.timschneeberger.rootlessjamesdsp.utils.extensions.buildNotificationChannelGroup

/**
* Class to manage the basic information of all the notifications used in the app.
*/
object Notifications {
/**
* Notification channel and ids used by the service.
*/
private const val GROUP_SERVICE = "group_service"
const val CHANNEL_SERVICE_STATUS = "service_status"
const val ID_SERVICE_STATUS = 1
const val CHANNEL_SERVICE_SESSION_LOSS = "service_session_loss"
const val ID_SERVICE_SESSION_LOSS = 2
const val CHANNEL_SERVICE_APP_COMPAT = "service_app_compat_alert"
const val ID_SERVICE_APPCOMPAT = 3
const val CHANNEL_SERVICE_STARTUP = "service_startup"
const val ID_SERVICE_STARTUP = 4

/**
* Notification channel and ids used by the backup/restore system.
*/
private const val GROUP_BACKUP_RESTORE = "group_backup_restore"
const val CHANNEL_BACKUP_RESTORE_PROGRESS = "backup_restore_progress_channel"
const val ID_BACKUP_PROGRESS = -501
const val ID_RESTORE_PROGRESS = -503
const val CHANNEL_BACKUP_RESTORE_COMPLETE = "backup_restore_complete_channel_v2"
const val ID_BACKUP_COMPLETE = -502
const val ID_RESTORE_COMPLETE = -504


private val deprecatedChannels = listOf(
"JamesDSP",
"Session loss alert",
"Permission prompt",
"App incompatibility alert"
)

/**
* Creates the notification channels introduced in Android Oreo.
* This won't do anything on Android versions that don't support notification channels.
*
* @param context The application context.
*/
fun createChannels(context: Context) {
val notificationService = NotificationManagerCompat.from(context)

// Delete old notification channels
deprecatedChannels.forEach(notificationService::deleteNotificationChannel)

notificationService.createNotificationChannelGroupsCompat(
listOf(
buildNotificationChannelGroup(GROUP_SERVICE) {
setName(context.getString(R.string.notification_group_service))
},
buildNotificationChannelGroup(GROUP_BACKUP_RESTORE) {
setName(context.getString(R.string.notification_group_backup))
}
),
)

notificationService.createNotificationChannelsCompat(
listOf(
buildNotificationChannel(CHANNEL_SERVICE_STATUS, IMPORTANCE_NONE) {
setName(context.getString(R.string.notification_channel_service))
setGroup(GROUP_SERVICE)
setShowBadge(false)
setVibrationEnabled(false)
setSound(null, null)
},
buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) {
setName(context.getString(R.string.notification_channel_backup_progress))
setGroup(GROUP_BACKUP_RESTORE)
setShowBadge(false)
},
buildNotificationChannel(CHANNEL_BACKUP_RESTORE_COMPLETE, IMPORTANCE_HIGH) {
setName(context.getString(R.string.notification_channel_backup_complete))
setGroup(GROUP_BACKUP_RESTORE)
setShowBadge(false)
setSound(null, null)
}
)
)

if(BuildConfig.ROOTLESS) {
notificationService.createNotificationChannelsCompat(
listOf(
buildNotificationChannel(CHANNEL_SERVICE_SESSION_LOSS, IMPORTANCE_HIGH) {
setName(context.getString(R.string.notification_channel_session_loss_alert))
setGroup(GROUP_SERVICE)
},
buildNotificationChannel(CHANNEL_SERVICE_APP_COMPAT, IMPORTANCE_HIGH) {
setName(context.getString(R.string.notification_channel_app_compat_alert))
setGroup(GROUP_SERVICE)
},
buildNotificationChannel(CHANNEL_SERVICE_STARTUP, IMPORTANCE_DEFAULT) {
setName(context.getString(R.string.notification_channel_permission_prompt))
setGroup(GROUP_SERVICE)
setVibrationEnabled(false)
},
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AeqSelectorActivity : BaseActivity() {
)

val initialResults = savedInstanceState
?.getSerializableAs(STATE_RESULTS, Array<AeqSearchResult>::class.java)
?.getSerializableAs<Array<AeqSearchResult>>(STATE_RESULTS)
?: arrayOf()

val isLoadingOld = savedInstanceState?.getBoolean(STATE_IS_LOADING, false) ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import me.timschneeberger.rootlessjamesdsp.BuildConfig
import me.timschneeberger.rootlessjamesdsp.MainApplication
import me.timschneeberger.rootlessjamesdsp.Notifications
import me.timschneeberger.rootlessjamesdsp.R
import me.timschneeberger.rootlessjamesdsp.activity.MainActivity
import me.timschneeberger.rootlessjamesdsp.databinding.FragmentAppCompatibilityBinding
Expand Down Expand Up @@ -51,7 +52,7 @@ class AppCompatibilityFragment : Fragment() {
savedInstanceState: Bundle?,
): View {
SystemServices.get<NotificationManager>(requireContext())
.cancel(Constants.NOTIFICATION_ID_APP_INCOMPATIBILITY)
.cancel(Notifications.ID_SERVICE_APPCOMPAT)

val args = requireArguments()
val projectIntent = args.getParcelableAs<Intent>(BUNDLE_MEDIA_PROJECTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GraphicEqNodeList : ObservableArrayList<GraphicEqNode>() {

val freq = bundle.getDoubleArray(STATE_FREQ) ?: return
val gain = bundle.getDoubleArray(STATE_GAIN) ?: return
val uuids = bundle.getSerializableAs(STATE_UUID, Array<UUID>::class.java)
val uuids = bundle.getSerializableAs<Array<UUID>>(STATE_UUID)

val count = Integer.min(freq.size, gain.size)
for (i in 0 until count) {
Expand Down
Loading

0 comments on commit c256340

Please sign in to comment.