Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.FileActionManager
import com.itsaky.androidide.actions.observers.FileActionObserver
import com.itsaky.androidide.actions.requireFile
import com.itsaky.androidide.adapters.viewholders.FileTreeViewHolder
import com.itsaky.androidide.databinding.LayoutCreateFileJavaBinding
import com.itsaky.androidide.eventbus.events.file.FileCreationEvent
import com.itsaky.androidide.idetooltips.TooltipTag
Expand Down Expand Up @@ -208,10 +207,6 @@ class NewFileAction(
.showWithLongPressTooltip(
context = context,
tooltipTag = TooltipTag.PROJECT_FOLDER_NEWTYPE,
binding.typeClass,
binding.typeActivity,
binding.typeInterface,
binding.typeEnum,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,45 @@ class RenameAction(
builder.setTitle(R.string.rename_file)
builder.setMessage(R.string.msg_rename_file)
builder.setView(binding.root)
builder.setCancelable(false)
builder.setNegativeButton(android.R.string.cancel, null)
builder.setPositiveButton(R.string.rename_file) { dialogInterface, _ ->
val fileManagerViewModel: FileManagerViewModel by context.viewModels()
val name: String = binding.name.editText?.text.toString().trim()
when {
name.isEmpty() -> {
flashError(R.string.msg_invalid_name)
return@setPositiveButton
}
name.length > 40 -> {
flashError(R.string.file_name_too_long)
return@setPositiveButton
}
}
val fileManagerViewModel: FileManagerViewModel by context.viewModels()
val name: String =
binding.name.editText
?.text
.toString()
.trim()
when {
name.isEmpty() -> {
flashError(R.string.msg_invalid_name)
return@setPositiveButton
}

dialogInterface.dismiss()
fileManagerViewModel.renameFile(file, name, context) { renamed ->
if (!renamed) return@renameFile
name.length > 40 -> {
flashError(R.string.file_name_too_long)
return@setPositiveButton
}
}

val parent = lastHeld?.parent
dialogInterface.dismiss()
fileManagerViewModel.renameFile(file, name, context) { renamed ->
if (!renamed) return@renameFile

if (parent != null) {
requestCollapseNode(parent, false)
requestExpandNode(parent)
} else {
requestFileListing()
}
}
val parent = lastHeld?.parent

if (parent != null) {
requestCollapseNode(parent, false)
requestExpandNode(parent)
} else {
requestFileListing()
}
}
}

builder.showWithLongPressTooltip(
context = context,
tooltipTag = TooltipTag.PROJECT_RENAME_DIALOG
)
builder.showWithLongPressTooltip(
context = context,
tooltipTag = TooltipTag.PROJECT_RENAME_DIALOG,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity() {

builder.setNegativeButton(android.R.string.cancel) { dialog, _ -> dialog.dismiss() }
val dialog = builder.create()
dialog.onLongPress { view ->
dialog.onLongPress(includeEditTexts = true) { view ->
if (
view is EditText
) {
Expand Down
97 changes: 47 additions & 50 deletions app/src/main/java/com/itsaky/androidide/utils/DialogExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Activity
import android.content.Context
import android.graphics.Rect
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.AdapterView
Expand All @@ -16,60 +15,58 @@ import com.itsaky.androidide.idetooltips.TooltipManager

@SuppressLint("ClickableViewAccessibility")
fun MaterialAlertDialogBuilder.showWithLongPressTooltip(
context: Context,
tooltipTag: String,
vararg customViews: View
context: Context,
tooltipTag: String,
): AlertDialog {
val dialog = this.create()
val dialog = this.create()
dialog.show()

fun longPressAction() {
dialog.dismiss()
val anchor = (context as? Activity)?.window?.decorView ?: return
TooltipManager.showIdeCategoryTooltip(
context = context,
anchorView = anchor,
tag = tooltipTag,
)
}
fun longPressAction() {
val anchor = (context as? Activity)?.window?.decorView ?: return
TooltipManager.showIdeCategoryTooltip(
context = context,
anchorView = anchor,
tag = tooltipTag,
)
}

dialog.onLongPress {
longPressAction()
true
}
dialog.onLongPress {
longPressAction()
true
}

dialog.listView?.onItemLongClickListener =
AdapterView.OnItemLongClickListener { _, _, _, _ ->
longPressAction()
true
}
dialog.listView?.onItemLongClickListener =
AdapterView.OnItemLongClickListener { _, _, _, _ ->
longPressAction()
true
}

val customPanel: ViewGroup? = dialog.findViewById(androidx.appcompat.R.id.customPanel)
val customPanel: ViewGroup? = dialog.findViewById(androidx.appcompat.R.id.customPanel)

customPanel?.forEachViewRecursively { view ->
if (view is EditText) {
dialog.setOnShowListener {
view.requestFocus()
val imm =
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}
customPanel?.forEachViewRecursively { view ->
if (view is EditText) {
dialog.setOnShowListener {
view.requestFocus()
val imm =
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}

dialog.window?.decorView?.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
val outRect = Rect()
view.getGlobalVisibleRect(outRect)
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
view.clearFocus()
val imm =
view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
false
}
}
}
dialog.window?.decorView?.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
val outRect = Rect()
view.getGlobalVisibleRect(outRect)
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
view.clearFocus()
val imm =
view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
false
}
}
}

dialog.show()
return dialog
}
return dialog
}
Loading
Loading