Skip to content

Commit

Permalink
Adds auto keyboard popup to ListsActivity, FollowedTagsActivity, Edit…
Browse files Browse the repository at this point in the history
…FilterActivity, CaptionDialog, and AddPollDialog.kt. These are all dialog screens which editing with the main purpose being to edit texts
  • Loading branch information
andrewhamilton0 committed Sep 10, 2024
1 parent 50ca44a commit 3a40778
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.PopupMenu
import androidx.activity.viewModels
import androidx.annotation.StringRes
Expand Down Expand Up @@ -136,11 +137,14 @@ class ListsActivity : BaseActivity() {
.setNegativeButton(android.R.string.cancel, null)
.show()

dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)

binding.nameText.let { editText ->
editText.doOnTextChanged { s, _, _, _ ->
dialog.getButton(Dialog.BUTTON_POSITIVE).isEnabled = s?.isNotBlank() == true
}
editText.setText(list?.title)
editText.requestFocus()
editText.text?.let { editText.setSelection(it.length) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.view.LayoutInflater
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputEditText
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.DialogAddPollBinding
import com.keylesspalace.tusky.entity.NewPoll
Expand Down Expand Up @@ -106,6 +107,14 @@ fun showAddPollDialog(

dialog.show()

dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
binding.pollChoices.post {
val firstItemView = binding.pollChoices.layoutManager?.findViewByPosition(0)
val editText = firstItemView?.findViewById<TextInputEditText>(R.id.optionEditText)
editText?.requestFocus()
editText?.setSelection(editText.length())
}

// make the dialog focusable so the keyboard does not stay behind it
dialog.window?.clearFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class CaptionDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val imageView = binding.imageDescriptionView
imageView.maxZoom = 6f
val imageDescriptionText = binding.imageDescriptionText
imageDescriptionText.post {
imageDescriptionText.requestFocus()
imageDescriptionText.setSelection(imageDescriptionText.length())
}

binding.imageDescriptionText.hint = resources.getQuantityString(
R.plurals.hint_describe_for_visually_impaired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.keylesspalace.tusky.components.filters
import android.content.Context
import android.content.DialogInterface.BUTTON_POSITIVE
import android.os.Bundle
import android.view.WindowManager
import android.widget.AdapterView
import androidx.activity.viewModels
import androidx.core.view.size
Expand Down Expand Up @@ -211,7 +212,7 @@ class EditFilterActivity : BaseActivity() {
private fun showAddKeywordDialog() {
val binding = DialogFilterBinding.inflate(layoutInflater)
binding.phraseWholeWord.isChecked = true
MaterialAlertDialogBuilder(this)
val dialog = MaterialAlertDialogBuilder(this)
.setTitle(R.string.filter_keyword_addition_title)
.setView(binding.root)
.setPositiveButton(android.R.string.ok) { _, _ ->
Expand All @@ -225,14 +226,20 @@ class EditFilterActivity : BaseActivity() {
}
.setNegativeButton(android.R.string.cancel, null)
.show()

dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)

val editText = binding.phraseEditText
editText.requestFocus()
editText.setSelection(editText.length())
}

private fun showEditKeywordDialog(keyword: FilterKeyword) {
val binding = DialogFilterBinding.inflate(layoutInflater)
binding.phraseEditText.setText(keyword.keyword)
binding.phraseWholeWord.isChecked = keyword.wholeWord

MaterialAlertDialogBuilder(this)
val dialog = MaterialAlertDialogBuilder(this)
.setTitle(R.string.filter_edit_keyword_title)
.setView(binding.root)
.setPositiveButton(R.string.filter_dialog_update_button) { _, _ ->
Expand All @@ -246,6 +253,12 @@ class EditFilterActivity : BaseActivity() {
}
.setNegativeButton(android.R.string.cancel, null)
.show()

dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)

val editText = binding.phraseEditText
editText.requestFocus()
editText.setSelection(editText.length())
}

private fun validateSaveButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.DialogInterface
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
import android.widget.AutoCompleteTextView
import androidx.activity.viewModels
import androidx.fragment.app.DialogFragment
Expand Down Expand Up @@ -194,6 +195,8 @@ class FollowedTagsActivity :
showBotBadge = false
)
)
autoCompleteTextView.requestFocus()
autoCompleteTextView.setSelection(autoCompleteTextView.length())

return MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.dialog_follow_hashtag_title)
Expand All @@ -207,6 +210,11 @@ class FollowedTagsActivity :
.create()
}

override fun onStart() {
super.onStart()
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
}

companion object {
fun newInstance(): FollowTagDialog = FollowTagDialog()
}
Expand Down

0 comments on commit 3a40778

Please sign in to comment.