Rewrite PreferencesHelper. Allow to customize navigation with volume keys and tapping. Closes #251 and closes #129.

This commit is contained in:
len 2016-04-18 17:29:46 +02:00
parent 6d0254c5e5
commit a7840bc247
21 changed files with 258 additions and 199 deletions

View File

@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.download.model.DownloadQueue import eu.kanade.tachiyomi.data.download.model.DownloadQueue
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.source.SourceManager import eu.kanade.tachiyomi.data.source.SourceManager
import eu.kanade.tachiyomi.data.source.base.Source import eu.kanade.tachiyomi.data.source.base.Source
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
@ -365,7 +366,7 @@ class DownloadManager(private val context: Context, private val sourceManager: S
File.separator + File.separator +
manga.title.replace("[^\\sa-zA-Z0-9.-]".toRegex(), "_") manga.title.replace("[^\\sa-zA-Z0-9.-]".toRegex(), "_")
return File(preferences.downloadsDirectory, mangaRelativePath) return File(preferences.downloadsDirectory().getOrDefault(), mangaRelativePath)
} }
// Get the absolute path to the chapter directory // Get the absolute path to the chapter directory

View File

@ -24,8 +24,8 @@ abstract class MangaSyncService(private val context: Context, val id: Int) {
abstract fun login(username: String, password: String): Observable<Boolean> abstract fun login(username: String, password: String): Observable<Boolean>
open val isLogged: Boolean open val isLogged: Boolean
get() = !preferences.getMangaSyncUsername(this).isEmpty() && get() = !preferences.mangaSyncUsername(this).isEmpty() &&
!preferences.getMangaSyncPassword(this).isEmpty() !preferences.mangaSyncPassword(this).isEmpty()
abstract fun update(manga: MangaSync): Observable<Response> abstract fun update(manga: MangaSync): Observable<Response>

View File

@ -46,8 +46,8 @@ class MyAnimeList(private val context: Context, id: Int) : MangaSyncService(cont
} }
init { init {
val username = preferences.getMangaSyncUsername(this) val username = preferences.mangaSyncUsername(this)
val password = preferences.getMangaSyncPassword(this) val password = preferences.mangaSyncPassword(this)
if (!username.isEmpty() && !password.isEmpty()) { if (!username.isEmpty() && !password.isEmpty()) {
createHeaders(username, password) createHeaders(username, password)

View File

@ -0,0 +1,87 @@
package eu.kanade.tachiyomi.data.preference
import android.content.Context
import eu.kanade.tachiyomi.R
/**
* This class stores the keys for the preferences in the application. Most of them are defined
* in the file "keys.xml". By using this class we can define preferences in one place and get them
* referenced here.
*/
class PreferenceKeys(context: Context) {
val rotation = context.getString(R.string.pref_rotation_type_key)
val enableTransitions = context.getString(R.string.pref_enable_transitions_key)
val showPageNumber = context.getString(R.string.pref_show_page_number_key)
val hideStatusBar = context.getString(R.string.pref_hide_status_bar_key)
val keepScreenOn = context.getString(R.string.pref_keep_screen_on_key)
val customBrightness = context.getString(R.string.pref_custom_brightness_key)
val customBrightnessValue = context.getString(R.string.pref_custom_brightness_value_key)
val defaultViewer = context.getString(R.string.pref_default_viewer_key)
val imageScaleType = context.getString(R.string.pref_image_scale_type_key)
val imageDecoder = context.getString(R.string.pref_image_decoder_key)
val zoomStart = context.getString(R.string.pref_zoom_start_key)
val readerTheme = context.getString(R.string.pref_reader_theme_key)
val readWithTapping = context.getString(R.string.pref_read_with_tapping_key)
val readWithVolumeKeys = context.getString(R.string.pref_read_with_volume_keys_key)
val portraitColumns = context.getString(R.string.pref_library_columns_portrait_key)
val landscapeColumns = context.getString(R.string.pref_library_columns_landscape_key)
val updateOnlyNonCompleted = context.getString(R.string.pref_update_only_non_completed_key)
val autoUpdateMangaSync = context.getString(R.string.pref_auto_update_manga_sync_key)
val askUpdateMangaSync = context.getString(R.string.pref_ask_update_manga_sync_key)
val lastUsedCatalogueSource = context.getString(R.string.pref_last_catalogue_source_key)
val seamlessMode = context.getString(R.string.pref_seamless_mode_key)
val catalogueAsList = context.getString(R.string.pref_display_catalogue_as_list)
val enabledLanguages = context.getString(R.string.pref_source_languages)
val downloadsDirectory = context.getString(R.string.pref_download_directory_key)
val downloadThreads = context.getString(R.string.pref_download_slots_key)
val downloadOnlyOverWifi = context.getString(R.string.pref_download_only_over_wifi_key)
val removeAfterRead = context.getString(R.string.pref_remove_after_read_key)
val removeAfterReadPrevious = context.getString(R.string.pref_remove_after_read_previous_key)
val removeAfterMarkedAsRead = context.getString(R.string.pref_remove_after_marked_as_read_key)
val updateOnlyWhenCharging = context.getString(R.string.pref_update_only_when_charging_key)
val libraryUpdateInterval = context.getString(R.string.pref_library_update_interval_key)
val filterDownloaded = context.getString(R.string.pref_filter_downloaded_key)
val filterUnread = context.getString(R.string.pref_filter_unread_key)
fun sourceUsername(sourceId: Int) = "pref_source_username_$sourceId}"
fun sourcePassword(sourceId: Int) = "pref_source_password_$sourceId"
fun syncUsername(syncId: Int) = "pref_mangasync_username_$syncId"
fun syncPassword(syncId: Int) = "pref_mangasync_password_$syncId"
}

View File

@ -15,31 +15,25 @@ fun <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!!
class PreferencesHelper(private val context: Context) { class PreferencesHelper(private val context: Context) {
val keys = PreferenceKeys(context)
private val prefs = PreferenceManager.getDefaultSharedPreferences(context) private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
private val rxPrefs = RxSharedPreferences.create(prefs) private val rxPrefs = RxSharedPreferences.create(prefs)
private val defaultDownloadsDir: File private val defaultDownloadsDir = File(Environment.getExternalStorageDirectory().absolutePath +
init {
defaultDownloadsDir = File(Environment.getExternalStorageDirectory().absolutePath +
File.separator + context.getString(R.string.app_name), "downloads") File.separator + context.getString(R.string.app_name), "downloads")
init {
// Don't display downloaded chapters in gallery apps creating a ".nomedia" file // Don't display downloaded chapters in gallery apps creating a ".nomedia" file
try { try {
File(downloadsDirectory, ".nomedia").createNewFile() File(downloadsDirectory().getOrDefault(), ".nomedia").createNewFile()
} catch (e: IOException) { } catch (e: IOException) {
/* Ignore */ /* Ignore */
} }
} }
companion object { companion object {
const val SOURCE_ACCOUNT_USERNAME = "pref_source_username_"
const val SOURCE_ACCOUNT_PASSWORD = "pref_source_password_"
const val MANGASYNC_ACCOUNT_USERNAME = "pref_mangasync_username_"
const val MANGASYNC_ACCOUNT_PASSWORD = "pref_mangasync_password_"
fun getLibraryUpdateInterval(context: Context): Int { fun getLibraryUpdateInterval(context: Context): Int {
return PreferenceManager.getDefaultSharedPreferences(context).getInt( return PreferenceManager.getDefaultSharedPreferences(context).getInt(
context.getString(R.string.pref_library_update_interval_key), 0) context.getString(R.string.pref_library_update_interval_key), 0)
@ -52,165 +46,96 @@ class PreferencesHelper(private val context: Context) {
} }
} }
private fun getKey(keyResource: Int): String {
return context.getString(keyResource)
}
fun clear() { fun clear() {
prefs.edit().clear().apply() prefs.edit().clear().apply()
} }
fun rotation(): Preference<Int> { fun rotation() = rxPrefs.getInteger(keys.rotation, 1)
return rxPrefs.getInteger(getKey(R.string.pref_rotation_type_key), 1)
}
fun enableTransitions(): Preference<Boolean> { fun enableTransitions() = rxPrefs.getBoolean(keys.enableTransitions, true)
return rxPrefs.getBoolean(getKey(R.string.pref_enable_transitions_key), true)
}
fun showPageNumber(): Preference<Boolean> { fun showPageNumber() = rxPrefs.getBoolean(keys.showPageNumber, true)
return rxPrefs.getBoolean(getKey(R.string.pref_show_page_number_key), true)
}
fun hideStatusBar(): Preference<Boolean> { fun hideStatusBar() = rxPrefs.getBoolean(keys.hideStatusBar, true)
return rxPrefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true)
}
fun keepScreenOn(): Preference<Boolean> { fun keepScreenOn() = rxPrefs.getBoolean(keys.keepScreenOn, true)
return rxPrefs.getBoolean(getKey(R.string.pref_keep_screen_on_key), true)
}
fun customBrightness(): Preference<Boolean> { fun customBrightness() = rxPrefs.getBoolean(keys.customBrightness, false)
return rxPrefs.getBoolean(getKey(R.string.pref_custom_brightness_key), false)
}
fun customBrightnessValue(): Preference<Float> { fun customBrightnessValue() = rxPrefs.getFloat(keys.customBrightnessValue, 0f)
return rxPrefs.getFloat(getKey(R.string.pref_custom_brightness_value_key), 0f)
}
val defaultViewer: Int fun defaultViewer() = prefs.getInt(keys.defaultViewer, 1)
get() = prefs.getInt(getKey(R.string.pref_default_viewer_key), 1)
fun imageScaleType(): Preference<Int> { fun imageScaleType() = rxPrefs.getInteger(keys.imageScaleType, 1)
return rxPrefs.getInteger(getKey(R.string.pref_image_scale_type_key), 1)
}
fun imageDecoder(): Preference<Int> { fun imageDecoder() = rxPrefs.getInteger(keys.imageDecoder, 0)
return rxPrefs.getInteger(getKey(R.string.pref_image_decoder_key), 0)
}
fun zoomStart(): Preference<Int> { fun zoomStart() = rxPrefs.getInteger(keys.zoomStart, 1)
return rxPrefs.getInteger(getKey(R.string.pref_zoom_start_key), 1)
}
fun readerTheme(): Preference<Int> { fun readerTheme() = rxPrefs.getInteger(keys.readerTheme, 0)
return rxPrefs.getInteger(getKey(R.string.pref_reader_theme_key), 0)
}
fun portraitColumns(): Preference<Int> { fun readWithTapping() = rxPrefs.getBoolean(keys.readWithTapping, true)
return rxPrefs.getInteger(getKey(R.string.pref_library_columns_portrait_key), 0)
}
fun landscapeColumns(): Preference<Int> { fun readWithVolumeKeys() = rxPrefs.getBoolean(keys.readWithVolumeKeys, false)
return rxPrefs.getInteger(getKey(R.string.pref_library_columns_landscape_key), 0)
}
fun updateOnlyNonCompleted(): Boolean { fun portraitColumns() = rxPrefs.getInteger(keys.portraitColumns, 0)
return prefs.getBoolean(getKey(R.string.pref_update_only_non_completed_key), false)
}
fun autoUpdateMangaSync(): Boolean { fun landscapeColumns() = rxPrefs.getInteger(keys.landscapeColumns, 0)
return prefs.getBoolean(getKey(R.string.pref_auto_update_manga_sync_key), true)
}
fun askUpdateMangaSync(): Boolean { fun updateOnlyNonCompleted() = prefs.getBoolean(keys.updateOnlyNonCompleted, false)
return prefs.getBoolean(getKey(R.string.pref_ask_update_manga_sync_key), false)
}
fun lastUsedCatalogueSource(): Preference<Int> { fun autoUpdateMangaSync() = prefs.getBoolean(keys.autoUpdateMangaSync, true)
return rxPrefs.getInteger(getKey(R.string.pref_last_catalogue_source_key), -1)
}
fun seamlessMode(): Boolean { fun askUpdateMangaSync() = prefs.getBoolean(keys.askUpdateMangaSync, false)
return prefs.getBoolean(getKey(R.string.pref_seamless_mode_key), true)
}
fun catalogueAsList(): Preference<Boolean> { fun lastUsedCatalogueSource() = rxPrefs.getInteger(keys.lastUsedCatalogueSource, -1)
return rxPrefs.getBoolean(getKey(R.string.pref_display_catalogue_as_list), false)
}
fun enabledLanguages(): Preference<MutableSet<String>> { fun seamlessMode() = prefs.getBoolean(keys.seamlessMode, true)
return rxPrefs.getStringSet(getKey(R.string.pref_source_languages), setOf("EN"))
}
fun getSourceUsername(source: Source): String { fun catalogueAsList() = rxPrefs.getBoolean(keys.catalogueAsList, false)
return prefs.getString(SOURCE_ACCOUNT_USERNAME + source.id, "")
}
fun getSourcePassword(source: Source): String { fun enabledLanguages() = rxPrefs.getStringSet(keys.enabledLanguages, setOf("EN"))
return prefs.getString(SOURCE_ACCOUNT_PASSWORD + source.id, "")
} fun sourceUsername(source: Source) = prefs.getString(keys.sourceUsername(source.id), "")
fun sourcePassword(source: Source) = prefs.getString(keys.sourcePassword(source.id), "")
fun setSourceCredentials(source: Source, username: String, password: String) { fun setSourceCredentials(source: Source, username: String, password: String) {
prefs.edit() prefs.edit()
.putString(SOURCE_ACCOUNT_USERNAME + source.id, username) .putString(keys.sourceUsername(source.id), username)
.putString(SOURCE_ACCOUNT_PASSWORD + source.id, password) .putString(keys.sourcePassword(source.id), password)
.apply() .apply()
} }
fun getMangaSyncUsername(sync: MangaSyncService): String { fun mangaSyncUsername(sync: MangaSyncService) = prefs.getString(keys.syncUsername(sync.id), "")
return prefs.getString(MANGASYNC_ACCOUNT_USERNAME + sync.id, "")
}
fun getMangaSyncPassword(sync: MangaSyncService): String { fun mangaSyncPassword(sync: MangaSyncService) = prefs.getString(keys.syncPassword(sync.id), "")
return prefs.getString(MANGASYNC_ACCOUNT_PASSWORD + sync.id, "")
}
fun setMangaSyncCredentials(sync: MangaSyncService, username: String, password: String) { fun setMangaSyncCredentials(sync: MangaSyncService, username: String, password: String) {
prefs.edit() prefs.edit()
.putString(MANGASYNC_ACCOUNT_USERNAME + sync.id, username) .putString(keys.syncUsername(sync.id), username)
.putString(MANGASYNC_ACCOUNT_PASSWORD + sync.id, password) .putString(keys.syncPassword(sync.id), password)
.apply() .apply()
} }
var downloadsDirectory: String fun downloadsDirectory() = rxPrefs.getString(keys.downloadsDirectory, defaultDownloadsDir.absolutePath)
get() = prefs.getString(getKey(R.string.pref_download_directory_key), defaultDownloadsDir.absolutePath)
set(path) = prefs.edit().putString(getKey(R.string.pref_download_directory_key), path).apply()
fun downloadThreads(): Preference<Int> { fun downloadThreads() = rxPrefs.getInteger(keys.downloadThreads, 1)
return rxPrefs.getInteger(getKey(R.string.pref_download_slots_key), 1)
}
fun downloadOnlyOverWifi(): Boolean { fun downloadOnlyOverWifi() = prefs.getBoolean(keys.downloadOnlyOverWifi, true)
return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true)
}
fun removeAfterRead(): Boolean { fun removeAfterRead() = prefs.getBoolean(keys.removeAfterRead, false)
return prefs.getBoolean(getKey(R.string.pref_remove_after_read_key), false)
}
fun removeAfterReadPrevious(): Boolean { fun removeAfterReadPrevious() = prefs.getBoolean(keys.removeAfterReadPrevious, false)
return prefs.getBoolean(getKey(R.string.pref_remove_after_read_previous_key), false)
}
fun removeAfterMarkedAsRead(): Boolean { fun removeAfterMarkedAsRead() = prefs.getBoolean(keys.removeAfterMarkedAsRead, false)
return prefs.getBoolean(getKey(R.string.pref_remove_after_marked_as_read_key), false)
}
fun updateOnlyWhenCharging(): Boolean { fun updateOnlyWhenCharging() = prefs.getBoolean(keys.updateOnlyWhenCharging, false)
return prefs.getBoolean(getKey(R.string.pref_update_only_when_charging_key), false)
}
fun libraryUpdateInterval(): Preference<Int> { fun libraryUpdateInterval() = rxPrefs.getInteger(keys.libraryUpdateInterval, 0)
return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0)
}
fun filterDownloaded(): Preference<Boolean> { fun filterDownloaded() = rxPrefs.getBoolean(keys.filterDownloaded, false)
return rxPrefs.getBoolean(getKey(R.string.pref_filter_downloaded_key), false)
}
fun filterUnread(): Preference<Boolean> { fun filterUnread() = rxPrefs.getBoolean(keys.filterUnread, false)
return rxPrefs.getBoolean(getKey(R.string.pref_filter_unread_key), false)
}
} }

View File

@ -372,8 +372,8 @@ public class Batoto extends LoginSource {
@Override @Override
public Observable<List<Chapter>> pullChaptersFromNetwork(final String mangaUrl) { public Observable<List<Chapter>> pullChaptersFromNetwork(final String mangaUrl) {
Observable<List<Chapter>> observable; Observable<List<Chapter>> observable;
String username = getPrefs().getSourceUsername(this); String username = getPrefs().sourceUsername(this);
String password = getPrefs().getSourcePassword(this); String password = getPrefs().sourcePassword(this);
if (username.isEmpty() && password.isEmpty()) { if (username.isEmpty() && password.isEmpty()) {
observable = Observable.error(new Exception("User not logged")); observable = Observable.error(new Exception("User not logged"));
} }

View File

@ -41,7 +41,7 @@ public class UpdateDownloader extends AsyncTask<String, Void, Void> {
this.context = context; this.context = context;
// Get cache directory from parameter. // Get cache directory from parameter.
cacheDir = new File(preferencesHelper.getDownloadsDirectory(), PARAMETER_CACHE_DIRECTORY); cacheDir = new File(preferencesHelper.downloadsDirectory().get(), PARAMETER_CACHE_DIRECTORY);
// Create cache directory. // Create cache directory.
createCacheDir(); createCacheDir();

View File

@ -288,7 +288,7 @@ class CataloguePresenter : BasePresenter<CatalogueFragment>() {
if (!isLoginRequired || isLogged) if (!isLoginRequired || isLogged)
return true return true
prefs.getSourceUsername(this) != "" && prefs.getSourcePassword(this) != "" prefs.sourceUsername(this) != "" && prefs.sourcePassword(this) != ""
} }
/** /**

View File

@ -81,6 +81,8 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
private var prevChapterBtn: MenuItem? = null private var prevChapterBtn: MenuItem? = null
private val volumeKeysEnabled by lazy { preferences.readWithVolumeKeys().getOrDefault() }
val preferences: PreferencesHelper val preferences: PreferencesHelper
get() = presenter.prefs get() = presenter.prefs
@ -174,20 +176,34 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
override fun dispatchKeyEvent(event: KeyEvent): Boolean { override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (!isFinishing) { if (!isFinishing) {
val action = event.action when (event.keyCode) {
val keyCode = event.keyCode KeyEvent.KEYCODE_VOLUME_DOWN -> {
when (keyCode) { if (volumeKeysEnabled) {
KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT -> { if (event.action == KeyEvent.ACTION_UP) {
if (action == KeyEvent.ACTION_UP)
viewer?.moveToNext() viewer?.moveToNext()
}
return true return true
} }
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_DPAD_LEFT -> { }
if (action == KeyEvent.ACTION_UP) KeyEvent.KEYCODE_VOLUME_UP -> {
if (volumeKeysEnabled) {
if (event.action == KeyEvent.ACTION_UP) {
viewer?.moveToPrevious() viewer?.moveToPrevious()
}
return true return true
} }
} }
KeyEvent.KEYCODE_DPAD_RIGHT -> {
if (event.action == KeyEvent.ACTION_UP) {
viewer?.moveToNext()
}
}
KeyEvent.KEYCODE_DPAD_LEFT -> {
if (event.action == KeyEvent.ACTION_UP) {
viewer?.moveToPrevious()
}
}
}
} }
return super.dispatchKeyEvent(event) return super.dispatchKeyEvent(event)
} }
@ -258,7 +274,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
private fun getOrCreateViewer(manga: Manga): BaseReader { private fun getOrCreateViewer(manga: Manga): BaseReader {
val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer else manga.viewer val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer() else manga.viewer
// Try to reuse the viewer using its tag // Try to reuse the viewer using its tag
var fragment: BaseReader? = supportFragmentManager.findFragmentByTag(manga.viewer.toString()) as? BaseReader var fragment: BaseReader? = supportFragmentManager.findFragmentByTag(manga.viewer.toString()) as? BaseReader

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer.base
import com.davemorrissey.labs.subscaleview.decoder.* import com.davemorrissey.labs.subscaleview.decoder.*
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
@ -54,6 +55,11 @@ abstract class BaseReader : BaseFragment() {
lateinit var bitmapDecoderClass: Class<out ImageDecoder> lateinit var bitmapDecoderClass: Class<out ImageDecoder>
private set private set
/**
* Whether tap navigation is enabled or not.
*/
val tappingEnabled by lazy { readerActivity.preferences.readWithTapping().getOrDefault() }
/** /**
* Whether the reader has requested to append a chapter. Used with seamless mode to avoid * Whether the reader has requested to append a chapter. Used with seamless mode to avoid
* restarting requests when changing pages. * restarting requests when changing pages.

View File

@ -164,9 +164,9 @@ abstract class PagerReader : BaseReader() {
val positionX = e.x val positionX = e.x
if (positionX < pager.width * LEFT_REGION) { if (positionX < pager.width * LEFT_REGION) {
onLeftSideTap() if (tappingEnabled) onLeftSideTap()
} else if (positionX > pager.width * RIGHT_REGION) { } else if (positionX > pager.width * RIGHT_REGION) {
onRightSideTap() if (tappingEnabled) onRightSideTap()
} else { } else {
readerActivity.onCenterSingleTap() readerActivity.onCenterSingleTap()
} }

View File

@ -126,9 +126,9 @@ class WebtoonReader : BaseReader() {
val positionX = e.x val positionX = e.x
if (positionX < recycler.width * LEFT_REGION) { if (positionX < recycler.width * LEFT_REGION) {
moveToPrevious() if (tappingEnabled) moveToPrevious()
} else if (positionX > recycler.width * RIGHT_REGION) { } else if (positionX > recycler.width * RIGHT_REGION) {
moveToNext() if (tappingEnabled) moveToNext()
} else { } else {
readerActivity.onCenterSingleTap() readerActivity.onCenterSingleTap()
} }

View File

@ -14,12 +14,13 @@ import com.nononsenseapps.filepicker.FilePickerActivity
import com.nononsenseapps.filepicker.FilePickerFragment import com.nononsenseapps.filepicker.FilePickerFragment
import com.nononsenseapps.filepicker.LogicHandler import com.nononsenseapps.filepicker.LogicHandler
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.inflate import eu.kanade.tachiyomi.util.inflate
import rx.Subscription
import java.io.File import java.io.File
class SettingsDownloadsFragment : SettingsNestedFragment() { class SettingsDownloadsFragment : SettingsNestedFragment() {
val downloadDirPref by lazy { findPreference(getString(R.string.pref_download_directory_key)) }
companion object { companion object {
val DOWNLOAD_DIR_CODE = 103 val DOWNLOAD_DIR_CODE = 103
@ -31,11 +32,16 @@ class SettingsDownloadsFragment : SettingsNestedFragment() {
} }
} }
val downloadDirPref by lazy { findPreference(getString(R.string.pref_download_directory_key)) }
var downloadDirSubscription: Subscription? = null
override fun onViewCreated(view: View, savedState: Bundle?) { override fun onViewCreated(view: View, savedState: Bundle?) {
downloadDirPref.setOnPreferenceClickListener { downloadDirPref.setOnPreferenceClickListener {
val currentDir = preferences.downloadsDirectory().getOrDefault()
val externalDirs = getExternalFilesDirs() val externalDirs = getExternalFilesDirs()
val selectedIndex = externalDirs.indexOf(File(preferences.downloadsDirectory)) val selectedIndex = externalDirs.indexOf(File(currentDir))
MaterialDialog.Builder(activity) MaterialDialog.Builder(activity)
.items(externalDirs + getString(R.string.custom_dir)) .items(externalDirs + getString(R.string.custom_dir))
@ -46,13 +52,12 @@ class SettingsDownloadsFragment : SettingsNestedFragment() {
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false) i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true) i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR) i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR)
i.putExtra(FilePickerActivity.EXTRA_START_PATH, preferences.downloadsDirectory) i.putExtra(FilePickerActivity.EXTRA_START_PATH, currentDir)
startActivityForResult(i, DOWNLOAD_DIR_CODE) startActivityForResult(i, DOWNLOAD_DIR_CODE)
} else { } else {
// One of the predefined folders was selected // One of the predefined folders was selected
preferences.downloadsDirectory = text.toString() preferences.downloadsDirectory().set(text.toString())
updateDownloadsDir()
} }
true true
}) })
@ -60,15 +65,14 @@ class SettingsDownloadsFragment : SettingsNestedFragment() {
true true
} }
downloadDirSubscription = preferences.downloadsDirectory().asObservable()
.subscribe { downloadDirPref.summary = it }
} }
override fun onResume() { override fun onDestroyView() {
super.onResume() downloadDirSubscription?.unsubscribe()
updateDownloadsDir() super.onDestroyView()
}
fun updateDownloadsDir() {
downloadDirPref.summary = preferences.downloadsDirectory
} }
fun getExternalFilesDirs(): List<File> { fun getExternalFilesDirs(): List<File> {
@ -81,7 +85,7 @@ class SettingsDownloadsFragment : SettingsNestedFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (data != null && requestCode == DOWNLOAD_DIR_CODE && resultCode == Activity.RESULT_OK) { if (data != null && requestCode == DOWNLOAD_DIR_CODE && resultCode == Activity.RESULT_OK) {
preferences.downloadsDirectory = data.data.path preferences.downloadsDirectory().set(data.data.path)
} }
} }

View File

@ -44,9 +44,5 @@ open class SettingsNestedFragment : PreferenceFragment() {
get() = settingsActivity.preferences get() = settingsActivity.preferences
val fragmentManagerCompat: FragmentManager val fragmentManagerCompat: FragmentManager
get() = if (Build.VERSION.SDK_INT >= 17) { get() = if (Build.VERSION.SDK_INT >= 17) childFragmentManager else fragmentManager
childFragmentManager
} else {
fragmentManager
}
} }

View File

@ -6,7 +6,6 @@ import android.support.v14.preference.MultiSelectListPreference
import android.support.v7.preference.Preference import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceGroup import android.support.v7.preference.PreferenceGroup
import android.view.View import android.view.View
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.source.base.Source import eu.kanade.tachiyomi.data.source.base.Source
import eu.kanade.tachiyomi.data.source.getLanguages import eu.kanade.tachiyomi.data.source.getLanguages
@ -65,7 +64,7 @@ class SettingsSourcesFragment : SettingsNestedFragment() {
fun createSource(source: Source): Preference { fun createSource(source: Source): Preference {
return LoginPreference(preferenceManager.context).apply { return LoginPreference(preferenceManager.context).apply {
key = PreferencesHelper.SOURCE_ACCOUNT_USERNAME + source.id key = preferences.keys.sourceUsername(source.id)
title = source.visibleName title = source.visibleName
setOnPreferenceClickListener { setOnPreferenceClickListener {
@ -80,7 +79,7 @@ class SettingsSourcesFragment : SettingsNestedFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SOURCE_CHANGE_REQUEST) { if (requestCode == SOURCE_CHANGE_REQUEST) {
val pref = findPreference(PreferencesHelper.SOURCE_ACCOUNT_USERNAME + resultCode) as? LoginPreference val pref = findPreference(preferences.keys.sourceUsername(resultCode)) as? LoginPreference
pref?.notifyChanged() pref?.notifyChanged()
} }
} }

View File

@ -4,7 +4,6 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.preference.PreferenceCategory import android.support.v7.preference.PreferenceCategory
import android.view.View import android.view.View
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.widget.preference.LoginPreference import eu.kanade.tachiyomi.widget.preference.LoginPreference
import eu.kanade.tachiyomi.widget.preference.MangaSyncLoginDialog import eu.kanade.tachiyomi.widget.preference.MangaSyncLoginDialog
@ -27,7 +26,7 @@ class SettingsSyncFragment : SettingsNestedFragment() {
for (sync in settingsActivity.syncManager.services) { for (sync in settingsActivity.syncManager.services) {
val pref = LoginPreference(themedContext).apply { val pref = LoginPreference(themedContext).apply {
key = PreferencesHelper.MANGASYNC_ACCOUNT_USERNAME + sync.id key = preferences.keys.syncUsername(sync.id)
title = sync.name title = sync.name
setOnPreferenceClickListener { setOnPreferenceClickListener {
@ -44,7 +43,7 @@ class SettingsSyncFragment : SettingsNestedFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SYNC_CHANGE_REQUEST) { if (requestCode == SYNC_CHANGE_REQUEST) {
val pref = findPreference(PreferencesHelper.MANGASYNC_ACCOUNT_USERNAME + resultCode) as? LoginPreference val pref = findPreference(preferences.keys.syncUsername(resultCode)) as? LoginPreference
pref?.notifyChanged() pref?.notifyChanged()
} }
} }

View File

@ -34,8 +34,8 @@ class MangaSyncLoginDialog : LoginDialogPreference() {
override fun setCredentialsOnView(view: View) = with(view) { override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = getString(R.string.login_title, sync.name) dialog_title.text = getString(R.string.login_title, sync.name)
username.setText(preferences.getMangaSyncUsername(sync)) username.setText(preferences.mangaSyncUsername(sync))
password.setText(preferences.getMangaSyncPassword(sync)) password.setText(preferences.mangaSyncPassword(sync))
} }
override fun checkLogin() { override fun checkLogin() {

View File

@ -34,8 +34,8 @@ class SourceLoginDialog : LoginDialogPreference() {
override fun setCredentialsOnView(view: View) = with(view) { override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = getString(R.string.login_title, source.visibleName) dialog_title.text = getString(R.string.login_title, source.visibleName)
username.setText(preferences.getSourceUsername(source)) username.setText(preferences.sourceUsername(source))
password.setText(preferences.getSourcePassword(source)) password.setText(preferences.sourcePassword(source))
} }
override fun checkLogin() { override fun checkLogin() {

View File

@ -31,6 +31,8 @@
<string name="pref_reader_theme_key">pref_reader_theme_key</string> <string name="pref_reader_theme_key">pref_reader_theme_key</string>
<string name="pref_image_decoder_key">pref_image_decoder_key</string> <string name="pref_image_decoder_key">pref_image_decoder_key</string>
<string name="pref_seamless_mode_key">pref_seamless_mode_key</string> <string name="pref_seamless_mode_key">pref_seamless_mode_key</string>
<string name="pref_read_with_volume_keys_key">reader_volume_keys</string>
<string name="pref_read_with_tapping_key">reader_tap</string>
<string name="pref_filter_downloaded_key">pref_filter_downloaded_key</string> <string name="pref_filter_downloaded_key">pref_filter_downloaded_key</string>
<string name="pref_filter_unread_key">pref_filter_unread_key</string> <string name="pref_filter_unread_key">pref_filter_unread_key</string>

View File

@ -97,6 +97,9 @@
<string name="pref_custom_brightness">Use custom brightness</string> <string name="pref_custom_brightness">Use custom brightness</string>
<string name="pref_seamless_mode">Seamless chapter transitions</string> <string name="pref_seamless_mode">Seamless chapter transitions</string>
<string name="pref_keep_screen_on">Keep screen on</string> <string name="pref_keep_screen_on">Keep screen on</string>
<string name="pref_reader_navigation">Navigation</string>
<string name="pref_read_with_volume_keys">Volume keys</string>
<string name="pref_read_with_tapping">Tapping</string>
<string name="pref_reader_theme">Background color</string> <string name="pref_reader_theme">Background color</string>
<string name="white_background">White</string> <string name="white_background">White</string>
<string name="black_background">Black</string> <string name="black_background">Black</string>

View File

@ -2,30 +2,6 @@
<android.support.v7.preference.PreferenceScreen <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreferenceCompat android:title="@string/pref_hide_status_bar"
android:key="@string/pref_hide_status_bar_key"
android:defaultValue="true" />
<SwitchPreferenceCompat android:title="@string/pref_enable_transitions"
android:key="@string/pref_enable_transitions_key"
android:defaultValue="true" />
<SwitchPreferenceCompat android:title="@string/pref_show_page_number"
android:key="@string/pref_show_page_number_key"
android:defaultValue="true" />
<SwitchPreferenceCompat android:title="@string/pref_custom_brightness"
android:key="@string/pref_custom_brightness_key"
android:defaultValue="false" />
<SwitchPreferenceCompat android:title="@string/pref_keep_screen_on"
android:key="@string/pref_keep_screen_on_key"
android:defaultValue="true" />
<SwitchPreferenceCompat android:title="@string/pref_seamless_mode"
android:key="@string/pref_seamless_mode_key"
android:defaultValue="true" />
<eu.kanade.tachiyomi.widget.preference.IntListPreference <eu.kanade.tachiyomi.widget.preference.IntListPreference
android:title="@string/pref_viewer_type" android:title="@string/pref_viewer_type"
android:key="@string/pref_default_viewer_key" android:key="@string/pref_default_viewer_key"
@ -74,4 +50,49 @@
android:defaultValue="0" android:defaultValue="0"
android:summary="%s" /> android:summary="%s" />
<SwitchPreferenceCompat
android:title="@string/pref_hide_status_bar"
android:key="@string/pref_hide_status_bar_key"
android:defaultValue="true" />
<SwitchPreferenceCompat
android:title="@string/pref_enable_transitions"
android:key="@string/pref_enable_transitions_key"
android:defaultValue="true" />
<SwitchPreferenceCompat
android:title="@string/pref_show_page_number"
android:key="@string/pref_show_page_number_key"
android:defaultValue="true" />
<SwitchPreferenceCompat
android:title="@string/pref_custom_brightness"
android:key="@string/pref_custom_brightness_key"
android:defaultValue="false" />
<SwitchPreferenceCompat
android:title="@string/pref_keep_screen_on"
android:key="@string/pref_keep_screen_on_key"
android:defaultValue="true" />
<SwitchPreferenceCompat
android:title="@string/pref_seamless_mode"
android:key="@string/pref_seamless_mode_key"
android:defaultValue="true" />
<PreferenceCategory
android:title="@string/pref_reader_navigation">
<SwitchPreferenceCompat
android:title="@string/pref_read_with_tapping"
android:key="@string/pref_read_with_tapping_key"
android:defaultValue="true" />
<SwitchPreferenceCompat
android:title="@string/pref_read_with_volume_keys"
android:key="@string/pref_read_with_volume_keys_key"
android:defaultValue="false" />
</PreferenceCategory>
</android.support.v7.preference.PreferenceScreen> </android.support.v7.preference.PreferenceScreen>