Show a toast when language switching occurs with only one language active

This commit is contained in:
Aleksandras Kostarevas 2024-07-20 22:38:06 +03:00
parent ed7d990224
commit e306c29ccd

View File

@ -7,6 +7,7 @@ import android.util.Log
import android.view.inputmethod.InputMethodManager
import android.view.inputmethod.InputMethodSubtype
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder
import android.widget.Toast
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@ -258,6 +259,13 @@ object Subtypes {
val enabledSubtypes = context.getSettingBlocking(SubtypesSetting).toList()
val currentSubtype = context.getSettingBlocking(ActiveSubtype)
if(enabledSubtypes.isEmpty()) return
if(enabledSubtypes.size == 1) {
Toast.makeText(context, "Only one language is enabled, can't switch to next", Toast.LENGTH_SHORT).show()
return
}
val index = enabledSubtypes.indexOf(currentSubtype)
val nextIndex = if(index == -1) {
0
@ -265,8 +273,6 @@ object Subtypes {
(index + direction.sign).mod(enabledSubtypes.size)
}
if(enabledSubtypes.isEmpty()) return
context.setSettingBlocking(ActiveSubtype.key, enabledSubtypes[nextIndex])
}
}