popup position changer

This commit is contained in:
lucky 2022-02-14 04:22:31 +03:00
parent ca19155cea
commit 539bb9397e
9 changed files with 37 additions and 3 deletions

View file

@ -8,6 +8,8 @@ import android.os.Bundle
import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import java.lang.NumberFormatException
import me.lucky.red.databinding.ActivityMainBinding
@ -45,6 +47,7 @@ class MainActivity : AppCompatActivity() {
roleManager = getSystemService(RoleManager::class.java)
binding.apply {
redirectionDelay.value = (prefs.redirectionDelay / 1000).toFloat()
popupPosition.editText?.setText(prefs.popupPosition.toString())
toggle.isChecked = prefs.isServiceEnabled
}
}
@ -57,6 +60,11 @@ class MainActivity : AppCompatActivity() {
redirectionDelay.addOnChangeListener { _, value, _ ->
prefs.redirectionDelay = (value * 1000).toLong()
}
popupPosition.editText?.doAfterTextChanged {
try {
prefs.popupPosition = it?.toString()?.toInt() ?: return@doAfterTextChanged
} catch (exc: NumberFormatException) {}
}
toggle.setOnCheckedChangeListener { _, isChecked ->
if (isChecked && !hasPermissions()) {
toggle.isChecked = false

View file

@ -31,7 +31,7 @@ class PopupWindow(private val service: CallRedirectionService) {
gravity = Gravity.BOTTOM
width = WindowManager.LayoutParams.WRAP_CONTENT
height = WindowManager.LayoutParams.WRAP_CONTENT
y = 333
y = service.prefs.popupPosition
}
private var timer: Timer? = null

View file

@ -8,6 +8,7 @@ class Preferences(ctx: Context) {
companion object {
private const val SERVICE_ENABLED = "service_enabled"
private const val REDIRECTION_DELAY = "redirection_delay"
private const val POPUP_POSITION = "popup_position_y"
}
private val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
@ -19,4 +20,8 @@ class Preferences(ctx: Context) {
var redirectionDelay: Long
get() = prefs.getLong(REDIRECTION_DELAY, 2000L)
set(value) = prefs.edit { putLong(REDIRECTION_DELAY, value) }
var popupPosition: Int
get() = prefs.getInt(POPUP_POSITION, 333)
set(value) = prefs.edit { putInt(POPUP_POSITION, value) }
}

View file

@ -46,6 +46,24 @@
android:layout_height="wrap_content"
android:text="@string/redirection_delay_description" />
<Space
android:layout_marginVertical="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/popupPosition"
android:hint="@string/popup_position"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>

View file

@ -7,4 +7,5 @@
<string name="destination_telegram">Telegram</string>
<string name="destination_threema">Threema</string>
<string name="redirection_delay_description">Задержка до того, как звонок будет перенаправлен.</string>
<string name="popup_position">Позиция всплывающего окна</string>
</resources>

View file

@ -7,4 +7,5 @@
<string name="destination_telegram">Telegram</string>
<string name="destination_threema">Threema</string>
<string name="redirection_delay_description">Delay before a call will be redirected.</string>
<string name="popup_position">Popup position</string>
</resources>