mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Migrate to Tachiyomi 6.1
Rewrite batch add UI Rewrite lock UI
This commit is contained in:
@@ -67,7 +67,7 @@ class NHentai(context: Context) : HttpSource() {
|
||||
= parseResultPage(response)
|
||||
|
||||
override fun mangaDetailsParse(response: Response)
|
||||
= parseGallery(jsonParser.parse(response.body().string()).asJsonObject)
|
||||
= parseGallery(jsonParser.parse(response.body()!!.string()).asJsonObject)
|
||||
|
||||
//Used so we can use a different URL for fetching manga details and opening the details in the browser
|
||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
|
||||
@@ -85,7 +85,7 @@ class NHentai(context: Context) : HttpSource() {
|
||||
= nhGet(baseUrl + "/api/gallery/" + url.split("/").last())
|
||||
|
||||
fun parseResultPage(response: Response): MangasPage {
|
||||
val res = jsonParser.parse(response.body().string()).asJsonObject
|
||||
val res = jsonParser.parse(response.body()!!.string()).asJsonObject
|
||||
|
||||
val error = res.get("error")
|
||||
if(error == null) {
|
||||
@@ -154,7 +154,7 @@ class NHentai(context: Context) : HttpSource() {
|
||||
?: client.newCall(urlToDetailsRequest(url))
|
||||
.asObservableSuccess()
|
||||
.map {
|
||||
rawParseGallery(jsonParser.parse(it.body().string()).asJsonObject)
|
||||
rawParseGallery(jsonParser.parse(it.body()!!.string()).asJsonObject)
|
||||
}.toBlocking().first()
|
||||
}!!
|
||||
|
||||
|
||||
@@ -4,54 +4,8 @@ import android.support.v7.app.AppCompatActivity
|
||||
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||
|
||||
abstract class BaseActivity : AppCompatActivity() {
|
||||
|
||||
init {
|
||||
@Suppress("LeakingThis")
|
||||
LocaleHelper.updateConfiguration(this)
|
||||
}
|
||||
|
||||
var willLock = false
|
||||
var disableLock = false
|
||||
override fun onRestart() {
|
||||
super.onRestart()
|
||||
if(willLock && lockEnabled() && !disableLock) {
|
||||
showLockActivity(this)
|
||||
}
|
||||
|
||||
willLock = false
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
tryLock()
|
||||
}
|
||||
|
||||
fun tryLock() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
val mUsageStatsManager = getSystemService("usagestats") as UsageStatsManager
|
||||
val time = System.currentTimeMillis()
|
||||
// We get usage stats for the last 20 seconds
|
||||
val stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 20, time)
|
||||
// Sort the stats by the last time used
|
||||
if (stats != null) {
|
||||
val mySortedMap = TreeMap<Long, UsageStats>()
|
||||
for (usageStats in stats) {
|
||||
mySortedMap.put(usageStats.lastTimeUsed, usageStats)
|
||||
}
|
||||
if (!mySortedMap.isEmpty()) {
|
||||
if(mySortedMap[mySortedMap.lastKey()]?.packageName != packageName) {
|
||||
willLock = true
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val am = getSystemService(Service.ACTIVITY_SERVICE) as ActivityManager
|
||||
val tasks: List<ActivityManager.RunningTaskInfo>
|
||||
tasks = am.getRunningTasks(1)
|
||||
val running = tasks[0]
|
||||
if (running.topActivity.packageName != packageName) {
|
||||
willLock = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,6 @@ class LibraryCategoryAdapter(view: LibraryCategoryView) :
|
||||
*/
|
||||
private var mangas: List<LibraryItem> = emptyList()
|
||||
|
||||
//EH
|
||||
private val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
private val searchEngine = SearchEngine()
|
||||
private val metadataHelper = MetadataHelper()
|
||||
|
||||
var asyncSearchText: String? = null
|
||||
|
||||
/**
|
||||
@@ -36,49 +30,6 @@ class LibraryCategoryAdapter(view: LibraryCategoryView) :
|
||||
performFilter()
|
||||
}
|
||||
|
||||
// --> EH
|
||||
/**
|
||||
* Filters the list of manga applying [filterObject] for each element.
|
||||
*
|
||||
* @param param the filter. Not used.
|
||||
*/
|
||||
override fun updateDataSet(param: String?) {
|
||||
//Async search filter (EH)
|
||||
val filtered = asyncSearchText?.let { search ->
|
||||
mangas.filter {
|
||||
filterObject(it, search)
|
||||
}
|
||||
} ?: mangas
|
||||
//The rest of the filters run on the main loop
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
filterItems(filtered)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters a manga depending on a query.
|
||||
*
|
||||
* @param manga the manga to filter.
|
||||
* @param query the query to apply.
|
||||
* @return true if the manga should be included, false otherwise.
|
||||
*/
|
||||
override fun filterObject(manga: Manga, query: String): Boolean = with(manga) {
|
||||
if(!isLewdSource(manga.source)) {
|
||||
//Regular searching for normal manga
|
||||
title.toLowerCase().contains(query) ||
|
||||
author != null && author!!.toLowerCase().contains(query)
|
||||
} else {
|
||||
//Use gallery search engine for EH manga
|
||||
val metadata = metadataHelper.fetchMetadata(manga.url, manga.source)
|
||||
metadata?.let {
|
||||
searchEngine.matches(it, searchEngine.parseQuery(query))
|
||||
} ?: title.contains(query, ignoreCase = true) //Use regular searching when the metadata is not set up for this gallery
|
||||
}
|
||||
}
|
||||
|
||||
// <-- EH
|
||||
|
||||
/**
|
||||
* Returns the position in the adapter for the given manga.
|
||||
*
|
||||
@@ -89,7 +40,9 @@ class LibraryCategoryAdapter(view: LibraryCategoryView) :
|
||||
}
|
||||
|
||||
fun performFilter() {
|
||||
updateDataSet(mangas.filter { it.filter(searchText) })
|
||||
updateDataSet(mangas.filter {
|
||||
it.filter(searchText)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -102,19 +102,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
fun onBind(category: Category) {
|
||||
this.category = category
|
||||
|
||||
//TODO Fix
|
||||
// --> EH
|
||||
val presenter = fragment.presenter
|
||||
|
||||
searchSubscription = presenter
|
||||
.searchSubject
|
||||
.debounce(10L, TimeUnit.MILLISECONDS)
|
||||
.subscribe { text -> //Debounce search (EH)
|
||||
adapter.asyncSearchText = text?.trim()?.toLowerCase()
|
||||
adapter.updateDataSet()
|
||||
}
|
||||
// <-- EH
|
||||
|
||||
adapter.mode = if (controller.selectedMangas.isNotEmpty()) {
|
||||
FlexibleAdapter.MODE_MULTI
|
||||
} else {
|
||||
|
||||
@@ -12,10 +12,18 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.util.inflate
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import exh.isLewdSource
|
||||
import exh.metadata.MetadataHelper
|
||||
import exh.search.SearchEngine
|
||||
import kotlinx.android.synthetic.main.catalogue_grid_item.view.*
|
||||
|
||||
class LibraryItem(val manga: Manga) : AbstractFlexibleItem<LibraryHolder>(), IFilterable {
|
||||
|
||||
// --> EH
|
||||
private val searchEngine = SearchEngine()
|
||||
private val metadataHelper = MetadataHelper()
|
||||
// <-- EH
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.catalogue_grid_item
|
||||
}
|
||||
@@ -53,6 +61,15 @@ class LibraryItem(val manga: Manga) : AbstractFlexibleItem<LibraryHolder>(), IFi
|
||||
* @return true if the manga should be included, false otherwise.
|
||||
*/
|
||||
override fun filter(constraint: String): Boolean {
|
||||
// --> EH
|
||||
if(!isLewdSource(manga.source)) {
|
||||
//Use gallery search engine for EH manga
|
||||
metadataHelper.fetchMetadata(manga.url, manga.source)?.let {
|
||||
return searchEngine.matches(it, searchEngine.parseQuery(constraint))
|
||||
}
|
||||
}
|
||||
// <-- EH
|
||||
|
||||
return manga.title.contains(constraint, true) ||
|
||||
(manga.author?.contains(constraint, true) ?: false)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package eu.kanade.tachiyomi.ui.main
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.ActivityManager
|
||||
import android.app.Service
|
||||
import android.app.usage.UsageStats
|
||||
import android.app.usage.UsageStatsManager
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v4.view.GravityCompat
|
||||
import android.support.v4.widget.DrawerLayout
|
||||
@@ -10,6 +15,8 @@ import android.support.v7.graphics.drawable.DrawerArrowDrawable
|
||||
import android.view.ViewGroup
|
||||
import com.bluelinelabs.conductor.*
|
||||
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
||||
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
|
||||
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
|
||||
import eu.kanade.tachiyomi.Migrations
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
@@ -26,8 +33,14 @@ import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController
|
||||
import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsMainController
|
||||
import exh.ui.batchadd.BatchAddController
|
||||
import exh.ui.lock.LockChangeHandler
|
||||
import exh.ui.lock.LockController
|
||||
import exh.ui.lock.lockEnabled
|
||||
import exh.ui.lock.notifyLockSecurity
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.*
|
||||
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
@@ -86,9 +99,8 @@ class MainActivity : BaseActivity() {
|
||||
R.id.nav_drawer_recently_read -> setRoot(RecentlyReadController(), id)
|
||||
R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id)
|
||||
R.id.nav_drawer_latest_updates -> setRoot(LatestUpdatesController(), id)
|
||||
//TODO
|
||||
// --> EH
|
||||
R.id.nav_drawer_batch_add -> setFragment(BatchAddFragment.newInstance(), id)
|
||||
R.id.nav_drawer_batch_add -> setRoot(BatchAddController(), id)
|
||||
// <-- EH
|
||||
R.id.nav_drawer_downloads -> {
|
||||
router.pushController(RouterTransaction.with(DownloadController())
|
||||
@@ -137,6 +149,17 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
})
|
||||
|
||||
//Show lock
|
||||
if (savedInstanceState == null) {
|
||||
val lockEnabled = lockEnabled(preferences)
|
||||
if (lockEnabled) {
|
||||
doLock()
|
||||
|
||||
//Check lock security
|
||||
notifyLockSecurity(this)
|
||||
}
|
||||
}
|
||||
|
||||
syncActivityViewWithController(router.backstack.lastOrNull()?.controller())
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
@@ -144,15 +167,6 @@ class MainActivity : BaseActivity() {
|
||||
if (Migrations.upgrade(preferences)) {
|
||||
ChangelogDialogController().showDialog(router)
|
||||
}
|
||||
|
||||
//Show lock
|
||||
val lockEnabled = lockEnabled(preferences)
|
||||
if(lockEnabled) {
|
||||
showLockActivity(this)
|
||||
|
||||
//Check lock security
|
||||
notifyLockSecurity(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,6 +267,54 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
// --> EH
|
||||
//Lock code
|
||||
var willLock = false
|
||||
var disableLock = false
|
||||
override fun onRestart() {
|
||||
super.onRestart()
|
||||
if(willLock && lockEnabled() && !disableLock) {
|
||||
doLock()
|
||||
}
|
||||
|
||||
willLock = false
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
tryLock()
|
||||
}
|
||||
|
||||
fun tryLock() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
val mUsageStatsManager = getSystemService("usagestats") as UsageStatsManager
|
||||
val time = System.currentTimeMillis()
|
||||
// We get usage stats for the last 20 seconds
|
||||
val sortedStats =
|
||||
mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
|
||||
time - 1000 * 20,
|
||||
time)
|
||||
?.associateBy {
|
||||
it.lastTimeUsed
|
||||
}?.toSortedMap()
|
||||
if(sortedStats != null && sortedStats.isNotEmpty())
|
||||
if(sortedStats[sortedStats.lastKey()]?.packageName != packageName)
|
||||
willLock = true
|
||||
} else {
|
||||
val am = getSystemService(Service.ACTIVITY_SERVICE) as ActivityManager
|
||||
val running = am.getRunningTasks(1)[0]
|
||||
if (running.topActivity.packageName != packageName) {
|
||||
willLock = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doLock() {
|
||||
router.pushController(RouterTransaction.with(LockController())
|
||||
.popChangeHandler(LockChangeHandler()))
|
||||
}
|
||||
// <-- EH
|
||||
|
||||
companion object {
|
||||
// Shortcut actions
|
||||
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.PreferenceScreen
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import exh.ui.migration.MetadataFetchDialog
|
||||
import exh.ui.login.LoginActivity
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
/**
|
||||
* EH Settings fragment
|
||||
*/
|
||||
|
||||
class SettingsEhFragment : SettingsController() {
|
||||
class SettingsEhController : SettingsController() {
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
||||
title = "E-Hentai"
|
||||
|
||||
@@ -27,13 +23,24 @@ class SettingsEhFragment : SettingsController() {
|
||||
.asObservable().subscribeUntilDestroy {
|
||||
isChecked = it
|
||||
}
|
||||
|
||||
onChange { newVal ->
|
||||
newVal as Boolean
|
||||
if(!newVal) {
|
||||
preferences.enableExhentai().set(false)
|
||||
true
|
||||
} else {
|
||||
startActivity(Intent(context, LoginActivity::class.java))
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switchPreference {
|
||||
title = "Use Hentai@Home Network"
|
||||
summary = "Do you wish to load images through the Hentai@Home Network? Disabling this option will reduce the amount of pages you are able to view"
|
||||
key = "enable_hah"
|
||||
defaultValue = "true"
|
||||
defaultValue = true
|
||||
}
|
||||
|
||||
switchPreference {
|
||||
@@ -41,11 +48,11 @@ class SettingsEhFragment : SettingsController() {
|
||||
summaryOn = "Currently showing Japanese titles in search results. Clear the chapter cache after changing this (in the Advanced section)"
|
||||
summaryOff = "Currently showing English/Romanized titles in search results. Clear the chapter cache after changing this (in the Advanced section)"
|
||||
key = "use_jp_title"
|
||||
defaultValue = "false"
|
||||
defaultValue = false
|
||||
}
|
||||
|
||||
switchPreference {
|
||||
defaultValue = "true"
|
||||
defaultValue = true
|
||||
key = "secure_exh"
|
||||
title = "Secure ExHentai/E-Hentai"
|
||||
summary = "Use the HTTPS version of ExHentai/E-Hentai."
|
||||
@@ -91,15 +98,13 @@ class SettingsEhFragment : SettingsController() {
|
||||
"rc_2",
|
||||
"rc_3"
|
||||
)
|
||||
dependency = "enable_exhentai"
|
||||
}
|
||||
}.dependency = "enable_exhentai"
|
||||
|
||||
listPreference {
|
||||
defaultValue = "tr_2"
|
||||
title = "Thumbnail rows"
|
||||
summary = "Affects loading speeds. It is recommended to set this to the maximum size your hath perks allow"
|
||||
key = "ex_thumb_rows"
|
||||
dependency = "enable_exhentai"
|
||||
entries = arrayOf(
|
||||
"4",
|
||||
"10 (requires 'More Thumbs' hath perk)",
|
||||
@@ -112,7 +117,7 @@ class SettingsEhFragment : SettingsController() {
|
||||
"tr_10",
|
||||
"tr_20"
|
||||
)
|
||||
}
|
||||
}.dependency = "enable_exhentai"
|
||||
|
||||
preferenceCategory {
|
||||
title = "Advanced"
|
||||
@@ -122,48 +127,14 @@ class SettingsEhFragment : SettingsController() {
|
||||
title = "Migrate library metadata"
|
||||
isPersistent = false
|
||||
key = "ex_migrate_library"
|
||||
summary = "Fetch the library metadata to enable tag searching in the library. This button will be visible even if you have already fetched the metadata" />
|
||||
summary = "Fetch the library metadata to enable tag searching in the library. This button will be visible even if you have already fetched the metadata"
|
||||
|
||||
onClick {
|
||||
activity?.let {
|
||||
MetadataFetchDialog().askMigration(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
val enableExhentaiPref by lazy {
|
||||
findPreference("enable_exhentai") as SwitchPreference
|
||||
}
|
||||
|
||||
val migrateLibraryPref by lazy {
|
||||
findPreference("ex_migrate_library") as Preference
|
||||
}
|
||||
|
||||
val useJpTitlePref by lazy {
|
||||
findPreference("use_jp_title") as SwitchPreference
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
||||
enableExhentaiPref.setOnPreferenceChangeListener { preference, newVal ->
|
||||
newVal as Boolean
|
||||
(activity as SettingsActivity).parentFlags = SettingsActivity.FLAG_EH_RECREATE
|
||||
if(!newVal) {
|
||||
preferences.enableExhentai().set(false)
|
||||
true
|
||||
} else {
|
||||
startActivity(Intent(context, LoginActivity::class.java))
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
migrateLibraryPref.setOnPreferenceClickListener {
|
||||
MetadataFetchDialog().askMigration(activity)
|
||||
true
|
||||
}
|
||||
|
||||
useJpTitlePref.setOnPreferenceChangeListener { preference, any ->
|
||||
(activity as SettingsActivity).parentFlags = SettingsActivity.FLAG_EH_RECREATE
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||
import exh.ui.lock.LockPreference
|
||||
import kotlinx.android.synthetic.main.pref_library_columns.view.*
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@@ -175,6 +176,13 @@ class SettingsGeneralController : SettingsController() {
|
||||
true
|
||||
}
|
||||
}
|
||||
LockPreference(context).apply {
|
||||
key = "pref_app_lock"
|
||||
title = "Application lock"
|
||||
isPersistent = false
|
||||
|
||||
addPreference(this)
|
||||
}
|
||||
}
|
||||
|
||||
class LibraryColumnsDialog : DialogController() {
|
||||
|
||||
@@ -48,6 +48,12 @@ class SettingsMainController : SettingsController() {
|
||||
titleRes = R.string.backup
|
||||
onClick { navigateTo(SettingsBackupController()) }
|
||||
}
|
||||
preference {
|
||||
iconRes = R.drawable.eh_ic_ehlogo_red_24dp
|
||||
iconTint = tintColor
|
||||
titleRes = R.string.pref_category_eh
|
||||
onClick { navigateTo(SettingsEhController()) }
|
||||
}
|
||||
preference {
|
||||
iconRes = R.drawable.ic_code_black_24dp
|
||||
iconTint = tintColor
|
||||
|
||||
Reference in New Issue
Block a user