Add crop borders functionality, #219

This commit is contained in:
len 2017-02-12 00:30:32 +01:00
parent c8e3375248
commit 91c58640a7
18 changed files with 50 additions and 12 deletions

View File

@ -98,7 +98,7 @@ android {
dependencies { dependencies {
// Modified dependencies // Modified dependencies
compile 'com.github.inorichi:subsampling-scale-image-view:44aa442' compile 'com.github.inorichi:subsampling-scale-image-view:9048f23'
compile 'com.github.inorichi:junrar-android:634c1f5' compile 'com.github.inorichi:junrar-android:634c1f5'
// Android support library // Android support library

View File

@ -41,6 +41,8 @@ class PreferenceKeys(context: Context) {
val readerTheme = context.getString(R.string.pref_reader_theme_key) val readerTheme = context.getString(R.string.pref_reader_theme_key)
val cropBorders = context.getString(R.string.pref_crop_borders_key)
val readWithTapping = context.getString(R.string.pref_read_with_tapping_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 readWithVolumeKeys = context.getString(R.string.pref_read_with_volume_keys_key)

View File

@ -34,7 +34,7 @@ class PreferencesHelper(val context: Context) {
fun rotation() = rxPrefs.getInteger(keys.rotation, 1) fun rotation() = rxPrefs.getInteger(keys.rotation, 1)
fun enableTransitions() = rxPrefs.getBoolean(keys.enableTransitions, true) fun pageTransitions() = rxPrefs.getBoolean(keys.enableTransitions, true)
fun showPageNumber() = rxPrefs.getBoolean(keys.showPageNumber, true) fun showPageNumber() = rxPrefs.getBoolean(keys.showPageNumber, true)
@ -60,6 +60,8 @@ class PreferencesHelper(val context: Context) {
fun readerTheme() = rxPrefs.getInteger(keys.readerTheme, 0) fun readerTheme() = rxPrefs.getInteger(keys.readerTheme, 0)
fun cropBorders() = rxPrefs.getBoolean(keys.cropBorders, false)
fun readWithTapping() = rxPrefs.getBoolean(keys.readWithTapping, true) fun readWithTapping() = rxPrefs.getBoolean(keys.readWithTapping, true)
fun readWithVolumeKeys() = rxPrefs.getBoolean(keys.readWithVolumeKeys, false) fun readWithVolumeKeys() = rxPrefs.getBoolean(keys.readWithVolumeKeys, false)

View File

@ -83,6 +83,11 @@ class ReaderSettingsDialog : DialogFragment() {
fullscreen.setOnCheckedChangeListener { v, isChecked -> fullscreen.setOnCheckedChangeListener { v, isChecked ->
preferences.fullscreen().set(isChecked) preferences.fullscreen().set(isChecked)
} }
crop_borders.isChecked = preferences.cropBorders().getOrDefault()
crop_borders.setOnCheckedChangeListener { v, isChecked ->
preferences.cropBorders().set(isChecked)
}
} }
override fun onDestroyView() { override fun onDestroyView() {

View File

@ -70,6 +70,7 @@ class PageView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
setRegionDecoderClass(reader.regionDecoderClass) setRegionDecoderClass(reader.regionDecoderClass)
setBitmapDecoderClass(reader.bitmapDecoderClass) setBitmapDecoderClass(reader.bitmapDecoderClass)
setVerticalScrollingParent(reader is VerticalReader) setVerticalScrollingParent(reader is VerticalReader)
setCropBorders(reader.cropBorders)
setOnTouchListener { v, motionEvent -> reader.gestureDetector.onTouchEvent(motionEvent) } setOnTouchListener { v, motionEvent -> reader.gestureDetector.onTouchEvent(motionEvent) }
setOnLongClickListener { reader.onLongClick(page) } setOnLongClickListener { reader.onLongClick(page) }
setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() { setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() {

View File

@ -79,6 +79,12 @@ abstract class PagerReader : BaseReader() {
var transitions: Boolean = false var transitions: Boolean = false
private set private set
/**
* Whether to crop image borders.
*/
var cropBorders: Boolean = false
private set
/** /**
* Scale type (fit width, fit screen, etc). * Scale type (fit width, fit screen, etc).
*/ */
@ -150,9 +156,16 @@ abstract class PagerReader : BaseReader() {
.distinctUntilChanged() .distinctUntilChanged()
.subscribe { refreshAdapter() }) .subscribe { refreshAdapter() })
add(preferences.enableTransitions() add(preferences.pageTransitions()
.asObservable() .asObservable()
.subscribe { transitions = it }) .subscribe { transitions = it })
add(preferences.cropBorders()
.asObservable()
.doOnNext { cropBorders = it }
.skip(1)
.distinctUntilChanged()
.subscribe { refreshAdapter() })
} }
setPagesOnAdapter() setPagesOnAdapter()

View File

@ -165,6 +165,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/pref_show_page_number"/> android:text="@string/pref_show_page_number"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/crop_borders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_crop_borders"/>
<android.support.v7.widget.SwitchCompat <android.support.v7.widget.SwitchCompat
android:id="@+id/fullscreen" android:id="@+id/fullscreen"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -118,7 +118,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Цял екран</string> <string name="pref_fullscreen">Цял екран</string>
<string name="pref_lock_orientation">Заключи ориентацията</string> <string name="pref_lock_orientation">Заключи ориентацията</string>
<string name="pref_enable_transitions">Преходи</string> <string name="pref_page_transitions">Преходи</string>
<string name="pref_show_page_number">Номер на страница</string> <string name="pref_show_page_number">Номер на страница</string>
<string name="pref_custom_brightness">Персонализирана яркост</string> <string name="pref_custom_brightness">Персонализирана яркост</string>
<string name="pref_custom_color_filter">Персонализиран цветен филтър</string> <string name="pref_custom_color_filter">Персонализиран цветен филтър</string>

View File

@ -95,7 +95,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Pantalla completa</string> <string name="pref_fullscreen">Pantalla completa</string>
<string name="pref_lock_orientation">Bloquear orientación</string> <string name="pref_lock_orientation">Bloquear orientación</string>
<string name="pref_enable_transitions">Habilitar transiciones</string> <string name="pref_page_transitions">Habilitar transiciones</string>
<string name="pref_show_page_number">Mostrar el número de página</string> <string name="pref_show_page_number">Mostrar el número de página</string>
<string name="pref_custom_brightness">Utilizar brillo personalizado</string> <string name="pref_custom_brightness">Utilizar brillo personalizado</string>
<string name="pref_keep_screen_on">Mantener la pantalla encendida</string> <string name="pref_keep_screen_on">Mantener la pantalla encendida</string>

View File

@ -115,7 +115,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Plein écran</string> <string name="pref_fullscreen">Plein écran</string>
<string name="pref_lock_orientation">Verrouiller l\'orientation</string> <string name="pref_lock_orientation">Verrouiller l\'orientation</string>
<string name="pref_enable_transitions">Activer les transitions</string> <string name="pref_page_transitions">Activer les transitions</string>
<string name="pref_show_page_number">Afficher le numéro de page</string> <string name="pref_show_page_number">Afficher le numéro de page</string>
<string name="pref_custom_brightness">Utiliser une luminosité personnalisée</string> <string name="pref_custom_brightness">Utiliser une luminosité personnalisée</string>
<string name="pref_custom_color_filter">Utiliser un filtre de couleur personnalisé</string> <string name="pref_custom_color_filter">Utiliser un filtre de couleur personnalisé</string>

View File

@ -115,7 +115,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Schermo intero</string> <string name="pref_fullscreen">Schermo intero</string>
<string name="pref_lock_orientation">Blocca orientamento</string> <string name="pref_lock_orientation">Blocca orientamento</string>
<string name="pref_enable_transitions">Abilita transizioni</string> <string name="pref_page_transitions">Abilita transizioni</string>
<string name="pref_show_page_number">Mostra numero di pagina</string> <string name="pref_show_page_number">Mostra numero di pagina</string>
<string name="pref_custom_brightness">Usa luminosità personalizzata</string> <string name="pref_custom_brightness">Usa luminosità personalizzata</string>
<string name="pref_custom_color_filter">Usa filtro colore personalizzato</string> <string name="pref_custom_color_filter">Usa filtro colore personalizzato</string>

View File

@ -100,7 +100,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Ocultar barra de estado</string> <string name="pref_fullscreen">Ocultar barra de estado</string>
<string name="pref_lock_orientation">Bloquear orientação</string> <string name="pref_lock_orientation">Bloquear orientação</string>
<string name="pref_enable_transitions">Permitir transições</string> <string name="pref_page_transitions">Permitir transições</string>
<string name="pref_show_page_number">Mostrar número de página</string> <string name="pref_show_page_number">Mostrar número de página</string>
<string name="pref_custom_brightness">Usar brilho personalizado</string> <string name="pref_custom_brightness">Usar brilho personalizado</string>
<string name="pref_keep_screen_on">Manter ecrã ligado</string> <string name="pref_keep_screen_on">Manter ecrã ligado</string>

View File

@ -213,7 +213,7 @@
<string name="pref_enable_acra">Отсылать отчеты о падениях</string> <string name="pref_enable_acra">Отсылать отчеты о падениях</string>
<string name="pref_enable_automatic_updates">Проверять обновления</string> <string name="pref_enable_automatic_updates">Проверять обновления</string>
<string name="pref_enable_automatic_updates_summary">Автоматически проверять новые версии</string> <string name="pref_enable_automatic_updates_summary">Автоматически проверять новые версии</string>
<string name="pref_enable_transitions">Включить переходы</string> <string name="pref_page_transitions">Включить переходы</string>
<string name="pref_fullscreen">Полноэкранный режим</string> <string name="pref_fullscreen">Полноэкранный режим</string>
<string name="pref_image_decoder">Декодер изображений</string> <string name="pref_image_decoder">Декодер изображений</string>
<string name="pref_image_scale_type">Масштабирование</string> <string name="pref_image_scale_type">Масштабирование</string>

View File

@ -118,7 +118,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Đầy màn hình</string> <string name="pref_fullscreen">Đầy màn hình</string>
<string name="pref_lock_orientation">Khóa xoay</string> <string name="pref_lock_orientation">Khóa xoay</string>
<string name="pref_enable_transitions">Bật hiệu ứng chuyển trang</string> <string name="pref_page_transitions">Bật hiệu ứng chuyển trang</string>
<string name="pref_show_page_number">Hiện số trang</string> <string name="pref_show_page_number">Hiện số trang</string>
<string name="pref_custom_brightness">Dùng độ sáng tùy chỉnh</string> <string name="pref_custom_brightness">Dùng độ sáng tùy chỉnh</string>
<string name="pref_custom_color_filter">Dùng bộ lọc màu tùy chỉnh</string> <string name="pref_custom_color_filter">Dùng bộ lọc màu tùy chỉnh</string>

View File

@ -37,8 +37,10 @@
<string name="pref_red_filter_value_key" translatable="false">pref_red_filter_value</string> <string name="pref_red_filter_value_key" translatable="false">pref_red_filter_value</string>
<string name="pref_reader_theme_key" translatable="false">pref_reader_theme_key</string> <string name="pref_reader_theme_key" translatable="false">pref_reader_theme_key</string>
<string name="pref_image_decoder_key" translatable="false">image_decoder</string> <string name="pref_image_decoder_key" translatable="false">image_decoder</string>
<string name="pref_crop_borders_key" translatable="false">crop_borders</string>
<string name="pref_read_with_volume_keys_key" translatable="false">reader_volume_keys</string> <string name="pref_read_with_volume_keys_key" translatable="false">reader_volume_keys</string>
<string name="pref_read_with_tapping_key" translatable="false">reader_tap</string> <string name="pref_read_with_tapping_key" translatable="false">reader_tap</string>
<string name="pref_filter_downloaded_key" translatable="false">pref_filter_downloaded_key</string> <string name="pref_filter_downloaded_key" translatable="false">pref_filter_downloaded_key</string>
<string name="pref_filter_unread_key" translatable="false">pref_filter_unread_key</string> <string name="pref_filter_unread_key" translatable="false">pref_filter_unread_key</string>
<string name="pref_library_sorting_mode_key" translatable="false">library_sorting_mode</string> <string name="pref_library_sorting_mode_key" translatable="false">library_sorting_mode</string>

View File

@ -120,8 +120,9 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Fullscreen</string> <string name="pref_fullscreen">Fullscreen</string>
<string name="pref_lock_orientation">Lock orientation</string> <string name="pref_lock_orientation">Lock orientation</string>
<string name="pref_enable_transitions">Enable transitions</string> <string name="pref_page_transitions">Page transitions</string>
<string name="pref_show_page_number">Show page number</string> <string name="pref_show_page_number">Show page number</string>
<string name="pref_crop_borders">Crop borders</string>
<string name="pref_custom_brightness">Use custom brightness</string> <string name="pref_custom_brightness">Use custom brightness</string>
<string name="pref_custom_color_filter">Use custom color filter</string> <string name="pref_custom_color_filter">Use custom color filter</string>
<string name="pref_keep_screen_on">Keep screen on</string> <string name="pref_keep_screen_on">Keep screen on</string>

View File

@ -64,7 +64,7 @@
android:defaultValue="true" /> android:defaultValue="true" />
<SwitchPreference <SwitchPreference
android:title="@string/pref_enable_transitions" android:title="@string/pref_page_transitions"
android:key="@string/pref_enable_transitions_key" android:key="@string/pref_enable_transitions_key"
android:defaultValue="true" /> android:defaultValue="true" />
@ -73,6 +73,11 @@
android:key="@string/pref_show_page_number_key" android:key="@string/pref_show_page_number_key"
android:defaultValue="true" /> android:defaultValue="true" />
<SwitchPreference
android:title="@string/pref_crop_borders"
android:key="@string/pref_crop_borders_key"
android:defaultValue="false" />
<SwitchPreference <SwitchPreference
android:title="@string/pref_keep_screen_on" android:title="@string/pref_keep_screen_on"
android:key="@string/pref_keep_screen_on_key" android:key="@string/pref_keep_screen_on_key"

View File

@ -17,5 +17,6 @@ allprojects {
repositories { repositories {
jcenter() jcenter()
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
maven { url "https://dl.bintray.com/inorichi/maven" }
} }
} }