forked from Jays2Kings/tachiyomiJ2K
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'j2k/master'
# Conflicts: # .github/ISSUE_TEMPLATE.md # .github/ISSUE_TEMPLATE/feature_request.yml # .github/ISSUE_TEMPLATE/issue_report.yml # .github/workflows/build_push.yml # app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt # app/src/main/res/values-ar/strings.xml # app/src/main/res/values-pt-rBR/strings.xml # app/src/main/res/values-ro/strings.xml # app/src/main/res/values-sk/strings.xml # buildSrc/src/main/kotlin/Dependencies.kt
- Loading branch information
Showing
314 changed files
with
10,441 additions
and
3,988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/eu/kanade/tachiyomi/appwidget/TachiyomiWidgetManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package eu.kanade.tachiyomi.appwidget | ||
|
||
import android.content.Context | ||
import androidx.glance.appwidget.GlanceAppWidgetManager | ||
|
||
class TachiyomiWidgetManager { | ||
|
||
suspend fun Context.init() { | ||
val manager = GlanceAppWidgetManager(this) | ||
if (manager.getGlanceIds(UpdatesGridGlanceWidget::class.java).isNotEmpty()) { | ||
UpdatesGridGlanceWidget().loadData() | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/eu/kanade/tachiyomi/appwidget/UpdatesGridGlanceReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package eu.kanade.tachiyomi.appwidget | ||
|
||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.GlanceAppWidgetReceiver | ||
|
||
class UpdatesGridGlanceReceiver : GlanceAppWidgetReceiver() { | ||
override val glanceAppWidget: GlanceAppWidget = UpdatesGridGlanceWidget().apply { loadData() } | ||
} |
126 changes: 126 additions & 0 deletions
126
app/src/main/java/eu/kanade/tachiyomi/appwidget/UpdatesGridGlanceWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package eu.kanade.tachiyomi.appwidget | ||
|
||
import android.app.Application | ||
import android.graphics.Bitmap | ||
import android.os.Build | ||
import androidx.compose.runtime.Composable | ||
import androidx.core.graphics.drawable.toBitmap | ||
import androidx.glance.GlanceModifier | ||
import androidx.glance.ImageProvider | ||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.GlanceAppWidgetManager | ||
import androidx.glance.appwidget.SizeMode | ||
import androidx.glance.appwidget.appWidgetBackground | ||
import androidx.glance.appwidget.updateAll | ||
import androidx.glance.background | ||
import androidx.glance.layout.fillMaxSize | ||
import coil.executeBlocking | ||
import coil.imageLoader | ||
import coil.request.CachePolicy | ||
import coil.request.ImageRequest | ||
import coil.size.Precision | ||
import coil.size.Scale | ||
import coil.transform.RoundedCornersTransformation | ||
import eu.kanade.tachiyomi.R | ||
import eu.kanade.tachiyomi.appwidget.components.CoverHeight | ||
import eu.kanade.tachiyomi.appwidget.components.CoverWidth | ||
import eu.kanade.tachiyomi.appwidget.components.LockedWidget | ||
import eu.kanade.tachiyomi.appwidget.util.appWidgetBackgroundRadius | ||
import eu.kanade.tachiyomi.appwidget.util.calculateRowAndColumnCount | ||
import eu.kanade.tachiyomi.data.database.models.Manga | ||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper | ||
import eu.kanade.tachiyomi.ui.recents.RecentsPresenter | ||
import eu.kanade.tachiyomi.util.system.dpToPx | ||
import eu.kanade.tachiyomi.util.system.launchIO | ||
import kotlinx.coroutines.MainScope | ||
import tachiyomi.presentation.widget.components.UpdatesWidget | ||
import uy.kohesive.injekt.injectLazy | ||
import java.util.Calendar | ||
import java.util.Date | ||
|
||
class UpdatesGridGlanceWidget : GlanceAppWidget() { | ||
private val app: Application by injectLazy() | ||
private val preferences: PreferencesHelper by injectLazy() | ||
|
||
private val coroutineScope = MainScope() | ||
|
||
private var data: List<Pair<Long, Bitmap?>>? = null | ||
|
||
override val sizeMode = SizeMode.Exact | ||
|
||
@Composable | ||
override fun Content() { | ||
// If app lock enabled, don't do anything | ||
if (preferences.useBiometrics().get()) { | ||
LockedWidget() | ||
return | ||
} | ||
UpdatesWidget(data) | ||
} | ||
|
||
fun loadData(list: List<Pair<Manga, Long>>? = null) { | ||
coroutineScope.launchIO { | ||
// Don't show anything when lock is active | ||
if (preferences.useBiometrics().get()) { | ||
updateAll(app) | ||
return@launchIO | ||
} | ||
|
||
val manager = GlanceAppWidgetManager(app) | ||
val ids = manager.getGlanceIds(this@UpdatesGridGlanceWidget::class.java) | ||
if (ids.isEmpty()) return@launchIO | ||
|
||
val (rowCount, columnCount) = ids | ||
.flatMap { manager.getAppWidgetSizes(it) } | ||
.maxBy { it.height.value * it.width.value } | ||
.calculateRowAndColumnCount() | ||
val processList = list ?: RecentsPresenter.getRecentManga(customAmount = rowCount * columnCount) | ||
|
||
data = prepareList(processList, rowCount * columnCount) | ||
ids.forEach { update(app, it) } | ||
} | ||
} | ||
|
||
private fun prepareList(processList: List<Pair<Manga, Long>>, take: Int): List<Pair<Long, Bitmap?>> { | ||
// Resize to cover size | ||
val widthPx = CoverWidth.value.toInt().dpToPx | ||
val heightPx = CoverHeight.value.toInt().dpToPx | ||
val roundPx = app.resources.getDimension(R.dimen.appwidget_inner_radius) | ||
return processList | ||
// .distinctBy { it.first.id } | ||
.sortedByDescending { it.second } | ||
.take(take) | ||
.map { it.first } | ||
.map { updatesView -> | ||
val request = ImageRequest.Builder(app) | ||
.data(updatesView) | ||
.memoryCachePolicy(CachePolicy.DISABLED) | ||
.precision(Precision.EXACT) | ||
.size(widthPx, heightPx) | ||
.scale(Scale.FILL) | ||
.let { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { | ||
it.transformations(RoundedCornersTransformation(roundPx)) | ||
} else { | ||
it // Handled by system | ||
} | ||
} | ||
.build() | ||
Pair(updatesView.id!!, app.imageLoader.executeBlocking(request).drawable?.toBitmap()) | ||
} | ||
} | ||
|
||
companion object { | ||
val DateLimit: Calendar | ||
get() = Calendar.getInstance().apply { | ||
time = Date() | ||
add(Calendar.MONTH, -3) | ||
} | ||
} | ||
} | ||
|
||
val ContainerModifier = GlanceModifier | ||
.fillMaxSize() | ||
.background(ImageProvider(R.drawable.appwidget_background)) | ||
.appWidgetBackground() | ||
.appWidgetBackgroundRadius() |
Oops, something went wrong.