Add hitomi.la preferences screen

Add hitomi.la early refresh
Fix some typos in comments
This commit is contained in:
NerdNumber9 2018-04-15 13:35:38 -04:00
parent fb1db914aa
commit aafe863774
9 changed files with 115 additions and 6 deletions

View File

@ -155,6 +155,8 @@ object PreferenceKeys {
const val eh_showSettingsUploadWarning = "eh_showSettingsUploadWarning1" const val eh_showSettingsUploadWarning = "eh_showSettingsUploadWarning1"
const val eh_hl_earlyRefresh = "eh_lh_early_refresh"
const val eh_hl_refreshFrequency = "eh_lh_refresh_frequency" const val eh_hl_refreshFrequency = "eh_lh_refresh_frequency"
const val eh_hl_lastRefresh = "eh_lh_last_refresh" const val eh_hl_lastRefresh = "eh_lh_last_refresh"

View File

@ -226,6 +226,8 @@ class PreferencesHelper(val context: Context) {
fun eh_showSettingsUploadWarning() = rxPrefs.getBoolean(Keys.eh_showSettingsUploadWarning, true) fun eh_showSettingsUploadWarning() = rxPrefs.getBoolean(Keys.eh_showSettingsUploadWarning, true)
// Default is 24h, refresh daily // Default is 24h, refresh daily
fun eh_hl_earlyRefresh() = rxPrefs.getBoolean(Keys.eh_hl_earlyRefresh, false)
fun eh_hl_refreshFrequency() = rxPrefs.getString(Keys.eh_hl_refreshFrequency, "24") fun eh_hl_refreshFrequency() = rxPrefs.getString(Keys.eh_hl_refreshFrequency, "24")
fun eh_hl_lastRefresh() = rxPrefs.getLong(Keys.eh_hl_lastRefresh, 0L) fun eh_hl_lastRefresh() = rxPrefs.getLong(Keys.eh_hl_lastRefresh, 0L)

View File

@ -249,7 +249,7 @@ class Hitomi(private val context: Context)
override fun imageUrlParse(response: Response) = throw UnsupportedOperationException("Unused method called!") override fun imageUrlParse(response: Response) = throw UnsupportedOperationException("Unused method called!")
override val name = "hitomi.la" override val name = "hitomi.la (very slow search)"
override val baseUrl = BASE_URL override val baseUrl = BASE_URL
@ -519,7 +519,7 @@ class Hitomi(private val context: Context)
.findFirst()?.let { realm.copyFromRealm(it) } .findFirst()?.let { realm.copyFromRealm(it) }
} }
private fun ensureCacheLoaded(blocking: Boolean = true): Observable<Any> { fun ensureCacheLoaded(blocking: Boolean = true): Observable<Any> {
return Observable.fromCallable { return Observable.fromCallable {
if(prefs.eh_hl_lastRealmIndex().getOrDefault() >= 0) { return@fromCallable Any() } if(prefs.eh_hl_lastRealmIndex().getOrDefault() >= 0) { return@fromCallable Any() }
@ -651,6 +651,29 @@ class Hitomi(private val context: Context)
.deleteRealmIfMigrationNeeded() .deleteRealmIfMigrationNeeded()
.build() .build()
fun forceEnsureCacheLoaded(): Boolean {
// Lock all caches
if(!cacheLocks[0].tryLock() || !cacheLocks[1].tryLock()) {
if(cacheLocks[0].isHeldByCurrentThread)
cacheLocks[0].unlock()
if(cacheLocks[1].isHeldByCurrentThread)
cacheLocks[1].unlock()
return false
}
try {
prefs.eh_hl_lastRealmIndex().set(-1)
prefs.eh_hl_lastRefresh().set(0)
ensureCacheLoaded(false).subscribeOn(Schedulers.computation()).subscribe()
} finally {
cacheLocks[0].unlock()
cacheLocks[1].unlock()
}
return true
}
companion object { companion object {
private val PAGE_SIZE = 25 private val PAGE_SIZE = 25
private val CHAR_MALE = "" private val CHAR_MALE = ""

View File

@ -15,7 +15,6 @@ import android.support.v7.graphics.drawable.DrawerArrowDrawable
import android.support.v7.widget.Toolbar import android.support.v7.widget.Toolbar
import android.view.ViewGroup import android.view.ViewGroup
import com.bluelinelabs.conductor.* import com.bluelinelabs.conductor.*
import com.jakewharton.rxbinding.support.v7.widget.navigationClicks
import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
@ -41,11 +40,15 @@ import exh.ui.migration.MetadataFetchDialog
import exh.util.defRealm import exh.util.defRealm
import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.main_activity.*
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import android.view.View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
import com.jakewharton.rxbinding.view.longClicks import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.Hitomi
import eu.kanade.tachiyomi.util.vibrate import eu.kanade.tachiyomi.util.vibrate
import exh.HITOMI_SOURCE_ID
import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class MainActivity : BaseActivity() { class MainActivity : BaseActivity() {
@ -170,6 +173,14 @@ class MainActivity : BaseActivity() {
notifyLockSecurity(this) notifyLockSecurity(this)
} }
} }
// Early hitomi.la refresh
if(preferences.eh_hl_earlyRefresh().getOrDefault()) {
(Injekt.get<SourceManager>().get(HITOMI_SOURCE_ID) as Hitomi)
.ensureCacheLoaded(false)
.subscribeOn(Schedulers.computation())
.subscribe()
}
// <-- EH // <-- EH
syncActivityViewWithController(router.backstack.lastOrNull()?.controller()) syncActivityViewWithController(router.backstack.lastOrNull()?.controller())

View File

@ -0,0 +1,58 @@
package eu.kanade.tachiyomi.ui.setting
import android.support.v7.preference.PreferenceScreen
import android.widget.Toast
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.Hitomi
import eu.kanade.tachiyomi.util.toast
import exh.HITOMI_SOURCE_ID
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
/**
* hitomi.la Settings fragment
*/
class SettingsHlController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
title = "hitomi.la"
editTextPreference {
title = "Search database refresh frequency"
summary = "How often to get new entries for the search database in hours. Setting this frequency too high may cause high CPU usage and network usage."
key = PreferenceKeys.eh_hl_refreshFrequency
defaultValue = "24"
onChange {
it as String
if((it.toLongOrNull() ?: -1) <= 0) {
context.toast("Invalid frequency. Frequency must be a positive whole number.")
false
} else true
}
}
switchPreference {
title = "Begin refreshing search database on app launch"
summary = "Normally the search database gets refreshed (if required) when you open the hitomi.la catalogue. If you enable this option, the database gets refreshed in the background as soon as you open the app. It will result in higher data usage but may increase hitomi.la search speeds."
key = PreferenceKeys.eh_hl_earlyRefresh
defaultValue = false
}
preference {
title = "Force refresh search database now"
summary = "Delete the local copy of the hitomi.la search database and download the new database now. Hitomi.la searching will not working in the ~10mins that it takes to refresh the search database"
isPersistent = false
onClick {
context.toast(if((Injekt.get<SourceManager>().get(HITOMI_SOURCE_ID) as Hitomi).forceEnsureCacheLoaded()) {
"Refreshing database. You will NOT be notified when it is complete!"
} else {
"Could not begin refresh process as there is already one ongoing!"
}, Toast.LENGTH_LONG)
}
}
}
}

View File

@ -53,6 +53,12 @@ class SettingsMainController : SettingsController() {
titleRes = R.string.pref_category_nh titleRes = R.string.pref_category_nh
onClick { navigateTo(SettingsNhController()) } onClick { navigateTo(SettingsNhController()) }
} }
preference {
iconRes = R.drawable.eh_ic_hllogo
iconTint = tintColor
titleRes = R.string.pref_category_hl
onClick { navigateTo(SettingsHlController()) }
}
preference { preference {
iconRes = R.drawable.ic_code_black_24dp iconRes = R.drawable.ic_code_black_24dp
iconTint = tintColor iconTint = tintColor

View File

@ -4,7 +4,7 @@ import android.support.v7.preference.PreferenceScreen
import eu.kanade.tachiyomi.data.preference.PreferenceKeys import eu.kanade.tachiyomi.data.preference.PreferenceKeys
/** /**
* EH Settings fragment * nhentai Settings fragment
*/ */
class SettingsNhController : SettingsController() { class SettingsNhController : SettingsController() {

View File

@ -0,0 +1,6 @@
<vector android:height="24dp" android:viewportHeight="192"
android:viewportWidth="192" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000000" android:pathData="M115.49,34.82C115.55,30.11 115.5,25.39 115.52,20.67C127.62,20.66 139.72,20.66 151.82,20.67C151.8,28.84 151.81,37.01 151.81,45.18C147.62,47.04 143.85,49.73 140.84,53.2C140.04,45.99 136.12,38.9 129.61,35.39C125.35,32.93 119.98,33.01 115.49,34.82Z"/>
<path android:fillColor="#000000" android:pathData="M35.62,22.63C47.61,22.59 59.59,22.65 71.58,22.6C71.71,41.53 71.56,60.46 71.65,79.39C85.41,79.39 99.17,79.38 112.92,79.39C119.31,86.01 124.89,93.89 126.83,103.02C133.6,96.24 142.69,92.25 151.8,89.7C151.83,116.66 151.79,143.61 151.82,170.57C139.71,170.57 127.61,170.6 115.5,170.56C115.56,151.14 115.47,131.73 115.55,112.31C100.9,112.22 86.25,112.27 71.61,112.29C71.59,131.65 71.72,151.02 71.54,170.38C59.57,170.14 47.6,170.89 35.63,170.49C35.59,121.2 35.6,71.91 35.62,22.63Z"/>
<path android:fillColor="#000000" android:pathData="M115.49,34.82C119.98,33.01 125.35,32.93 129.61,35.39C136.12,38.9 140.04,45.99 140.84,53.2C143.85,49.73 147.62,47.04 151.81,45.18C155.23,44.08 158.99,44.25 162.54,44.63C168.17,46.15 172.94,50.53 174.96,56C177.57,63.12 176.41,71.32 172.73,77.84C168.17,85.05 159.47,87.4 151.8,89.7C142.69,92.25 133.6,96.24 126.83,103.02C124.89,93.89 119.31,86.01 112.92,79.39C107.32,73.38 101.28,66.67 100.79,58.01C101.31,48.58 106.31,38.46 115.49,34.82Z"/>
</vector>

View File

@ -500,5 +500,6 @@
<string name="label_login">Login</string> <string name="label_login">Login</string>
<string name="pref_category_eh">E-Hentai</string> <string name="pref_category_eh">E-Hentai</string>
<string name="pref_category_nh">nhentai</string> <string name="pref_category_nh">nhentai</string>
<string name="pref_category_hl">hitomi.la</string>
</resources> </resources>