Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d0982b244 | ||
|
|
ef4dd82e92 | ||
|
|
bc825681a8 | ||
|
|
da6204f44f | ||
|
|
10c68bdd72 | ||
|
|
b1e90dde8f | ||
|
|
e0d45961f8 | ||
|
|
b732a220f6 | ||
|
|
582adae11f | ||
|
|
3014ebdfd4 | ||
|
|
12b13f98f8 | ||
|
|
c13c43c616 | ||
|
|
ab1eacea3f | ||
|
|
ac4b97928a | ||
|
|
aa8281678b | ||
|
|
0be4f56538 | ||
|
|
679c06557e | ||
|
|
1d387709f2 | ||
|
|
a78774d10e | ||
|
|
390639e9e3 | ||
|
|
b98ec2199d | ||
|
|
8b28f1cd74 | ||
|
|
904b78a01e | ||
|
|
a774d2d915 | ||
|
|
9d19b5fec0 | ||
|
|
b6c0f3ca8c | ||
|
|
e06cb1230f | ||
|
|
1720fde4c4 | ||
|
|
4c3dbe1643 | ||
|
|
3f31bd5ad1 | ||
|
|
3a79b4667b | ||
|
|
de49877178 | ||
|
|
65e92fa206 | ||
|
|
9cb181d53e | ||
|
|
a2d4a63eb1 | ||
|
|
c4f712be3a | ||
|
|
9e8367e45e | ||
|
|
fa2d1de2f2 | ||
|
|
f8f4573486 | ||
|
|
f15f0ce769 | ||
|
|
450daf17fd | ||
|
|
aad26d24ec | ||
|
|
80c8344f8d | ||
|
|
44b23d0b69 | ||
|
|
f230f2d198 | ||
|
|
cf50b608a7 |
8
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel>
|
||||
<module name="Kotatsu.app" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/gradle.xml
generated
@@ -15,6 +15,7 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="TrailingComma" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
Kotatsu is a free and open source manga reader for Android.
|
||||
|
||||
  [](https://travis-ci.org/nv95/Kotatsu)  [](http://4pda.ru/forum/index.php?showtopic=697669)
|
||||
  [](https://travis-ci.org/nv95/Kotatsu)  [](http://4pda.ru/forum/index.php?showtopic=697669)
|
||||
|
||||
### Download
|
||||
|
||||
Latest unstable build: [get here](https://github.com/nv95/Kotatsu/releases/latest)
|
||||
|
||||
Stable release: _Coming soon_
|
||||
Latest release: [get here](https://github.com/nv95/Kotatsu/releases/latest)
|
||||
|
||||
### Main Features
|
||||
|
||||
@@ -20,9 +18,6 @@ Stable release: _Coming soon_
|
||||
* Tablet-optimized modern UI
|
||||
* Reading third-party comics from CBZ
|
||||
* Standard and Webtoon-optimized reader
|
||||
|
||||
### Coming Features
|
||||
|
||||
* Checking for new chapters
|
||||
|
||||
### Screenshots
|
||||
|
||||
@@ -15,7 +15,7 @@ android {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode gitCommits
|
||||
versionName '0.1.2'
|
||||
versionName '0.3'
|
||||
|
||||
buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\""
|
||||
|
||||
@@ -61,14 +61,16 @@ dependencies {
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.3.0-alpha02'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.2.3'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-alpha03'
|
||||
implementation 'androidx.core:core-ktx:1.3.0-rc01'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.2.4'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
|
||||
implementation 'androidx.preference:preference:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.2.0-alpha05'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-rc01'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha02'
|
||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
|
||||
implementation 'androidx.preference:preference-ktx:1.1.1'
|
||||
implementation 'androidx.work:work-runtime-ktx:2.3.4'
|
||||
implementation 'com.google.android.material:material:1.2.0-alpha06'
|
||||
|
||||
implementation 'androidx.room:room-runtime:2.2.5'
|
||||
implementation 'androidx.room:room-ktx:2.2.5'
|
||||
@@ -80,11 +82,11 @@ dependencies {
|
||||
implementation 'com.github.moxy-community:moxy-ktx:2.1.2'
|
||||
kapt 'com.github.moxy-community:moxy-compiler:2.1.2'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.4.1'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.5.0'
|
||||
implementation 'com.squareup.okio:okio:2.5.0'
|
||||
implementation 'org.jsoup:jsoup:1.13.1'
|
||||
|
||||
implementation 'org.koin:koin-android:2.1.4'
|
||||
implementation 'org.koin:koin-android:2.1.5'
|
||||
implementation 'io.coil-kt:coil:0.9.5'
|
||||
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
|
||||
implementation 'com.tomclaw.cache:cache:1.0'
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:name="org.koitharu.kotatsu.KotatsuApp"
|
||||
@@ -44,21 +46,38 @@
|
||||
android:label="@string/settings" />
|
||||
<activity
|
||||
android:name=".ui.reader.SimpleSettingsActivity"
|
||||
android:label="@string/settings" />
|
||||
android:label="@string/settings">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ui.browser.BrowserActivity" />
|
||||
<activity
|
||||
android:name=".ui.browser.BrowserActivity"
|
||||
android:launchMode="singleInstance" />
|
||||
android:name=".ui.utils.CrashActivity"
|
||||
android:label="@string/error_occurred"
|
||||
android:theme="@android:style/Theme.DeviceDefault.Dialog"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity
|
||||
android:name=".ui.main.list.favourites.categories.CategoriesActivity"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"
|
||||
android:label="@string/favourites_categories" />
|
||||
|
||||
<service
|
||||
android:name=".ui.download.DownloadService"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
<service android:name=".ui.settings.AppUpdateService" />
|
||||
<service
|
||||
android:name=".ui.widget.shelf.ShelfWidgetService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
<service
|
||||
android:name=".ui.widget.recent.RecentWidgetService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
|
||||
<provider
|
||||
android:name=".ui.search.MangaSuggestionsProvider"
|
||||
android:authorities="${applicationId}.MangaSuggestionsProvider"
|
||||
android:exported="false" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.files"
|
||||
@@ -68,6 +87,23 @@
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths" />
|
||||
</provider>
|
||||
|
||||
<receiver android:name=".ui.widget.shelf.ShelfWidgetProvider"
|
||||
android:label="@string/manga_shelf">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_shelf" />
|
||||
</receiver>
|
||||
<receiver android:name=".ui.widget.recent.RecentWidgetProvider"
|
||||
android:label="@string/recent_manga">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_recent" />
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.koin.dsl.module
|
||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration1To2
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration2To3
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration3To4
|
||||
import org.koitharu.kotatsu.core.local.CbzFetcher
|
||||
import org.koitharu.kotatsu.core.local.PagesCache
|
||||
import org.koitharu.kotatsu.core.local.cookies.PersistentCookieJar
|
||||
@@ -24,6 +25,10 @@ import org.koitharu.kotatsu.core.local.cookies.persistence.SharedPrefsCookiePers
|
||||
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.ui.utils.AppCrashHandler
|
||||
import org.koitharu.kotatsu.ui.widget.WidgetUpdater
|
||||
import org.koitharu.kotatsu.utils.CacheUtils
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -41,10 +46,14 @@ class KotatsuApp : Application() {
|
||||
super.onCreate()
|
||||
initKoin()
|
||||
initCoil()
|
||||
Thread.setDefaultUncaughtExceptionHandler(AppCrashHandler(applicationContext))
|
||||
if (BuildConfig.DEBUG) {
|
||||
initErrorHandler()
|
||||
}
|
||||
AppCompatDelegate.setDefaultNightMode(AppSettings(this).theme)
|
||||
val widgetUpdater = WidgetUpdater(applicationContext)
|
||||
FavouritesRepository.subscribe(widgetUpdater)
|
||||
HistoryRepository.subscribe(widgetUpdater)
|
||||
}
|
||||
|
||||
private fun initKoin() {
|
||||
@@ -111,5 +120,5 @@ class KotatsuApp : Application() {
|
||||
applicationContext,
|
||||
MangaDatabase::class.java,
|
||||
"kotatsu-db"
|
||||
).addMigrations(Migration1To2, Migration2To3)
|
||||
).addMigrations(Migration1To2, Migration2To3, Migration3To4)
|
||||
}
|
||||
@@ -17,4 +17,7 @@ abstract class FavouriteCategoriesDao {
|
||||
|
||||
@Query("DELETE FROM favourite_categories WHERE category_id = :id")
|
||||
abstract suspend fun delete(id: Long)
|
||||
|
||||
@Query("UPDATE favourite_categories SET title = :title WHERE category_id = :id")
|
||||
abstract suspend fun update(id: Long, title: String)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.db
|
||||
import androidx.room.*
|
||||
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
||||
import org.koitharu.kotatsu.core.db.entity.FavouriteManga
|
||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||
|
||||
@Dao
|
||||
abstract class FavouritesDao {
|
||||
@@ -11,6 +12,9 @@ abstract class FavouritesDao {
|
||||
@Query("SELECT * FROM favourites GROUP BY manga_id ORDER BY :orderBy LIMIT :limit OFFSET :offset")
|
||||
abstract suspend fun findAll(offset: Int, limit: Int, orderBy: String): List<FavouriteManga>
|
||||
|
||||
@Query("SELECT * FROM manga WHERE manga_id IN (SELECT manga_id FROM favourites)")
|
||||
abstract suspend fun findAllManga(): List<MangaEntity>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM favourites WHERE manga_id = :id GROUP BY manga_id")
|
||||
abstract suspend fun find(id: Long): FavouriteManga?
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.db
|
||||
import androidx.room.*
|
||||
import org.koitharu.kotatsu.core.db.entity.HistoryEntity
|
||||
import org.koitharu.kotatsu.core.db.entity.HistoryWithManga
|
||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||
|
||||
|
||||
@Dao
|
||||
@@ -15,6 +16,9 @@ abstract class HistoryDao {
|
||||
@Query("SELECT * FROM history ORDER BY updated_at DESC LIMIT :limit OFFSET :offset")
|
||||
abstract suspend fun findAll(offset: Int, limit: Int): List<HistoryWithManga>
|
||||
|
||||
@Query("SELECT * FROM manga WHERE manga_id IN (SELECT manga_id FROM history)")
|
||||
abstract suspend fun findAllManga(): List<MangaEntity>
|
||||
|
||||
@Query("SELECT * FROM history WHERE manga_id = :id")
|
||||
abstract suspend fun find(id: Long): HistoryEntity?
|
||||
|
||||
@@ -33,10 +37,11 @@ abstract class HistoryDao {
|
||||
suspend fun update(entity: HistoryEntity) = update(entity.mangaId, entity.page, entity.chapterId, entity.scroll, entity.updatedAt)
|
||||
|
||||
@Transaction
|
||||
open suspend fun upsert(entity: HistoryEntity) {
|
||||
if (update(entity) == 0) {
|
||||
open suspend fun upsert(entity: HistoryEntity): Boolean {
|
||||
return if (update(entity) == 0) {
|
||||
insert(entity)
|
||||
}
|
||||
true
|
||||
} else false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,20 +7,22 @@ import org.koitharu.kotatsu.core.db.entity.*
|
||||
@Database(
|
||||
entities = [
|
||||
MangaEntity::class, TagEntity::class, HistoryEntity::class, MangaTagsEntity::class,
|
||||
FavouriteCategoryEntity::class, FavouriteEntity::class, MangaPrefsEntity::class
|
||||
], version = 3
|
||||
FavouriteCategoryEntity::class, FavouriteEntity::class, MangaPrefsEntity::class, TrackEntity::class
|
||||
], version = 4
|
||||
)
|
||||
abstract class MangaDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun historyDao(): HistoryDao
|
||||
abstract val historyDao: HistoryDao
|
||||
|
||||
abstract fun tagsDao(): TagsDao
|
||||
abstract val tagsDao: TagsDao
|
||||
|
||||
abstract fun mangaDao(): MangaDao
|
||||
abstract val mangaDao: MangaDao
|
||||
|
||||
abstract fun favouritesDao(): FavouritesDao
|
||||
abstract val favouritesDao: FavouritesDao
|
||||
|
||||
abstract fun preferencesDao(): PreferencesDao
|
||||
abstract val preferencesDao: PreferencesDao
|
||||
|
||||
abstract fun favouriteCategoriesDao(): FavouriteCategoriesDao
|
||||
abstract val favouriteCategoriesDao: FavouriteCategoriesDao
|
||||
|
||||
abstract val tracksDao: TracksDao
|
||||
}
|
||||
35
app/src/main/java/org/koitharu/kotatsu/core/db/TracksDao.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.koitharu.kotatsu.core.db
|
||||
|
||||
import androidx.room.*
|
||||
import org.koitharu.kotatsu.core.db.entity.TrackEntity
|
||||
|
||||
|
||||
@Dao
|
||||
abstract class TracksDao {
|
||||
|
||||
@Query("SELECT * FROM tracks")
|
||||
abstract suspend fun findAll(): List<TrackEntity>
|
||||
|
||||
@Query("SELECT * FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract suspend fun find(mangaId: Long): TrackEntity?
|
||||
|
||||
@Query("DELETE FROM tracks")
|
||||
abstract suspend fun clear()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
abstract suspend fun insert(entity: TrackEntity): Long
|
||||
|
||||
@Update
|
||||
abstract suspend fun update(entity: TrackEntity): Int
|
||||
|
||||
@Query("DELETE FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract suspend fun delete(mangaId: Long)
|
||||
|
||||
@Transaction
|
||||
open suspend fun upsert(entity: TrackEntity) {
|
||||
if (update(entity) == 0) {
|
||||
insert(entity)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.koitharu.kotatsu.core.db.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(
|
||||
tableName = "tracks", foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = MangaEntity::class,
|
||||
parentColumns = ["manga_id"],
|
||||
childColumns = ["manga_id"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
]
|
||||
)
|
||||
data class TrackEntity (
|
||||
@PrimaryKey(autoGenerate = false)
|
||||
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
||||
@ColumnInfo(name = "chapters_total") val totalChapters: Int,
|
||||
@ColumnInfo(name = "last_chapter_id") val lastChapterId: Long,
|
||||
@ColumnInfo(name = "chapters_new") val newChapters: Int,
|
||||
@ColumnInfo(name = "last_check") val lastCheck: Long,
|
||||
@ColumnInfo(name = "last_notified_id") val lastNotifiedChapterId: Long
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.koitharu.kotatsu.core.db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
object Migration3To4 : Migration(3, 4) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS tracks (manga_id INTEGER NOT NULL, chapters_total INTEGER NOT NULL, last_chapter_id INTEGER NOT NULL, chapters_new INTEGER NOT NULL, last_check INTEGER NOT NULL, last_notified_id INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,4 @@ data class AppVersion(
|
||||
val url: String,
|
||||
val apkSize: Long,
|
||||
val apkUrl: String
|
||||
) : Parcelable {
|
||||
|
||||
fun isGreaterThen(version: String) {
|
||||
val thisParts = name.substringBeforeLast('-').split('.')
|
||||
val parts = version.substringBeforeLast('-').split('.')
|
||||
}
|
||||
}
|
||||
) : Parcelable
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.koitharu.kotatsu.core.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import java.util.*
|
||||
|
||||
@Parcelize
|
||||
data class MangaTracking (
|
||||
val manga: Manga,
|
||||
val knownChaptersCount: Int,
|
||||
val lastChapterId: Long,
|
||||
val lastNotifiedChapterId: Long,
|
||||
val lastCheck: Date?
|
||||
): Parcelable
|
||||
@@ -6,7 +6,7 @@ import org.koitharu.kotatsu.core.model.*
|
||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||
import org.koitharu.kotatsu.utils.ext.*
|
||||
|
||||
abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
|
||||
protected abstract val defaultDomain: String
|
||||
|
||||
@@ -20,7 +20,7 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
offset: Int,
|
||||
query: String?,
|
||||
sortOrder: SortOrder?,
|
||||
tag: MangaTag?
|
||||
tag: MangaTag?,
|
||||
): List<Manga> {
|
||||
val domain = conf.getDomain(defaultDomain)
|
||||
val doc = when {
|
||||
@@ -28,7 +28,8 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
"https://$domain/search",
|
||||
mapOf("q" to query, "offset" to offset.toString())
|
||||
)
|
||||
tag == null -> loaderContext.httpGet("https://$domain/list?sortType=${getSortKey(sortOrder)}&offset=$offset")
|
||||
tag == null -> loaderContext.httpGet("https://$domain/list?sortType=${getSortKey(
|
||||
sortOrder)}&offset=$offset")
|
||||
else -> loaderContext.httpGet(
|
||||
"https://$domain/list/genre/${tag.key}?sortType=${getSortKey(
|
||||
sortOrder
|
||||
@@ -85,12 +86,22 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
override suspend fun getDetails(manga: Manga): Manga {
|
||||
val domain = conf.getDomain(defaultDomain)
|
||||
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||
val root = doc.body().getElementById("mangaBox") ?: throw ParseException("Cannot find root")
|
||||
val root = doc.body().getElementById("mangaBox")?.selectFirst("div.leftContent")
|
||||
?: throw ParseException("Cannot find root")
|
||||
return manga.copy(
|
||||
description = root.selectFirst("div.manga-description")?.html(),
|
||||
largeCoverUrl = root.selectFirst("div.subject-cower")?.selectFirst("img")?.attr(
|
||||
"data-full"
|
||||
),
|
||||
tags = manga.tags + root.select("div.subject-meta").select("span.elem_genre ")
|
||||
.mapNotNull {
|
||||
val a = it.selectFirst("a.element-link") ?: return@mapNotNull null
|
||||
MangaTag(
|
||||
title = a.text(),
|
||||
key = a.attr("href").substringAfterLast('/'),
|
||||
source = source
|
||||
)
|
||||
},
|
||||
chapters = root.selectFirst("div.chapters-link")?.selectFirst("table")
|
||||
?.select("a")?.asReversed()?.mapIndexedNotNull { i, a ->
|
||||
val href =
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.prefs
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Resources
|
||||
import android.provider.Settings
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -52,6 +53,31 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
|
||||
0L
|
||||
)
|
||||
|
||||
val trackerNotifications by BoolPreferenceDelegate(
|
||||
resources.getString(R.string.key_tracker_notifications),
|
||||
true
|
||||
)
|
||||
|
||||
var notificationSound by StringPreferenceDelegate(
|
||||
resources.getString(R.string.key_notifications_sound),
|
||||
Settings.System.DEFAULT_NOTIFICATION_URI.toString()
|
||||
)
|
||||
|
||||
val notificationVibrate by BoolPreferenceDelegate(
|
||||
resources.getString(R.string.key_notifications_vibrate),
|
||||
false
|
||||
)
|
||||
|
||||
val notificationLight by BoolPreferenceDelegate(
|
||||
resources.getString(R.string.key_notifications_light),
|
||||
true
|
||||
)
|
||||
|
||||
val readerAnimation by BoolPreferenceDelegate(
|
||||
resources.getString(R.string.key_reader_animation),
|
||||
false
|
||||
)
|
||||
|
||||
private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
|
||||
|
||||
var sourcesOrder: List<Int>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.domain
|
||||
|
||||
import androidx.room.withTransaction
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||
@@ -13,24 +14,33 @@ class MangaDataRepository : KoinComponent {
|
||||
|
||||
private val db: MangaDatabase by inject()
|
||||
|
||||
suspend fun savePreferences(mangaId: Long, mode: ReaderMode) {
|
||||
db.preferencesDao().upsert(
|
||||
MangaPrefsEntity(
|
||||
mangaId = mangaId,
|
||||
mode = mode.id
|
||||
suspend fun savePreferences(manga: Manga, mode: ReaderMode) {
|
||||
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||
db.withTransaction {
|
||||
db.tagsDao.upsert(tags)
|
||||
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||
db.preferencesDao.upsert(
|
||||
MangaPrefsEntity(
|
||||
mangaId = manga.id,
|
||||
mode = mode.id
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
|
||||
return db.preferencesDao().find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
||||
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
||||
}
|
||||
|
||||
suspend fun findMangaById(mangaId: Long): Manga? {
|
||||
return db.mangaDao().find(mangaId)?.toManga()
|
||||
return db.mangaDao.find(mangaId)?.toManga()
|
||||
}
|
||||
|
||||
suspend fun storeManga(manga: Manga) {
|
||||
db.mangaDao().upsert(MangaEntity.from(manga), manga.tags.map(TagEntity.Companion::fromMangaTag))
|
||||
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||
db.withTransaction {
|
||||
db.tagsDao.upsert(tags)
|
||||
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.domain.favourites
|
||||
|
||||
import androidx.room.withTransaction
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.KoinComponent
|
||||
@@ -18,17 +19,17 @@ class FavouritesRepository : KoinComponent {
|
||||
private val db: MangaDatabase by inject()
|
||||
|
||||
suspend fun getAllManga(offset: Int): List<Manga> {
|
||||
val entities = db.favouritesDao().findAll(offset, 20, "created_at")
|
||||
val entities = db.favouritesDao.findAll(offset, 20, "created_at")
|
||||
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||
}
|
||||
|
||||
suspend fun getAllCategories(): List<FavouriteCategory> {
|
||||
val entities = db.favouriteCategoriesDao().findAll("created_at")
|
||||
val entities = db.favouriteCategoriesDao.findAll("created_at")
|
||||
return entities.map { it.toFavouriteCategory() }
|
||||
}
|
||||
|
||||
suspend fun getCategories(mangaId: Long): List<FavouriteCategory> {
|
||||
val entities = db.favouritesDao().find(mangaId)?.categories
|
||||
val entities = db.favouritesDao.find(mangaId)?.categories
|
||||
return entities?.map { it.toFavouriteCategory() }.orEmpty()
|
||||
}
|
||||
|
||||
@@ -38,25 +39,30 @@ class FavouritesRepository : KoinComponent {
|
||||
createdAt = System.currentTimeMillis(),
|
||||
categoryId = 0
|
||||
)
|
||||
val id = db.favouriteCategoriesDao().insert(entity)
|
||||
val id = db.favouriteCategoriesDao.insert(entity)
|
||||
return entity.toFavouriteCategory(id)
|
||||
}
|
||||
suspend fun renameCategory(id: Long, title: String) {
|
||||
db.favouriteCategoriesDao.update(id, title)
|
||||
}
|
||||
|
||||
suspend fun removeCategory(id: Long) {
|
||||
db.favouriteCategoriesDao().delete(id)
|
||||
db.favouriteCategoriesDao.delete(id)
|
||||
}
|
||||
|
||||
suspend fun addToCategory(manga: Manga, categoryId: Long) {
|
||||
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||
db.tagsDao().upsert(tags)
|
||||
db.mangaDao().upsert(MangaEntity.from(manga), tags)
|
||||
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
|
||||
db.favouritesDao().add(entity)
|
||||
db.withTransaction {
|
||||
db.tagsDao.upsert(tags)
|
||||
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
|
||||
db.favouritesDao.add(entity)
|
||||
}
|
||||
notifyFavouritesChanged(manga.id)
|
||||
}
|
||||
|
||||
suspend fun removeFromCategory(manga: Manga, categoryId: Long) {
|
||||
db.favouritesDao().delete(categoryId, manga.id)
|
||||
db.favouritesDao.delete(categoryId, manga.id)
|
||||
notifyFavouritesChanged(manga.id)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.domain.history
|
||||
|
||||
import androidx.room.withTransaction
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.KoinComponent
|
||||
@@ -10,6 +11,7 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
||||
import java.util.*
|
||||
|
||||
class HistoryRepository : KoinComponent {
|
||||
@@ -17,29 +19,34 @@ class HistoryRepository : KoinComponent {
|
||||
private val db: MangaDatabase by inject()
|
||||
|
||||
suspend fun getList(offset: Int, limit: Int = 20): List<Manga> {
|
||||
val entities = db.historyDao().findAll(offset, limit)
|
||||
val entities = db.historyDao.findAll(offset, limit)
|
||||
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||
}
|
||||
|
||||
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Float) {
|
||||
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||
db.tagsDao().upsert(tags)
|
||||
db.mangaDao().upsert(MangaEntity.from(manga), tags)
|
||||
db.historyDao().upsert(
|
||||
HistoryEntity(
|
||||
mangaId = manga.id,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
updatedAt = System.currentTimeMillis(),
|
||||
chapterId = chapterId,
|
||||
page = page,
|
||||
scroll = scroll
|
||||
)
|
||||
)
|
||||
db.withTransaction {
|
||||
db.tagsDao.upsert(tags)
|
||||
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||
if (db.historyDao.upsert(
|
||||
HistoryEntity(
|
||||
mangaId = manga.id,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
updatedAt = System.currentTimeMillis(),
|
||||
chapterId = chapterId,
|
||||
page = page,
|
||||
scroll = scroll
|
||||
)
|
||||
)
|
||||
) {
|
||||
TrackingRepository().insertOrNothing(manga)
|
||||
}
|
||||
}
|
||||
notifyHistoryChanged()
|
||||
}
|
||||
|
||||
suspend fun getOne(manga: Manga): MangaHistory? {
|
||||
return db.historyDao().find(manga.id)?.let {
|
||||
return db.historyDao.find(manga.id)?.let {
|
||||
MangaHistory(
|
||||
createdAt = Date(it.createdAt),
|
||||
updatedAt = Date(it.updatedAt),
|
||||
@@ -51,12 +58,12 @@ class HistoryRepository : KoinComponent {
|
||||
}
|
||||
|
||||
suspend fun clear() {
|
||||
db.historyDao().clear()
|
||||
db.historyDao.clear()
|
||||
notifyHistoryChanged()
|
||||
}
|
||||
|
||||
suspend fun delete(manga: Manga) {
|
||||
db.historyDao().delete(manga.id)
|
||||
db.historyDao.delete(manga.id)
|
||||
notifyHistoryChanged()
|
||||
}
|
||||
|
||||
@@ -65,8 +72,8 @@ class HistoryRepository : KoinComponent {
|
||||
* Useful for replacing saved manga on deleting it with remove source
|
||||
*/
|
||||
suspend fun deleteOrSwap(manga: Manga, alternative: Manga?) {
|
||||
if (alternative == null || db.mangaDao().update(MangaEntity.from(alternative)) <= 0) {
|
||||
db.historyDao().delete(manga.id)
|
||||
if (alternative == null || db.mangaDao.update(MangaEntity.from(alternative)) <= 0) {
|
||||
db.historyDao.delete(manga.id)
|
||||
notifyHistoryChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||
import org.koitharu.kotatsu.utils.ext.sub
|
||||
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
||||
import org.koitharu.kotatsu.utils.ext.toFileName
|
||||
import org.koitharu.kotatsu.utils.ext.toFileNameSafe
|
||||
import java.io.File
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
@@ -91,7 +91,7 @@ class MangaZip(val file: File) {
|
||||
const val INDEX_ENTRY = "index.json"
|
||||
|
||||
fun findInDir(root: File, manga: Manga): MangaZip {
|
||||
val name = manga.title.toFileName() + ".cbz"
|
||||
val name = manga.title.toFileNameSafe() + ".cbz"
|
||||
val file = File(root, name)
|
||||
return MangaZip(file)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.koitharu.kotatsu.domain.tracking
|
||||
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||
import org.koitharu.kotatsu.core.db.entity.TrackEntity
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaTracking
|
||||
import java.util.*
|
||||
|
||||
class TrackingRepository : KoinComponent {
|
||||
|
||||
private val db: MangaDatabase by inject()
|
||||
|
||||
suspend fun getNewChaptersCount(mangaId: Long): Int {
|
||||
val entity = db.tracksDao.find(mangaId) ?: return 0
|
||||
return entity.newChapters
|
||||
}
|
||||
|
||||
suspend fun getAllTracks(): List<MangaTracking> {
|
||||
val favourites = db.favouritesDao.findAllManga()
|
||||
val history = db.historyDao.findAllManga()
|
||||
val manga = (favourites + history).distinctBy { it.id }
|
||||
val tracks = db.tracksDao.findAll().groupBy { it.mangaId }
|
||||
return manga.map { m ->
|
||||
val track = tracks[m.id]?.singleOrNull()
|
||||
MangaTracking(
|
||||
manga = m.toManga(),
|
||||
knownChaptersCount = track?.totalChapters ?: -1,
|
||||
lastChapterId = track?.lastChapterId ?: 0L,
|
||||
lastNotifiedChapterId = track?.lastNotifiedChapterId ?: 0L,
|
||||
lastCheck = track?.lastCheck?.takeUnless { it == 0L }?.let(::Date)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun storeTrackResult(
|
||||
mangaId: Long,
|
||||
knownChaptersCount: Int,
|
||||
lastChapterId: Long,
|
||||
newChapters: Int,
|
||||
lastNotifiedChapterId: Long
|
||||
) {
|
||||
val entity = TrackEntity(
|
||||
mangaId = mangaId,
|
||||
newChapters = newChapters,
|
||||
lastCheck = System.currentTimeMillis(),
|
||||
lastChapterId = lastChapterId,
|
||||
totalChapters = knownChaptersCount,
|
||||
lastNotifiedChapterId = lastNotifiedChapterId
|
||||
)
|
||||
db.tracksDao.upsert(entity)
|
||||
}
|
||||
|
||||
suspend fun insertOrNothing(manga: Manga) {
|
||||
val chapters = manga.chapters ?: return
|
||||
val entity = TrackEntity(
|
||||
mangaId = manga.id,
|
||||
totalChapters = chapters.size,
|
||||
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = 0,
|
||||
lastCheck = System.currentTimeMillis(),
|
||||
lastNotifiedChapterId = 0L
|
||||
)
|
||||
db.tracksDao.insert(entity)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import moxy.MvpAppCompatActivity
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.dialog.StorageSelectDialog
|
||||
|
||||
abstract class BaseActivity : MvpAppCompatActivity(), KoinComponent {
|
||||
|
||||
@@ -70,7 +69,7 @@ abstract class BaseActivity : MvpAppCompatActivity(), KoinComponent {
|
||||
return true
|
||||
}
|
||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
StorageSelectDialog.Builder(this).create().show()
|
||||
throw StackOverflowError("test")
|
||||
return true
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
|
||||
@@ -3,12 +3,11 @@ package org.koitharu.kotatsu.ui.common
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
|
||||
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
||||
PreferenceFragmentCompat(), KoinComponent {
|
||||
PreferenceFragmentCompat() {
|
||||
|
||||
protected val settings by inject<AppSettings>()
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ import androidx.annotation.CallSuper
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import org.koin.core.KoinComponent
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
abstract class BaseService : Service(), KoinComponent, CoroutineScope {
|
||||
abstract class BaseService : Service(), CoroutineScope {
|
||||
|
||||
private val job = SupervisorJob()
|
||||
|
||||
|
||||
@@ -3,28 +3,16 @@ package org.koitharu.kotatsu.ui.common.dialog
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.text.InputFilter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import kotlinx.android.synthetic.main.dialog_input.view.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.utils.ext.showKeyboard
|
||||
|
||||
class TextInputDialog private constructor(private val delegate: AlertDialog) :
|
||||
DialogInterface by delegate {
|
||||
|
||||
init {
|
||||
delegate.setOnShowListener {
|
||||
val view = delegate.findViewById<TextView>(R.id.inputEdit)?:return@setOnShowListener
|
||||
view.post {
|
||||
view.requestFocus()
|
||||
view.showKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun show() = delegate.show()
|
||||
|
||||
class Builder(context: Context) {
|
||||
@@ -34,10 +22,6 @@ class TextInputDialog private constructor(private val delegate: AlertDialog) :
|
||||
|
||||
private val delegate = AlertDialog.Builder(context)
|
||||
.setView(view)
|
||||
.setOnDismissListener {
|
||||
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
|
||||
}
|
||||
|
||||
fun setTitle(@StringRes titleResId: Int): Builder {
|
||||
delegate.setTitle(titleResId)
|
||||
@@ -54,11 +38,28 @@ class TextInputDialog private constructor(private val delegate: AlertDialog) :
|
||||
return this
|
||||
}
|
||||
|
||||
fun setMaxLength(maxLength: Int, strict: Boolean): Builder {
|
||||
with(view.inputLayout) {
|
||||
counterMaxLength = maxLength
|
||||
isCounterEnabled = maxLength > 0
|
||||
}
|
||||
if (strict && maxLength > 0) {
|
||||
view.inputEdit.filters += InputFilter.LengthFilter(maxLength)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun setInputType(inputType: Int): Builder {
|
||||
view.inputEdit.inputType = inputType
|
||||
return this
|
||||
}
|
||||
|
||||
fun setText(text: String): Builder {
|
||||
view.inputEdit.setText(text)
|
||||
view.inputEdit.setSelection(text.length)
|
||||
return this
|
||||
}
|
||||
|
||||
fun setPositiveButton(@StringRes textId: Int, listener: (DialogInterface, String) -> Unit): Builder {
|
||||
delegate.setPositiveButton(textId) { dialog, _ ->
|
||||
listener(dialog, view.inputEdit.text?.toString().orEmpty())
|
||||
|
||||
@@ -80,6 +80,10 @@ abstract class BaseRecyclerAdapter<T, E>(private val onItemClickListener: OnRecy
|
||||
onDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: BaseViewHolder<T, E>) {
|
||||
holder.onRecycled()
|
||||
}
|
||||
|
||||
final override fun getItemCount() = dataSet.size
|
||||
|
||||
final override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<T, E> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.ui.common.list
|
||||
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
@@ -31,14 +32,21 @@ abstract class BaseViewHolder<T, E> protected constructor(view: View) :
|
||||
fun setOnItemClickListener(listener: OnRecyclerItemClickListener<T>?): BaseViewHolder<T, E> {
|
||||
if (listener != null) {
|
||||
itemView.setOnClickListener {
|
||||
listener.onItemClick(boundData ?: return@setOnClickListener, adapterPosition, it)
|
||||
listener.onItemClick(boundData ?: return@setOnClickListener, bindingAdapterPosition, it)
|
||||
}
|
||||
itemView.setOnLongClickListener {
|
||||
listener.onItemLongClick(boundData ?: return@setOnLongClickListener false, adapterPosition, it)
|
||||
listener.onItemLongClick(boundData ?: return@setOnLongClickListener false, bindingAdapterPosition, it)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
itemView.setOnContextClickListener {
|
||||
listener.onItemLongClick(boundData ?: return@setOnContextClickListener false, bindingAdapterPosition, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
open fun onRecycled() = Unit
|
||||
|
||||
abstract fun onBind(data: T, extra: E)
|
||||
}
|
||||
@@ -16,6 +16,13 @@ class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChap
|
||||
updateCurrentPosition()
|
||||
}
|
||||
|
||||
var newChaptersCount: Int = 0
|
||||
set(value) {
|
||||
val updated = maxOf(field, value)
|
||||
field = value
|
||||
notifyItemRangeChanged(itemCount - updated, updated)
|
||||
}
|
||||
|
||||
var currentChapterPosition = RecyclerView.NO_POSITION
|
||||
private set
|
||||
|
||||
@@ -24,9 +31,13 @@ class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChap
|
||||
override fun onGetItemId(item: MangaChapter) = item.id
|
||||
|
||||
override fun getExtra(item: MangaChapter, position: Int): ChapterExtra = when {
|
||||
currentChapterPosition == RecyclerView.NO_POSITION -> ChapterExtra.UNREAD
|
||||
currentChapterPosition == RecyclerView.NO_POSITION
|
||||
|| currentChapterPosition < position -> if (position >= itemCount - newChaptersCount) {
|
||||
ChapterExtra.NEW
|
||||
} else {
|
||||
ChapterExtra.UNREAD
|
||||
}
|
||||
currentChapterPosition == position -> ChapterExtra.CURRENT
|
||||
currentChapterPosition < position -> ChapterExtra.UNREAD
|
||||
currentChapterPosition > position -> ChapterExtra.READ
|
||||
else -> ChapterExtra.UNREAD
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.koitharu.kotatsu.ui.details
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.fragment_chapters.*
|
||||
import moxy.ktx.moxyPresenter
|
||||
@@ -44,6 +46,7 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
|
||||
override fun onMangaUpdated(manga: Manga) {
|
||||
this.manga = manga
|
||||
adapter.replaceData(manga.chapters.orEmpty())
|
||||
scrollToCurrent()
|
||||
}
|
||||
|
||||
override fun onLoadingStateChanged(isLoading: Boolean) {
|
||||
@@ -56,17 +59,29 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
|
||||
|
||||
override fun onHistoryChanged(history: MangaHistory?) {
|
||||
adapter.currentChapterId = history?.chapterId
|
||||
scrollToCurrent()
|
||||
}
|
||||
|
||||
override fun onNewChaptersChanged(newChapters: Int) {
|
||||
adapter.newChaptersCount = newChapters
|
||||
}
|
||||
|
||||
override fun onFavouriteChanged(categories: List<FavouriteCategory>) = Unit
|
||||
|
||||
override fun onItemClick(item: MangaChapter, position: Int, view: View) {
|
||||
val options = ActivityOptions.makeScaleUpAnimation(
|
||||
view,
|
||||
0,
|
||||
0,
|
||||
view.measuredWidth,
|
||||
view.measuredHeight
|
||||
)
|
||||
startActivity(
|
||||
ReaderActivity.newIntent(
|
||||
context ?: return,
|
||||
manga ?: return,
|
||||
item.id
|
||||
)
|
||||
), options.toBundle()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -86,4 +101,13 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun scrollToCurrent() {
|
||||
val pos = (recyclerView_chapters.adapter as? ChaptersAdapter)?.currentChapterPosition
|
||||
?: RecyclerView.NO_POSITION
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
(recyclerView_chapters.layoutManager as? LinearLayoutManager)
|
||||
?.scrollToPositionWithOffset(pos, 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,9 @@ import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.ui.browser.BrowserActivity
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
import org.koitharu.kotatsu.ui.download.DownloadService
|
||||
import org.koitharu.kotatsu.utils.MangaShortcut
|
||||
import org.koitharu.kotatsu.utils.ShareHelper
|
||||
import org.koitharu.kotatsu.utils.ShortcutUtils
|
||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.ext.showDialog
|
||||
|
||||
class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
|
||||
|
||||
@@ -80,6 +79,17 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewChaptersChanged(newChapters: Int) {
|
||||
val tab = tabs.getTabAt(1) ?: return
|
||||
if (newChapters == 0) {
|
||||
tab.removeBadge()
|
||||
} else {
|
||||
val badge = tab.orCreateBadge
|
||||
badge.number = newChapters
|
||||
badge.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.opt_details, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
@@ -108,14 +118,14 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
|
||||
}
|
||||
R.id.action_delete -> {
|
||||
manga?.let { m ->
|
||||
showDialog {
|
||||
setTitle(R.string.delete_manga)
|
||||
setMessage(getString(R.string.text_delete_local_manga, m.title))
|
||||
setPositiveButton(R.string.delete) { _, _ ->
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.delete_manga)
|
||||
.setMessage(getString(R.string.text_delete_local_manga, m.title))
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
presenter.deleteLocal(m)
|
||||
}
|
||||
setNegativeButton(android.R.string.cancel, null)
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -145,7 +155,7 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
|
||||
R.id.action_shortcut -> {
|
||||
manga?.let {
|
||||
lifecycleScope.launch {
|
||||
if (!ShortcutUtils.requestPinShortcut(this@MangaDetailsActivity, manga)) {
|
||||
if (!MangaShortcut(it).requestPinShortcut(this@MangaDetailsActivity)) {
|
||||
Snackbar.make(
|
||||
pager,
|
||||
R.string.operation_not_supported,
|
||||
@@ -162,7 +172,7 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
|
||||
companion object {
|
||||
|
||||
private const val EXTRA_MANGA = "manga"
|
||||
private const val EXTRA_MANGA_ID = "manga_id"
|
||||
const val EXTRA_MANGA_ID = "manga_id"
|
||||
|
||||
const val ACTION_MANGA_VIEW = "${BuildConfig.APPLICATION_ID}.action.VIEW_MANGA"
|
||||
|
||||
|
||||
@@ -13,14 +13,17 @@ import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||
import org.koitharu.kotatsu.ui.common.BaseFragment
|
||||
import org.koitharu.kotatsu.ui.main.list.favourites.categories.FavouriteCategoriesDialog
|
||||
import org.koitharu.kotatsu.ui.main.list.favourites.categories.select.FavouriteCategoriesDialog
|
||||
import org.koitharu.kotatsu.ui.reader.ReaderActivity
|
||||
import org.koitharu.kotatsu.ui.search.MangaSearchSheet
|
||||
import org.koitharu.kotatsu.utils.ext.addChips
|
||||
import org.koitharu.kotatsu.utils.ext.showPopupMenu
|
||||
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetailsView, View.OnClickListener {
|
||||
class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetailsView,
|
||||
View.OnClickListener,
|
||||
View.OnLongClickListener {
|
||||
|
||||
@Suppress("unused")
|
||||
private val presenter by moxyPresenter(factory = MangaDetailsPresenter.Companion::getInstance)
|
||||
@@ -64,9 +67,9 @@ class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetai
|
||||
onClickListener = this@MangaDetailsFragment
|
||||
)
|
||||
}
|
||||
imageView_favourite.setOnClickListener {
|
||||
FavouriteCategoriesDialog.show(childFragmentManager, manga)
|
||||
}
|
||||
imageView_favourite.setOnClickListener(this)
|
||||
button_read.setOnClickListener(this)
|
||||
button_read.setOnLongClickListener(this)
|
||||
updateReadButton()
|
||||
}
|
||||
|
||||
@@ -93,12 +96,55 @@ class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetai
|
||||
|
||||
override fun onMangaRemoved(manga: Manga) = Unit //handled in activity
|
||||
|
||||
override fun onNewChaptersChanged(newChapters: Int) = Unit
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (v is Chip) {
|
||||
when(val tag = v.tag) {
|
||||
is String -> MangaSearchSheet.show(activity?.supportFragmentManager ?: childFragmentManager,
|
||||
manga?.source ?: return, tag)
|
||||
when {
|
||||
v.id == R.id.imageView_favourite -> {
|
||||
FavouriteCategoriesDialog.show(childFragmentManager, manga ?: return)
|
||||
}
|
||||
v.id == R.id.button_read -> {
|
||||
startActivity(
|
||||
ReaderActivity.newIntent(
|
||||
context ?: return,
|
||||
manga ?: return,
|
||||
history
|
||||
)
|
||||
)
|
||||
}
|
||||
v is Chip -> {
|
||||
when (val tag = v.tag) {
|
||||
is String -> MangaSearchSheet.show(activity?.supportFragmentManager
|
||||
?: childFragmentManager,
|
||||
manga?.source ?: return, tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View): Boolean {
|
||||
when {
|
||||
v.id == R.id.button_read -> {
|
||||
if (history == null) {
|
||||
return false
|
||||
}
|
||||
v.showPopupMenu(R.menu.popup_read) {
|
||||
when (it.itemId) {
|
||||
R.id.action_read -> {
|
||||
startActivity(
|
||||
ReaderActivity.newIntent(
|
||||
context ?: return@showPopupMenu false,
|
||||
manga ?: return@showPopupMenu false
|
||||
)
|
||||
)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,15 +160,6 @@ class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetai
|
||||
button_read.setText(R.string._continue)
|
||||
button_read.setIconResource(R.drawable.ic_play)
|
||||
}
|
||||
button_read.setOnClickListener {
|
||||
startActivity(
|
||||
ReaderActivity.newIntent(
|
||||
context ?: return@setOnClickListener,
|
||||
manga ?: return@setOnClickListener,
|
||||
history
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
|
||||
import org.koitharu.kotatsu.domain.favourites.OnFavouritesChangeListener
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
|
||||
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
||||
import org.koitharu.kotatsu.ui.common.BasePresenter
|
||||
import org.koitharu.kotatsu.utils.ext.safe
|
||||
import java.io.IOException
|
||||
@@ -28,12 +29,14 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
||||
|
||||
private lateinit var historyRepository: HistoryRepository
|
||||
private lateinit var favouritesRepository: FavouritesRepository
|
||||
private lateinit var trackingRepository: TrackingRepository
|
||||
|
||||
private var manga: Manga? = null
|
||||
|
||||
override fun onFirstViewAttach() {
|
||||
historyRepository = HistoryRepository()
|
||||
favouritesRepository = FavouritesRepository()
|
||||
trackingRepository = TrackingRepository()
|
||||
super.onFirstViewAttach()
|
||||
HistoryRepository.subscribe(this)
|
||||
FavouritesRepository.subscribe(this)
|
||||
@@ -75,6 +78,7 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
||||
}
|
||||
viewState.onMangaUpdated(data)
|
||||
this@MangaDetailsPresenter.manga = data
|
||||
viewState.onNewChaptersChanged(trackingRepository.getNewChaptersCount(manga.id))
|
||||
} catch (_: CancellationException){
|
||||
} catch (e: Throwable) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.koitharu.kotatsu.ui.details
|
||||
|
||||
import moxy.MvpView
|
||||
import moxy.viewstate.strategy.alias.AddToEndSingle
|
||||
import moxy.viewstate.strategy.alias.OneExecution
|
||||
import moxy.viewstate.strategy.alias.SingleState
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
@@ -22,4 +20,7 @@ interface MangaDetailsView : BaseMvpView {
|
||||
|
||||
@SingleState
|
||||
fun onMangaRemoved(manga: Manga)
|
||||
|
||||
@AddToEndSingle
|
||||
fun onNewChaptersChanged(newChapters: Int)
|
||||
}
|
||||
@@ -5,10 +5,11 @@ import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
@@ -31,9 +32,13 @@ class DownloadNotification(private val context: Context) {
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
)
|
||||
channel.enableVibration(false)
|
||||
channel.enableLights(false)
|
||||
channel.setSound(null, null)
|
||||
manager.createNotificationChannel(channel)
|
||||
}
|
||||
builder.setOnlyAlertOnce(true)
|
||||
builder.setDefaults(0)
|
||||
builder.color = ContextCompat.getColor(context, R.color.blue_primary)
|
||||
}
|
||||
|
||||
fun fillFrom(manga: Manga) {
|
||||
@@ -70,10 +75,11 @@ class DownloadNotification(private val context: Context) {
|
||||
builder.setContentText(e.getDisplayMessage(context.resources))
|
||||
builder.setAutoCancel(true)
|
||||
builder.setContentIntent(null)
|
||||
builder.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||
}
|
||||
|
||||
fun setLargeIcon(icon: Drawable?) {
|
||||
builder.setLargeIcon((icon as? BitmapDrawable)?.bitmap)
|
||||
builder.setLargeIcon(icon?.toBitmap())
|
||||
}
|
||||
|
||||
fun setProgress(chaptersTotal: Int, pagesTotal: Int, chapter: Int, page: Int) {
|
||||
@@ -83,6 +89,7 @@ class DownloadNotification(private val context: Context) {
|
||||
val percent = (progress / max.toFloat() * 100).roundToInt()
|
||||
builder.setProgress(max, progress, false)
|
||||
builder.setContentText("%d%%".format(percent))
|
||||
builder.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
}
|
||||
|
||||
fun setPostProcessing() {
|
||||
@@ -96,6 +103,7 @@ class DownloadNotification(private val context: Context) {
|
||||
builder.setContentIntent(createIntent(context, manga))
|
||||
builder.setAutoCancel(true)
|
||||
builder.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
builder.setCategory(null)
|
||||
}
|
||||
|
||||
fun setCancelling() {
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.PowerManager
|
||||
import android.os.WorkSource
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -14,7 +13,7 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.koin.core.inject
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.local.PagesCache
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.koitharu.kotatsu.ui.main
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@@ -30,6 +32,7 @@ import org.koitharu.kotatsu.ui.reader.ReaderActivity
|
||||
import org.koitharu.kotatsu.ui.reader.ReaderState
|
||||
import org.koitharu.kotatsu.ui.settings.AppUpdateService
|
||||
import org.koitharu.kotatsu.ui.settings.SettingsActivity
|
||||
import org.koitharu.kotatsu.ui.tracker.TrackWorker
|
||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||
|
||||
@@ -44,7 +47,6 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
drawerToggle =
|
||||
ActionBarDrawerToggle(this, drawer, toolbar, R.string.open_menu, R.string.close_menu)
|
||||
drawer.addDrawerListener(drawerToggle)
|
||||
@@ -69,6 +71,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
drawer.postDelayed(2000) {
|
||||
AppUpdateService.startIfRequired(applicationContext)
|
||||
}
|
||||
TrackWorker.setup(applicationContext)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@@ -117,7 +120,16 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
}
|
||||
|
||||
override fun onOpenReader(state: ReaderState) {
|
||||
startActivity(ReaderActivity.newIntent(this, state))
|
||||
val options = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
ActivityOptions.makeClipRevealAnimation(
|
||||
fab, 0, 0, fab.measuredWidth, fab.measuredHeight
|
||||
)
|
||||
} else {
|
||||
ActivityOptions.makeScaleUpAnimation(
|
||||
fab, 0, 0, fab.measuredWidth, fab.measuredHeight
|
||||
)
|
||||
}
|
||||
startActivity(ReaderActivity.newIntent(this, state), options?.toBundle())
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.koitharu.kotatsu.ui.main.list
|
||||
|
||||
import android.view.ViewGroup
|
||||
import coil.api.clear
|
||||
import coil.api.load
|
||||
import coil.request.RequestDisposable
|
||||
import kotlinx.android.synthetic.main.item_manga_grid.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
@@ -11,15 +11,17 @@ import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
|
||||
class MangaGridHolder(parent: ViewGroup) : BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_grid) {
|
||||
|
||||
private var coverRequest: RequestDisposable? = null
|
||||
|
||||
override fun onBind(data: Manga, extra: MangaHistory?) {
|
||||
coverRequest?.dispose()
|
||||
imageView_cover.clear()
|
||||
textView_title.text = data.title
|
||||
coverRequest = imageView_cover.load(data.coverUrl) {
|
||||
imageView_cover.load(data.coverUrl) {
|
||||
placeholder(R.drawable.ic_placeholder)
|
||||
fallback(R.drawable.ic_placeholder)
|
||||
error(R.drawable.ic_placeholder)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRecycled() {
|
||||
imageView_cover.clear()
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package org.koitharu.kotatsu.ui.main.list
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import coil.api.clear
|
||||
import coil.api.load
|
||||
import coil.request.RequestDisposable
|
||||
import kotlinx.android.synthetic.main.item_manga_list_details.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
@@ -15,14 +15,12 @@ import kotlin.math.roundToInt
|
||||
|
||||
class MangaListDetailsHolder(parent: ViewGroup) : BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_list_details) {
|
||||
|
||||
private var coverRequest: RequestDisposable? = null
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBind(data: Manga, extra: MangaHistory?) {
|
||||
coverRequest?.dispose()
|
||||
imageView_cover.clear()
|
||||
textView_title.text = data.title
|
||||
textView_subtitle.textAndVisible = data.altTitle
|
||||
coverRequest = imageView_cover.load(data.coverUrl) {
|
||||
imageView_cover.load(data.coverUrl) {
|
||||
placeholder(R.drawable.ic_placeholder)
|
||||
fallback(R.drawable.ic_placeholder)
|
||||
error(R.drawable.ic_placeholder)
|
||||
@@ -37,4 +35,8 @@ class MangaListDetailsHolder(parent: ViewGroup) : BaseViewHolder<Manga, MangaHis
|
||||
it.title
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRecycled() {
|
||||
imageView_cover.clear()
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.android.synthetic.main.fragment_list.*
|
||||
import moxy.MvpDelegate
|
||||
@@ -39,7 +40,7 @@ import org.koitharu.kotatsu.utils.ext.*
|
||||
abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), MangaListView<E>,
|
||||
PaginationScrollListener.Callback, OnRecyclerItemClickListener<Manga>,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener, OnFilterChangedListener,
|
||||
SectionItemDecoration.Callback {
|
||||
SectionItemDecoration.Callback, SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private val settings by inject<AppSettings>()
|
||||
|
||||
@@ -58,9 +59,7 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
|
||||
initListMode(settings.listMode)
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.addOnScrollListener(PaginationScrollListener(4, this))
|
||||
swipeRefreshLayout.setOnRefreshListener {
|
||||
onRequestMoreItems(0)
|
||||
}
|
||||
swipeRefreshLayout.setOnRefreshListener(this)
|
||||
recyclerView_filter.setHasFixedSize(true)
|
||||
recyclerView_filter.addItemDecoration(ItemTypeDividerDecoration(view.context))
|
||||
recyclerView_filter.addItemDecoration(SectionItemDecoration(false, this))
|
||||
@@ -122,6 +121,10 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
|
||||
}
|
||||
}
|
||||
|
||||
final override fun onRefresh() {
|
||||
onRequestMoreItems(0)
|
||||
}
|
||||
|
||||
override fun onListChanged(list: List<Manga>) {
|
||||
adapter?.replaceData(list)
|
||||
if (list.isEmpty()) {
|
||||
@@ -171,6 +174,7 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
|
||||
Snackbar.make(recyclerView, e.getDisplayMessage(resources), Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
override fun onLoadingStateChanged(isLoading: Boolean) {
|
||||
val hasItems = recyclerView.hasItems
|
||||
progressBar.isVisible = isLoading && !hasItems
|
||||
@@ -181,7 +185,11 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
|
||||
}
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
||||
if (context == null) {
|
||||
return
|
||||
}
|
||||
when (key) {
|
||||
getString(R.string.key_list_mode) -> initListMode(settings.listMode)
|
||||
getString(R.string.key_grid_size) -> UiUtils.SpanCountResolver.update(recyclerView)
|
||||
@@ -229,6 +237,7 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
|
||||
ListMode.GRID -> GridLayoutManager(ctx, UiUtils.resolveGridSpanCount(ctx))
|
||||
else -> LinearLayoutManager(ctx)
|
||||
}
|
||||
recyclerView.recycledViewPool.clear()
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.addItemDecoration(
|
||||
when (mode) {
|
||||
@@ -246,13 +255,13 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
|
||||
recyclerView.firstItem = position
|
||||
}
|
||||
|
||||
override fun isSection(position: Int): Boolean {
|
||||
final override fun isSection(position: Int): Boolean {
|
||||
return position == 0 || recyclerView_filter.adapter?.run {
|
||||
getItemViewType(position) != getItemViewType(position - 1)
|
||||
} ?: false
|
||||
}
|
||||
|
||||
override fun getSectionTitle(position: Int): CharSequence? {
|
||||
final override fun getSectionTitle(position: Int): CharSequence? {
|
||||
return when (recyclerView_filter.adapter?.getItemViewType(position)) {
|
||||
FilterAdapter.VIEW_TYPE_SORT -> getString(R.string.sort_order)
|
||||
FilterAdapter.VIEW_TYPE_TAG -> getString(R.string.genre)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.koitharu.kotatsu.ui.main.list
|
||||
|
||||
import android.view.ViewGroup
|
||||
import coil.api.clear
|
||||
import coil.api.load
|
||||
import coil.request.RequestDisposable
|
||||
import kotlinx.android.synthetic.main.item_manga_list.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
@@ -13,16 +13,18 @@ import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||
class MangaListHolder(parent: ViewGroup) :
|
||||
BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_list) {
|
||||
|
||||
private var coverRequest: RequestDisposable? = null
|
||||
|
||||
override fun onBind(data: Manga, extra: MangaHistory?) {
|
||||
coverRequest?.dispose()
|
||||
imageView_cover.clear()
|
||||
textView_title.text = data.title
|
||||
textView_subtitle.textAndVisible = data.tags.joinToString(", ") { it.title }
|
||||
coverRequest = imageView_cover.load(data.coverUrl) {
|
||||
imageView_cover.load(data.coverUrl) {
|
||||
placeholder(R.drawable.ic_placeholder)
|
||||
fallback(R.drawable.ic_placeholder)
|
||||
error(R.drawable.ic_placeholder)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRecycled() {
|
||||
imageView_cover.clear()
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@ import android.view.MenuItem
|
||||
import kotlinx.android.synthetic.main.fragment_list.*
|
||||
import moxy.ktx.moxyPresenter
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.ui.main.list.MangaListFragment
|
||||
import org.koitharu.kotatsu.ui.main.list.MangaListView
|
||||
import org.koitharu.kotatsu.ui.main.list.favourites.categories.CategoriesActivity
|
||||
|
||||
class FavouritesListFragment : MangaListFragment<Unit>(), MangaListView<Unit>{
|
||||
class FavouritesListFragment : MangaListFragment<Unit>(), MangaListView<Unit> {
|
||||
|
||||
private val presenter by moxyPresenter(factory = ::FavouritesListPresenter)
|
||||
|
||||
@@ -19,12 +19,17 @@ class FavouritesListFragment : MangaListFragment<Unit>(), MangaListView<Unit>{
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
// inflater.inflate(R.menu.opt_history, menu)
|
||||
inflater.inflate(R.menu.opt_favourites, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem) = when(item.itemId) {
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||
R.id.action_categories -> {
|
||||
context?.let {
|
||||
startActivity(CategoriesActivity.newIntent(it))
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.android.synthetic.main.activity_categories.*
|
||||
import moxy.ktx.moxyPresenter
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
import org.koitharu.kotatsu.ui.common.dialog.TextInputDialog
|
||||
import org.koitharu.kotatsu.ui.common.list.OnRecyclerItemClickListener
|
||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.ext.showPopupMenu
|
||||
|
||||
class CategoriesActivity : BaseActivity(), OnRecyclerItemClickListener<FavouriteCategory>,
|
||||
FavouriteCategoriesView, View.OnClickListener {
|
||||
|
||||
private val presenter by moxyPresenter(factory = ::FavouriteCategoriesPresenter)
|
||||
|
||||
private lateinit var adapter: CategoriesAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_categories)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
fab_add.imageTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
adapter = CategoriesAdapter(this)
|
||||
recyclerView.addItemDecoration(DividerItemDecoration(this, RecyclerView.VERTICAL))
|
||||
recyclerView.adapter = adapter
|
||||
fab_add.setOnClickListener(this)
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
when (v.id) {
|
||||
R.id.fab_add -> createCategory()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemClick(item: FavouriteCategory, position: Int, view: View) {
|
||||
view.showPopupMenu(R.menu.popup_category) {
|
||||
when (it.itemId) {
|
||||
R.id.action_remove -> deleteCategory(item)
|
||||
R.id.action_rename -> renameCategory(item)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCategoriesChanged(categories: List<FavouriteCategory>) {
|
||||
adapter.replaceData(categories)
|
||||
textView_holder.isVisible = categories.isEmpty()
|
||||
}
|
||||
|
||||
override fun onCheckedCategoriesChanged(checkedIds: Set<Int>) = Unit
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Snackbar.make(recyclerView, e.getDisplayMessage(resources), Snackbar.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun deleteCategory(category: FavouriteCategory) {
|
||||
AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.category_delete_confirm, category.title))
|
||||
.setTitle(R.string.remove_category)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.remove) { _, _ ->
|
||||
presenter.deleteCategory(category.id)
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun renameCategory(category: FavouriteCategory) {
|
||||
TextInputDialog.Builder(this)
|
||||
.setTitle(R.string.rename)
|
||||
.setText(category.title)
|
||||
.setHint(R.string.enter_category_name)
|
||||
.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setMaxLength(12, false)
|
||||
.setPositiveButton(R.string.rename) { _, name ->
|
||||
presenter.renameCategory(category.id, name)
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun createCategory() {
|
||||
TextInputDialog.Builder(this)
|
||||
.setTitle(R.string.add_new_category)
|
||||
.setHint(R.string.enter_category_name)
|
||||
.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setMaxLength(12, false)
|
||||
.setPositiveButton(R.string.add) { _, name ->
|
||||
presenter.createCategory(name)
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun newIntent(context: Context) = Intent(context, CategoriesActivity::class.java)
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,17 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories
|
||||
|
||||
import android.util.SparseBooleanArray
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Checkable
|
||||
import androidx.core.util.set
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseRecyclerAdapter
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
import org.koitharu.kotatsu.ui.common.list.OnRecyclerItemClickListener
|
||||
import org.koitharu.kotatsu.ui.main.list.favourites.categories.select.CategoryCheckableHolder
|
||||
|
||||
class CategoriesAdapter(private val listener: OnCategoryCheckListener) :
|
||||
BaseRecyclerAdapter<FavouriteCategory, Boolean>() {
|
||||
class CategoriesAdapter(onItemClickListener: OnRecyclerItemClickListener<FavouriteCategory>? = null) :
|
||||
BaseRecyclerAdapter<FavouriteCategory, Unit>(onItemClickListener) {
|
||||
|
||||
private val checkedIds = SparseBooleanArray()
|
||||
|
||||
fun setCheckedIds(ids: Iterable<Int>) {
|
||||
checkedIds.clear()
|
||||
ids.forEach {
|
||||
checkedIds[it] = true
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getExtra(item: FavouriteCategory, position: Int) =
|
||||
checkedIds.get(item.id.toInt(), false)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup) =
|
||||
CategoryHolder(
|
||||
parent
|
||||
)
|
||||
override fun onCreateViewHolder(parent: ViewGroup) = CategoryHolder(parent)
|
||||
|
||||
override fun onGetItemId(item: FavouriteCategory) = item.id
|
||||
|
||||
override fun onViewHolderCreated(holder: BaseViewHolder<FavouriteCategory, Boolean>) {
|
||||
super.onViewHolderCreated(holder)
|
||||
holder.itemView.setOnClickListener {
|
||||
if (it !is Checkable) return@setOnClickListener
|
||||
it.toggle()
|
||||
if (it.isChecked) {
|
||||
listener.onCategoryChecked(holder.requireData())
|
||||
} else {
|
||||
listener.onCategoryUnchecked(holder.requireData())
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun getExtra(item: FavouriteCategory, position: Int) = Unit
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories
|
||||
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.synthetic.main.item_category_checkable.*
|
||||
import kotlinx.android.synthetic.main.item_category.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
|
||||
class CategoryHolder(parent: ViewGroup) :
|
||||
BaseViewHolder<FavouriteCategory, Boolean>(parent, R.layout.item_category_checkable) {
|
||||
BaseViewHolder<FavouriteCategory, Unit>(parent, R.layout.item_category) {
|
||||
|
||||
override fun onBind(data: FavouriteCategory, extra: Boolean) {
|
||||
checkedTextView.text = data.title
|
||||
checkedTextView.isChecked = extra
|
||||
override fun onBind(data: FavouriteCategory, extra: Unit) {
|
||||
textView.text = data.title
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,40 @@ class FavouriteCategoriesPresenter : BasePresenter<FavouriteCategoriesView>() {
|
||||
}
|
||||
}
|
||||
|
||||
fun renameCategory(id: Long, name: String) {
|
||||
presenterScope.launch {
|
||||
try {
|
||||
val categories = withContext(Dispatchers.IO) {
|
||||
repository.renameCategory(id, name)
|
||||
repository.getAllCategories()
|
||||
}
|
||||
viewState.onCategoriesChanged(categories)
|
||||
} catch (e: Exception) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
viewState.onError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteCategory(id: Long) {
|
||||
presenterScope.launch {
|
||||
try {
|
||||
val categories = withContext(Dispatchers.IO) {
|
||||
repository.removeCategory(id)
|
||||
repository.getAllCategories()
|
||||
}
|
||||
viewState.onCategoriesChanged(categories)
|
||||
} catch (e: Exception) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
viewState.onError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun addToCategory(manga: Manga, categoryId: Long) {
|
||||
presenterScope.launch {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories.select
|
||||
|
||||
import android.util.SparseBooleanArray
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Checkable
|
||||
import androidx.core.util.set
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseRecyclerAdapter
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
|
||||
class CategoriesSelectAdapter(private val listener: OnCategoryCheckListener) :
|
||||
BaseRecyclerAdapter<FavouriteCategory, Boolean>() {
|
||||
|
||||
private val checkedIds = SparseBooleanArray()
|
||||
|
||||
fun setCheckedIds(ids: Iterable<Int>) {
|
||||
checkedIds.clear()
|
||||
ids.forEach {
|
||||
checkedIds[it] = true
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getExtra(item: FavouriteCategory, position: Int) =
|
||||
checkedIds.get(item.id.toInt(), false)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup) =
|
||||
CategoryCheckableHolder(
|
||||
parent
|
||||
)
|
||||
|
||||
override fun onGetItemId(item: FavouriteCategory) = item.id
|
||||
|
||||
override fun onViewHolderCreated(holder: BaseViewHolder<FavouriteCategory, Boolean>) {
|
||||
super.onViewHolderCreated(holder)
|
||||
holder.itemView.setOnClickListener {
|
||||
if (it !is Checkable) return@setOnClickListener
|
||||
it.toggle()
|
||||
if (it.isChecked) {
|
||||
listener.onCategoryChecked(holder.requireData())
|
||||
} else {
|
||||
listener.onCategoryUnchecked(holder.requireData())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories.select
|
||||
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.synthetic.main.item_category_checkable.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
|
||||
class CategoryCheckableHolder(parent: ViewGroup) :
|
||||
BaseViewHolder<FavouriteCategory, Boolean>(parent, R.layout.item_category_checkable) {
|
||||
|
||||
override fun onBind(data: FavouriteCategory, extra: Boolean) {
|
||||
checkedTextView.text = data.title
|
||||
checkedTextView.isChecked = extra
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories.select
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
@@ -12,6 +12,8 @@ import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.ui.common.BaseBottomSheet
|
||||
import org.koitharu.kotatsu.ui.common.dialog.TextInputDialog
|
||||
import org.koitharu.kotatsu.ui.main.list.favourites.categories.FavouriteCategoriesPresenter
|
||||
import org.koitharu.kotatsu.ui.main.list.favourites.categories.FavouriteCategoriesView
|
||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||
|
||||
@@ -23,11 +25,13 @@ class FavouriteCategoriesDialog : BaseBottomSheet(R.layout.dialog_favorite_categ
|
||||
|
||||
private val manga get() = arguments?.getParcelable<Manga>(ARG_MANGA)
|
||||
|
||||
private var adapter: CategoriesAdapter? = null
|
||||
private var adapter: CategoriesSelectAdapter? = null
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
adapter = CategoriesAdapter(this)
|
||||
adapter =
|
||||
CategoriesSelectAdapter(
|
||||
this)
|
||||
recyclerView_categories.adapter = adapter
|
||||
textView_add.setOnClickListener {
|
||||
createCategory()
|
||||
@@ -66,6 +70,7 @@ class FavouriteCategoriesDialog : BaseBottomSheet(R.layout.dialog_favorite_categ
|
||||
TextInputDialog.Builder(context ?: return)
|
||||
.setTitle(R.string.add_new_category)
|
||||
.setHint(R.string.enter_category_name)
|
||||
.setMaxLength(12, false)
|
||||
.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setPositiveButton(R.string.add) { _, name ->
|
||||
@@ -79,8 +84,10 @@ class FavouriteCategoriesDialog : BaseBottomSheet(R.layout.dialog_favorite_categ
|
||||
private const val ARG_MANGA = "manga"
|
||||
private const val TAG = "FavouriteCategoriesDialog"
|
||||
|
||||
fun show(fm: FragmentManager, manga: Manga) = FavouriteCategoriesDialog().withArgs(1) {
|
||||
fun show(fm: FragmentManager, manga: Manga) = FavouriteCategoriesDialog()
|
||||
.withArgs(1) {
|
||||
putParcelable(ARG_MANGA, manga)
|
||||
}.show(fm, TAG)
|
||||
}.show(fm,
|
||||
TAG)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories
|
||||
package org.koitharu.kotatsu.ui.main.list.favourites.categories.select
|
||||
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package org.koitharu.kotatsu.ui.main.list.history
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.android.synthetic.main.fragment_list.*
|
||||
import moxy.ktx.moxyPresenter
|
||||
@@ -53,7 +48,7 @@ class HistoryListFragment : MangaListFragment<MangaHistory>(), MangaListView<Man
|
||||
}
|
||||
|
||||
override fun setUpEmptyListHolder() {
|
||||
textView_holder.setText(R.string.history_is_empty)
|
||||
textView_holder.setText(R.string.text_history_holder)
|
||||
textView_holder.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.koitharu.kotatsu.core.model.MangaHistory
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.ui.common.BasePresenter
|
||||
import org.koitharu.kotatsu.ui.main.list.MangaListView
|
||||
import org.koitharu.kotatsu.utils.ShortcutUtils
|
||||
import org.koitharu.kotatsu.utils.MangaShortcut
|
||||
|
||||
@InjectViewState
|
||||
class HistoryListPresenter : BasePresenter<MangaListView<MangaHistory>>() {
|
||||
@@ -62,7 +62,7 @@ class HistoryListPresenter : BasePresenter<MangaListView<MangaHistory>>() {
|
||||
repository.clear()
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
ShortcutUtils.clearAppShortcuts(get())
|
||||
MangaShortcut.clearAppShortcuts(get())
|
||||
}
|
||||
viewState.onListChanged(emptyList())
|
||||
} catch (_: CancellationException) {
|
||||
@@ -84,7 +84,7 @@ class HistoryListPresenter : BasePresenter<MangaListView<MangaHistory>>() {
|
||||
repository.delete(manga)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
ShortcutUtils.removeAppShortcut(get(), manga)
|
||||
MangaShortcut(manga).removeAppShortcut(get())
|
||||
}
|
||||
viewState.onItemRemoved(manga)
|
||||
} catch (_: CancellationException) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Intent
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.android.synthetic.main.fragment_list.*
|
||||
import moxy.ktx.moxyPresenter
|
||||
@@ -14,7 +15,6 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.ui.main.list.MangaListFragment
|
||||
import org.koitharu.kotatsu.utils.ext.ellipsize
|
||||
import org.koitharu.kotatsu.utils.ext.showDialog
|
||||
import java.io.File
|
||||
|
||||
class LocalListFragment : MangaListFragment<File>() {
|
||||
@@ -59,7 +59,7 @@ class LocalListFragment : MangaListFragment<File>() {
|
||||
}
|
||||
|
||||
override fun setUpEmptyListHolder() {
|
||||
textView_holder.setText(R.string.no_saved_manga)
|
||||
textView_holder.setText(R.string.text_local_holder)
|
||||
textView_holder.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
@@ -81,14 +81,14 @@ class LocalListFragment : MangaListFragment<File>() {
|
||||
override fun onPopupMenuItemSelected(item: MenuItem, data: Manga): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_delete -> {
|
||||
context?.showDialog {
|
||||
setTitle(R.string.delete_manga)
|
||||
setMessage(getString(R.string.text_delete_local_manga, data.title))
|
||||
setPositiveButton(R.string.delete) { _, _ ->
|
||||
AlertDialog.Builder(context ?: return false)
|
||||
.setTitle(R.string.delete_manga)
|
||||
.setMessage(getString(R.string.text_delete_local_manga, data.title))
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
presenter.delete(data)
|
||||
}
|
||||
setNegativeButton(android.R.string.cancel, null)
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
true
|
||||
}
|
||||
else -> super.onPopupMenuItemSelected(item, data)
|
||||
|
||||
@@ -19,8 +19,8 @@ import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.ui.common.BasePresenter
|
||||
import org.koitharu.kotatsu.ui.main.list.MangaListView
|
||||
import org.koitharu.kotatsu.utils.MangaShortcut
|
||||
import org.koitharu.kotatsu.utils.MediaStoreCompat
|
||||
import org.koitharu.kotatsu.utils.ShortcutUtils
|
||||
import org.koitharu.kotatsu.utils.ext.safe
|
||||
import org.koitharu.kotatsu.utils.ext.sub
|
||||
import java.io.File
|
||||
@@ -98,7 +98,7 @@ class LocalListPresenter : BasePresenter<MangaListView<File>>() {
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
ShortcutUtils.removeAppShortcut(get(), manga)
|
||||
MangaShortcut(manga).removeAppShortcut(get())
|
||||
}
|
||||
viewState.onItemRemoved(manga)
|
||||
} catch (e: CancellationException) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import kotlin.coroutines.CoroutineContext
|
||||
class PageLoader : KoinComponent, CoroutineScope, DisposableHandle {
|
||||
|
||||
private val job = SupervisorJob()
|
||||
private val tasks = HashMap<String, Job>()
|
||||
private val tasks = HashMap<String, Deferred<File>>()
|
||||
private val okHttp by inject<OkHttpClient>()
|
||||
private val cache by inject<PagesCache>()
|
||||
|
||||
@@ -30,8 +30,13 @@ class PageLoader : KoinComponent, CoroutineScope, DisposableHandle {
|
||||
return it
|
||||
}
|
||||
}
|
||||
val task = tasks[url]?.takeUnless { it.isCancelled }
|
||||
return (task ?: loadAsync(url).also { tasks[url] = it }).await()
|
||||
}
|
||||
|
||||
private fun loadAsync(url: String) = async(Dispatchers.IO) {
|
||||
val uri = Uri.parse(url)
|
||||
return if (uri.scheme == "cbz") {
|
||||
if (uri.scheme == "cbz") {
|
||||
val zip = ZipFile(uri.schemeSpecificPart)
|
||||
val entry = zip.getEntry(uri.fragment)
|
||||
zip.getInputStream(entry).use {
|
||||
@@ -60,5 +65,6 @@ class PageLoader : KoinComponent, CoroutineScope, DisposableHandle {
|
||||
|
||||
override fun dispose() {
|
||||
coroutineContext.cancel()
|
||||
tasks.clear()
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.postDelayed
|
||||
import androidx.core.view.updatePadding
|
||||
@@ -34,8 +35,8 @@ import org.koitharu.kotatsu.ui.reader.thumbnails.OnPageSelectListener
|
||||
import org.koitharu.kotatsu.ui.reader.thumbnails.PagesThumbnailsSheet
|
||||
import org.koitharu.kotatsu.ui.reader.wetoon.WebtoonReaderFragment
|
||||
import org.koitharu.kotatsu.utils.GridTouchHelper
|
||||
import org.koitharu.kotatsu.utils.MangaShortcut
|
||||
import org.koitharu.kotatsu.utils.ShareHelper
|
||||
import org.koitharu.kotatsu.utils.ShortcutUtils
|
||||
import org.koitharu.kotatsu.utils.anim.Motion
|
||||
import org.koitharu.kotatsu.utils.ext.*
|
||||
|
||||
@@ -91,7 +92,7 @@ class ReaderActivity : BaseFullscreenActivity(), ReaderView, ChaptersDialog.OnCh
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
GlobalScope.launch {
|
||||
safe {
|
||||
ShortcutUtils.addAppShortcut(applicationContext, state.manga)
|
||||
MangaShortcut(state.manga).addAppShortcut(applicationContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,16 +208,16 @@ class ReaderActivity : BaseFullscreenActivity(), ReaderView, ChaptersDialog.OnCh
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
showDialog {
|
||||
setTitle(R.string.error_occurred)
|
||||
setMessage(e.message)
|
||||
setPositiveButton(R.string.close, null)
|
||||
if (reader?.hasItems != true) {
|
||||
setOnDismissListener {
|
||||
finish()
|
||||
}
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(R.string.error_occurred)
|
||||
.setMessage(e.message)
|
||||
.setPositiveButton(R.string.close, null)
|
||||
if (reader?.hasItems != true) {
|
||||
dialog.setOnDismissListener {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onGridTouch(area: Int) {
|
||||
@@ -225,11 +226,13 @@ class ReaderActivity : BaseFullscreenActivity(), ReaderView, ChaptersDialog.OnCh
|
||||
setUiIsVisible(!appbar_top.isVisible)
|
||||
}
|
||||
GridTouchHelper.AREA_TOP,
|
||||
GridTouchHelper.AREA_LEFT -> if (isTapSwitchEnabled) {
|
||||
GridTouchHelper.AREA_LEFT,
|
||||
-> if (isTapSwitchEnabled) {
|
||||
reader?.switchPageBy(-1)
|
||||
}
|
||||
GridTouchHelper.AREA_BOTTOM,
|
||||
GridTouchHelper.AREA_RIGHT -> if (isTapSwitchEnabled) {
|
||||
GridTouchHelper.AREA_RIGHT,
|
||||
-> if (isTapSwitchEnabled) {
|
||||
reader?.switchPageBy(1)
|
||||
}
|
||||
}
|
||||
@@ -267,13 +270,15 @@ class ReaderActivity : BaseFullscreenActivity(), ReaderView, ChaptersDialog.OnCh
|
||||
KeyEvent.KEYCODE_SPACE,
|
||||
KeyEvent.KEYCODE_PAGE_DOWN,
|
||||
KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||
-> {
|
||||
reader?.switchPageBy(1)
|
||||
true
|
||||
}
|
||||
KeyEvent.KEYCODE_PAGE_UP,
|
||||
KeyEvent.KEYCODE_DPAD_UP,
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT,
|
||||
-> {
|
||||
reader?.switchPageBy(-1)
|
||||
true
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import moxy.presenterScope
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.koin.core.get
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||
@@ -39,7 +40,7 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
|
||||
mode = MangaUtils.determineReaderMode(pages)
|
||||
if (mode != null) {
|
||||
prefs.savePreferences(
|
||||
mangaId = manga.id,
|
||||
manga = manga,
|
||||
mode = mode
|
||||
)
|
||||
}
|
||||
@@ -49,6 +50,9 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
|
||||
viewState.onInitReader(manga, mode)
|
||||
} catch (_: CancellationException) {
|
||||
} catch (e: Throwable) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
viewState.onError(e)
|
||||
} finally {
|
||||
viewState.onLoadingStateChanged(isLoading = false)
|
||||
@@ -59,7 +63,7 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
|
||||
fun setMode(manga: Manga, mode: ReaderMode) {
|
||||
presenterScope.launch(Dispatchers.IO) {
|
||||
MangaDataRepository().savePreferences(
|
||||
mangaId = manga.id,
|
||||
manga = manga,
|
||||
mode = mode
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.commit
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
import org.koitharu.kotatsu.ui.settings.MainSettingsFragment
|
||||
import org.koitharu.kotatsu.ui.settings.NetworkSettingsFragment
|
||||
import org.koitharu.kotatsu.ui.settings.ReaderSettingsFragment
|
||||
|
||||
class SimpleSettingsActivity : BaseActivity() {
|
||||
@@ -15,10 +17,10 @@ class SimpleSettingsActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_settings_simple)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
val section = intent?.getIntExtra(EXTRA_SECTION, 0)
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.container, when(section) {
|
||||
SECTION_READER -> ReaderSettingsFragment()
|
||||
replace(R.id.container, when(intent?.action) {
|
||||
Intent.ACTION_MANAGE_NETWORK_USAGE -> NetworkSettingsFragment()
|
||||
ACTION_READER -> ReaderSettingsFragment()
|
||||
else -> MainSettingsFragment()
|
||||
})
|
||||
}
|
||||
@@ -26,10 +28,9 @@ class SimpleSettingsActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
|
||||
private const val EXTRA_SECTION = "section"
|
||||
private const val SECTION_READER = 1
|
||||
private const val ACTION_READER = "${BuildConfig.APPLICATION_ID}.action.MANAGE_READER_SETTINGS"
|
||||
|
||||
fun newReaderSettingsIntent(context: Context) = Intent(context, SimpleSettingsActivity::class.java)
|
||||
.putExtra(EXTRA_SECTION, SECTION_READER)
|
||||
.setAction(ACTION_READER)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.koitharu.kotatsu.ui.reader.standard
|
||||
|
||||
import android.view.View
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
|
||||
class PageAnimTransformer : ViewPager2.PageTransformer {
|
||||
|
||||
override fun transformPage(page: View, position: Float) {
|
||||
page.apply {
|
||||
val pageWidth = width
|
||||
when {
|
||||
position < -1 -> alpha = 0f
|
||||
position <= 0 -> { // [-1,0]
|
||||
alpha = 1f
|
||||
translationX = 0f
|
||||
translationZ = 0f
|
||||
scaleX = 1 + FACTOR * position
|
||||
scaleY = 1f
|
||||
}
|
||||
position <= 1 -> { // (0,1]
|
||||
alpha = 1f
|
||||
translationX = pageWidth * -position
|
||||
translationZ = -1f
|
||||
scaleX = 1f
|
||||
scaleY = 1f
|
||||
}
|
||||
else -> alpha = 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
const val FACTOR = 0.1f
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,11 @@ class PageHolder(parent: ViewGroup, private val loader: PageLoader) :
|
||||
doLoad(data, force = false)
|
||||
}
|
||||
|
||||
override fun onRecycled() {
|
||||
job?.cancel()
|
||||
ssiv.recycle()
|
||||
}
|
||||
|
||||
private fun doLoad(data: MangaPage, force: Boolean) {
|
||||
job?.cancel()
|
||||
job = launch {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package org.koitharu.kotatsu.ui.reader.standard
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import kotlinx.android.synthetic.main.fragment_reader_standard.*
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.ui.reader.ReaderState
|
||||
import org.koitharu.kotatsu.ui.reader.base.AbstractReader
|
||||
import org.koitharu.kotatsu.ui.reader.base.BaseReaderAdapter
|
||||
@@ -12,19 +16,34 @@ import org.koitharu.kotatsu.ui.reader.base.GroupedList
|
||||
import org.koitharu.kotatsu.utils.ext.doOnPageChanged
|
||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||
|
||||
class PagerReaderFragment : AbstractReader(R.layout.fragment_reader_standard) {
|
||||
class PagerReaderFragment : AbstractReader(R.layout.fragment_reader_standard),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private var paginationListener: PagerPaginationListener? = null
|
||||
private val settings by inject<AppSettings>()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
paginationListener = PagerPaginationListener(adapter!!, 2, this)
|
||||
pager.adapter = adapter
|
||||
if (settings.readerAnimation) {
|
||||
pager.setPageTransformer(PageAnimTransformer())
|
||||
}
|
||||
pager.offscreenPageLimit = 2
|
||||
pager.registerOnPageChangeCallback(paginationListener!!)
|
||||
pager.doOnPageChanged(::notifyPageChanged)
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
settings.subscribe(this)
|
||||
}
|
||||
|
||||
override fun onDetach() {
|
||||
settings.unsubscribe(this)
|
||||
super.onDetach()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
paginationListener = null
|
||||
super.onDestroyView()
|
||||
@@ -47,6 +66,18 @@ class PagerReaderFragment : AbstractReader(R.layout.fragment_reader_standard) {
|
||||
|
||||
override fun restorePageScroll(position: Int, scroll: Float) = Unit
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
when (key) {
|
||||
getString(R.string.key_reader_animation) -> {
|
||||
if (settings.readerAnimation) {
|
||||
pager.setPageTransformer(PageAnimTransformer())
|
||||
} else {
|
||||
pager.setPageTransformer(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(state: ReaderState) = PagerReaderFragment().withArgs(1) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.ui.reader.thumbnails
|
||||
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.net.toUri
|
||||
import coil.Coil
|
||||
import coil.api.get
|
||||
import coil.size.PixelSize
|
||||
@@ -8,20 +9,18 @@ import coil.size.Size
|
||||
import kotlinx.android.synthetic.main.item_page_thumb.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.local.PagesCache
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
|
||||
class PageThumbnailHolder(parent: ViewGroup, private val scope: CoroutineScope) :
|
||||
BaseViewHolder<MangaPage, Unit>(parent, R.layout.item_page_thumb) {
|
||||
BaseViewHolder<MangaPage, PagesCache>(parent, R.layout.item_page_thumb) {
|
||||
|
||||
private var job: Job? = null
|
||||
private val thumbSize: Size
|
||||
|
||||
init {
|
||||
// FIXME
|
||||
// val color = DrawUtils.invertColor(textView_number.currentTextColor)
|
||||
// textView_number.setShadowLayer(parent.resources.resolveDp(26f), 0f, 0f, color)
|
||||
val width = itemView.context.resources.getDimensionPixelSize(R.dimen.preferred_grid_width)
|
||||
thumbSize = PixelSize(
|
||||
width = width,
|
||||
@@ -29,14 +28,15 @@ class PageThumbnailHolder(parent: ViewGroup, private val scope: CoroutineScope)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBind(data: MangaPage, extra: Unit) {
|
||||
override fun onBind(data: MangaPage, extra: PagesCache) {
|
||||
imageView_thumb.setImageDrawable(null)
|
||||
textView_number.text = (adapterPosition + 1).toString()
|
||||
textView_number.text = (bindingAdapterPosition + 1).toString()
|
||||
job?.cancel()
|
||||
job = scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val url = data.preview ?: data.url.let {
|
||||
MangaProviderFactory.create(data.source).getPageFullUrl(data)
|
||||
val pageUrl = MangaProviderFactory.create(data.source).getPageFullUrl(data)
|
||||
extra[pageUrl]?.toUri()?.toString() ?: pageUrl
|
||||
}
|
||||
val drawable = Coil.get(url) {
|
||||
size(thumbSize)
|
||||
@@ -50,4 +50,9 @@ class PageThumbnailHolder(parent: ViewGroup, private val scope: CoroutineScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRecycled() {
|
||||
job?.cancel()
|
||||
imageView_thumb.setImageDrawable(null)
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,18 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.DisposableHandle
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import org.koin.core.inject
|
||||
import org.koitharu.kotatsu.core.local.PagesCache
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseRecyclerAdapter
|
||||
import org.koitharu.kotatsu.ui.common.list.OnRecyclerItemClickListener
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class PagesThumbnailsAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaPage>?) :
|
||||
BaseRecyclerAdapter<MangaPage, Unit>(onItemClickListener), CoroutineScope, DisposableHandle {
|
||||
BaseRecyclerAdapter<MangaPage, PagesCache>(onItemClickListener), CoroutineScope, DisposableHandle {
|
||||
|
||||
private val job = SupervisorJob()
|
||||
private val cache by inject<PagesCache>()
|
||||
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.Main + job
|
||||
@@ -22,7 +25,7 @@ class PagesThumbnailsAdapter(onItemClickListener: OnRecyclerItemClickListener<Ma
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
override fun getExtra(item: MangaPage, position: Int) = Unit
|
||||
override fun getExtra(item: MangaPage, position: Int) = cache
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup) = PageThumbnailHolder(parent, this)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import androidx.core.net.toUri
|
||||
import androidx.core.view.isVisible
|
||||
import com.davemorrissey.labs.subscaleview.ImageSource
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import kotlinx.android.synthetic.main.item_page.*
|
||||
import kotlinx.android.synthetic.main.item_page_webtoon.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
@@ -53,6 +53,11 @@ class WebtoonHolder(parent: ViewGroup, private val loader: PageLoader) :
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRecycled() {
|
||||
job?.cancel()
|
||||
ssiv.recycle()
|
||||
}
|
||||
|
||||
fun getScrollY() = ssiv.center?.y ?: 0f
|
||||
|
||||
fun restoreScroll(scroll: Float) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.ui.reader.wetoon
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.fragment_reader_webtoon.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
@@ -12,7 +11,7 @@ import org.koitharu.kotatsu.ui.reader.base.AbstractReader
|
||||
import org.koitharu.kotatsu.ui.reader.base.BaseReaderAdapter
|
||||
import org.koitharu.kotatsu.ui.reader.base.GroupedList
|
||||
import org.koitharu.kotatsu.utils.ext.doOnCurrentItemChanged
|
||||
import org.koitharu.kotatsu.utils.ext.findMiddleVisibleItemPosition
|
||||
import org.koitharu.kotatsu.utils.ext.findCenterViewPosition
|
||||
import org.koitharu.kotatsu.utils.ext.firstItem
|
||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||
|
||||
@@ -43,7 +42,7 @@ class WebtoonReaderFragment : AbstractReader(R.layout.fragment_reader_webtoon) {
|
||||
get() = adapter?.itemCount ?: 0
|
||||
|
||||
override fun getCurrentItem(): Int {
|
||||
return (recyclerView.layoutManager as LinearLayoutManager).findMiddleVisibleItemPosition()
|
||||
return recyclerView.findCenterViewPosition()
|
||||
}
|
||||
|
||||
override fun setCurrentItem(position: Int, isSmooth: Boolean) {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.koitharu.kotatsu.ui.settings
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -21,8 +24,18 @@ import org.koitharu.kotatsu.core.github.VersionId
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.ui.common.BaseService
|
||||
import org.koitharu.kotatsu.utils.FileSizeUtils
|
||||
import org.koitharu.kotatsu.utils.ext.byte2HexFormatted
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.InputStream
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.security.cert.CertificateEncodingException
|
||||
import java.security.cert.CertificateException
|
||||
import java.security.cert.CertificateFactory
|
||||
import java.security.cert.X509Certificate
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
class AppUpdateService : BaseService() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
@@ -80,22 +93,37 @@ class AppUpdateService : BaseService() {
|
||||
PendingIntent.FLAG_CANCEL_CURRENT
|
||||
)
|
||||
)
|
||||
builder.addAction(
|
||||
R.drawable.ic_download, getString(R.string.download),
|
||||
PendingIntent.getActivity(
|
||||
this,
|
||||
NOTIFICATION_ID + 1,
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(newVersion.apkUrl)),
|
||||
PendingIntent.FLAG_CANCEL_CURRENT
|
||||
)
|
||||
)
|
||||
builder.setSmallIcon(R.drawable.ic_stat_update)
|
||||
builder.setAutoCancel(true)
|
||||
builder.color = ContextCompat.getColor(this, R.color.blue_primary_dark)
|
||||
builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
|
||||
manager.notify(NOTIFICATION_ID, builder.build())
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
||||
private const val NOTIFICATION_ID = 202
|
||||
private const val CHANNEL_ID = "update"
|
||||
private val PERIOD = TimeUnit.HOURS.toMillis(6)
|
||||
|
||||
fun start(context: Context) =
|
||||
context.startService(Intent(context, AppUpdateService::class.java))
|
||||
fun isUpdateSupported(context: Context): Boolean {
|
||||
return getCertificateSHA1Fingerprint(context) == CERT_SHA1
|
||||
}
|
||||
|
||||
fun startIfRequired(context: Context) {
|
||||
if (!isUpdateSupported(context)) {
|
||||
return
|
||||
}
|
||||
val settings = AppSettings(context)
|
||||
if (settings.appUpdateAuto) {
|
||||
val lastUpdate = settings.appUpdate
|
||||
@@ -104,5 +132,47 @@ class AppUpdateService : BaseService() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun start(context: Context) {
|
||||
try {
|
||||
context.startService(Intent(context, AppUpdateService::class.java))
|
||||
} catch (_: IllegalStateException) {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@SuppressLint("PackageManagerGetSignatures")
|
||||
private fun getCertificateSHA1Fingerprint(context: Context): String? {
|
||||
val packageInfo = try {
|
||||
context.packageManager.getPackageInfo(
|
||||
context.packageName,
|
||||
PackageManager.GET_SIGNATURES
|
||||
)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
return null
|
||||
}
|
||||
val signatures = packageInfo?.signatures
|
||||
val cert: ByteArray = signatures?.firstOrNull()?.toByteArray() ?: return null
|
||||
val input: InputStream = ByteArrayInputStream(cert)
|
||||
val c = try {
|
||||
val cf = CertificateFactory.getInstance("X509")
|
||||
cf.generateCertificate(input) as X509Certificate
|
||||
} catch (e: CertificateException) {
|
||||
e.printStackTrace()
|
||||
return null
|
||||
}
|
||||
return try {
|
||||
val md: MessageDigest = MessageDigest.getInstance("SHA1")
|
||||
val publicKey: ByteArray = md.digest(c.getEncoded())
|
||||
publicKey.byte2HexFormatted()
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
} catch (e: CertificateEncodingException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.koitharu.kotatsu.ui.settings
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.collection.arrayMapOf
|
||||
@@ -15,6 +18,8 @@ import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.ui.main.list.ListModeSelectDialog
|
||||
import org.koitharu.kotatsu.ui.settings.utils.MultiSummaryProvider
|
||||
import org.koitharu.kotatsu.ui.tracker.TrackWorker
|
||||
|
||||
|
||||
class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@@ -32,11 +37,8 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
|
||||
}
|
||||
findPreference<MultiSelectListPreference>(R.string.key_reader_switchers)?.summaryProvider =
|
||||
MultiSummaryProvider(R.string.gestures_only)
|
||||
findPreference<PreferenceScreen>(R.string.key_remote_sources)?.run {
|
||||
val total = MangaSource.values().size - 1
|
||||
summary = getString(
|
||||
R.string.enabled_d_from_d, total - settings.hiddenSources.size, total
|
||||
)
|
||||
findPreference<Preference>(R.string.key_app_update_auto)?.run {
|
||||
isVisible = AppUpdateService.isUpdateSupported(context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,12 +62,33 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
findPreference<PreferenceScreen>(R.string.key_remote_sources)?.run {
|
||||
val total = MangaSource.values().size - 1
|
||||
summary = getString(
|
||||
R.string.enabled_d_from_d, total - settings.hiddenSources.size, total
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
||||
return when (preference?.key) {
|
||||
getString(R.string.key_list_mode) -> {
|
||||
ListModeSelectDialog.show(childFragmentManager)
|
||||
true
|
||||
}
|
||||
getString(R.string.key_notifications_settings) -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
|
||||
.putExtra(Settings.EXTRA_CHANNEL_ID, TrackWorker.CHANNEL_ID)
|
||||
startActivity(intent)
|
||||
} else {
|
||||
(activity as? SettingsActivity)?.openNotificationSettingsLegacy()
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.koitharu.kotatsu.ui.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
|
||||
class NetworkSettingsFragment : BasePreferenceFragment(R.string.settings) {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
//TODO https://developer.android.com/training/basics/network-ops/managing
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.koitharu.kotatsu.ui.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import androidx.preference.Preference
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.utils.ext.toUriOrNull
|
||||
|
||||
class NotificationSettingsLegacyFragment : BasePreferenceFragment(R.string.notifications) {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_notifications)
|
||||
findPreference<Preference>(R.string.key_notifications_sound)?.run {
|
||||
val uri = settings.notificationSound.toUriOrNull()
|
||||
summary = RingtoneManager.getRingtone(context, uri).getTitle(context)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
||||
return when (preference?.key) {
|
||||
getString(R.string.key_notifications_sound) -> {
|
||||
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
|
||||
RingtoneManager.TYPE_NOTIFICATION)
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
|
||||
Settings.System.DEFAULT_NOTIFICATION_URI)
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, preference.title)
|
||||
val existingValue = settings.notificationSound.toUriOrNull()
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, existingValue)
|
||||
startActivityForResult(intent, REQUEST_RINGTONE)
|
||||
true
|
||||
}
|
||||
else -> super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_RINGTONE -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val uri =
|
||||
data?.getParcelableExtra<Uri>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
|
||||
settings.notificationSound = uri?.toString().orEmpty()
|
||||
findPreference<Preference>(R.string.key_notifications_sound)?.run {
|
||||
summary = RingtoneManager.getRingtone(context, uri).getTitle(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
const val REQUEST_RINGTONE = 340
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package org.koitharu.kotatsu.ui.settings
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.transition.Slide
|
||||
import android.view.Gravity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
@@ -20,7 +23,9 @@ class SettingsActivity : BaseActivity(),
|
||||
|
||||
if (supportFragmentManager.findFragmentById(R.id.container) == null) {
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.container, MainSettingsFragment())
|
||||
replace(R.id.container, MainSettingsFragment().also {
|
||||
it.exitTransition = Slide(Gravity.START)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,16 +35,23 @@ class SettingsActivity : BaseActivity(),
|
||||
val fragment = fm.fragmentFactory.instantiate(classLoader, pref.fragment)
|
||||
fragment.arguments = pref.extras
|
||||
fragment.setTargetFragment(caller, 0)
|
||||
fm.commit {
|
||||
replace(R.id.container, fragment)
|
||||
addToBackStack(null)
|
||||
}
|
||||
openFragment(fragment)
|
||||
return true
|
||||
}
|
||||
|
||||
fun openMangaSourceSettings(mangaSource: MangaSource) {
|
||||
openFragment(SourceSettingsFragment.newInstance(mangaSource))
|
||||
}
|
||||
|
||||
fun openNotificationSettingsLegacy() {
|
||||
openFragment(NotificationSettingsLegacyFragment())
|
||||
}
|
||||
|
||||
private fun openFragment(fragment: Fragment) {
|
||||
fragment.enterTransition = Slide(Gravity.END)
|
||||
fragment.exitTransition = Slide(Gravity.START)
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.container, SourceSettingsFragment.newInstance(mangaSource))
|
||||
replace(R.id.container, fragment)
|
||||
addToBackStack(null)
|
||||
}
|
||||
}
|
||||
|
||||
210
app/src/main/java/org/koitharu/kotatsu/ui/tracker/TrackWorker.kt
Normal file
@@ -0,0 +1,210 @@
|
||||
package org.koitharu.kotatsu.ui.tracker
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.work.*
|
||||
import coil.Coil
|
||||
import coil.api.get
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
import org.koitharu.kotatsu.utils.ext.safe
|
||||
import org.koitharu.kotatsu.utils.ext.toUriOrNull
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class TrackWorker(context: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(context, workerParams), KoinComponent {
|
||||
|
||||
private val notificationManager by lazy(LazyThreadSafetyMode.NONE) {
|
||||
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
}
|
||||
|
||||
private val settings by inject<AppSettings>()
|
||||
|
||||
override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
|
||||
val repo = TrackingRepository()
|
||||
val tracks = repo.getAllTracks()
|
||||
if (tracks.isEmpty()) {
|
||||
return@withContext Result.success()
|
||||
}
|
||||
var success = 0
|
||||
for (track in tracks) {
|
||||
val details = safe {
|
||||
MangaProviderFactory.create(track.manga.source)
|
||||
.getDetails(track.manga)
|
||||
}
|
||||
val chapters = details?.chapters ?: continue
|
||||
when {
|
||||
track.knownChaptersCount == -1 -> { //first check
|
||||
repo.storeTrackResult(
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = chapters.size,
|
||||
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
lastNotifiedChapterId = 0L,
|
||||
newChapters = 0
|
||||
)
|
||||
}
|
||||
track.knownChaptersCount == 0 && track.lastChapterId == 0L -> { //manga was empty on last check
|
||||
repo.storeTrackResult(
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = track.knownChaptersCount,
|
||||
lastChapterId = 0L,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = chapters.size
|
||||
)
|
||||
showNotification(track.manga, chapters)
|
||||
}
|
||||
chapters.size == track.knownChaptersCount -> {
|
||||
if (chapters.lastOrNull()?.id == track.lastChapterId) {
|
||||
// manga was not updated. skip
|
||||
} else {
|
||||
// number of chapters still the same, bu last chapter changed.
|
||||
// maybe some chapters are removed. we need to find last known chapter
|
||||
val knownChapter = chapters.indexOfLast { it.id == track.lastChapterId }
|
||||
if (knownChapter == -1) {
|
||||
// confuse. reset anything
|
||||
repo.storeTrackResult(
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = chapters.size,
|
||||
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = 0
|
||||
)
|
||||
} else {
|
||||
val newChapters = chapters.size - knownChapter + 1
|
||||
repo.storeTrackResult(
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = knownChapter + 1,
|
||||
lastChapterId = track.lastChapterId,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = newChapters
|
||||
)
|
||||
if (chapters.lastOrNull()?.id != track.lastNotifiedChapterId) {
|
||||
showNotification(track.manga, chapters.takeLast(newChapters))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val newChapters = chapters.size - track.knownChaptersCount
|
||||
repo.storeTrackResult(
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = track.knownChaptersCount,
|
||||
lastChapterId = track.lastChapterId,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = newChapters
|
||||
)
|
||||
if (chapters.lastOrNull()?.id != track.lastNotifiedChapterId) {
|
||||
showNotification(track.manga, chapters.takeLast(newChapters))
|
||||
}
|
||||
}
|
||||
}
|
||||
success++
|
||||
}
|
||||
if (success == 0) {
|
||||
Result.retry()
|
||||
} else {
|
||||
Result.success()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun showNotification(manga: Manga, newChapters: List<MangaChapter>) {
|
||||
if (newChapters.isEmpty() || !settings.trackerNotifications) {
|
||||
return
|
||||
}
|
||||
val id = manga.url.hashCode()
|
||||
val colorPrimary = ContextCompat.getColor(applicationContext, R.color.blue_primary)
|
||||
val builder = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
|
||||
val summary = applicationContext.resources.getQuantityString(R.plurals.new_chapters,
|
||||
newChapters.size, newChapters.size)
|
||||
with(builder) {
|
||||
setContentText(summary)
|
||||
setContentText(manga.title)
|
||||
setNumber(newChapters.size)
|
||||
setLargeIcon(safe {
|
||||
Coil.loader().get(manga.coverUrl).toBitmap()
|
||||
})
|
||||
setSmallIcon(R.drawable.ic_stat_book_plus)
|
||||
val style = NotificationCompat.InboxStyle(this)
|
||||
for (chapter in newChapters) {
|
||||
style.addLine(chapter.name)
|
||||
}
|
||||
style.setSummaryText(manga.title)
|
||||
style.setBigContentTitle(summary)
|
||||
setStyle(style)
|
||||
val intent = MangaDetailsActivity.newIntent(applicationContext, manga)
|
||||
setContentIntent(PendingIntent.getActivity(applicationContext, id,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
setAutoCancel(true)
|
||||
color = colorPrimary
|
||||
priority = NotificationCompat.PRIORITY_DEFAULT
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
builder.setSound(settings.notificationSound.toUriOrNull())
|
||||
var defaults = if (settings.notificationLight) {
|
||||
setLights(colorPrimary, 1000, 5000)
|
||||
NotificationCompat.DEFAULT_LIGHTS
|
||||
} else 0
|
||||
if (settings.notificationVibrate) {
|
||||
builder.setVibrate(longArrayOf(500, 500, 500, 500))
|
||||
defaults = defaults or NotificationCompat.DEFAULT_VIBRATE
|
||||
}
|
||||
builder.setDefaults(defaults)
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
notificationManager.notify(TAG, id, builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val CHANNEL_ID = "tracking"
|
||||
private const val TAG = "tracking"
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun createNotificationChannel(context: Context) {
|
||||
val manager =
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
if (manager.getNotificationChannel(CHANNEL_ID) == null) {
|
||||
val channel = NotificationChannel(CHANNEL_ID,
|
||||
context.getString(R.string.new_chapters),
|
||||
NotificationManager.IMPORTANCE_DEFAULT)
|
||||
channel.setShowBadge(true)
|
||||
channel.lightColor = ContextCompat.getColor(context, R.color.blue_primary)
|
||||
channel.enableLights(true)
|
||||
manager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
|
||||
fun setup(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createNotificationChannel(context)
|
||||
}
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.build()
|
||||
val request = PeriodicWorkRequestBuilder<TrackWorker>(4, TimeUnit.HOURS)
|
||||
.setConstraints(constraints)
|
||||
.addTag(TAG)
|
||||
.setBackoffCriteria(BackoffPolicy.LINEAR, 30, TimeUnit.MINUTES)
|
||||
.build()
|
||||
WorkManager.getInstance(context)
|
||||
.enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.KEEP, request)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.koitharu.kotatsu.ui.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class AppCrashHandler(private val applicationContext: Context) : Thread.UncaughtExceptionHandler {
|
||||
|
||||
override fun uncaughtException(t: Thread, e: Throwable) {
|
||||
val crashInfo = buildString {
|
||||
val writer = StringWriter()
|
||||
e.printStackTrace(PrintWriter(writer))
|
||||
append(writer.toString().trimIndent())
|
||||
}
|
||||
val intent = Intent(applicationContext, CrashActivity::class.java)
|
||||
intent.putExtra(Intent.EXTRA_TEXT, crashInfo)
|
||||
intent.flags = (Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
try {
|
||||
applicationContext.startActivity(intent)
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
e.printStackTrace()
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.koitharu.kotatsu.ui.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import kotlinx.android.synthetic.main.activity_crash.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.main.MainActivity
|
||||
|
||||
class CrashActivity : Activity(), View.OnClickListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_crash)
|
||||
textView.text = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||
button_close.setOnClickListener(this)
|
||||
button_restart.setOnClickListener(this)
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
when(v.id) {
|
||||
R.id.button_close -> {
|
||||
finish()
|
||||
}
|
||||
R.id.button_restart -> {
|
||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||
intent.flags = (Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.koitharu.kotatsu.ui.widget
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import org.koitharu.kotatsu.domain.favourites.OnFavouritesChangeListener
|
||||
import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
|
||||
import org.koitharu.kotatsu.ui.widget.recent.RecentWidgetProvider
|
||||
import org.koitharu.kotatsu.ui.widget.shelf.ShelfWidgetProvider
|
||||
|
||||
class WidgetUpdater(private val context: Context) : OnFavouritesChangeListener,
|
||||
OnHistoryChangeListener {
|
||||
|
||||
override fun onFavouritesChanged(mangaId: Long) {
|
||||
updateWidget(ShelfWidgetProvider::class.java)
|
||||
}
|
||||
|
||||
override fun onHistoryChanged() {
|
||||
updateWidget(RecentWidgetProvider::class.java)
|
||||
}
|
||||
|
||||
private fun updateWidget(cls: Class<*>) {
|
||||
val intent = Intent(context, cls)
|
||||
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
val ids = AppWidgetManager.getInstance(context)
|
||||
.getAppWidgetIds(ComponentName(context, cls))
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
||||
context.sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.koitharu.kotatsu.ui.widget.recent
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.RemoteViewsService
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import coil.Coil
|
||||
import coil.api.get
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okio.IOException
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
|
||||
class RecentListFactory(context: Context, private val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
private val packageName = context.packageName
|
||||
|
||||
private val dataSet = ArrayList<Manga>()
|
||||
|
||||
override fun onCreate() {
|
||||
}
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
override fun getItemId(position: Int) = dataSet[position].id
|
||||
|
||||
override fun onDataSetChanged() {
|
||||
dataSet.clear()
|
||||
val data = runBlocking { HistoryRepository().getList(0, 10) }
|
||||
dataSet.addAll(data)
|
||||
}
|
||||
|
||||
override fun hasStableIds() = true
|
||||
|
||||
override fun getViewAt(position: Int): RemoteViews {
|
||||
val views = RemoteViews(packageName, R.layout.item_recent)
|
||||
val item = dataSet[position]
|
||||
try {
|
||||
val cover = runBlocking {
|
||||
Coil.loader().get(item.coverUrl).toBitmap()
|
||||
}
|
||||
views.setImageViewBitmap(R.id.imageView_cover, cover)
|
||||
} catch (e: IOException) {
|
||||
views.setImageViewResource(R.id.imageView_cover, R.drawable.ic_placeholder)
|
||||
}
|
||||
val intent = Intent()
|
||||
intent.putExtra(MangaDetailsActivity.EXTRA_MANGA_ID, item.id)
|
||||
views.setOnClickFillInIntent(R.id.imageView_cover, intent)
|
||||
return views
|
||||
}
|
||||
|
||||
override fun getCount() = dataSet.size
|
||||
|
||||
override fun getViewTypeCount() = 1
|
||||
|
||||
override fun onDestroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.koitharu.kotatsu.ui.widget.recent
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.widget.RemoteViews
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
|
||||
class RecentWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
override fun onUpdate(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetIds: IntArray
|
||||
) {
|
||||
appWidgetIds.forEach { id ->
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_recent)
|
||||
val adapter = Intent(context, RecentWidgetService::class.java)
|
||||
adapter.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id)
|
||||
adapter.data = Uri.parse(adapter.toUri(Intent.URI_INTENT_SCHEME))
|
||||
views.setRemoteAdapter(R.id.stackView, adapter)
|
||||
val intent = Intent(context, MangaDetailsActivity::class.java)
|
||||
intent.action = MangaDetailsActivity.ACTION_MANGA_VIEW
|
||||
views.setPendingIntentTemplate(R.id.stackView, PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
))
|
||||
views.setEmptyView(R.id.stackView, R.id.textView_holder)
|
||||
appWidgetManager.updateAppWidget(id, views)
|
||||
}
|
||||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.stackView)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.koitharu.kotatsu.ui.widget.recent
|
||||
|
||||
import android.content.Intent
|
||||
import android.widget.RemoteViewsService
|
||||
|
||||
class RecentWidgetService : RemoteViewsService() {
|
||||
|
||||
override fun onGetViewFactory(intent: Intent): RemoteViewsFactory {
|
||||
return RecentListFactory(this, intent)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.koitharu.kotatsu.ui.widget.shelf
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.RemoteViewsService
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import coil.Coil
|
||||
import coil.api.get
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okio.IOException
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
|
||||
class ShelfListFactory(context: Context, private val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
private val packageName = context.packageName
|
||||
|
||||
private val dataSet = ArrayList<Manga>()
|
||||
|
||||
override fun onCreate() {
|
||||
}
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
override fun getItemId(position: Int) = dataSet[position].id
|
||||
|
||||
override fun onDataSetChanged() {
|
||||
dataSet.clear()
|
||||
val data = runBlocking { FavouritesRepository().getAllManga(0) }
|
||||
dataSet.addAll(data)
|
||||
}
|
||||
|
||||
override fun hasStableIds() = true
|
||||
|
||||
override fun getViewAt(position: Int): RemoteViews {
|
||||
val views = RemoteViews(packageName, R.layout.item_shelf)
|
||||
val item = dataSet[position]
|
||||
views.setTextViewText(R.id.textView_title, item.title)
|
||||
try {
|
||||
val cover = runBlocking {
|
||||
Coil.loader().get(item.coverUrl).toBitmap()
|
||||
}
|
||||
views.setImageViewBitmap(R.id.imageView_cover, cover)
|
||||
} catch (e: IOException) {
|
||||
views.setImageViewResource(R.id.imageView_cover, R.drawable.ic_placeholder)
|
||||
}
|
||||
val intent = Intent()
|
||||
intent.putExtra(MangaDetailsActivity.EXTRA_MANGA_ID, item.id)
|
||||
views.setOnClickFillInIntent(R.id.rootLayout, intent)
|
||||
return views
|
||||
}
|
||||
|
||||
override fun getCount() = dataSet.size
|
||||
|
||||
override fun getViewTypeCount() = 1
|
||||
|
||||
override fun onDestroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.koitharu.kotatsu.ui.widget.shelf
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.widget.RemoteViews
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
|
||||
class ShelfWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
override fun onUpdate(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetIds: IntArray
|
||||
) {
|
||||
appWidgetIds.forEach { id ->
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_shelf)
|
||||
val adapter = Intent(context, ShelfWidgetService::class.java)
|
||||
adapter.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id)
|
||||
adapter.data = Uri.parse(adapter.toUri(Intent.URI_INTENT_SCHEME))
|
||||
views.setRemoteAdapter(R.id.gridView, adapter)
|
||||
val intent = Intent(context, MangaDetailsActivity::class.java)
|
||||
intent.action = MangaDetailsActivity.ACTION_MANGA_VIEW
|
||||
views.setPendingIntentTemplate(R.id.gridView, PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
))
|
||||
views.setEmptyView(R.id.gridView, R.id.textView_holder)
|
||||
appWidgetManager.updateAppWidget(id, views)
|
||||
}
|
||||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.gridView)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.koitharu.kotatsu.ui.widget.shelf
|
||||
|
||||
import android.content.Intent
|
||||
import android.widget.RemoteViewsService
|
||||
|
||||
class ShelfWidgetService : RemoteViewsService() {
|
||||
|
||||
override fun onGetViewFactory(intent: Intent): RemoteViewsFactory {
|
||||
return ShelfListFactory(this, intent)
|
||||
}
|
||||
}
|
||||
@@ -22,25 +22,18 @@ import org.koitharu.kotatsu.domain.MangaDataRepository
|
||||
import org.koitharu.kotatsu.ui.details.MangaDetailsActivity
|
||||
import org.koitharu.kotatsu.utils.ext.safe
|
||||
|
||||
object ShortcutUtils {
|
||||
class MangaShortcut(private val manga: Manga) {
|
||||
|
||||
suspend fun requestPinShortcut(context: Context, manga: Manga?): Boolean {
|
||||
return manga != null && ShortcutManagerCompat.requestPinShortcut(
|
||||
context,
|
||||
buildShortcutInfo(context, manga).build(),
|
||||
null
|
||||
)
|
||||
}
|
||||
private val shortcutId = manga.id.toString()
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
suspend fun addAppShortcut(context: Context, manga: Manga) {
|
||||
val id = manga.id.toString()
|
||||
val builder = buildShortcutInfo(context, manga)
|
||||
suspend fun addAppShortcut(context: Context) {
|
||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||
val limit = manager.maxShortcutCountPerActivity
|
||||
val builder = buildShortcutInfo(context, manga)
|
||||
val shortcuts = manager.dynamicShortcuts
|
||||
for (shortcut in shortcuts) {
|
||||
if (shortcut.id == id) {
|
||||
if (shortcut.id == shortcutId) {
|
||||
builder.setRank(shortcut.rank + 1)
|
||||
manager.updateShortcuts(listOf(builder.build().toShortcutInfo()))
|
||||
return
|
||||
@@ -53,22 +46,23 @@ object ShortcutUtils {
|
||||
manager.addDynamicShortcuts(listOf(builder.build().toShortcutInfo()))
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
fun removeAppShortcut(context: Context, manga: Manga) {
|
||||
val id = manga.id.toString()
|
||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||
manager.removeDynamicShortcuts(listOf(id))
|
||||
suspend fun requestPinShortcut(context: Context): Boolean {
|
||||
return ShortcutManagerCompat.requestPinShortcut(
|
||||
context,
|
||||
buildShortcutInfo(context, manga).build(),
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
fun clearAppShortcuts(context: Context) {
|
||||
fun removeAppShortcut(context: Context) {
|
||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||
manager.removeAllDynamicShortcuts()
|
||||
manager.removeDynamicShortcuts(listOf(shortcutId))
|
||||
}
|
||||
|
||||
private suspend fun buildShortcutInfo(
|
||||
context: Context,
|
||||
manga: Manga
|
||||
manga: Manga,
|
||||
): ShortcutInfoCompat.Builder {
|
||||
val icon = safe {
|
||||
val size = getIconSize(context)
|
||||
@@ -77,12 +71,7 @@ object ShortcutUtils {
|
||||
size(size)
|
||||
scale(Scale.FILL)
|
||||
}.toBitmap()
|
||||
ThumbnailUtils.extractThumbnail(
|
||||
bmp,
|
||||
size.width,
|
||||
size.height,
|
||||
ThumbnailUtils.OPTIONS_RECYCLE_INPUT
|
||||
)
|
||||
ThumbnailUtils.extractThumbnail(bmp, size.width, size.height, 0)
|
||||
}
|
||||
}
|
||||
MangaDataRepository().storeManga(manga)
|
||||
@@ -109,4 +98,13 @@ object ShortcutUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
fun clearAppShortcuts(context: Context) {
|
||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||
manager.removeAllDynamicShortcuts()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.koitharu.kotatsu.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -14,16 +12,6 @@ import kotlin.math.roundToInt
|
||||
|
||||
object UiUtils {
|
||||
|
||||
@JvmStatic
|
||||
@ColorInt
|
||||
fun invertColor(@ColorInt color: Int): Int {
|
||||
val red = Color.red(color)
|
||||
val green = Color.green(color)
|
||||
val blue = Color.blue(color)
|
||||
val alpha = Color.alpha(color)
|
||||
return Color.argb(alpha, 255 - red, 255 - green, 255 - blue)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun resolveGridSpanCount(context: Context, width: Int = 0): Int {
|
||||
val scaleFactor = AppSettings(context).gridSize / 100f
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.delay
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -43,4 +44,12 @@ fun Throwable.getDisplayMessage(resources: Resources) = when (this) {
|
||||
} else {
|
||||
resources.getString(R.string.error_occurred)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> measured(tag: String, block: () -> T): T {
|
||||
val time = System.currentTimeMillis()
|
||||
val res = block()
|
||||
val spent = System.currentTimeMillis() - time
|
||||
Log.d("measured", "$tag ${spent.format(1)} ms")
|
||||
return res
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
|
||||
@Deprecated("Useless")
|
||||
fun Context.showDialog(block: AlertDialog.Builder.() -> Unit): AlertDialog {
|
||||
return AlertDialog.Builder(this)
|
||||
.apply(block)
|
||||
.show()
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import okhttp3.internal.closeQuietly
|
||||
import org.json.JSONObject
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
|
||||
fun Response.parseHtml(): Document {
|
||||
try {
|
||||
@@ -28,6 +27,4 @@ fun Response.parseJson(): JSONObject {
|
||||
} finally {
|
||||
closeQuietly()
|
||||
}
|
||||
}
|
||||
|
||||
fun Element.firstChild(): Element? = children().first()
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import java.text.DecimalFormat
|
||||
import java.text.NumberFormat
|
||||
import java.util.*
|
||||
|
||||
fun Number?.asBoolean() = (this?.toInt() ?: 0) > 0
|
||||
|
||||
fun Number.format(decimals: Int = 0, decPoint: Char = '.', thousandsSep: Char? = ' '): String {
|
||||
val formatter = NumberFormat.getInstance(Locale.US) as DecimalFormat
|
||||
val symbols = formatter.decimalFormatSymbols
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.net.Uri
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
|
||||
fun String.longHashCode(): Long {
|
||||
var h = 1125899906842597L
|
||||
@@ -57,7 +59,7 @@ fun String.transliterate(skipMissing: Boolean): String {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.toFileName() = this.transliterate(false)
|
||||
fun String.toFileNameSafe() = this.transliterate(false)
|
||||
.replace(Regex("[^a-z0-9_\\-]", setOf(RegexOption.IGNORE_CASE)), " ")
|
||||
.replace(Regex("\\s+"), "_")
|
||||
|
||||
@@ -65,4 +67,29 @@ fun String.ellipsize(maxLength: Int) = if (this.length > maxLength) {
|
||||
this.take(maxLength - 1) + Typography.ellipsis
|
||||
} else this
|
||||
|
||||
fun String.urlEncoded(): String = URLEncoder.encode(this, Charsets.UTF_8.name())
|
||||
fun String.urlEncoded(): String = URLEncoder.encode(this, Charsets.UTF_8.name())
|
||||
|
||||
fun String.toUriOrNull(): Uri? = if (isEmpty()) {
|
||||
null
|
||||
} else {
|
||||
Uri.parse(this)
|
||||
}
|
||||
|
||||
fun ByteArray.byte2HexFormatted(): String? {
|
||||
val str = StringBuilder(size * 2)
|
||||
for (i in indices) {
|
||||
var h = Integer.toHexString(this[i].toInt())
|
||||
val l = h.length
|
||||
if (l == 1) {
|
||||
h = "0$h"
|
||||
}
|
||||
if (l > 2) {
|
||||
h = h.substring(l - 2, l)
|
||||
}
|
||||
str.append(h.toUpperCase(Locale.ROOT))
|
||||
if (i < size - 1) {
|
||||
str.append(':')
|
||||
}
|
||||
}
|
||||
return str.toString()
|
||||
}
|
||||
@@ -17,6 +17,7 @@ fun Context.getThemeDrawable(@AttrRes resId: Int) = obtainStyledAttributes(intAr
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun Context.getThemeColor(@AttrRes resId: Int, @ColorInt default: Int = Color.TRANSPARENT) = obtainStyledAttributes(intArrayOf(resId)).use {
|
||||
it.getColor(0, default)
|
||||
}
|
||||
fun Context.getThemeColor(@AttrRes resId: Int, @ColorInt default: Int = Color.TRANSPARENT) =
|
||||
obtainStyledAttributes(intArrayOf(resId)).use {
|
||||
it.getColor(0, default)
|
||||
}
|
||||
@@ -2,11 +2,9 @@ package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.MenuRes
|
||||
@@ -23,7 +21,6 @@ import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import org.koitharu.kotatsu.ui.common.ChipsFactory
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
fun View.hideKeyboard() {
|
||||
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
@@ -35,14 +32,9 @@ fun View.showKeyboard() {
|
||||
imm.showSoftInput(this, 0)
|
||||
}
|
||||
|
||||
val EditText.plainText
|
||||
get() = text?.toString().orEmpty()
|
||||
|
||||
inline fun <reified T : View> ViewGroup.inflate(@LayoutRes resId: Int) =
|
||||
LayoutInflater.from(context).inflate(resId, this, false) as T
|
||||
|
||||
val TextView.hasText get() = !text.isNullOrEmpty()
|
||||
|
||||
fun RecyclerView.lookupSpanSize(callback: (Int) -> Int) {
|
||||
(layoutManager as? GridLayoutManager)?.spanSizeLookup =
|
||||
object : GridLayoutManager.SpanSizeLookup() {
|
||||
@@ -53,20 +45,6 @@ fun RecyclerView.lookupSpanSize(callback: (Int) -> Int) {
|
||||
val RecyclerView.hasItems: Boolean
|
||||
get() = (adapter?.itemCount ?: 0) > 0
|
||||
|
||||
var TextView.drawableStart: Drawable?
|
||||
get() = compoundDrawablesRelative[0]
|
||||
set(value) {
|
||||
val old = compoundDrawablesRelative
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(value, old[1], old[2], old[3])
|
||||
}
|
||||
|
||||
var TextView.drawableEnd: Drawable?
|
||||
get() = compoundDrawablesRelative[2]
|
||||
set(value) {
|
||||
val old = compoundDrawablesRelative
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(old[0], old[1], value, old[3])
|
||||
}
|
||||
|
||||
var TextView.textAndVisible: CharSequence?
|
||||
get() = text?.takeIf { visibility == View.VISIBLE }
|
||||
set(value) {
|
||||
@@ -106,7 +84,7 @@ fun View.disableFor(timeInMillis: Long) {
|
||||
|
||||
fun View.showPopupMenu(
|
||||
@MenuRes menuRes: Int, onPrepare: ((Menu) -> Unit)? = null,
|
||||
onItemClick: (MenuItem) -> Boolean
|
||||
onItemClick: (MenuItem) -> Boolean,
|
||||
) {
|
||||
val menu = PopupMenu(context, this)
|
||||
menu.inflate(menuRes)
|
||||
@@ -182,9 +160,8 @@ fun RecyclerView.doOnCurrentItemChanged(callback: (Int) -> Unit) {
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
val item = (recyclerView.layoutManager as? LinearLayoutManager)
|
||||
?.findMiddleVisibleItemPosition()
|
||||
if (item != null && item != RecyclerView.NO_POSITION && item != lastItem) {
|
||||
val item = recyclerView.findCenterViewPosition()
|
||||
if (item != RecyclerView.NO_POSITION && item != lastItem) {
|
||||
lastItem = item
|
||||
callback(item)
|
||||
}
|
||||
@@ -222,6 +199,9 @@ fun ViewPager2.callOnPageChaneListeners() {
|
||||
}
|
||||
}
|
||||
|
||||
fun LinearLayoutManager.findMiddleVisibleItemPosition(): Int {
|
||||
return ((findFirstVisibleItemPosition() + findLastVisibleItemPosition()) / 2.0).roundToInt()
|
||||
fun RecyclerView.findCenterViewPosition(): Int {
|
||||
val centerX = width / 2f
|
||||
val centerY = height / 2f
|
||||
val view = findChildViewUnder(centerX, centerY) ?: return RecyclerView.NO_POSITION
|
||||
return getChildAdapterPosition(view)
|
||||
}
|
||||
10
app/src/main/res/drawable-anydpi-v24/ic_stat_book_plus.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M4,6H2V20A2,2 0 0,0 4,22H18V20H4V6M20,2H8A2,2 0 0,0 6,4V16A2,2 0 0,0 8,18H20A2,2 0 0,0 22,16V4A2,2 0 0,0 20,2M20,12L17.5,10.5L15,12V4H20V12Z" />
|
||||
</vector>
|
||||
BIN
app/src/main/res/drawable-hdpi/ic_stat_book_plus.png
Normal file
|
After Width: | Height: | Size: 323 B |
BIN
app/src/main/res/drawable-mdpi/ic_stat_book_plus.png
Normal file
|
After Width: | Height: | Size: 291 B |
BIN
app/src/main/res/drawable-nodpi/ic_appwidget_recent.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
app/src/main/res/drawable-nodpi/ic_appwidget_shelf.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
app/src/main/res/drawable-xhdpi/ic_stat_book_plus.png
Normal file
|
After Width: | Height: | Size: 500 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_stat_book_plus.png
Normal file
|
After Width: | Height: | Size: 592 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_stat_book_plus.png
Normal file
|
After Width: | Height: | Size: 938 B |
@@ -1,12 +1,12 @@
|
||||
<!-- drawable/book_outline.xml -->
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M18,2A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2H18M18,4H13V12L10.5,9.75L8,12V4H6V20H18V4Z" />
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M13,5V11H14.17L12,13.17L9.83,11H11V5H13M15,3H9V9H5L12,16L19,9H15V3M19,18H5V20H19V18Z" />
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z" />
|
||||
</vector>
|
||||