use some helper functions for hiding/showing keyboard at dialogs

This commit is contained in:
tibbi 2018-03-02 16:53:34 +01:00
parent fc9c1a62a7
commit 39b4677887
6 changed files with 59 additions and 63 deletions

View file

@ -46,7 +46,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.13.8' implementation 'com.simplemobiletools:commons:3.14.5'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'com.android.support:multidex:1.0.2' implementation 'com.android.support:multidex:1.0.2'
implementation 'com.google.code.gson:gson:2.8.2' implementation 'com.google.code.gson:gson:2.8.2'

View file

@ -22,9 +22,7 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m
val medium = media[position] val medium = media[position]
val bundle = Bundle() val bundle = Bundle()
bundle.putSerializable(MEDIUM, medium) bundle.putSerializable(MEDIUM, medium)
val fragment: ViewPagerFragment val fragment = if (medium.isVideo()) {
fragment = if (medium.isVideo()) {
VideoFragment() VideoFragment()
} else { } else {
PhotoFragment() PhotoFragment()
@ -39,7 +37,7 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m
override fun instantiateItem(container: ViewGroup, position: Int): Any { override fun instantiateItem(container: ViewGroup, position: Int): Any {
val fragment = super.instantiateItem(container, position) as ViewPagerFragment val fragment = super.instantiateItem(container, position) as ViewPagerFragment
fragments.put(position, fragment) fragments[position] = fragment
return fragment return fragment
} }

View file

@ -4,10 +4,10 @@ import android.graphics.Point
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.WindowManager
import android.widget.EditText import android.widget.EditText
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
@ -72,22 +72,22 @@ class ResizeDialog(val activity: BaseSimpleActivity, val size: Point, val callba
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) activity.setupDialogStuff(view, this, R.string.resize_and_save) {
activity.setupDialogStuff(view, this, R.string.resize_and_save) { showKeyboard(view.image_width)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val width = getViewValue(widthView) val width = getViewValue(widthView)
val height = getViewValue(heightView) val height = getViewValue(heightView)
if (width <= 0 || height <= 0) { if (width <= 0 || height <= 0) {
activity.toast(R.string.invalid_values) activity.toast(R.string.invalid_values)
return@setOnClickListener return@setOnClickListener
} }
val newSize = Point(getViewValue(widthView), getViewValue(heightView)) val newSize = Point(getViewValue(widthView), getViewValue(heightView))
callback(newSize) callback(newSize)
dismiss() dismiss()
}
}
} }
}
}
} }
fun getViewValue(view: EditText): Int { fun getViewValue(view: EditText): Int {

View file

@ -1,7 +1,6 @@
package com.simplemobiletools.gallery.dialogs package com.simplemobiletools.gallery.dialogs
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.WindowManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
@ -45,40 +44,40 @@ class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appen
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) activity.setupDialogStuff(view, this, R.string.save_as) {
activity.setupDialogStuff(view, this, R.string.save_as) { showKeyboard(view.save_as_name)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.save_as_name.value val filename = view.save_as_name.value
val extension = view.save_as_extension.value val extension = view.save_as_extension.value
if (filename.isEmpty()) { if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty) activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener return@setOnClickListener
} }
if (extension.isEmpty()) { if (extension.isEmpty()) {
activity.toast(R.string.extension_cannot_be_empty) activity.toast(R.string.extension_cannot_be_empty)
return@setOnClickListener return@setOnClickListener
} }
val newFile = File(realPath, "$filename.$extension") val newFile = File(realPath, "$filename.$extension")
if (!newFile.name.isAValidFilename()) { if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters) activity.toast(R.string.filename_invalid_characters)
return@setOnClickListener return@setOnClickListener
} }
if (newFile.exists()) { if (newFile.exists()) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name) val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name)
ConfirmationDialog(activity, title) { ConfirmationDialog(activity, title) {
callback(newFile.absolutePath) callback(newFile.absolutePath)
dismiss() dismiss()
}
} else {
callback(newFile.absolutePath)
dismiss()
}
} }
} else {
callback(newFile.absolutePath)
dismiss()
} }
} }
}
}
} }
} }

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.dialogs
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.View import android.view.View
import android.view.WindowManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.hideKeyboard
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
@ -71,20 +70,20 @@ class SlideshowDialog(val activity: BaseSimpleActivity, val callback: () -> Unit
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) activity.setupDialogStuff(view, this) {
activity.setupDialogStuff(view, this) { hideKeyboard()
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (!view.include_photos.isChecked && !view.include_videos.isChecked && !view.include_gifs.isChecked) { if (!view.include_photos.isChecked && !view.include_videos.isChecked && !view.include_gifs.isChecked) {
activity.toast(R.string.no_media_for_slideshow) activity.toast(R.string.no_media_for_slideshow)
return@setOnClickListener return@setOnClickListener
} }
storeValues() storeValues()
callback() callback()
dismiss() dismiss()
}
}
} }
}
}
} }
private fun setupValues() { private fun setupValues() {

View file

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.2.21' ext.kotlin_version = '1.2.30'
repositories { repositories {
jcenter() jcenter()