Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
aayush262 2024-04-30 00:41:50 +05:30
commit e30124d342
4 changed files with 31 additions and 37 deletions

View file

@ -135,7 +135,6 @@ class App : MultiDexApplication() {
val useAlarmManager = PrefManager.getVal<Boolean>(PrefName.UseAlarmManager) val useAlarmManager = PrefManager.getVal<Boolean>(PrefName.UseAlarmManager)
val scheduler = TaskScheduler.create(this, useAlarmManager) val scheduler = TaskScheduler.create(this, useAlarmManager)
scheduler.scheduleAllTasks(this) scheduler.scheduleAllTasks(this)
scheduler.scheduleSingleWork(this)
} }
private fun setupNotificationChannels() { private fun setupNotificationChannels() {

View file

@ -48,6 +48,7 @@ import ani.dantotsu.home.LoginFragment
import ani.dantotsu.home.MangaFragment import ani.dantotsu.home.MangaFragment
import ani.dantotsu.home.NoInternet import ani.dantotsu.home.NoInternet
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.notifications.TaskScheduler
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
import ani.dantotsu.notifications.comment.CommentNotificationWorker import ani.dantotsu.notifications.comment.CommentNotificationWorker
import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.others.CustomBottomDialog
@ -102,12 +103,7 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
TaskScheduler.scheduleSingleWork(this)
androidx.work.WorkManager.getInstance(this)
.enqueue(OneTimeWorkRequest.Companion.from(CommentNotificationWorker::class.java))
androidx.work.WorkManager.getInstance(this)
.enqueue(OneTimeWorkRequest.Companion.from(AnilistNotificationWorker::class.java))
val action = intent.action val action = intent.action
val type = intent.type val type = intent.type

View file

@ -1586,14 +1586,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
} }
}.show() }.show()
dialog.window?.setDimAmount(0.8f) dialog.window?.setDimAmount(0.8f)
} } else buildExoplayer()
if (!this::exoPlayer.isInitialized) buildExoplayer()
val isDisabled = (subtitle == null && hasExtSubtitles)
exoPlayer.trackSelectionParameters = exoPlayer.trackSelectionParameters
.buildUpon()
.setTrackTypeDisabled(TRACK_TYPE_TEXT, isDisabled)
.build()
} }
private fun buildExoplayer() { private fun buildExoplayer() {
@ -1644,6 +1637,12 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
if (!hasExtSubtitles && !PrefManager.getVal<Boolean>(PrefName.Subtitles)) { if (!hasExtSubtitles && !PrefManager.getVal<Boolean>(PrefName.Subtitles)) {
onSetTrackGroupOverride(dummyTrack, TRACK_TYPE_TEXT) onSetTrackGroupOverride(dummyTrack, TRACK_TYPE_TEXT)
} }
val isDisabled = (subtitle == null && hasExtSubtitles)
exoPlayer.trackSelectionParameters = exoPlayer.trackSelectionParameters
.buildUpon()
.setTrackTypeDisabled(TRACK_TYPE_TEXT, isDisabled)
.build()
} }
private fun releasePlayer() { private fun releasePlayer() {

View file

@ -36,28 +36,6 @@ interface TaskScheduler {
} }
} }
fun scheduleSingleWork(context: Context) {
val workManager = androidx.work.WorkManager.getInstance(context)
workManager.enqueueUniqueWork(
CommentNotificationWorker.WORK_NAME,
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(CommentNotificationWorker::class.java)
.build()
)
workManager.enqueueUniqueWork(
AnilistNotificationWorker.WORK_NAME,
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(AnilistNotificationWorker::class.java)
.build()
)
workManager.enqueueUniqueWork(
SubscriptionNotificationWorker.WORK_NAME,
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(SubscriptionNotificationWorker::class.java)
.build()
)
}
companion object { companion object {
fun create(context: Context, useAlarmManager: Boolean): TaskScheduler { fun create(context: Context, useAlarmManager: Boolean): TaskScheduler {
return if (useAlarmManager) { return if (useAlarmManager) {
@ -66,6 +44,28 @@ interface TaskScheduler {
WorkManagerScheduler(context) WorkManagerScheduler(context)
} }
} }
fun scheduleSingleWork(context: Context) {
val workManager = androidx.work.WorkManager.getInstance(context)
workManager.enqueueUniqueWork(
CommentNotificationWorker.WORK_NAME + "_single",
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(CommentNotificationWorker::class.java)
.build()
)
workManager.enqueueUniqueWork(
AnilistNotificationWorker.WORK_NAME + "_single",
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(AnilistNotificationWorker::class.java)
.build()
)
workManager.enqueueUniqueWork(
SubscriptionNotificationWorker.WORK_NAME + "_single",
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(SubscriptionNotificationWorker::class.java)
.build()
)
}
} }
enum class TaskType { enum class TaskType {