Skip to content

Commit

Permalink
automatically selects the filename without the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed May 24, 2022
1 parent fab089b commit 49f47f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.core.widget.addTextChangedListener
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import com.google.android.material.textfield.TextInputEditText
import com.infomaniak.drive.R
import com.infomaniak.drive.data.cache.DriveInfosController
import com.infomaniak.drive.data.cache.FileController
Expand Down Expand Up @@ -91,6 +92,18 @@ class SaveExternalFilesActivity : BaseActivity() {
fetchSelectedDrive()
fetchFolder()
setupSaveButton()

fileNameEdit.selectAllButFileExtension()
}

private fun TextInputEditText.selectAllButFileExtension() {
setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
val fileName = (text ?: "").toString()
val endIndex = fileName.substringBeforeLast(".").length
post { setSelection(0, endIndex) }
}
}
}

private fun isAuth(): Boolean {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/infomaniak/drive/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.net.Uri
import android.os.Environment
import android.provider.DocumentsContract
import android.view.View
import android.view.WindowManager
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
Expand Down Expand Up @@ -155,7 +156,10 @@ object Utils {
.setNegativeButton(R.string.buttonCancel) { _, _ -> }
.setCancelable(false)
.create()
.also { it.show() }
.apply {
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
show()
}

val buttonPositive = dialog.getButton(AlertDialog.BUTTON_POSITIVE)

Expand Down

0 comments on commit 49f47f6

Please sign in to comment.