store values set at the slideshow setup dialog

This commit is contained in:
tibbi 2017-08-04 22:53:43 +02:00
parent c06fe43a68
commit 1dec1b7457
10 changed files with 58 additions and 13 deletions

View file

@ -17,7 +17,6 @@ import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.support.v4.view.ViewPager
import android.transition.Slide
import android.util.DisplayMetrics
import android.view.*
import com.simplemobiletools.commons.dialogs.ConfirmationDialog

View file

@ -84,6 +84,6 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
config.fileSorting = sorting
}
}
callback.invoke()
callback()
}
}

View file

@ -45,7 +45,7 @@ class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: List<
private fun dialogConfirmed() {
val path = if (alternativePaths.isEmpty()) selectedPaths[0] else alternativePaths[radioGroup!!.checkedRadioButtonId]
activity.config.addExcludedFolder(path)
callback.invoke()
callback()
}
private fun getAlternativePathsList(): List<String> {

View file

@ -50,7 +50,7 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String,
fun showOtherFolder() {
val showHidden = activity.config.shouldShowHidden
FilePickerDialog(activity, sourcePath, false, showHidden, true) {
callback.invoke(it)
callback(it)
}
}
@ -64,7 +64,7 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String,
activity.toast(R.string.source_and_destination_same)
return@DirectoryAdapter
} else {
callback.invoke(it.path)
callback(it.path)
dialog.dismiss()
}
}

View file

@ -84,7 +84,7 @@ class ResizeDialog(val activity: SimpleActivity, val size: Point, val callback:
}
val newSize = Point(getViewValue(widthView), getViewValue(heightView))
callback.invoke(newSize)
callback(newSize)
dismiss()
})
}

View file

@ -66,11 +66,11 @@ class SaveAsDialog(val activity: SimpleActivity, val path: String, val callback:
if (newFile.exists()) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name)
ConfirmationDialog(activity, title) {
callback.invoke(newFile.absolutePath)
callback(newFile.absolutePath)
dismiss()
}
} else {
callback.invoke(newFile.absolutePath)
callback(newFile.absolutePath)
dismiss()
}
})

View file

@ -2,18 +2,21 @@ package com.simplemobiletools.gallery.dialogs
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.helpers.SLIDESHOW_DEFAULT_DURATION
import kotlinx.android.synthetic.main.dialog_slideshow.view.*
class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) {
var dialog: AlertDialog
val dialog: AlertDialog
val view: View
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_slideshow, null).apply {
view = LayoutInflater.from(activity).inflate(R.layout.dialog_slideshow, null).apply {
interval_value.setOnClickListener {
val text = interval_value.text
if (text.isNotEmpty()) {
@ -34,6 +37,7 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) {
use_fade.toggle()
}
}
setupValues()
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
@ -41,11 +45,31 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) {
.create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
activity.setupDialogStuff(view, this)
currentFocus?.clearFocus()
}
}
private fun setupValues() {
val config = activity.config
view.apply {
interval_value.setText(config.slideshowInterval.toString())
include_videos.isChecked = config.slideshowIncludeVideos
random_order.isChecked = config.slideshowRandomOrder
use_fade.isChecked = config.slideshowUseFade
}
}
private fun dialogConfirmed() {
var interval = view.interval_value.text.toString()
if (interval.trim('0').isEmpty())
interval = SLIDESHOW_DEFAULT_DURATION.toString()
activity.config.apply {
slideshowInterval = interval.toInt()
slideshowIncludeVideos = view.include_videos.isChecked
slideshowRandomOrder = view.random_order.isChecked
slideshowUseFade = view.use_fade.isChecked
}
dialog.dismiss()
callback()
}
}

View file

@ -232,4 +232,20 @@ class Config(context: Context) : BaseConfig(context) {
var replaceShare: Boolean
get() = prefs.getBoolean(REPLACE_SHARE_WITH_ROTATE, false)
set(replaceShare) = prefs.edit().putBoolean(REPLACE_SHARE_WITH_ROTATE, replaceShare).apply()
var slideshowInterval: Int
get() = prefs.getInt(SLIDESHOW_INTERVAL, SLIDESHOW_DEFAULT_DURATION)
set(slideshowInterval) = prefs.edit().putInt(SLIDESHOW_INTERVAL, slideshowInterval).apply()
var slideshowIncludeVideos: Boolean
get() = prefs.getBoolean(SLIDESHOW_INCLUDE_VIDEOS, false)
set(slideshowIncludeVideos) = prefs.edit().putBoolean(SLIDESHOW_INCLUDE_VIDEOS, slideshowIncludeVideos).apply()
var slideshowRandomOrder: Boolean
get() = prefs.getBoolean(SLIDESHOW_RANDOM_ORDER, false)
set(slideshowRandomOrder) = prefs.edit().putBoolean(SLIDESHOW_RANDOM_ORDER, slideshowRandomOrder).apply()
var slideshowUseFade: Boolean
get() = prefs.getBoolean(SLIDESHOW_USE_FADE, false)
set(slideshowUseFade) = prefs.edit().putBoolean(SLIDESHOW_USE_FADE, slideshowUseFade).apply()
}

View file

@ -34,6 +34,13 @@ val SCROLL_HORIZONTALLY = "scroll_horizontally"
val HIDE_SYSTEM_UI = "hide_system_ui"
val REPLACE_SHARE_WITH_ROTATE = "replace_share_with_rotate"
// slideshow
val SLIDESHOW_INTERVAL = "slideshow_interval"
val SLIDESHOW_INCLUDE_VIDEOS = "slideshow_include_videos"
val SLIDESHOW_RANDOM_ORDER = "slideshow_random_order"
val SLIDESHOW_USE_FADE = "slideshow_use_fade"
val SLIDESHOW_DEFAULT_DURATION = 5
val NOMEDIA = ".nomedia"
val DIRECTORY = "directory"

View file

@ -35,7 +35,6 @@
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="2"
android:text="5"
android:textCursorDrawable="@null"/>
<RelativeLayout