fixed permission asking and template shortcuts duplicating
This commit is contained in:
parent
7d28c31ffc
commit
c3730c46dc
7 changed files with 32 additions and 30 deletions
|
|
@ -126,7 +126,7 @@ dependencies {
|
|||
|
||||
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
||||
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.core:core:1.9.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".ui.more.CommandTemplatesActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:exported="true">
|
||||
|
|
|
|||
|
|
@ -185,25 +185,23 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun askPermissions() {
|
||||
val permissions = arrayListOf<String>()
|
||||
if (!checkFilePermission()) {
|
||||
if (Build.VERSION.SDK_INT >= 33){
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO),
|
||||
1
|
||||
)
|
||||
permissions.add(Manifest.permission.READ_MEDIA_AUDIO)
|
||||
permissions.add(Manifest.permission.READ_MEDIA_VIDEO)
|
||||
}else{
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
1
|
||||
)
|
||||
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
}
|
||||
if (!checkNotificationPermission()){
|
||||
permissions.add(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
|
||||
if (permissions.isNotEmpty()){
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||
permissions.toTypedArray(),
|
||||
1
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,11 @@ interface CommandTemplateDao {
|
|||
@Query("DELETE FROM commandTemplates WHERE id=:itemId")
|
||||
suspend fun delete(itemId: Long)
|
||||
|
||||
@Query("INSERT INTO templateShortcuts(content) VALUES(:content)")
|
||||
suspend fun insertShortcut(content: String)
|
||||
@Insert(TemplateShortcut::class, OnConflictStrategy.REPLACE)
|
||||
suspend fun insertShortcut(shortcut: TemplateShortcut)
|
||||
|
||||
@Query("SELECT COUNT(id) FROM templateShortcuts WHERE content=:content")
|
||||
suspend fun checkExistingShortcut(content: String) : Int
|
||||
|
||||
@Query("DELETE FROM templateShortcuts WHERE id=:itemId")
|
||||
suspend fun deleteShortcut(itemId: Long)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ class CommandTemplateRepository(private val commandDao: CommandTemplateDao) {
|
|||
}
|
||||
|
||||
suspend fun insertShortcut(item: TemplateShortcut){
|
||||
commandDao.insertShortcut(item.content)
|
||||
if (commandDao.checkExistingShortcut(item.content) == 0){
|
||||
commandDao.insertShortcut(item)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteShortcut(item: TemplateShortcut){
|
||||
|
|
|
|||
|
|
@ -88,8 +88,8 @@ class UiUtil(private val fileUtil: FileUtil) {
|
|||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
ok.isEnabled =
|
||||
!(title.editText!!.text.isEmpty() || content.editText!!.text.isEmpty())
|
||||
if (ok.isEnabled){
|
||||
(title.editText!!.text.isNotEmpty() && content.editText!!.text.isNotEmpty())
|
||||
if (content.editText!!.text.isNotEmpty()){
|
||||
content.endIconDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_all)
|
||||
}else{
|
||||
content.endIconDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_clipboard)
|
||||
|
|
@ -97,10 +97,6 @@ class UiUtil(private val fileUtil: FileUtil) {
|
|||
}
|
||||
})
|
||||
|
||||
if (content.editText!!.text.isEmpty()){
|
||||
|
||||
}
|
||||
|
||||
content.setEndIconOnClickListener {
|
||||
if(content.editText!!.text.isEmpty()){
|
||||
val clipboard: ClipboardManager =
|
||||
|
|
@ -117,7 +113,7 @@ class UiUtil(private val fileUtil: FileUtil) {
|
|||
val chip = context.layoutInflater.inflate(R.layout.suggestion_chip, shortcutsChipGroup, false) as Chip
|
||||
chip.text = shortcut.content
|
||||
chip.setOnClickListener {
|
||||
content.editText!!.append(shortcut.content + " ")
|
||||
content.editText!!.text.insert(content.editText!!.selectionStart, shortcut.content + " ")
|
||||
}
|
||||
shortcutsChipGroup.addView(chip)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,16 @@
|
|||
android:orientation="vertical"
|
||||
android:padding="15dp">
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/shortcutsChipGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:singleLine="false">
|
||||
|
||||
|
||||
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -69,16 +79,8 @@
|
|||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/shortcutsChipGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:singleLine="false">
|
||||
|
||||
|
||||
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue