Convert Settings to kotlin

This commit is contained in:
FooIbar authored and tarsin committed 2023-02-27 20:53:19 +08:00
1 parent 92f8e67a60
commit c4c654079d
32 files changed
+603 -675

No files matched your search

@@ -75,7 +75,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
val handler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { t, e ->
try {
if (Settings.getSaveCrashLog()) {
if (Settings.saveCrashLog) {
Crash.saveCrashLog(e)
}
} catch (ignored: Throwable) {
@@ -89,7 +89,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
ReadableTime.initialize(this)
AppConfig.initialize(this)
EhTagDatabase.update()
AppCompatDelegate.setDefaultNightMode(Settings.getTheme())
AppCompatDelegate.setDefaultNightMode(Settings.theme)
launchIO {
launchIO {
ehDatabase
@@ -106,8 +106,8 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
private fun cleanupDownload() {
try {
val downloadLocation = Settings.getDownloadLocation()
if (Settings.getMediaScan()) {
val downloadLocation = Settings.downloadLocation
if (Settings.mediaScan) {
CommonOperations.removeNoMediaFile(downloadLocation)
} else {
CommonOperations.ensureNoMediaFile(downloadLocation)
@@ -212,7 +212,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
.dns(EhDns)
.proxySelector(ehProxySelector)
if (Settings.getDF()) {
if (Settings.dF) {
val factory =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())!!
factory.init(null as KeyStore?)
File diff suppressed because it is too large. Load diff
@@ -114,17 +114,17 @@ object EhDns : Dns {
vararg ips: Pair<String, Boolean>
) {
map[host] = ips.mapNotNull { pair ->
Hosts.toInetAddress(host, pair.first).takeUnless { Settings.getDF() && pair.second }
Hosts.toInetAddress(host, pair.first).takeUnless { Settings.dF && pair.second }
}
}
@Throws(UnknownHostException::class)
override fun lookup(hostname: String): List<InetAddress> {
return hosts[hostname] ?: builtInHosts[hostname].takeIf { Settings.getBuiltInHosts() }
return hosts[hostname] ?: builtInHosts[hostname].takeIf { Settings.builtInHosts }
?: Dns.SYSTEM.lookup(hostname)
}
fun isInHosts(hostname: String): Boolean {
return hosts.contains(hostname) || (builtInHosts.contains(hostname) && Settings.getBuiltInHosts())
return hosts.contains(hostname) || (builtInHosts.contains(hostname) && Settings.builtInHosts)
}
}
@@ -109,7 +109,7 @@ object EhEngine {
} else if (body != null && !body.contains("<")) {
throw EhException(body)
} else {
if (Settings.getSaveParseErrorBody()) {
if (Settings.saveParseErrorBody) {
AppConfig.saveParseErrorBody(e as ParseException?)
}
throw EhException(GetText.getString(R.string.error_parse_error))
@@ -186,7 +186,7 @@ object EhEngine {
}
}
val needApi =
filter && sEhFilter.needTags() && !hasTags || Settings.getShowGalleryPages() && !hasPages ||
filter && sEhFilter.needTags() && !hasTags || Settings.showGalleryPages && !hasPages ||
hasRated
if (needApi) {
fillGalleryListByApi(list, url)
@@ -55,21 +55,21 @@ object EhUrl {
const val URL_PREFIX_THUMB_EX = "https://exhentai.org/t/"
val host: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> HOST_E
SITE_EX -> HOST_EX
else -> HOST_E
}
val favoritesUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> URL_FAVORITES_E
SITE_EX -> URL_FAVORITES_EX
else -> URL_FAVORITES_E
}
val apiUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> API_E
SITE_EX -> API_EX
else -> API_E
@@ -77,14 +77,14 @@ object EhUrl {
@JvmStatic
val referer: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> REFERER_E
SITE_EX -> REFERER_EX
else -> REFERER_E
}
val origin: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> ORIGIN_E
SITE_EX -> ORIGIN_EX
else -> ORIGIN_E
@@ -92,7 +92,7 @@ object EhUrl {
@JvmStatic
val uConfigUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> URL_UCONFIG_E
SITE_EX -> URL_UCONFIG_EX
else -> URL_UCONFIG_E
@@ -100,28 +100,28 @@ object EhUrl {
@JvmStatic
val myTagsUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> URL_MY_TAGS_E
SITE_EX -> URL_MY_TAGS_EX
else -> URL_MY_TAGS_E
}
val popularUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> URL_POPULAR_E
SITE_EX -> URL_POPULAR_EX
else -> URL_POPULAR_E
}
val imageSearchUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> URL_IMAGE_SEARCH_E
SITE_EX -> URL_IMAGE_SEARCH_EX
else -> URL_IMAGE_SEARCH_E
}
val watchedUrl: String
get() = when (Settings.getGallerySite()) {
get() = when (Settings.gallerySite) {
SITE_E -> URL_WATCHED_E
SITE_EX -> URL_WATCHED_EX
else -> URL_WATCHED_E
@@ -167,7 +167,7 @@ object EhUrl {
}
fun getThumbUrlPrefix(): String {
return when (Settings.getGallerySite()) {
return when (Settings.gallerySite) {
SITE_E -> URL_PREFIX_THUMB_E
SITE_EX -> URL_PREFIX_THUMB_EX
else -> URL_PREFIX_THUMB_E
@@ -78,7 +78,7 @@ object EhUtils {
private val CATEGORY_STRINGS = CATEGORY_VALUES.entries.map { (k, v) -> v to k }
val isExHentai: Boolean
get() = Settings.getGallerySite() == EhUrl.SITE_EX
get() = Settings.gallerySite == EhUrl.SITE_EX
@JvmStatic
fun getCategory(type: String?): Int {
@@ -120,12 +120,12 @@ object EhUtils {
}
fun needSignedIn(): Boolean {
return Settings.getNeedSignIn() && !ehCookieStore.hasSignedIn()
return Settings.needSignIn && !ehCookieStore.hasSignedIn()
}
@JvmStatic
fun getSuitableTitle(gi: GalleryInfo): String {
return if (Settings.getShowJpnTitle()) {
return if (Settings.showJpnTitle) {
if (TextUtils.isEmpty(gi.titleJpn)) gi.title else gi.titleJpn
} else {
if (TextUtils.isEmpty(gi.title)) gi.titleJpn else gi.title
@@ -156,7 +156,7 @@ object EhUtils {
if (null == url) {
return null
}
val resolution = when (Settings.getThumbResolution()) {
val resolution = when (Settings.thumbResolution) {
0 -> return url
1 -> "250"
2 -> "300"
@@ -43,7 +43,7 @@ class DailyCheckWork(val context: Context, workerParams: WorkerParameters) :
@SuppressLint("MissingPermission")
private fun showEventPane(html: String) {
if (Settings.getHideHvEvents() && html.contains("You have encountered a monster!")) {
if (Settings.hideHvEvents && html.contains("You have encountered a monster!")) {
return
}
val notificationManager = NotificationManagerCompat.from(context)
@@ -93,7 +93,7 @@ private fun getDailyCheckWorkRequest(): PeriodicWorkRequest {
private const val workName = "DailyCheckWork"
fun updateDailyCheckWork(context: Context) {
if (Settings.getRequestNews()) {
if (Settings.requestNews) {
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
workName,
ExistingPeriodicWorkPolicy.UPDATE,
@@ -49,7 +49,7 @@ class ArchivePageLoader(context: Context, uri: Uri, passwdFlow: Flow<String>) :
}
archiveAccessor.run {
if (needPassword()) {
Settings.getArchivePasswds()?.forEach {
Settings.archivePasswds?.forEach {
if (providePassword(it)) return@launch
}
passwdFlow.collect {
@@ -52,7 +52,7 @@ class CleanRedundancyPreference @JvmOverloads constructor(
}
private fun doRealWork(): Int {
return Settings.getDownloadLocation()?.listFiles()?.sumOf { clearFile(it).compareTo(false) } ?: 0
return Settings.downloadLocation?.listFiles()?.sumOf { clearFile(it).compareTo(false) } ?: 0
}
override fun launchJob() {
@@ -47,7 +47,7 @@ class ProxyPreference @JvmOverloads constructor(
init {
mArray = context.resources.getStringArray(R.array.proxy_types)
dialogLayoutResource = R.layout.preference_dialog_proxy
updateSummary(Settings.getProxyType(), Settings.getProxyIp(), Settings.getProxyPort())
updateSummary(Settings.proxyType, Settings.proxyIp, Settings.proxyPort)
}
private fun getProxyTypeText(type: Int): String {
@@ -93,7 +93,7 @@ class ProxyPreference @JvmOverloads constructor(
mIp = ViewUtils.`$$`(dialog, R.id.ip) as EditText
mPortInputLayout = ViewUtils.`$$`(dialog, R.id.port_input_layout) as TextInputLayout
mPort = ViewUtils.`$$`(dialog, R.id.port) as EditText
val type = Settings.getProxyType()
val type = Settings.proxyType
(mType!!.editText as AutoCompleteTextView).setText(
array[MathUtils.clamp(
type,
@@ -101,9 +101,9 @@ class ProxyPreference @JvmOverloads constructor(
array.size
)], false
)
mIp!!.setText(Settings.getProxyIp())
mIp!!.setText(Settings.proxyIp)
val portString: String?
val port = Settings.getProxyPort()
val port = Settings.proxyPort
portString = if (!InetValidator.isValidInetPort(port)) {
null
} else {
@@ -71,7 +71,7 @@ class RestoreDownloadPreference @JvmOverloads constructor(
}
private suspend fun doRealWork(): List<GalleryInfo>? {
val dir = Settings.getDownloadLocation() ?: return null
val dir = Settings.downloadLocation ?: return null
val files = dir.listFiles() ?: return null
val restoreItemList = files.mapNotNull { getRestoreItem(it) }
return runSuspendCatching {
@@ -303,14 +303,14 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
private val sCache by lazy {
DiskCache.Builder().directory(File(application.cacheDir, "gallery_image"))
.maxSizeBytes(
MathUtils.clamp(Settings.getReadCacheSize(), 40, 1280).toLong() * 1024 * 1024
MathUtils.clamp(Settings.readCacheSize, 40, 1280).toLong() * 1024 * 1024
).build()
}
private val COMPAT_IMAGE_EXTENSIONS = SUPPORT_IMAGE_EXTENSIONS + ".jpeg"
fun getGalleryDownloadDir(gid: Long): UniFile? {
val dir = Settings.getDownloadLocation()
val dir = Settings.downloadLocation
// Read from DB
var dirname = EhDB.getDownloadDirname(gid)
return if (dir != null && dirname != null) {
@@ -527,11 +527,11 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
private val mWorkerScope = object {
private val mFetcherJobMap = hashMapOf<Int, Job>()
private val mSemaphore = Semaphore(Settings.getMultiThreadDownload())
private val mSemaphore = Semaphore(Settings.multiThreadDownload)
private val pTokenLock = Mutex()
private var showKey: String? = null
private val showKeyLock = Mutex()
private val mDownloadDelay = Settings.getDownloadDelay()
private val mDownloadDelay = Settings.downloadDelay
private var isDownloadMode = false
fun cancelDecode(index: Int) {
@@ -721,7 +721,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
val targetImageUrl: String?
val referer: String?
if (Settings.getDownloadOriginImage() && !originImageUrl.isNullOrBlank()) {
if (Settings.downloadOriginImage && !originImageUrl.isNullOrBlank()) {
targetImageUrl = originImageUrl
referer = EhUrl.getPageUrl(mSpiderInfo.gid, index, pToken)
} else {
@@ -68,9 +68,9 @@ object CommonOperations {
activity: Activity, galleryInfo: GalleryInfo,
listener: EhClient.Callback<Void?>, select: Boolean = false
) {
val slot = Settings.getDefaultFavSlot()
val slot = Settings.defaultFavSlot
val localFav = activity.getString(R.string.local_favorites)
val items = Settings.getFavCat().toMutableList().apply { add(0, localFav) }
val items = Settings.favCat.toMutableList().apply { add(0, localFav) }
if (!select && slot >= -1 && slot <= 9) {
val newFavoriteName = if (slot >= 0) items[slot + 1] else null
doAddToFavorites(
@@ -159,8 +159,8 @@ object CommonOperations {
var justStart = forceDefault
var label: String? = null
// Get default download label
if (!justStart && Settings.getHasDefaultDownloadLabel()) {
label = Settings.getDefaultDownloadLabel()
if (!justStart && Settings.hasDefaultDownloadLabel) {
label = Settings.defaultDownloadLabel
justStart = label == null || dm.containLabel(label)
}
// If there is no other label, just use null label
@@ -37,8 +37,7 @@ import rikka.layoutinflater.view.LayoutInflaterFactory
abstract class EhActivity : AppCompatActivity() {
@StyleRes
fun getThemeStyleRes(): Int {
val isBlackDarkTheme = Settings.getBoolean("black_dark_theme", false)
return if (isBlackDarkTheme && isNightMode()) R.style.ThemeOverlay_Black else R.style.ThemeOverlay
return if (Settings.blackDarkTheme && isNightMode()) R.style.ThemeOverlay_Black else R.style.ThemeOverlay
}
override fun onApplyThemeResource(theme: Theme, resid: Int, first: Boolean) {
@@ -65,13 +64,13 @@ abstract class EhActivity : AppCompatActivity() {
override fun onResume() {
val lockedResumeTime = System.currentTimeMillis() / 1000
val lockedDelayTime = lockedResumeTime - EhApplication.locked_last_leave_time
if (lockedDelayTime < Settings.getSecurityDelay() * 60) {
if (lockedDelayTime < Settings.securityDelay * 60) {
EhApplication.locked = false
} else if (Settings.getSecurity() && isAuthenticationSupported() && EhApplication.locked) {
} else if (Settings.security && isAuthenticationSupported() && EhApplication.locked) {
startActivity(Intent(this, SecurityActivity::class.java))
}
super.onResume()
window.setSecureScreen(Settings.getEnabledSecurity())
window.setSecureScreen(Settings.enabledSecurity)
}
private val requestPermissionLauncher =
@@ -84,7 +83,7 @@ abstract class EhActivity : AppCompatActivity() {
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) return
if (Settings.getNotificationRequired()) return
if (Settings.notificationRequired) return
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
@@ -212,7 +212,7 @@ class MainActivity : EhActivity() {
private fun setNavGraph() {
navController.apply {
graph = navInflater.inflate(R.navigation.nav_graph).apply {
when (Settings.getLaunchPageGalleryListSceneAction()) {
when (Settings.launchPageGalleryListSceneAction) {
GalleryListScene.ACTION_HOMEPAGE -> setStartDestination(R.id.nav_homepage)
GalleryListScene.ACTION_SUBSCRIPTION -> setStartDestination(R.id.nav_subscription)
GalleryListScene.ACTION_WHATS_HOT -> setStartDestination(R.id.nav_whats_hot)
@@ -223,7 +223,7 @@ class MainActivity : EhActivity() {
}
override fun onCreate(savedInstanceState: Bundle?) {
if (Settings.getDF() && Settings.getBypassVpn()) {
if (Settings.dF && Settings.bypassVpn) {
bypassVpn()
}
super.onCreate(savedInstanceState)
@@ -260,11 +260,11 @@ class MainActivity : EhActivity() {
onNewIntent(intent)
}
checkDownloadLocation()
if (Settings.getMeteredNetworkWarning()) {
if (Settings.meteredNetworkWarning) {
checkMeteredNetwork()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!Settings.getAppLinkVerifyTip()) {
if (!Settings.appLinkVerifyTip) {
try {
checkAppLinkVerify()
} catch (ignored: PackageManager.NameNotFoundException) {
@@ -332,7 +332,7 @@ class MainActivity : EhActivity() {
}
private fun checkDownloadLocation() {
val uniFile = Settings.getDownloadLocation()
val uniFile = Settings.downloadLocation
// null == uniFile for first start
if (null == uniFile || uniFile.ensureDir()) {
return
@@ -391,7 +391,7 @@ class MainActivity : EhActivity() {
private suspend fun checkClipboardUrl() {
val text = this.getClipboardManager().getUrlFromClipboard(this)
val hashCode = text?.hashCode() ?: 0
if (text != null && hashCode != 0 && Settings.getClipboardTextHashCode() != hashCode) {
if (text != null && hashCode != 0 && Settings.clipboardTextHashCode != hashCode) {
val result1 = GalleryDetailUrlParser.parse(text, false)
var launch: (() -> Unit)? = null
if (result1 != null) {
@@ -246,7 +246,7 @@ class AdvancedFragment : BasePreferenceFragment() {
exportData!!.onPreferenceClickListener = this
backupFavorite!!.onPreferenceClickListener = this
appLanguage!!.onPreferenceChangeListener = this
bypassVpn!!.isVisible = AppSettings.getDF()
bypassVpn!!.isVisible = AppSettings.dF
domainFronting!!.setOnPreferenceChangeListener { _, newValue ->
bypassVpn.isVisible = newValue as Boolean
true
@@ -342,7 +342,7 @@ class AdvancedFragment : BasePreferenceFragment() {
if (result.next != null) {
try {
runBlocking {
delay(AppSettings.getDownloadDelay().toLong())
delay(AppSettings.downloadDelay.toLong())
}
} catch (e: InterruptedException) {
e.printStackTrace()
@@ -70,7 +70,7 @@ class DownloadFragment : BasePreferenceFragment() {
}
private fun onUpdateDownloadLocation() {
val file = Settings.getDownloadLocation()
val file = Settings.downloadLocation
if (mDownloadLocation != null) {
if (file != null) {
mDownloadLocation!!.summary = file.uri.toString()
@@ -83,9 +83,9 @@ class DownloadFragment : BasePreferenceFragment() {
override fun onPreferenceClick(preference: Preference): Boolean {
val key = preference.key
if (KEY_DOWNLOAD_LOCATION == key) {
val file = Settings.getDownloadLocation()
val file = Settings.downloadLocation
if (file != null && !UniFile.isFileUri(
Settings.getDownloadLocation()!!.uri
Settings.downloadLocation!!.uri
)
) {
BaseDialogBuilder(requireContext())
@@ -126,7 +126,7 @@ class DownloadFragment : BasePreferenceFragment() {
val key = preference.key
if (Settings.KEY_MEDIA_SCAN == key) {
if (newValue is Boolean) {
val downloadLocation = Settings.getDownloadLocation()
val downloadLocation = Settings.downloadLocation
if (newValue) {
removeNoMediaFile(downloadLocation)
} else {
@@ -50,7 +50,7 @@ class EhFragment : BasePreferenceFragment() {
val thumbResolution = findPreference<Preference>(Settings.KEY_THUMB_RESOLUTION)
val showTagTranslations = findPreference<Preference>(Settings.KEY_SHOW_TAG_TRANSLATIONS)
val tagTranslationsSource = findPreference<Preference>(Settings.KEY_TAG_TRANSLATIONS_SOURCE)
Settings.getDisplayName()?.let { account?.summary = it }
Settings.displayName?.let { account?.summary = it }
theme!!.onPreferenceChangeListener = this
gallerySite!!.onPreferenceChangeListener = this
listMode!!.onPreferenceChangeListener = this
@@ -43,7 +43,7 @@ class LoginActivity : EhActivity() {
}
composable(SELECT_SITE_ROUTE_NAME) {
val selectSite by remember { mutableStateOf(Settings.getSelectSite()) }
val selectSite by remember { mutableStateOf(Settings.selectSite) }
if (selectSite) {
SelectSiteScreen()
} else {
@@ -215,7 +215,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe
private fun onInit() {
if (!handleArguments(arguments)) {
mLabel = Settings.getRecentDownloadLabel()
mLabel = Settings.recentDownloadLabel
updateForLabel()
}
}
@@ -253,7 +253,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe
mAdapter!!.setHasStableIds(true)
mRecyclerView!!.adapter = mAdapter
mLayoutManager = AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL)
mLayoutManager!!.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()))
mLayoutManager!!.setColumnSize(resources.getDimensionPixelOffset(Settings.detailSizeResId))
mLayoutManager!!.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE)
mRecyclerView!!.layoutManager = mLayoutManager
//mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !ResourcesKt.resolveColor(getTheme(), .getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
@@ -579,7 +579,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe
context,
getString(R.string.download_remove_dialog_message_2, gidList!!.size),
getString(R.string.download_remove_dialog_check_text),
Settings.getRemoveImageFiles()
Settings.removeImageFiles
)
val helper = DeleteRangeDialogHelper(
downloadInfoList!!, gidList, builder
@@ -96,9 +96,9 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
private var mClient: EhClient? = null
private var mFavCatArray: Array<String>? = Settings.getFavCat()
private var mFavCatArray: Array<String>? = Settings.favCat
private var mFavCountArray: IntArray? = Settings.getFavCount()
private var mFavCountArray: IntArray? = Settings.favCount
private var mUrlBuilder: FavListUrlBuilder? = null
private val showNormalFabsRunnable = Runnable {
@@ -132,8 +132,8 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mClient = EhClient
mFavLocalCount = Settings.getFavLocalCount()
mFavCountSum = Settings.getFavCloudCount()
mFavLocalCount = Settings.favLocalCount
mFavCountSum = Settings.favCloudCount
if (savedInstanceState == null) {
onInit()
} else {
@@ -143,7 +143,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
private fun onInit() {
mUrlBuilder = FavListUrlBuilder()
mUrlBuilder!!.favCat = Settings.getRecentFavCat()
mUrlBuilder!!.favCat = Settings.recentFavCat
}
private fun onRestore(savedInstanceState: Bundle) {
@@ -205,7 +205,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
mContentLayout.setHelper(mHelper)
mContentLayout.fastScroller.setOnDragHandlerListener(this)
mContentLayout.setFitPaddingTop(paddingTopSB)
mAdapter = FavoritesAdapter(inflater, resources, mRecyclerView!!, Settings.getListMode())
mAdapter = FavoritesAdapter(inflater, resources, mRecyclerView!!, Settings.listMode)
mRecyclerView!!.clipToPadding = false
mRecyclerView!!.clipChildren = false
mRecyclerView!!.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM)
@@ -333,7 +333,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
val items = arrayOfNulls<String>(12)
items[0] = getString(R.string.let_me_select)
items[1] = getString(R.string.local_favorites)
val favCat = Settings.getFavCat()
val favCat = Settings.favCat
System.arraycopy(favCat, 0, items, 2, 10)
BaseDialogBuilder(requireContext())
.setTitle(R.string.default_favorites_collection)
@@ -548,7 +548,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
// First is local favorite, the other 10 is cloud favorite
val array = arrayOfNulls<String>(11)
array[0] = getString(R.string.local_favorites)
System.arraycopy(Settings.getFavCat(), 0, array, 1, 10)
System.arraycopy(Settings.favCat, 0, array, 1, 10)
BaseDialogBuilder(context)
.setTitle(R.string.move_favorites_dialog_title)
.setItems(array, helper)
@@ -620,7 +620,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen
private fun onGetFavoritesSuccess(result: FavoritesParser.Result, taskId: Int) {
if (mHelper != null && mHelper!!.isCurrentTask(taskId)) {
if (mFavCatArray != null) {
System.arraycopy(result.catArray, 0, mFavCatArray, 0, 10)
System.arraycopy(result.catArray, 0, mFavCatArray!!, 0, 10)
}
mFavCountArray = result.countArray
if (mFavCountArray != null) {
@@ -64,7 +64,7 @@ internal abstract class GalleryAdapter(
when (type) {
TYPE_LIST -> {
val columnWidth =
mResources.getDimensionPixelOffset(Settings.getDetailSizeResId())
mResources.getDimensionPixelOffset(Settings.detailSizeResId)
mLayoutManager.setColumnSize(columnWidth)
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE)
if (null != mGirdDecoration) {
@@ -86,7 +86,7 @@ internal abstract class GalleryAdapter(
}
TYPE_GRID -> {
val columnWidth = Settings.getThumbSize()
val columnWidth = Settings.thumbSize
mLayoutManager.setColumnSize(columnWidth)
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_SUITABLE_SIZE)
if (null != mListDecoration) {
@@ -186,7 +186,7 @@ internal abstract class GalleryAdapter(
category.setBackgroundColor(EhUtils.getCategoryColor(gi.category))
}
holder.posted!!.text = gi.posted
if (gi.pages == 0 || !Settings.getShowGalleryPages()) {
if (gi.pages == 0 || !Settings.showGalleryPages) {
holder.pages?.text = null
holder.pages!!.visibility = View.GONE
} else {
@@ -397,7 +397,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
it.searchCover.setOnClickListener(this)
}
binding.content.actions.newerVersion.setOnClickListener(this)
if (Settings.getShowComments()) {
if (Settings.showComments) {
binding.content.comments.comments.setOnClickListener(this)
} else {
binding.content.comments.comments.visibility = View.GONE
@@ -618,7 +618,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
}
tagGroups ?: return
val ehTags =
if (Settings.getShowTagTranslations() && isTranslatable(requireContext())) EhTagDatabase else null
if (Settings.showTagTranslations && isTranslatable(requireContext())) EhTagDatabase else null
val colorTag = theme.resolveColor(R.attr.tagBackgroundColor)
val colorName = theme.resolveColor(R.attr.tagGroupBackgroundColor)
for (tg in tagGroups) {
@@ -719,7 +719,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
} else {
previewText.setText(R.string.more_previews)
}
val columnWidth = Settings.getThumbSize()
val columnWidth = Settings.thumbSize
gridLayout.setColumnSize(columnWidth)
gridLayout.setStrategy(SimpleGridAutoSpanLayout.STRATEGY_SUITABLE_SIZE)
viewLifecycleOwner.lifecycleScope.launchIO {
@@ -839,7 +839,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
context,
getString(R.string.download_remove_dialog_message, galleryInfo.title),
getString(R.string.download_remove_dialog_check_text),
Settings.getRemoveImageFiles()
Settings.removeImageFiles
)
val helper = DeleteDialogHelper(
downloadManager, galleryInfo, builder
@@ -364,7 +364,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
binding.contentLayout.setFitPaddingTop(paddingTopSB)
mAdapter = GalleryListAdapter(
inflater, resources,
binding.contentLayout.recyclerView, Settings.getListMode()
binding.contentLayout.recyclerView, Settings.listMode
)
binding.contentLayout.recyclerView.clipToPadding = false
binding.contentLayout.recyclerView.clipChildren = false
@@ -474,7 +474,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
builder.setTitle(R.string.add_quick_search_dialog_title)
builder.setPositiveButton(android.R.string.ok, null)
// TODO: It's ugly
val checked = booleanArrayOf(Settings.getQSSaveProgress())
val checked = booleanArrayOf(Settings.qSSaveProgress)
val hint = arrayOf(getString(R.string.save_progress))
builder.setMultiChoiceItems(
hint,
@@ -101,7 +101,7 @@ class GalleryPreviewsScene : BaseToolbarScene() {
setLiftOnScrollTargetView(binding.contentLayout)
mAdapter = GalleryPreviewAdapter()
binding.contentLayout.recyclerView.adapter = mAdapter
val columnWidth = Settings.getThumbSize()
val columnWidth = Settings.thumbSize
val layoutManager =
AutoGridLayoutManager(context, columnWidth, LayoutUtils.dp2pix(context, 16f))
layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE)
@@ -136,7 +136,7 @@ class HistoryScene : BaseToolbarScene() {
}.flow.cachedIn(viewLifecycleOwner.lifecycleScope)
binding.recyclerView.adapter = mAdapter
val layoutManager = AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL)
layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()))
layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.detailSizeResId))
layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE)
binding.recyclerView.layoutManager = layoutManager
val itemTouchHelper = ItemTouchHelper(HistoryItemTouchHelperCallback())
@@ -320,7 +320,7 @@ abstract class SearchBarScene : BaseScene(), ToolBarScene {
if (text.isNotEmpty() && !text.endsWith(' ')) {
val keyword = text.substringAfterLast(' ')
val translate =
Settings.getShowTagTranslations() && isTranslatable(requireContext())
Settings.showTagTranslations && isTranslatable(requireContext())
suggestFlow(keyword, translate, true).collect {
emit(TagSuggestion(it.first, it.second))
}
@@ -49,7 +49,7 @@ fun ListInfoCard(
modifier = modifier.padding(6.dp),
border = remember { BorderStroke(1.dp, Color.Transparent) }
) {
val listCardSize = remember { Settings.getListThumbSize().pxToDp }
val listCardSize = remember { Settings.listThumbSize.pxToDp }
Row(
modifier = Modifier
.height((listCardSize * 3).dp)
@@ -79,7 +79,7 @@ fun <T : GalleryInfo> GalleryListLongClickDialog(
val addToFavFailed = stringResource(id = R.string.add_to_favorite_failure)
suspend fun addToFav(slot: Int) {
val favNameList = Settings.getFavCat().toMutableList().apply { add(0, localFavName) }
val favNameList = Settings.favCat.toMutableList().apply { add(0, localFavName) }
runCatching {
if (slot == -1) {
EhDB.putLocalFavorites(info)
@@ -151,7 +151,7 @@ fun <T : GalleryInfo> GalleryListLongClickDialog(
if (info.favoriteSlot == -2) {
DialogSelectorItem(
onClick = {
val defaultFav = Settings.getDefaultFavSlot()
val defaultFav = Settings.defaultFavSlot
if (defaultFav in -1..9) {
launchIO {
addToFav(defaultFav)
@@ -267,7 +267,7 @@ fun SelectFavouriteDialog(
val localFavName = stringResource(id = R.string.local_favorites)
Column {
remember {
Settings.getFavCat().toMutableList().apply { add(0, localFavName) }
Settings.favCat.toMutableList().apply { add(0, localFavName) }
}.forEachIndexed { index, s ->
TextButton(
onClick = {
@@ -8,6 +8,6 @@ class ResizeableFixedThumb @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : FixedThumb(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
setMeasuredDimension(Settings.getListThumbSize() * 2, Settings.getListThumbSize() * 3)
setMeasuredDimension(Settings.listThumbSize * 2, Settings.listThumbSize * 3)
}
}
@@ -16,7 +16,7 @@ abstract class PageLoader {
(0 until size).map { ReaderPage(it) }
}
private val mPreloads = MathUtils.clamp(com.hippo.ehviewer.Settings.getPreloadImage(), 0, 100)
private val mPreloads = MathUtils.clamp(com.hippo.ehviewer.Settings.preloadImage, 0, 100)
abstract suspend fun awaitReady(): Boolean
abstract val isReady: Boolean