Fixed crash related to redirect popup
This commit is contained in:
parent
fc1f048e2c
commit
c8d65dda5f
4 changed files with 34 additions and 22 deletions
|
@ -11,8 +11,8 @@ android {
|
|||
applicationId = "partisan.weforge.xyz.pulse"
|
||||
minSdk = 29
|
||||
targetSdk = 34
|
||||
versionCode = 10
|
||||
versionName = "1.3.1"
|
||||
versionCode = 11
|
||||
versionName = "1.3.2"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.net.Uri
|
|||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.WindowManager
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.RequiresPermission
|
||||
import java.lang.ref.WeakReference
|
||||
|
@ -16,14 +17,14 @@ import java.util.*
|
|||
import kotlin.concurrent.timerTask
|
||||
|
||||
class PopupWindow(
|
||||
private val ctx: Context,
|
||||
ctx: Context,
|
||||
private val service: WeakReference<CallRedirectionService>?,
|
||||
) {
|
||||
private val prefs = Preferences(ctx)
|
||||
private val windowManager = ctx.getSystemService(WindowManager::class.java)
|
||||
private val audioManager = ctx.getSystemService(AudioManager::class.java)
|
||||
@Suppress("InflateParams")
|
||||
private val view = LayoutInflater.from(ctx).inflate(R.layout.popup, null)
|
||||
private val themedCtx = ContextThemeWrapper(ctx, R.style.Theme_Pulse)
|
||||
private val prefs = Preferences(themedCtx)
|
||||
private val windowManager = themedCtx.getSystemService(WindowManager::class.java)
|
||||
private val audioManager = themedCtx.getSystemService(AudioManager::class.java)
|
||||
private val view = LayoutInflater.from(themedCtx).inflate(R.layout.popup, null)
|
||||
private val layoutParams = WindowManager.LayoutParams().apply {
|
||||
format = PixelFormat.TRANSLUCENT
|
||||
flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||
|
@ -45,7 +46,7 @@ class PopupWindow(
|
|||
fun preview() {
|
||||
remove()
|
||||
layoutParams.y = prefs.popupPosition
|
||||
val destinations = mutableListOf(
|
||||
val destinations = listOf(
|
||||
R.string.destination_signal,
|
||||
R.string.destination_telegram,
|
||||
R.string.destination_threema,
|
||||
|
@ -87,33 +88,37 @@ class PopupWindow(
|
|||
}
|
||||
|
||||
private fun setDescription(id: Int) {
|
||||
view.findViewById<TextView>(R.id.description).text = ctx.getString(
|
||||
view.findViewById<TextView>(R.id.description).text = themedCtx.getString(
|
||||
R.string.popup,
|
||||
ctx.getString(id),
|
||||
themedCtx.getString(id),
|
||||
)
|
||||
}
|
||||
|
||||
@RequiresPermission(Manifest.permission.CALL_PHONE)
|
||||
private fun call(data: Uri) {
|
||||
Intent(Intent.ACTION_VIEW).let {
|
||||
it.data = data
|
||||
it.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
ctx.startActivity(it)
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
this.data = data
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
themedCtx.startActivity(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun add(): Boolean {
|
||||
try {
|
||||
windowManager?.addView(view, layoutParams)
|
||||
} catch (exc: WindowManager.BadTokenException) { return false }
|
||||
} catch (exc: WindowManager.BadTokenException) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun remove(): Boolean {
|
||||
try {
|
||||
windowManager?.removeView(view)
|
||||
} catch (exc: IllegalArgumentException) {
|
||||
} catch (exc: WindowManager.BadTokenException) { return false }
|
||||
} catch (_: IllegalArgumentException) {
|
||||
} catch (_: WindowManager.BadTokenException) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="24dp"
|
||||
app:cardElevation="4dp"
|
||||
app:cardBackgroundColor="?attr/colorSurface">
|
||||
app:cardBackgroundColor="?attr/colorSurface"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
|
@ -15,5 +18,6 @@
|
|||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||
android:textAlignment="center" />
|
||||
android:textAlignment="center"
|
||||
tools:text="Popup text" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Customize your theme here. -->
|
||||
|
||||
<item name="colorSurface">@color/white</item>
|
||||
<item name="colorOnSurface">@color/black</item>
|
||||
<item name="textAppearanceBodyMedium">@style/TextAppearance.Material3.BodyMedium</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue