mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-19 12:38:07 +00:00
Improved toasts mechanism so they don't overlap
This commit is contained in:
parent
ae7c35c75d
commit
16dc339b2d
11 changed files with 113 additions and 92 deletions
|
|
@ -20,6 +20,8 @@
|
|||
package org.linphone.ui.assistant
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.UiThread
|
||||
|
|
@ -30,6 +32,8 @@ import androidx.lifecycle.lifecycleScope
|
|||
import org.linphone.LinphoneApplication
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.AssistantActivityBinding
|
||||
import org.linphone.databinding.ToastGreenBinding
|
||||
import org.linphone.databinding.ToastRedBinding
|
||||
import org.linphone.utils.slideInToastFromTopForDuration
|
||||
|
||||
@UiThread
|
||||
|
|
@ -49,18 +53,38 @@ class AssistantActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
fun showGreenToast(message: String, @DrawableRes icon: Int) {
|
||||
binding.greenToast.message = message
|
||||
binding.greenToast.icon = icon
|
||||
val greenToast: ToastGreenBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(this),
|
||||
R.layout.toast_green,
|
||||
binding.toastsArea,
|
||||
false
|
||||
)
|
||||
greenToast.message = message
|
||||
greenToast.icon = icon
|
||||
greenToast.root.visibility = View.GONE
|
||||
binding.toastsArea.addView(greenToast.root)
|
||||
|
||||
val target = binding.greenToast.root
|
||||
target.slideInToastFromTopForDuration(binding.root as ViewGroup, lifecycleScope)
|
||||
greenToast.root.slideInToastFromTopForDuration(
|
||||
binding.toastsArea as ViewGroup,
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
|
||||
fun showRedToast(message: String, @DrawableRes icon: Int) {
|
||||
binding.redToast.message = message
|
||||
binding.redToast.icon = icon
|
||||
val redToast: ToastRedBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(this),
|
||||
R.layout.toast_red,
|
||||
binding.toastsArea,
|
||||
false
|
||||
)
|
||||
redToast.message = message
|
||||
redToast.icon = icon
|
||||
redToast.root.visibility = View.GONE
|
||||
binding.toastsArea.addView(redToast.root)
|
||||
|
||||
val target = binding.redToast.root
|
||||
target.slideInToastFromTopForDuration(binding.root as ViewGroup, lifecycleScope)
|
||||
redToast.root.slideInToastFromTopForDuration(
|
||||
binding.toastsArea as ViewGroup,
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import android.annotation.SuppressLint
|
|||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.UiThread
|
||||
|
|
@ -36,6 +38,7 @@ import androidx.navigation.findNavController
|
|||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.MainActivityBinding
|
||||
import org.linphone.databinding.ToastGreenBinding
|
||||
import org.linphone.utils.slideInToastFromTopForDuration
|
||||
|
||||
@UiThread
|
||||
|
|
@ -136,11 +139,21 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
fun showGreenToast(message: String, @DrawableRes icon: Int) {
|
||||
binding.greenToast.message = message
|
||||
binding.greenToast.icon = icon
|
||||
val greenToast: ToastGreenBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(this),
|
||||
R.layout.toast_green,
|
||||
binding.toastsArea,
|
||||
false
|
||||
)
|
||||
greenToast.message = message
|
||||
greenToast.icon = icon
|
||||
greenToast.root.visibility = View.GONE
|
||||
binding.toastsArea.addView(greenToast.root)
|
||||
|
||||
val target = binding.greenToast.root
|
||||
target.slideInToastFromTopForDuration(binding.root as ViewGroup, lifecycleScope)
|
||||
greenToast.root.slideInToastFromTopForDuration(
|
||||
binding.toastsArea as ViewGroup,
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadContacts() {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
package org.linphone.ui.voip
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.UiThread
|
||||
|
|
@ -36,6 +38,9 @@ import androidx.navigation.fragment.findNavController
|
|||
import org.linphone.LinphoneApplication
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ToastBlueBinding
|
||||
import org.linphone.databinding.ToastGreenBinding
|
||||
import org.linphone.databinding.ToastRedBinding
|
||||
import org.linphone.databinding.VoipActivityBinding
|
||||
import org.linphone.ui.voip.fragment.ActiveCallFragmentDirections
|
||||
import org.linphone.ui.voip.fragment.AudioDevicesMenuDialogFragment
|
||||
|
|
@ -154,32 +159,63 @@ class VoipActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
fun showBlueToast(message: String, @DrawableRes icon: Int) {
|
||||
binding.blueToast.message = message
|
||||
binding.blueToast.icon = icon
|
||||
val blueToast: ToastBlueBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(this),
|
||||
R.layout.toast_blue,
|
||||
binding.toastsArea,
|
||||
false
|
||||
)
|
||||
blueToast.message = message
|
||||
blueToast.icon = icon
|
||||
blueToast.root.visibility = View.GONE
|
||||
binding.toastsArea.addView(blueToast.root)
|
||||
|
||||
val target = binding.blueToast.root
|
||||
target.slideInToastFromTopForDuration(binding.root as ViewGroup, lifecycleScope)
|
||||
blueToast.root.slideInToastFromTopForDuration(
|
||||
binding.toastsArea as ViewGroup,
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
|
||||
private fun showRedToast(message: String, @DrawableRes icon: Int) {
|
||||
binding.redToast.message = message
|
||||
binding.redToast.icon = icon
|
||||
val redToast: ToastRedBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(this),
|
||||
R.layout.toast_red,
|
||||
binding.toastsArea,
|
||||
false
|
||||
)
|
||||
redToast.message = message
|
||||
redToast.icon = icon
|
||||
redToast.root.visibility = View.GONE
|
||||
binding.toastsArea.addView(redToast.root)
|
||||
|
||||
val target = binding.redToast.root
|
||||
target.slideInToastFromTop(binding.root as ViewGroup, true)
|
||||
redToast.root.slideInToastFromTop(
|
||||
binding.toastsArea as ViewGroup,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
private fun hideRedToast() {
|
||||
val target = binding.redToast.root
|
||||
target.slideInToastFromTop(binding.root as ViewGroup, false)
|
||||
// TODO: improve
|
||||
binding.toastsArea.removeAllViews()
|
||||
}
|
||||
|
||||
private fun showGreenToast(message: String, @DrawableRes icon: Int) {
|
||||
binding.greenToast.message = message
|
||||
binding.greenToast.icon = icon
|
||||
val greenToast: ToastGreenBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(this),
|
||||
R.layout.toast_green,
|
||||
binding.toastsArea,
|
||||
false
|
||||
)
|
||||
greenToast.message = message
|
||||
greenToast.icon = icon
|
||||
greenToast.root.visibility = View.GONE
|
||||
binding.toastsArea.addView(greenToast.root)
|
||||
|
||||
val target = binding.greenToast.root
|
||||
target.slideInToastFromTopForDuration(binding.root as ViewGroup, lifecycleScope, 2000)
|
||||
greenToast.root.slideInToastFromTopForDuration(
|
||||
binding.toastsArea as ViewGroup,
|
||||
lifecycleScope,
|
||||
2000
|
||||
)
|
||||
}
|
||||
|
||||
private fun hideUI(hide: Boolean) {
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ class CallsViewModel @UiThread constructor() : ViewModel() {
|
|||
@WorkerThread
|
||||
override fun onNewAlertTriggered(core: Core, alert: Alert) {
|
||||
val remote = alert.call.remoteAddress.asStringUriOnly()
|
||||
// TODO: differentiate WiFi from Cellular
|
||||
Log.w("$TAG Alert of type [${alert.type}] triggered for call from [$remote]")
|
||||
alert.addListener(alertListener)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,11 +38,6 @@ fun View.slideInToastFromTop(
|
|||
visible: Boolean
|
||||
) {
|
||||
val view = this
|
||||
if (visible && view.visibility == View.VISIBLE) {
|
||||
// Toast is already visible, hide existing one first
|
||||
view.visibility = View.GONE
|
||||
}
|
||||
|
||||
val transition: Transition = Slide(Gravity.TOP)
|
||||
transition.duration = 600
|
||||
transition.addTarget(view)
|
||||
|
|
@ -58,11 +53,6 @@ fun View.slideInToastFromTopForDuration(
|
|||
duration: Long = 4000
|
||||
) {
|
||||
val view = this
|
||||
if (view.visibility == View.VISIBLE) {
|
||||
// Toast is already visible, hide existing one first
|
||||
view.visibility = View.GONE
|
||||
}
|
||||
|
||||
val transition: Transition = Slide(Gravity.TOP)
|
||||
transition.duration = 600
|
||||
transition.addTarget(view)
|
||||
|
|
@ -74,8 +64,7 @@ fun View.slideInToastFromTopForDuration(
|
|||
withContext(Dispatchers.IO) {
|
||||
delay(duration)
|
||||
withContext(Dispatchers.Main) {
|
||||
TransitionManager.beginDelayedTransition(root, transition)
|
||||
view.visibility = View.GONE
|
||||
root.removeView(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,26 +27,11 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/green_toast"
|
||||
android:visibility="gone"
|
||||
layout="@layout/toast_green"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/toast_top_margin"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
app:layout_constraintWidth_max="@dimen/toast_max_width"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<include
|
||||
android:id="@+id/red_toast"
|
||||
android:visibility="gone"
|
||||
layout="@layout/toast_red"
|
||||
<LinearLayout
|
||||
android:id="@+id/toasts_area"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="@dimen/toast_top_margin"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
|
|
|
|||
|
|
@ -31,12 +31,11 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/green_toast"
|
||||
android:visibility="gone"
|
||||
layout="@layout/toast_green"
|
||||
<LinearLayout
|
||||
android:id="@+id/toasts_area"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="@dimen/toast_top_margin"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="17dp"
|
||||
android:layout_marginEnd="17dp">
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="17dp"
|
||||
android:layout_marginEnd="17dp">
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="17dp"
|
||||
android:layout_marginEnd="17dp">
|
||||
|
||||
|
|
|
|||
|
|
@ -23,40 +23,11 @@
|
|||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/voip_nav_graph"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/blue_toast"
|
||||
android:visibility="gone"
|
||||
layout="@layout/toast_blue"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/toast_top_margin"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
app:layout_constraintWidth_max="@dimen/toast_max_width"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<include
|
||||
android:id="@+id/green_toast"
|
||||
android:visibility="gone"
|
||||
layout="@layout/toast_green"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/toast_top_margin"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
app:layout_constraintWidth_max="@dimen/toast_max_width"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<include
|
||||
android:id="@+id/red_toast"
|
||||
android:visibility="gone"
|
||||
layout="@layout/toast_red"
|
||||
<LinearLayout
|
||||
android:id="@+id/toasts_area"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="@dimen/toast_top_margin"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue