Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
redirection delay selector
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky committed Feb 7, 2022
1 parent 48a9998 commit 53708dc
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "me.lucky.red"
minSdk 29
targetSdk 32
versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/me/lucky/red/CallRedirectionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CallRedirectionService : CallRedirectionService() {
)
}

private lateinit var prefs: Preferences
lateinit var prefs: Preferences
private lateinit var window: PopupWindow
private var connectivityManager: ConnectivityManager? = null

Expand All @@ -30,6 +30,11 @@ class CallRedirectionService : CallRedirectionService() {
init()
}

override fun onDestroy() {
super.onDestroy()
window.cancel()
}

private fun init() {
prefs = Preferences(this)
window = PopupWindow(this)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/me/lucky/red/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ class MainActivity : AppCompatActivity() {
prefs = Preferences(this)
roleManager = getSystemService(RoleManager::class.java)
binding.apply {
redirectionDelay.value = (prefs.redirectionDelay / 1000).toFloat()
toggle.isChecked = prefs.isServiceEnabled
}
}

private fun setup() {
binding.apply {
redirectionDelay.setLabelFormatter {
String.format("%.1f", it)
}
redirectionDelay.addOnChangeListener { _, value, _ ->
prefs.redirectionDelay = (value * 1000).toLong()
}
toggle.setOnCheckedChangeListener { _, isChecked ->
if (isChecked && !hasPermissions()) {
toggle.isChecked = false
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/me/lucky/red/PopupWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import java.util.*
import kotlin.concurrent.timerTask

class PopupWindow(private val service: CallRedirectionService) {
companion object {
private const val CANCEL_DELAY = 2000L
}

private val windowManager = service
.applicationContext
.getSystemService(WindowManager::class.java)
Expand All @@ -41,9 +37,8 @@ class PopupWindow(private val service: CallRedirectionService) {

init {
view.setOnClickListener {
timer?.cancel()
cancel()
service.placeCallUnmodified()
remove()
}
}

Expand All @@ -70,7 +65,7 @@ class PopupWindow(private val service: CallRedirectionService) {
return@timerTask
}
service.cancelCall()
}, CANCEL_DELAY)
}, service.prefs.redirectionDelay)
view.findViewById<TextView>(R.id.description).text = String.format(
service.getString(R.string.popup),
service.getString(destinationId),
Expand Down Expand Up @@ -104,4 +99,9 @@ class PopupWindow(private val service: CallRedirectionService) {
} catch (exc: WindowManager.BadTokenException) { return false }
return true
}

fun cancel() {
timer?.cancel()
remove()
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/me/lucky/red/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import androidx.preference.PreferenceManager
class Preferences(ctx: Context) {
companion object {
private const val SERVICE_ENABLED = "service_enabled"
private const val REDIRECTION_DELAY = "redirection_delay"
}

private val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)

var isServiceEnabled: Boolean
get() = prefs.getBoolean(SERVICE_ENABLED, false)
set(value) = prefs.edit { putBoolean(SERVICE_ENABLED, value) }

var redirectionDelay: Long
get() = prefs.getLong(REDIRECTION_DELAY, 2000L)
set(value) = prefs.edit { putLong(REDIRECTION_DELAY, value) }
}
33 changes: 33 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,39 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView
android:id="@+id/scrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginVertical="16dp"
app:layout_constraintBottom_toTopOf="@+id/toggle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.slider.Slider
android:id="@+id/redirectionDelay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/redirection_delay_description"
android:stepSize="0.5"
android:valueFrom="2"
android:valueTo="4" />

<TextView
android:id="@+id/description2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/redirection_delay_description" />

</LinearLayout>
</ScrollView>

<ToggleButton
android:id="@+id/toggle"
android:layout_width="0dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string name="popup">Перенаправление в %1$s</string>
<string name="signal">Signal</string>
<string name="telegram">Telegram</string>
<string name="redirection_delay_description">Задержка до того, как звонок будет перенаправлен.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string name="popup">Redirecting to %1$s</string>
<string name="signal">Signal</string>
<string name="telegram">Telegram</string>
<string name="redirection_delay_description">Delay before a call will be redirected.</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redirection delay selector
Binary file modified fastlane/metadata/android/en-US/images/phoneScreenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53708dc

Please sign in to comment.