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

Commit

Permalink
fallback mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky committed Feb 16, 2022
1 parent 539bb93 commit e8001df
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 6 deletions.
7 changes: 6 additions & 1 deletion PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ please read them at:

Signal: https://signal.org/legal/#privacy-policy
Telegram: https://telegram.org/privacy
Threema: https://threema.ch/privacy_policy/
Threema: https://threema.ch/privacy_policy/

Fallback services:

WhatsApp: https://www.whatsapp.com/privacy
Viber: https://www.viber.com/en/terms/viber-privacy-policy/
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 6
versionName "1.0.5"
versionCode 7
versionName "1.0.6"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/me/lucky/red/CallRedirectionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ class CallRedirectionService : CallRedirectionService() {
private const val SIGNAL_MIMETYPE = "$PREFIX.org.thoughtcrime.securesms.call"
private const val TELEGRAM_MIMETYPE = "$PREFIX.org.telegram.messenger.android.call"
private const val THREEMA_MIMETYPE = "$PREFIX.ch.threema.app.call"
private const val WHATSAPP_MIMETYPE = "$PREFIX.com.whatsapp.voip.call"
private const val VIBER_MIMETYPE = "$PREFIX.com.viber.voip.call"
private val MIMETYPES = mapOf(
SIGNAL_MIMETYPE to 0,
TELEGRAM_MIMETYPE to 1,
THREEMA_MIMETYPE to 2,
WHATSAPP_MIMETYPE to 48,
VIBER_MIMETYPE to 49,
)
private val FALLBACK_MIMETYPES = arrayOf(
WHATSAPP_MIMETYPE,
VIBER_MIMETYPE,
)
}

Expand Down Expand Up @@ -59,14 +67,16 @@ class CallRedirectionService : CallRedirectionService() {
return
}
val record = records.minByOrNull { MIMETYPES[it.mimetype] ?: 0 }
if (record == null) {
if (record == null || (record.mimetype in FALLBACK_MIMETYPES && !prefs.isFallbackChecked)) {
placeCallUnmodified()
return
}
window.show(record.uri, when (record.mimetype) {
SIGNAL_MIMETYPE -> R.string.destination_signal
TELEGRAM_MIMETYPE -> R.string.destination_telegram
THREEMA_MIMETYPE -> R.string.destination_threema
WHATSAPP_MIMETYPE -> R.string.fallback_destination_whatsapp
VIBER_MIMETYPE -> R.string.fallback_destination_viber
else -> return
})
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/me/lucky/red/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MainActivity : AppCompatActivity() {
binding.apply {
redirectionDelay.value = (prefs.redirectionDelay / 1000).toFloat()
popupPosition.editText?.setText(prefs.popupPosition.toString())
fallback.isChecked = prefs.isFallbackChecked
toggle.isChecked = prefs.isServiceEnabled
}
}
Expand All @@ -65,6 +66,9 @@ class MainActivity : AppCompatActivity() {
prefs.popupPosition = it?.toString()?.toInt() ?: return@doAfterTextChanged
} catch (exc: NumberFormatException) {}
}
fallback.setOnCheckedChangeListener { _, isChecked ->
prefs.isFallbackChecked = isChecked
}
toggle.setOnCheckedChangeListener { _, isChecked ->
if (isChecked && !hasPermissions()) {
toggle.isChecked = false
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/me/lucky/red/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Preferences(ctx: Context) {
private const val SERVICE_ENABLED = "service_enabled"
private const val REDIRECTION_DELAY = "redirection_delay"
private const val POPUP_POSITION = "popup_position_y"
private const val FALLBACK_CHECKED = "fallback_checked"

private const val DEFAULT_REDIRECTION_DELAY = 2000L
private const val DEFAULT_POPUP_POSITION = 333
}

private val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
Expand All @@ -18,10 +22,14 @@ class Preferences(ctx: Context) {
set(value) = prefs.edit { putBoolean(SERVICE_ENABLED, value) }

var redirectionDelay: Long
get() = prefs.getLong(REDIRECTION_DELAY, 2000L)
get() = prefs.getLong(REDIRECTION_DELAY, DEFAULT_REDIRECTION_DELAY)
set(value) = prefs.edit { putLong(REDIRECTION_DELAY, value) }

var popupPosition: Int
get() = prefs.getInt(POPUP_POSITION, 333)
get() = prefs.getInt(POPUP_POSITION, DEFAULT_POPUP_POSITION)
set(value) = prefs.edit { putInt(POPUP_POSITION, value) }

var isFallbackChecked: Boolean
get() = prefs.getBoolean(FALLBACK_CHECKED, false)
set(value) = prefs.edit { putBoolean(FALLBACK_CHECKED, value) }
}
29 changes: 29 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:id="@+id/scrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="16dp"
android:layout_marginVertical="16dp"
app:layout_constraintBottom_toTopOf="@+id/toggle"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -42,6 +43,7 @@

<TextView
android:id="@+id/description2"
android:textSize="12sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/redirection_delay_description" />
Expand All @@ -64,6 +66,33 @@

</com.google.android.material.textfield.TextInputLayout>

<Space
android:layout_marginVertical="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="8dp"
android:background="?android:attr/listDivider" />

<CheckBox
android:id="@+id/fallback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:text="@string/fallback"
android:textSize="16sp" />

<TextView
android:id="@+id/description3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fallback_description"
android:textSize="12sp" />

</LinearLayout>
</ScrollView>

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<string name="destination_threema">Threema</string>
<string name="redirection_delay_description">Задержка до того, как звонок будет перенаправлен.</string>
<string name="popup_position">Позиция всплывающего окна</string>
<string name="fallback">Обратная совместимость</string>
<string name="fallback_description">Перенаправлять в WhatsApp/Viber, если другие недоступны.</string>
<string name="fallback_destination_whatsapp">WhatsApp</string>
<string name="fallback_destination_viber">Viber</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<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>
<string name="fallback">Fallback</string>
<string name="fallback_description">Redirect to WhatsApp/Viber if no other available.</string>
<string name="fallback_destination_whatsapp">WhatsApp</string>
<string name="fallback_destination_viber">Viber</string>
</resources>
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fallback mode
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 e8001df

Please sign in to comment.