This commit is contained in:
Finnley Somdahl 2023-12-01 01:22:15 -06:00
parent 1df528c0dc
commit afa960c808
171 changed files with 3458 additions and 1915 deletions

View file

@ -5,11 +5,14 @@ import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import ani.dantotsu.*
import ani.dantotsu.currContext
import ani.dantotsu.isOnline
import ani.dantotsu.loadData
import ani.dantotsu.logger
import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime
import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription
import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes
import ani.dantotsu.tryWith
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View file

@ -58,15 +58,28 @@ class Notifications {
)
}
fun createChannel(context: Context, group: Group?, id: String, name: String, silent: Boolean = false) {
fun createChannel(
context: Context,
group: Group?,
id: String,
name: String,
silent: Boolean = false
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val importance = if (!silent) NotificationManager.IMPORTANCE_HIGH else NotificationManager.IMPORTANCE_LOW
val importance =
if (!silent) NotificationManager.IMPORTANCE_HIGH else NotificationManager.IMPORTANCE_LOW
val mChannel = NotificationChannel(id, name, importance)
val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val notificationManager =
context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
if (group != null) {
notificationManager.createNotificationChannelGroup(NotificationChannelGroup(group.name, group.title))
notificationManager.createNotificationChannelGroup(
NotificationChannelGroup(
group.name,
group.title
)
)
mChannel.group = group.name
}
@ -76,7 +89,8 @@ class Notifications {
fun deleteChannel(context: Context, id: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val notificationManager =
context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.deleteNotificationChannel(id)
}
}
@ -117,20 +131,21 @@ class Notifications {
.submit()
.get()
}
@Suppress("BlockingMethodInNonBlockingContext")
val largeBitmap = if (largeImg != null) Glide.with(context)
.asBitmap()
.load(GlideUrl(largeImg.url) { largeImg.headers })
.submit()
.get()
.asBitmap()
.load(GlideUrl(largeImg.url) { largeImg.headers })
.submit()
.get()
else null
if(largeBitmap!=null) builder.setStyle(
NotificationCompat
.BigPictureStyle()
.bigPicture(largeBitmap)
.bigLargeIcon(bitmap)
)
if (largeBitmap != null) builder.setStyle(
NotificationCompat
.BigPictureStyle()
.bigPicture(largeBitmap)
.bigLargeIcon(bitmap)
)
builder.setLargeIcon(bitmap)
} else builder

View file

@ -40,7 +40,8 @@ class Subscription {
val index = subscriptions.map { i++; it.key to i }.toMap()
val notificationManager = NotificationManagerCompat.from(context)
val progressEnabled = loadData("subscription_checking_notifications", context) ?: true
val progressEnabled =
loadData("subscription_checking_notifications", context) ?: true
val progressNotification = if (progressEnabled) getProgressNotification(
context,
subscriptions.size
@ -69,23 +70,26 @@ class Subscription {
subscriptions.toList().map {
val media = it.second
val text = if (media.isAnime) {
val parser = SubscriptionHelper.getAnimeParser(context, media.isAdult, media.id)
val parser =
SubscriptionHelper.getAnimeParser(context, media.isAdult, media.id)
progress(index[it.first]!!, parser.name, media.name)
val ep: Episode? = SubscriptionHelper.getEpisode(context, parser, media.id, media.isAdult)
if (ep != null) currActivity()!!.getString(R.string.episode)+"${ep.number}${
val ep: Episode? =
SubscriptionHelper.getEpisode(context, parser, media.id, media.isAdult)
if (ep != null) currActivity()!!.getString(R.string.episode) + "${ep.number}${
if (ep.title != null) " : ${ep.title}" else ""
}${
if (ep.isFiller) " [Filler]" else ""
} "+ currActivity()!!.getString(R.string.just_released) to ep.thumbnail
} " + currActivity()!!.getString(R.string.just_released) to ep.thumbnail
else null
} else {
val parser = SubscriptionHelper.getMangaParser(context, media.isAdult, media.id)
val parser =
SubscriptionHelper.getMangaParser(context, media.isAdult, media.id)
progress(index[it.first]!!, parser.name, media.name)
val ep: MangaChapter? =
SubscriptionHelper.getChapter(context, parser, media.id, media.isAdult)
if (ep != null) currActivity()!!.getString(R.string.chapter)+"${ep.number}${
if (ep != null) currActivity()!!.getString(R.string.chapter) + "${ep.number}${
if (ep.title != null) " : ${ep.title}" else ""
} "+ currActivity()!!.getString(R.string.just_released) to null
} " + currActivity()!!.getString(R.string.just_released) to null
else null
} ?: return@map
createNotification(context.applicationContext, media, text.first, text.second)
@ -96,7 +100,8 @@ class Subscription {
}
}
fun getChannelId(isAnime: Boolean, mediaId: Int) = "${if (isAnime) "anime" else "manga"}_${mediaId}"
fun getChannelId(isAnime: Boolean, mediaId: Int) =
"${if (isAnime) "anime" else "manga"}_${mediaId}"
private suspend fun createNotification(
context: Context,
@ -124,7 +129,10 @@ class Subscription {
private const val progressNotificationId = 100
private fun getProgressNotification(context: Context, size: Int): NotificationCompat.Builder {
private fun getProgressNotification(
context: Context,
size: Int
): NotificationCompat.Builder {
return Notifications.getNotification(
context,
null,

View file

@ -1,26 +1,41 @@
package ani.dantotsu.subcriptions
import android.content.Context
import ani.dantotsu.R
import ani.dantotsu.currContext
import ani.dantotsu.loadData
import ani.dantotsu.media.Media
import ani.dantotsu.media.Selected
import ani.dantotsu.parsers.*
import ani.dantotsu.media.manga.MangaNameAdapter
import ani.dantotsu.parsers.AnimeParser
import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.parsers.Episode
import ani.dantotsu.parsers.HAnimeSources
import ani.dantotsu.parsers.HMangaSources
import ani.dantotsu.parsers.MangaChapter
import ani.dantotsu.parsers.MangaParser
import ani.dantotsu.parsers.MangaSources
import ani.dantotsu.saveData
import ani.dantotsu.tryWithSuspend
import ani.dantotsu.R
import ani.dantotsu.media.manga.MangaNameAdapter
import kotlinx.coroutines.withTimeoutOrNull
class SubscriptionHelper {
companion object {
private fun loadSelected(context: Context, mediaId: Int, isAdult: Boolean, isAnime: Boolean): Selected {
private fun loadSelected(
context: Context,
mediaId: Int,
isAdult: Boolean,
isAnime: Boolean
): Selected {
val sharedPreferences = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
val data = loadData<Selected>("${mediaId}-select", context) ?: Selected().let {
it.sourceIndex =
if (isAdult) 0
else if (isAnime) {sharedPreferences.getInt("settings_def_anime_source_s_r",0)}
else {sharedPreferences.getInt("settings_def_manga_source_s_r",0)}
else if (isAnime) {
sharedPreferences.getInt("settings_def_anime_source_s_r", 0)
} else {
sharedPreferences.getInt("settings_def_manga_source_s_r", 0)
}
it.preferDub = loadData("settings_prefer_dub", context) ?: false
it
}
@ -39,15 +54,27 @@ class SubscriptionHelper {
return parser
}
suspend fun getEpisode(context: Context, parser: AnimeParser, id: Int, isAdult: Boolean): Episode? {
suspend fun getEpisode(
context: Context,
parser: AnimeParser,
id: Int,
isAdult: Boolean
): Episode? {
val selected = loadSelected(context, id, isAdult, true)
val ep = withTimeoutOrNull(10 * 1000) {
tryWithSuspend {
val show = parser.loadSavedShowResponse(id) ?: throw Exception(currContext()?.getString(R.string.failed_to_load_data, id))
val show = parser.loadSavedShowResponse(id) ?: throw Exception(
currContext()?.getString(
R.string.failed_to_load_data,
id
)
)
show.sAnime?.let {
parser.getLatestEpisode(show.link, show.extra,
it, selected.latest)
parser.getLatestEpisode(
show.link, show.extra,
it, selected.latest
)
}
}
}
@ -64,14 +91,26 @@ class SubscriptionHelper {
return sources[selected.sourceIndex]
}
suspend fun getChapter(context: Context, parser: MangaParser, id: Int, isAdult: Boolean): MangaChapter? {
suspend fun getChapter(
context: Context,
parser: MangaParser,
id: Int,
isAdult: Boolean
): MangaChapter? {
val selected = loadSelected(context, id, isAdult, true)
val chp = withTimeoutOrNull(10 * 1000) {
tryWithSuspend {
val show = parser.loadSavedShowResponse(id) ?: throw Exception(currContext()?.getString(R.string.failed_to_load_data, id))
val show = parser.loadSavedShowResponse(id) ?: throw Exception(
currContext()?.getString(
R.string.failed_to_load_data,
id
)
)
show.sManga?.let {
parser.getLatestChapter(show.link, show.extra,
it, selected.latest)
parser.getLatestChapter(
show.link, show.extra,
it, selected.latest
)
}
}
}
@ -91,8 +130,9 @@ class SubscriptionHelper {
) : java.io.Serializable
private const val subscriptions = "subscriptions"
fun getSubscriptions(context: Context): Map<Int, SubscribeMedia> = loadData(subscriptions, context)
?: mapOf<Int, SubscribeMedia>().also { saveData(subscriptions, it, context) }
fun getSubscriptions(context: Context): Map<Int, SubscribeMedia> =
loadData(subscriptions, context)
?: mapOf<Int, SubscribeMedia>().also { saveData(subscriptions, it, context) }
fun saveSubscription(context: Context, media: Media, subscribed: Boolean) {
val data = loadData<Map<Int, SubscribeMedia>>(subscriptions, context)!!.toMutableMap()

View file

@ -1,18 +1,25 @@
package ani.dantotsu.subcriptions
import android.content.Context
import androidx.work.*
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import ani.dantotsu.loadData
import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime
import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.concurrent.*
import java.util.concurrent.TimeUnit
class SubscriptionWorker(val context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
class SubscriptionWorker(val context: Context, params: WorkerParameters) :
CoroutineWorker(context, params) {
override suspend fun doWork(): Result {
withContext(Dispatchers.IO){
withContext(Dispatchers.IO) {
Subscription.perform(context)
}
return Result.success()
@ -23,8 +30,9 @@ class SubscriptionWorker(val context: Context, params: WorkerParameters) : Corou
private const val SUBSCRIPTION_WORK_NAME = "work_subscription"
fun enqueue(context: Context) {
val curTime = loadData<Int>("subscriptions_time_s") ?: defaultTime
if(timeMinutes[curTime]>0L) {
val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
if (timeMinutes[curTime] > 0L) {
val constraints =
Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
val periodicSyncDataWork = PeriodicWorkRequest.Builder(
SubscriptionWorker::class.java, 6, TimeUnit.HOURS
).apply {
@ -32,7 +40,9 @@ class SubscriptionWorker(val context: Context, params: WorkerParameters) : Corou
setConstraints(constraints)
}.build()
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
SUBSCRIPTION_WORK_NAME, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, periodicSyncDataWork
SUBSCRIPTION_WORK_NAME,
ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE,
periodicSyncDataWork
)
}
}