Fixed back navigation when cliked on chat message notification

This commit is contained in:
Sylvain Berfini 2021-10-27 14:58:58 +02:00
parent 137177d619
commit 23211f49ea
7 changed files with 21 additions and 19 deletions

View file

@ -16,13 +16,14 @@ Group changes to describe their impact on the project, as follows:
- Reply to chat message feature (with original message preview)
- Voice recordings in chat feature
- Allow video recording in chat file sharing
- Unread messages indicator in chat conversation that separates read & unread messages
- Notify incoming/outgoing calls on bluetooth devices using self-managed connections from telecom manager API
- New video call UI on foldable device like Galaxy Z Fold
- Setting to automatically record all calls
### Changed
- UI has been reworked around SlidingPane component to better handle tablets & foldable devices
- No longer scroll to bottom of chat room when new messages are received, a new button shows up to do it
- No longer scroll to bottom of chat room when new messages are received, a new button shows up to do it and it displays conversation's unread messages count
- Animations have been replaced to use com.google.android.material.transition ones
- Using new [Unified Content API](https://developer.android.com/about/versions/12/features/unified-content-api) to share files from keyboard (or other sources)
- Bumped dependencies, gradle updated from 4.2.2 to 7.0.2
@ -31,7 +32,8 @@ Group changes to describe their impact on the project, as follows:
### Fixed
- Chat notifications disappearing when app restarts
- "Infinite backstack", now each view is stored once (at most) in the backstack
- "Infinite backstack", now each view is stored (at most) once in the backstack
- Going back to the dialer when pressing back in a chat room after clicking on a chat message notification
### Removed
- Global push notification setting in Network, use the switch in each Account instead

View file

@ -24,7 +24,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.activity.addCallback
import androidx.core.view.doOnPreDraw
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
@ -56,10 +55,14 @@ abstract class GenericFragment<T : ViewDataBinding> : Fragment() {
return _binding!!.root
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun onResume() {
super.onResume()
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, onBackPressedCallback)
}
requireActivity().onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
override fun onPause() {
onBackPressedCallback.remove()
super.onPause()
}
override fun onStart() {
@ -90,7 +93,7 @@ abstract class GenericFragment<T : ViewDataBinding> : Fragment() {
}
}
} catch (ise: IllegalStateException) {
Log.e("[Generic Fragment] Can't go back: $ise")
Log.e("[Generic Fragment] [$this] Can't go back: $ise")
onBackPressedCallback.isEnabled = false
requireActivity().onBackPressed()
}

View file

@ -182,6 +182,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
registerComponentCallbacks(componentCallbacks)
findNavController(R.id.nav_host_fragment).addOnDestinationChangedListener(this)
@ -225,18 +226,6 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
tabsFragment.visibility = if (tabsFragmentVisible1 && tabsFragmentVisible2) View.VISIBLE else View.GONE
}
fun showTabsFragment() {
tabsFragment.visibility = View.VISIBLE
}
fun hideTabsFragment() {
tabsFragment.visibility = View.GONE
}
fun hideStatusFragment() {
statusFragment.visibility = View.GONE
}
private fun View.hideKeyboard() {
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(windowToken, 0)

View file

@ -57,5 +57,7 @@ class ListTopBarFragment : GenericFragment<ListEditTopBarFragmentBinding>() {
binding.setDeleteClickListener {
viewModel.deleteSelectionEvent.value = Event(true)
}
onBackPressedCallback.isEnabled = false
}
}

View file

@ -68,5 +68,7 @@ class StatusFragment : GenericFragment<StatusFragmentBinding>() {
binding.setRefreshClickListener {
viewModel.refreshRegister()
}
onBackPressedCallback.isEnabled = false
}
}

View file

@ -89,6 +89,8 @@ class TabsFragment : GenericFragment<TabsFragmentBinding>(), NavController.OnDes
}
navigateToChatRooms()
}
onBackPressedCallback.isEnabled = false
}
override fun onStart() {

View file

@ -113,6 +113,8 @@ class SideMenuFragment : GenericFragment<SideMenuFragmentBinding>() {
requireActivity().finishAndRemoveTask()
coreContext.stop()
}
onBackPressedCallback.isEnabled = false
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {