Skip to content
Snippets Groups Projects
Commit 5f5abdf5 authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Handled navigation to search screen from connection invitation

parent abcb594f
Branches
Tags
3 merge requests!84Version 2.92 build 629,!77v2.9 b627,!72FE-948: Invite Friend
This commit is part of merge request !72. Comments created here will be created in the context of that merge request.
......@@ -121,6 +121,16 @@ class UsernameSearchFragment : FactSearchFragment() {
}
override fun getSearchTabUi(): FactSearchUi = searchViewModel.usernameSearchUi
override fun onResume() {
super.onResume()
searchViewModel.invitationFrom.observe(viewLifecycleOwner) { username ->
username?.let {
onSearchClicked(it)
searchViewModel.onInvitationHandled()
}
}
}
}
class EmailSearchFragment : FactSearchFragment() {
......
......@@ -52,6 +52,9 @@ class UserSearchFragment : RequestsFragment() {
override val navController: NavController by lazy {
findNavController()
}
private val invitationUsername: String? by lazy {
UserSearchFragmentArgs.fromBundle(requireArguments()).username
}
override fun onAttach(context: Context) {
super.onAttach(context)
......@@ -161,9 +164,16 @@ class UserSearchFragment : RequestsFragment() {
override fun onStart() {
super.onStart()
handleInvitation()
observeUi()
}
private fun handleInvitation() {
invitationUsername?.let {
searchViewModel.onInvitationReceived(it)
}
}
private fun observeUi() {
searchViewModel.udSearchUi.observe(viewLifecycleOwner) { state ->
binding.ui = state
......
......@@ -206,6 +206,9 @@ class UserSearchViewModel @Inject constructor(
private var searchJob: Job? = null
val invitationFrom: LiveData<String?> by ::_invitationFrom
private val _invitationFrom = MutableLiveData<String?>(null)
init {
showNewUserPopups()
}
......@@ -271,6 +274,14 @@ class UserSearchViewModel @Inject constructor(
repo.enableDummyTraffic(enabled)
}
fun onInvitationReceived(username: String) {
_invitationFrom.value = username
}
fun onInvitationHandled() {
_invitationFrom.value = null
}
suspend fun onUsernameSearch(username: String?): Flow<List<RequestItem>> {
_usernameResults.value = listOf()
val factQuery = FactQuery.UsernameQuery(username)
......
......@@ -19,7 +19,9 @@ import io.xxlabs.messenger.support.isMockVersion
import io.xxlabs.messenger.support.util.Utils
import io.xxlabs.messenger.ui.base.BaseInjectorActivity
import io.xxlabs.messenger.ui.main.MainActivity
import io.xxlabs.messenger.ui.main.MainActivity.Companion.INTENT_INVITATION
import io.xxlabs.messenger.ui.main.MainActivity.Companion.INTENT_NOTIFICATION_CLICK
import timber.log.Timber
import javax.inject.Inject
class SplashScreenPlaceholderActivity : BaseInjectorActivity() {
......@@ -54,6 +56,26 @@ class SplashScreenPlaceholderActivity : BaseInjectorActivity() {
}
private fun handleIntent(intent: Intent) {
if (Intent.ACTION_VIEW == intent.action) {
// Implicit Intent from an invitation link
intent.data?.getQueryParameter("username")?.let { username ->
invitationIntent(username)
}
} else notificationIntent(intent)
}
private fun invitationIntent(username: String) {
// Invitations can only be handled if the user has an account.
if (preferencesRepository.name.isNotEmpty()) {
val intent = Intent(this, MainActivity::class.java).apply {
putExtra(INTENT_INVITATION, username)
}
startActivity(intent)
finish()
}
}
private fun notificationIntent(intent: Intent) {
// Pass this intent on to MainActivity.
mainIntent = intent.getBundleExtra(INTENT_NOTIFICATION_CLICK)?.let {
Intent(
......
......@@ -19,6 +19,7 @@ import androidx.lifecycle.*
import androidx.lifecycle.Observer
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import androidx.navigation.ui.onNavDestinationSelected
import com.bumptech.glide.Glide
import com.google.android.material.shape.CornerFamily
......@@ -164,8 +165,23 @@ class MainActivity : MediaProviderActivity(), SnackBarActivity, CustomToastActiv
private fun handleIntent(intent: Intent) {
intent.getBundleExtra(INTENT_NOTIFICATION_CLICK)?.let {
// PendingIntent from notifications
handleNotification(it)
return
}
intent.getStringExtra(INTENT_INVITATION)?.let { username ->
// Implicit intent from an invitation link
invitationIntent(username)
return
}
}
private fun invitationIntent(username: String) {
val userSearch = NavMainDirections.actionGlobalConnectionInvitation().apply {
this.username = username
}
mainNavController.navigateSafe(userSearch)
}
private fun handleNotification(bundle: Bundle) {
......@@ -811,6 +827,7 @@ class MainActivity : MediaProviderActivity(), SnackBarActivity, CustomToastActiv
const val INTENT_PRIVATE_CHAT = "private_message"
const val INTENT_GROUP_CHAT = "group_message"
const val INTENT_REQUEST = "request"
const val INTENT_INVITATION = "invitation"
private var activeInstances = 0
override fun activeInstancesCount(): Int {
......
......@@ -320,6 +320,11 @@
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<argument
android:name="username"
app:argType="string"
app:nullable="true"
android:defaultValue="@null" />
</fragment>
<fragment
......@@ -354,6 +359,15 @@
android:label="UdProfileFragment"
tools:layout="@layout/fragment_ud_profile" />
<action
android:id="@+id/action_global_connection_invitation"
app:destination="@id/udPrivateSearchFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_global_contact_invitation"
app:destination="@id/contactInvitationFragment"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment