From 272bf585cc457a96bbb7fc4bc65755c8452bccdc Mon Sep 17 00:00:00 2001 From: Shailesh Baldaniya Date: Sun, 16 Dec 2018 08:50:27 +0530 Subject: [PATCH 01/16] feat : Initial Dynamic link --- app/build.gradle | 1 + app/google-services.json | 20 ++--- .../android/app/RocketChatApplication.kt | 3 + .../ui/AuthenticationActivity.kt | 22 ++++++ .../android/chatrooms/ui/ChatRoomsFragment.kt | 17 ++++- .../android/contacts/ContactsFragment.kt | 73 +++++++++++++++++++ .../chat/rocket/android/helper/Constants.kt | 2 + .../res/layout/fragment_contact_parent.xml | 31 ++++++++ app/src/main/res/values/strings.xml | 1 + .../rocket/android/helper/SmartLockHelper.kt | 2 +- build.gradle | 2 +- dependencies.gradle | 10 ++- 12 files changed, 164 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9f4dd685b1..c3ed1ed7c5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -160,6 +160,7 @@ dependencies { playImplementation libraries.playServicesAuth playImplementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') { transitive = true } playImplementation('com.crashlytics.sdk.android:answers:1.4.3@aar') { transitive = true } + playImplementation libraries.dynamiclinks testImplementation libraries.junit testImplementation libraries.truth diff --git a/app/google-services.json b/app/google-services.json index 19eb910d1b..ecb8471b47 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -1,27 +1,27 @@ { "project_info": { - "project_number": "528542541788", - "firebase_url": "https://veranda-1d914.firebaseio.com", - "project_id": "veranda-1d914", - "storage_bucket": "veranda-1d914.appspot.com" + "project_number": "855027673764", + "firebase_url": "https://dynamiclinks-test-35c22.firebaseio.com", + "project_id": "dynamiclinks-test-35c22", + "storage_bucket": "dynamiclinks-test-35c22.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:528542541788:android:3b5032d671a29f81", + "mobilesdk_app_id": "1:855027673764:android:3b5032d671a29f81", "android_client_info": { "package_name": "chat.veranda.android" } }, "oauth_client": [ { - "client_id": "528542541788-0dv75a3mndkcbj9iji7lemh8hjo5njt1.apps.googleusercontent.com", + "client_id": "855027673764-tea1nqbjijv9sgsv8tvkf8crpgpl9h8b.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyDc2nC-kdBgnT1v8W2oz24TKvWAyij-h80" + "current_key": "AIzaSyA0ayomxX0RnIv2TkV0MtFbIJzSAqn_Qgk" } ], "services": { @@ -39,20 +39,20 @@ }, { "client_info": { - "mobilesdk_app_id": "1:528542541788:android:05d0047069ea8c30", + "mobilesdk_app_id": "1:855027673764:android:05d0047069ea8c30", "android_client_info": { "package_name": "chat.veranda.android.dev" } }, "oauth_client": [ { - "client_id": "528542541788-0dv75a3mndkcbj9iji7lemh8hjo5njt1.apps.googleusercontent.com", + "client_id": "855027673764-tea1nqbjijv9sgsv8tvkf8crpgpl9h8b.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyDc2nC-kdBgnT1v8W2oz24TKvWAyij-h80" + "current_key": "AIzaSyA0ayomxX0RnIv2TkV0MtFbIJzSAqn_Qgk" } ], "services": { diff --git a/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt b/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt index 8574f665bd..c4c9e172d2 100644 --- a/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt +++ b/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt @@ -32,6 +32,7 @@ import chat.rocket.core.internal.rest.getCustomEmojis import com.facebook.drawee.backends.pipeline.DraweeConfig import com.facebook.drawee.backends.pipeline.Fresco import com.facebook.imagepipeline.core.ImagePipelineConfig +import com.google.firebase.FirebaseApp import com.jakewharton.threetenabp.AndroidThreeTen import dagger.android.DispatchingAndroidInjector import dagger.android.HasActivityInjector @@ -99,6 +100,8 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje AndroidThreeTen.init(this) + FirebaseApp.initializeApp(this) + setupFabric(this) setupFresco() setupTimber() diff --git a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt index 7e23411eea..97dde2f155 100644 --- a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt +++ b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt @@ -2,9 +2,11 @@ package chat.rocket.android.authentication.ui import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import chat.rocket.android.R @@ -12,8 +14,12 @@ import chat.rocket.android.analytics.event.ScreenViewEvent import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo import chat.rocket.android.authentication.domain.model.getLoginDeepLinkInfo import chat.rocket.android.authentication.presentation.AuthenticationPresenter +import chat.rocket.android.helper.Constants +import chat.rocket.android.helper.SharedPreferenceHelper +import chat.rocket.android.util.TimberLogger import chat.rocket.android.util.extensions.addFragment import chat.rocket.common.util.ifNull +import com.google.firebase.dynamiclinks.FirebaseDynamicLinks import dagger.android.AndroidInjection import dagger.android.AndroidInjector import dagger.android.DispatchingAndroidInjector @@ -35,6 +41,7 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { setContentView(R.layout.activity_authentication) setupToolbar() loadCredentials() + getDynamicLink() } private fun setupToolbar() { @@ -104,6 +111,21 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { } private fun showChatList() = presenter.toChatList() + + private fun getDynamicLink() { + FirebaseDynamicLinks.getInstance() + .getDynamicLink(intent) + .addOnSuccessListener(this) { pendingDynamicLinkData -> + var deepLink: Uri? = null + if (pendingDynamicLinkData != null) { + deepLink = pendingDynamicLinkData.link + } + + TimberLogger.debug("DeepLink : deepLink.toString()") + SharedPreferenceHelper.putString(Constants.DEEP_LINK, deepLink.toString()) + } + .addOnFailureListener(this) { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } + } } const val INTENT_ADD_NEW_SERVER = "INTENT_ADD_NEW_SERVER" diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 828283a6af..87c0b56c5c 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -10,8 +10,6 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import android.widget.CheckBox -import android.widget.RadioGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible @@ -46,12 +44,12 @@ import javax.inject.Inject // WIDECHAT import android.graphics.Color -import android.widget.ImageView -import android.widget.TextView +import android.widget.* import chat.rocket.android.helper.UserHelper import chat.rocket.android.profile.ui.ProfileFragment import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.settings.ui.SettingsFragment +import chat.rocket.android.util.TimberLogger import chat.rocket.android.util.extensions.avatarUrl import com.facebook.drawee.view.SimpleDraweeView import kotlinx.android.synthetic.main.app_bar.* @@ -90,6 +88,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { private var searchCloseButton: ImageView? = null private var profileButton: SimpleDraweeView? = null private var onlineStatusButton:ImageView?=null + private var deepLink: String? = null // handles that recurring connection status bug in widechat private var currentlyConnected: Boolean? = false @@ -115,6 +114,16 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { chatRoomId = null } } + getDeepLink() + } + + private fun getDeepLink() { + deepLink = SharedPreferenceHelper.getString(Constants.DEEP_LINK, "null") + SharedPreferenceHelper.remove(Constants.DEEP_LINK) + TimberLogger.debug("Retrieved deep link on ChatRooms : $deepLink") + Toast.makeText(context, "Retrieved : $deepLink", Toast.LENGTH_SHORT).show() + + //Navigate to ChatRoom } override fun onDestroy() { diff --git a/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt b/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt index 8c48196162..cb81121c90 100644 --- a/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt +++ b/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt @@ -1,11 +1,14 @@ package chat.rocket.android.contacts import android.Manifest +import android.content.Intent import android.content.pm.PackageManager import android.graphics.Color +import android.net.Uri import android.os.Bundle import android.view.* import android.widget.ImageView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat @@ -39,6 +42,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.rxkotlin.subscribeBy import io.reactivex.schedulers.Schedulers import javax.inject.Inject +import com.google.firebase.dynamiclinks.DynamicLink +import com.google.firebase.dynamiclinks.FirebaseDynamicLinks +import com.google.firebase.dynamiclinks.ShortDynamicLink +import kotlinx.android.synthetic.main.fragment_contact_parent.view.* /** * Load a list of contacts in a recycler view @@ -58,6 +65,15 @@ class ContactsFragment : Fragment() { */ private var contactArrayList: ArrayList = ArrayList() + /** + * The mapping of contacts with their registration status + */ + private var contactHashMap: HashMap = HashMap() + + private val MY_PERMISSIONS_REQUEST_RW_CONTACTS = 0 + + private var createNewChannelLink: View? = null + private var shareViaAnotherApp: View? = null private var searchView: SearchView? = null private var sortView: MenuItem? = null private var searchIcon: ImageView? = null @@ -110,6 +126,37 @@ class ContactsFragment : Fragment() { this.recyclerView = view.findViewById(R.id.recycler_view) this.emptyTextView = view.findViewById(R.id.text_no_data_to_display) getContactsPermissions() + + shareViaAnotherApp = view.findViewById(R.id.share_via_another_app) + shareViaAnotherApp!!.setOnClickListener { _ -> + + FirebaseDynamicLinks.getInstance().createDynamicLink() + .setLink(Uri.parse("https://open.rocket.chat/direct/Shailesh351")) + .setDomainUriPrefix("https://dylinktesting.page.link") + .setAndroidParameters( + DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) + .setSocialMetaTagParameters( + DynamicLink.SocialMetaTagParameters.Builder() + .setTitle("Shailesh351") + .setDescription("Chat with Shailesh on Rocket.Chat") + .build()) + .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) + .addOnSuccessListener { result -> + val link = result.shortLink.toString() + Toast.makeText(context, link, Toast.LENGTH_SHORT).show() + + val shareIntent = Intent() + shareIntent.action = Intent.ACTION_SEND + shareIntent.putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") + shareIntent.type = "text/plain" + startActivity(shareIntent, null) + + }.addOnFailureListener { + // Error + Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() + } + } + return view } @@ -341,4 +388,30 @@ class ContactsFragment : Fragment() { finalList.add(inviteItemHolder("invite")) return finalList } + + companion object { + + /** + * Create a new ContactList fragment that displays the given list of contacts + * + * @param contactArrayList the list of contacts to load in the recycler view + * @param contactHashMap the mapping of contacts with their registration status + * @return the newly created ContactList fragment + */ + fun newInstance( + contactArrayList: ArrayList, + contactHashMap: HashMap + ): ContactsFragment { + val contactsFragment = ContactsFragment() + + val arguments = Bundle() + arguments.putParcelableArrayList("CONTACT_ARRAY_LIST", contactArrayList) + arguments.putSerializable("CONTACT_HASH_MAP", contactHashMap) + + contactsFragment.arguments = arguments + + return contactsFragment + } + } + } diff --git a/app/src/main/java/chat/rocket/android/helper/Constants.kt b/app/src/main/java/chat/rocket/android/helper/Constants.kt index c9edd8079d..6206f901bb 100644 --- a/app/src/main/java/chat/rocket/android/helper/Constants.kt +++ b/app/src/main/java/chat/rocket/android/helper/Constants.kt @@ -15,6 +15,8 @@ object Constants { // Use both WIDECHAT and WIDECHAT_DEV switches == true to allow for normal RC login sequence including login to any server const val WIDECHAT = true const val WIDECHAT_DEV = false + + const val DEEP_LINK = "deep_link" } object ChatRoomsSortOrder { diff --git a/app/src/main/res/layout/fragment_contact_parent.xml b/app/src/main/res/layout/fragment_contact_parent.xml index d975818522..711033f1ab 100644 --- a/app/src/main/res/layout/fragment_contact_parent.xml +++ b/app/src/main/res/layout/fragment_contact_parent.xml @@ -31,4 +31,35 @@ android:visibility="gone" android:background="?android:attr/listDivider" /> + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 88768162f0..4dd9ead8eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -363,6 +363,7 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin Delete My Account Log Out New Group Chat + Share via another App You Can get started by searching for people to chat with or by inviting your friends and family to get the app too. Welcome to Viasat Connect. diff --git a/app/src/play/java/chat/rocket/android/helper/SmartLockHelper.kt b/app/src/play/java/chat/rocket/android/helper/SmartLockHelper.kt index 6ca1a19e0b..080de37593 100644 --- a/app/src/play/java/chat/rocket/android/helper/SmartLockHelper.kt +++ b/app/src/play/java/chat/rocket/android/helper/SmartLockHelper.kt @@ -45,7 +45,7 @@ object SmartLockHelper { .addOnCompleteListener { when { it.isSuccessful -> { - credential = it.result.credential + credential = it.result!!.credential } it.exception is ResolvableApiException -> { val resolvableApiException = (it.exception as ResolvableApiException) diff --git a/build.gradle b/build.gradle index 1e7c4eb179..9b7e7eed76 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" classpath "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}" - classpath 'com.google.gms:google-services:4.1.0' + classpath 'com.google.gms:google-services:4.0.1' classpath 'io.fabric.tools:gradle:1.25.4' classpath "com.github.ben-manes:gradle-versions-plugin:0.20.0" diff --git a/dependencies.gradle b/dependencies.gradle index e7ce68b712..46288d24e2 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -21,9 +21,10 @@ ext { workmanager : '1.0.0-alpha09', dagger : '2.16', - firebaseCloudMessage : '17.3.0', - firebaseAnalytics : '16.0.3', - playServices : '16.0.0', + firebaseCloudMessage : '17.3.4', + firebaseAnalytics : '16.0.6', + dynamiclinks : '16.1.5', + playServices : '16.0.1', exoPlayer : '2.8.2', flexbox : '1.1.0', material : '1.0.0-beta01', @@ -54,7 +55,7 @@ ext { // For wearable wear : '2.3.0', - playServicesWearable : '15.0.1', + playServicesWearable : '16.0.1', supportWearable : '27.1.1', // For testing @@ -127,6 +128,7 @@ ext { fcm : "com.google.firebase:firebase-messaging:${versions.firebaseCloudMessage}", firebaseAnalytics : "com.google.firebase:firebase-core:${versions.firebaseAnalytics}", playServicesAuth : "com.google.android.gms:play-services-auth:${versions.playServices}", + dynamiclinks : "com.google.firebase:firebase-dynamic-links:${versions.dynamiclinks}", // For wearable wearable : "com.google.android.support:wearable:${versions.wear}", From b7705f20c905b21fe3a0c55af36fcb294c5dc126 Mon Sep 17 00:00:00 2001 From: Shailesh Baldaniya Date: Fri, 11 Jan 2019 13:25:45 +0530 Subject: [PATCH 02/16] feat: Add dynamic link support --- .../android/chatrooms/ui/ChatRoomsFragment.kt | 59 ++++++++++++++--- .../chatrooms/viewmodel/ChatRoomsViewModel.kt | 14 ++++ .../android/contacts/ContactsFragment.kt | 65 +++++++++++++++++++ .../contacts/di/ContactsFragmentProvider.kt | 12 ++++ .../chat/rocket/android/db/ChatRoomDao.kt | 1 - 5 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 87c0b56c5c..6e103d1302 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -44,7 +44,9 @@ import javax.inject.Inject // WIDECHAT import android.graphics.Color +import android.net.Uri import android.widget.* +import chat.rocket.android.chatrooms.adapter.model.RoomUiModel import chat.rocket.android.helper.UserHelper import chat.rocket.android.profile.ui.ProfileFragment import chat.rocket.android.server.domain.GetCurrentServerInteractor @@ -114,16 +116,6 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { chatRoomId = null } } - getDeepLink() - } - - private fun getDeepLink() { - deepLink = SharedPreferenceHelper.getString(Constants.DEEP_LINK, "null") - SharedPreferenceHelper.remove(Constants.DEEP_LINK) - TimberLogger.debug("Retrieved deep link on ChatRooms : $deepLink") - Toast.makeText(context, "Retrieved : $deepLink", Toast.LENGTH_SHORT).show() - - //Navigate to ChatRoom } override fun onDestroy() { @@ -156,6 +148,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { setupToolbar() setupFab() + getDeepLink() analyticsManager.logScreenView(ScreenViewEvent.ChatRooms) } @@ -524,4 +517,50 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { transaction?.addToBackStack("contactsFragment")?.commit(); } } + + private fun getDeepLink() { + + deepLink = SharedPreferenceHelper.getString(Constants.DEEP_LINK, "null") + SharedPreferenceHelper.remove(Constants.DEEP_LINK) + TimberLogger.debug("Retrieved deep link on ChatRooms : $deepLink") + + if(deepLink.isNullOrBlank() || deepLink.equals("null")){ + return + } else { + Toast.makeText(context, "Deep link : $deepLink", Toast.LENGTH_SHORT).show() + } + + val uri = Uri.parse(deepLink) + val username = uri.lastPathSegment + + username.ifNotNullNorEmpty { + val localRooms = viewModel.getChatRoomOfUsernameDB(username!!) + val filteredLocalRooms = localRooms.filter { itemHolder -> itemHolder.data is RoomUiModel && (itemHolder.data as RoomUiModel).username == username } + + if (filteredLocalRooms.isNotEmpty()) { + presenter.loadChatRoom(filteredLocalRooms.first().data as RoomUiModel) + } else { + //check from spotlight when connected + val statusLiveData = viewModel.getStatus() + statusLiveData.observe(viewLifecycleOwner, object: Observer{ + override fun onChanged(status: State?) { + if (status is State.Connected) { + val rooms = viewModel.getChatRoomOfUsernameSpotlight(username) + val filteredRooms = rooms?.filter { itemHolder -> itemHolder.data is RoomUiModel && (itemHolder.data as RoomUiModel).username == username } + + filteredRooms?.let { + if (filteredRooms.isNotEmpty()) { + presenter.loadChatRoom(filteredRooms.first().data as RoomUiModel) + } else { + Toast.makeText(context, "User not found or No internet connection", Toast.LENGTH_SHORT).show() + } + } + + statusLiveData.removeObserver(this) + } + } + }) + } + } + } } diff --git a/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt b/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt index de2a9217df..086d23999f 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt @@ -83,6 +83,20 @@ class ChatRoomsViewModel( } } + fun getChatRoomOfUsernameDB(string: String): List> { + val rooms = async(CommonPool) { + return@async repository.search(string).let { mapper.map(it, showLastMessage = showLastMessage) } + } + return runBlocking { rooms.await() } + } + + fun getChatRoomOfUsernameSpotlight(string: String): List>? { + val rooms = async(CommonPool) { + return@async spotlight(string)?.let { mapper.map(it, showLastMessage = showLastMessage) } + } + return runBlocking { rooms.await() } + } + private suspend fun spotlight(query: String): SpotlightResult? { return try { retryIO { client.spotlight(query) } diff --git a/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt b/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt index cb81121c90..496bde1cb9 100644 --- a/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt +++ b/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt @@ -17,12 +17,15 @@ import chat.rocket.android.R import chat.rocket.android.contacts.models.Contact import chat.rocket.android.main.ui.MainActivity import chat.rocket.android.util.extension.onQueryTextListener +import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.app_bar.* import java.util.ArrayList import kotlin.collections.HashMap // WIDECHAT import chat.rocket.android.helper.Constants +import chat.rocket.android.server.domain.GetAccountInteractor +import chat.rocket.android.server.domain.GetCurrentServerInteractor import com.facebook.drawee.view.SimpleDraweeView import android.view.LayoutInflater import android.widget.TextView @@ -46,11 +49,21 @@ import com.google.firebase.dynamiclinks.DynamicLink import com.google.firebase.dynamiclinks.FirebaseDynamicLinks import com.google.firebase.dynamiclinks.ShortDynamicLink import kotlinx.android.synthetic.main.fragment_contact_parent.view.* +import kotlinx.coroutines.experimental.launch +import javax.inject.Inject /** * Load a list of contacts in a recycler view */ class ContactsFragment : Fragment() { + + @Inject + lateinit var serverInteractor: GetCurrentServerInteractor + + @Inject + lateinit var getAccountInteractor: GetAccountInteractor + + /** @Inject lateinit var dbFactory: DatabaseManagerFactory @Inject @@ -389,6 +402,58 @@ class ContactsFragment : Fragment() { return finalList } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.fragment_contact_parent, container, false) + + createNewChannelLink = view.findViewById(R.id.create_new_channel_button) + createNewChannelLink!!.setOnClickListener { + val createChannelFragment = CreateChannelFragment() + val transaction = activity?.supportFragmentManager?.beginTransaction(); + transaction?.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); + transaction?.replace(this.id, createChannelFragment, "createChannelFragment"); + transaction?.addToBackStack(null)?.commit(); + } + + shareViaAnotherApp = view.findViewById(R.id.share_via_another_app) + shareViaAnotherApp!!.setOnClickListener { _ -> + + launch { + //get serverUrl and username + val server = serverInteractor.get()!! + val account = getAccountInteractor.get(server)!! + val userName = account.userName + + FirebaseDynamicLinks.getInstance().createDynamicLink() + .setLink(Uri.parse("$server/direct/$userName")) + .setDomainUriPrefix("https://dylinktesting.page.link") + .setAndroidParameters( + DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) + .setSocialMetaTagParameters( + DynamicLink.SocialMetaTagParameters.Builder() + .setTitle(userName) + .setDescription("Chat with $userName on Rocket.Chat") + .build()) + .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) + .addOnSuccessListener { result -> + val link = result.shortLink.toString() + Toast.makeText(context, link, Toast.LENGTH_SHORT).show() + + val shareIntent = Intent() + shareIntent.action = Intent.ACTION_SEND + shareIntent.putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") + shareIntent.type = "text/plain" + startActivity(shareIntent, null) + + }.addOnFailureListener { + // Error + Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() + } + } + } + + return view + } + companion object { /** diff --git a/app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt b/app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt new file mode 100644 index 0000000000..08b65227ed --- /dev/null +++ b/app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt @@ -0,0 +1,12 @@ +package chat.rocket.android.contacts.di + +import chat.rocket.android.contacts.ContactsFragment +import dagger.Module +import dagger.android.ContributesAndroidInjector + +@Module +abstract class ContactsFragmentProvider { + + @ContributesAndroidInjector() + abstract fun provideContactsFragment(): ContactsFragment +} \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt b/app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt index 2651e3f4df..383a94ba96 100644 --- a/app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt +++ b/app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt @@ -9,7 +9,6 @@ import androidx.room.Transaction import androidx.room.Update import chat.rocket.android.db.model.ChatRoom import chat.rocket.android.db.model.ChatRoomEntity -import chat.rocket.common.model.RoomType @Dao abstract class ChatRoomDao : BaseDao { From 7d80ca4ce912f77b39f2574b78d35a28f8fa2dfc Mon Sep 17 00:00:00 2001 From: Shailesh Baldaniya Date: Fri, 11 Jan 2019 15:21:57 +0530 Subject: [PATCH 03/16] fix: Fix conflicts --- .../android/contacts/ContactsFragment.kt | 139 +----------------- .../adapter/ContactRecyclerViewAdapter.kt | 8 +- .../contacts/di/ContactsFragmentProvider.kt | 12 -- .../main/presentation/MainPresenter.kt | 42 ++++++ .../res/layout/fragment_contact_parent.xml | 59 ++------ 5 files changed, 58 insertions(+), 202 deletions(-) delete mode 100644 app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt diff --git a/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt b/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt index 496bde1cb9..a908dbc22c 100644 --- a/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt +++ b/app/src/main/java/chat/rocket/android/contacts/ContactsFragment.kt @@ -1,14 +1,11 @@ package chat.rocket.android.contacts import android.Manifest -import android.content.Intent import android.content.pm.PackageManager import android.graphics.Color -import android.net.Uri import android.os.Bundle import android.view.* import android.widget.ImageView -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat @@ -17,15 +14,12 @@ import chat.rocket.android.R import chat.rocket.android.contacts.models.Contact import chat.rocket.android.main.ui.MainActivity import chat.rocket.android.util.extension.onQueryTextListener -import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.app_bar.* import java.util.ArrayList import kotlin.collections.HashMap // WIDECHAT import chat.rocket.android.helper.Constants -import chat.rocket.android.server.domain.GetAccountInteractor -import chat.rocket.android.server.domain.GetCurrentServerInteractor import com.facebook.drawee.view.SimpleDraweeView import android.view.LayoutInflater import android.widget.TextView @@ -45,48 +39,28 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.rxkotlin.subscribeBy import io.reactivex.schedulers.Schedulers import javax.inject.Inject -import com.google.firebase.dynamiclinks.DynamicLink -import com.google.firebase.dynamiclinks.FirebaseDynamicLinks -import com.google.firebase.dynamiclinks.ShortDynamicLink -import kotlinx.android.synthetic.main.fragment_contact_parent.view.* -import kotlinx.coroutines.experimental.launch -import javax.inject.Inject /** * Load a list of contacts in a recycler view */ class ContactsFragment : Fragment() { - @Inject - lateinit var serverInteractor: GetCurrentServerInteractor - - @Inject - lateinit var getAccountInteractor: GetAccountInteractor - - /** @Inject lateinit var dbFactory: DatabaseManagerFactory + @Inject lateinit var serverInteractor: GetCurrentServerInteractor + private var recyclerView :RecyclerView? = null private var emptyTextView: TextView? = null - private val MY_PERMISSIONS_REQUEST_RW_CONTACTS = 0 - /** * The list of contacts to load in the recycler view */ private var contactArrayList: ArrayList = ArrayList() - /** - * The mapping of contacts with their registration status - */ - private var contactHashMap: HashMap = HashMap() - private val MY_PERMISSIONS_REQUEST_RW_CONTACTS = 0 - private var createNewChannelLink: View? = null - private var shareViaAnotherApp: View? = null private var searchView: SearchView? = null private var sortView: MenuItem? = null private var searchIcon: ImageView? = null @@ -139,37 +113,6 @@ class ContactsFragment : Fragment() { this.recyclerView = view.findViewById(R.id.recycler_view) this.emptyTextView = view.findViewById(R.id.text_no_data_to_display) getContactsPermissions() - - shareViaAnotherApp = view.findViewById(R.id.share_via_another_app) - shareViaAnotherApp!!.setOnClickListener { _ -> - - FirebaseDynamicLinks.getInstance().createDynamicLink() - .setLink(Uri.parse("https://open.rocket.chat/direct/Shailesh351")) - .setDomainUriPrefix("https://dylinktesting.page.link") - .setAndroidParameters( - DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) - .setSocialMetaTagParameters( - DynamicLink.SocialMetaTagParameters.Builder() - .setTitle("Shailesh351") - .setDescription("Chat with Shailesh on Rocket.Chat") - .build()) - .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) - .addOnSuccessListener { result -> - val link = result.shortLink.toString() - Toast.makeText(context, link, Toast.LENGTH_SHORT).show() - - val shareIntent = Intent() - shareIntent.action = Intent.ACTION_SEND - shareIntent.putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") - shareIntent.type = "text/plain" - startActivity(shareIntent, null) - - }.addOnFailureListener { - // Error - Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() - } - } - return view } @@ -401,82 +344,4 @@ class ContactsFragment : Fragment() { finalList.add(inviteItemHolder("invite")) return finalList } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = inflater.inflate(R.layout.fragment_contact_parent, container, false) - - createNewChannelLink = view.findViewById(R.id.create_new_channel_button) - createNewChannelLink!!.setOnClickListener { - val createChannelFragment = CreateChannelFragment() - val transaction = activity?.supportFragmentManager?.beginTransaction(); - transaction?.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); - transaction?.replace(this.id, createChannelFragment, "createChannelFragment"); - transaction?.addToBackStack(null)?.commit(); - } - - shareViaAnotherApp = view.findViewById(R.id.share_via_another_app) - shareViaAnotherApp!!.setOnClickListener { _ -> - - launch { - //get serverUrl and username - val server = serverInteractor.get()!! - val account = getAccountInteractor.get(server)!! - val userName = account.userName - - FirebaseDynamicLinks.getInstance().createDynamicLink() - .setLink(Uri.parse("$server/direct/$userName")) - .setDomainUriPrefix("https://dylinktesting.page.link") - .setAndroidParameters( - DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) - .setSocialMetaTagParameters( - DynamicLink.SocialMetaTagParameters.Builder() - .setTitle(userName) - .setDescription("Chat with $userName on Rocket.Chat") - .build()) - .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) - .addOnSuccessListener { result -> - val link = result.shortLink.toString() - Toast.makeText(context, link, Toast.LENGTH_SHORT).show() - - val shareIntent = Intent() - shareIntent.action = Intent.ACTION_SEND - shareIntent.putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") - shareIntent.type = "text/plain" - startActivity(shareIntent, null) - - }.addOnFailureListener { - // Error - Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() - } - } - } - - return view - } - - companion object { - - /** - * Create a new ContactList fragment that displays the given list of contacts - * - * @param contactArrayList the list of contacts to load in the recycler view - * @param contactHashMap the mapping of contacts with their registration status - * @return the newly created ContactList fragment - */ - fun newInstance( - contactArrayList: ArrayList, - contactHashMap: HashMap - ): ContactsFragment { - val contactsFragment = ContactsFragment() - - val arguments = Bundle() - arguments.putParcelableArrayList("CONTACT_ARRAY_LIST", contactArrayList) - arguments.putSerializable("CONTACT_HASH_MAP", contactHashMap) - - contactsFragment.arguments = arguments - - return contactsFragment - } - } - } diff --git a/app/src/main/java/chat/rocket/android/contacts/adapter/ContactRecyclerViewAdapter.kt b/app/src/main/java/chat/rocket/android/contacts/adapter/ContactRecyclerViewAdapter.kt index 05324c77f3..9ad8ac6ece 100644 --- a/app/src/main/java/chat/rocket/android/contacts/adapter/ContactRecyclerViewAdapter.kt +++ b/app/src/main/java/chat/rocket/android/contacts/adapter/ContactRecyclerViewAdapter.kt @@ -1,6 +1,5 @@ package chat.rocket.android.contacts.adapter -import android.content.Intent import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import chat.rocket.android.R @@ -88,12 +87,7 @@ class ContactRecyclerViewAdapter( } private fun shareApp() { - with(Intent(Intent.ACTION_SEND)) { - type = "text/plain" - putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) - putExtra(Intent.EXTRA_TEXT, context.getString(R.string.play_store_link)) - context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) - } + context.presenter.shareViaApp(context) } companion object { diff --git a/app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt b/app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt deleted file mode 100644 index 08b65227ed..0000000000 --- a/app/src/main/java/chat/rocket/android/contacts/di/ContactsFragmentProvider.kt +++ /dev/null @@ -1,12 +0,0 @@ -package chat.rocket.android.contacts.di - -import chat.rocket.android.contacts.ContactsFragment -import dagger.Module -import dagger.android.ContributesAndroidInjector - -@Module -abstract class ContactsFragmentProvider { - - @ContributesAndroidInjector() - abstract fun provideContactsFragment(): ContactsFragment -} \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt index aa62551b2c..823fcc6f63 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt @@ -2,9 +2,11 @@ package chat.rocket.android.main.presentation import android.content.Context import android.content.Intent +import android.net.Uri import android.view.LayoutInflater import android.widget.EditText import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat.startActivity import chat.rocket.android.R @@ -55,8 +57,12 @@ import chat.rocket.common.model.roomTypeOf import chat.rocket.core.model.ChatRoom import chat.rocket.core.model.Myself import chat.rocket.common.model.RoomType +import com.google.firebase.dynamiclinks.DynamicLink +import com.google.firebase.dynamiclinks.FirebaseDynamicLinks +import com.google.firebase.dynamiclinks.ShortDynamicLink import kotlinx.coroutines.experimental.channels.Channel import kotlinx.coroutines.experimental.CommonPool +import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.withContext import timber.log.Timber import javax.inject.Inject @@ -354,6 +360,42 @@ class MainPresenter @Inject constructor( } } + fun shareViaApp(context: Context){ + launch { + //get serverUrl and username + val server = serverInteractor.get()!! + val account = getAccountInteractor.get(server)!! + val userName = account.userName + + FirebaseDynamicLinks.getInstance().createDynamicLink() + .setLink(Uri.parse("$server/direct/$userName")) + .setDomainUriPrefix("https://dylinktesting.page.link") + .setAndroidParameters( + DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) + .setSocialMetaTagParameters( + DynamicLink.SocialMetaTagParameters.Builder() + .setTitle(userName) + .setDescription("Chat with $userName on Rocket.Chat") + .build()) + .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) + .addOnSuccessListener { result -> + val link = result.shortLink.toString() + Toast.makeText(context, link, Toast.LENGTH_SHORT).show() + + with(Intent(Intent.ACTION_SEND)) { + type = "text/plain" + putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) + putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") + context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) + } + + }.addOnFailureListener { + // Error + Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() + } + } + } + fun connect() { refreshSettingsInteractor.refreshAsync(currentServer) refreshPermissionsInteractor.refreshAsync(currentServer) diff --git a/app/src/main/res/layout/fragment_contact_parent.xml b/app/src/main/res/layout/fragment_contact_parent.xml index 711033f1ab..b020f444d0 100644 --- a/app/src/main/res/layout/fragment_contact_parent.xml +++ b/app/src/main/res/layout/fragment_contact_parent.xml @@ -6,22 +6,20 @@ android:layout_height="match_parent" tools:context=".contacts.ContactsFragment"> - + - + - - - - - - - - - From c9e7b22c9fae8efb75ff90bddf3e25bd935d7702 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Tue, 15 Jan 2019 12:10:42 -0500 Subject: [PATCH 04/16] use our google-services.json, use our dynamic link hostname --- app/google-services.json | 22 +++++++++---------- .../main/presentation/MainPresenter.kt | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/google-services.json b/app/google-services.json index ecb8471b47..6d83ec0393 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -1,27 +1,27 @@ { "project_info": { - "project_number": "855027673764", - "firebase_url": "https://dynamiclinks-test-35c22.firebaseio.com", - "project_id": "dynamiclinks-test-35c22", - "storage_bucket": "dynamiclinks-test-35c22.appspot.com" + "project_number": "528542541788", + "firebase_url": "https://veranda-1d914.firebaseio.com", + "project_id": "veranda-1d914", + "storage_bucket": "veranda-1d914.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:855027673764:android:3b5032d671a29f81", + "mobilesdk_app_id": "1:528542541788:android:3b5032d671a29f81", "android_client_info": { "package_name": "chat.veranda.android" } }, "oauth_client": [ { - "client_id": "855027673764-tea1nqbjijv9sgsv8tvkf8crpgpl9h8b.apps.googleusercontent.com", + "client_id": "528542541788-0dv75a3mndkcbj9iji7lemh8hjo5njt1.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyA0ayomxX0RnIv2TkV0MtFbIJzSAqn_Qgk" + "current_key": "AIzaSyDc2nC-kdBgnT1v8W2oz24TKvWAyij-h80" } ], "services": { @@ -39,20 +39,20 @@ }, { "client_info": { - "mobilesdk_app_id": "1:855027673764:android:05d0047069ea8c30", + "mobilesdk_app_id": "1:528542541788:android:05d0047069ea8c30", "android_client_info": { "package_name": "chat.veranda.android.dev" } }, "oauth_client": [ { - "client_id": "855027673764-tea1nqbjijv9sgsv8tvkf8crpgpl9h8b.apps.googleusercontent.com", + "client_id": "528542541788-0dv75a3mndkcbj9iji7lemh8hjo5njt1.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyA0ayomxX0RnIv2TkV0MtFbIJzSAqn_Qgk" + "current_key": "AIzaSyDc2nC-kdBgnT1v8W2oz24TKvWAyij-h80" } ], "services": { @@ -70,4 +70,4 @@ } ], "configuration_version": "1" -} \ No newline at end of file +} diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt index 823fcc6f63..031a577d53 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt @@ -369,7 +369,7 @@ class MainPresenter @Inject constructor( FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("$server/direct/$userName")) - .setDomainUriPrefix("https://dylinktesting.page.link") + .setDomainUriPrefix("https://viasatconnect.page.link") .setAndroidParameters( DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) .setSocialMetaTagParameters( From 942dc2a572f4035ecb6a70414befb0c332eb4df3 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Wed, 16 Jan 2019 11:41:32 -0500 Subject: [PATCH 05/16] use strings instead of hard coded dynamic link info; cleanup --- .../main/presentation/MainPresenter.kt | 41 ++----------------- .../java/chat/rocket/android/main/ui/Menu.kt | 1 - app/src/main/res/values/defaults.xml | 3 ++ 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt index 031a577d53..0637ec1a95 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt @@ -325,41 +325,6 @@ class MainPresenter @Inject constructor( super.logout(userDataChannel) } - /** - * Invite - */ - fun invite(context: Context) { - launchUI(strategy) { - - //get serverUrl and username - val server = serverInteractor.get()!! - val account = getAccountInteractor.get(server)!! - val userName = account.userName - - val defaultMessage = "Hey! I’m on Veranda. If you sign up we can chat for free. \nMy username is “$userName” on server $server " - - //Dialog - val layoutInflater = LayoutInflater.from(context) - val dialogLayout = layoutInflater.inflate(R.layout.invite_dialog, null) - val editText = dialogLayout.findViewById(R.id.invite_text) - editText.setText(defaultMessage, TextView.BufferType.NORMAL) - - AlertDialog.Builder(context) - .setTitle(R.string.invite_label) - .setView(dialogLayout) - .setPositiveButton(R.string.action_invite) { dialog, _ -> - dialog.dismiss() - - //intent - val inviteIntent = Intent() - inviteIntent.action = Intent.ACTION_SEND - inviteIntent.putExtra(Intent.EXTRA_TEXT, editText.text.toString()) - inviteIntent.type = "text/plain" - startActivity(context, inviteIntent, null) - }.show() - } - } - fun shareViaApp(context: Context){ launch { //get serverUrl and username @@ -369,13 +334,13 @@ class MainPresenter @Inject constructor( FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("$server/direct/$userName")) - .setDomainUriPrefix("https://viasatconnect.page.link") + .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) .setAndroidParameters( - DynamicLink.AndroidParameters.Builder("chat.veranda.android.dev").build()) + DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) .setSocialMetaTagParameters( DynamicLink.SocialMetaTagParameters.Builder() .setTitle(userName) - .setDescription("Chat with $userName on Rocket.Chat") + .setDescription("Chat with $userName on " + context.getString(R.string.widechat_server_url)) .build()) .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) .addOnSuccessListener { result -> diff --git a/app/src/main/java/chat/rocket/android/main/ui/Menu.kt b/app/src/main/java/chat/rocket/android/main/ui/Menu.kt index 2bb6012e22..52385991ed 100644 --- a/app/src/main/java/chat/rocket/android/main/ui/Menu.kt +++ b/app/src/main/java/chat/rocket/android/main/ui/Menu.kt @@ -68,7 +68,6 @@ internal fun MainActivity.onNavDrawerItemSelected(menuItem: MenuItem) { when (menuItem.itemId) { R.id.menu_action_chats-> presenter.toChatList() R.id.menu_action_create_channel -> presenter.toCreateChannel() - R.id.menu_action_invite -> presenter.invite(this) R.id.menu_action_profile -> presenter.toUserProfile() R.id.menu_action_settings -> presenter.toSettings() R.id.menu_action_admin_panel -> presenter.toAdminPanel() diff --git a/app/src/main/res/values/defaults.xml b/app/src/main/res/values/defaults.xml index e2f007c437..917829213f 100644 --- a/app/src/main/res/values/defaults.xml +++ b/app/src/main/res/values/defaults.xml @@ -3,6 +3,9 @@ https:// viasatconnect.com viasatconnect.com + viasatconnect.page.link + chat.veranda.android + open.rocket.chat cloud.rocket.chat/trial https://play.google.com/store/apps/details?id=chat.rocket.android From 0a4b226858e8e824d83e67ea1930e129b7057f02 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Mon, 21 Jan 2019 10:48:52 -0500 Subject: [PATCH 06/16] WIP --- app/src/main/AndroidManifest.xml | 8 ++----- .../rocket/android/main/ui/MainActivity.kt | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b743a4e283..cbd2261b27 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,13 +41,9 @@ - - + diff --git a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt index 2053d34c02..acf3c0f58c 100644 --- a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt +++ b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt @@ -7,7 +7,6 @@ import android.app.AlertDialog import android.app.ProgressDialog import android.content.pm.PackageManager import android.os.Bundle -import android.text.Layout import androidx.annotation.IdRes import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat @@ -15,7 +14,6 @@ import androidx.core.content.ContextCompat import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout import androidx.fragment.app.Fragment -import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import androidx.work.OneTimeWorkRequestBuilder @@ -48,9 +46,17 @@ import kotlinx.android.synthetic.main.app_bar.* import kotlinx.android.synthetic.main.nav_header.view.* import javax.inject.Inject +// TEST +import chat.rocket.android.chatrooms.ui.TAG_CHAT_ROOMS_FRAGMENT +import chat.rocket.android.chatrooms.ui.ChatRoomsFragment + + // WIDECHAT import chat.rocket.android.helper.Constants +// test +import timber.log.Timber + private const val CURRENT_STATE = "current_state" class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, @@ -73,6 +79,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, override fun onCreate(savedInstanceState: Bundle?) { AndroidInjection.inject(this) super.onCreate(savedInstanceState) + if (Constants.WIDECHAT) { setContentView(R.layout.widechat_activity_main) } else { @@ -109,16 +116,21 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, override fun onResume() { supportFragmentManager.popBackStackImmediate("contactsFragment", 1) + + Timber.d("########### EAR >> just hit onResume in main activity...") + super.onResume() syncContacts() if (!isFragmentAdded) { presenter.toChatList(chatRoomId) isFragmentAdded = true } - } - override fun onPause() { - super.onPause() + + var myFrag = supportFragmentManager.findFragmentByTag("ChatRoomsFragment") as ChatRoomsFragment? + myFrag?.getDeepLink() + Timber.d("####### EAR >> this is myFrag to string fwiw...") + Timber.d(myFrag.toString()) } override fun onDestroy() { From 8b1495e62e42def4213c1567d5cdb9ffd5e161c8 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Tue, 22 Jan 2019 10:48:40 -0500 Subject: [PATCH 07/16] handle all use cases using singleInstance and onNewIntent --- app/src/main/AndroidManifest.xml | 3 ++- .../ui/AuthenticationActivity.kt | 22 ++++++++++++++----- .../android/chatrooms/ui/ChatRoomsFragment.kt | 7 ++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cbd2261b27..f4339aae66 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,7 @@ @@ -54,7 +55,7 @@ + android:windowSoftInputMode="adjustResize|stateAlwaysHidden"/> if (isAuthenticated) { - showChatList() + getDynamicLink(true, intent) } else { showOnBoardingFragment() } @@ -110,9 +110,11 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { } } - private fun showChatList() = presenter.toChatList() + private fun showChatList() { + presenter.toChatList() + } - private fun getDynamicLink() { + private fun getDynamicLink(authenticated: Boolean = false, intent: Intent) { FirebaseDynamicLinks.getInstance() .getDynamicLink(intent) .addOnSuccessListener(this) { pendingDynamicLinkData -> @@ -121,11 +123,19 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { deepLink = pendingDynamicLinkData.link } - TimberLogger.debug("DeepLink : deepLink.toString()") + TimberLogger.debug("DeepLink:" + deepLink.toString()) SharedPreferenceHelper.putString(Constants.DEEP_LINK, deepLink.toString()) + if (authenticated) { + showChatList() + } } .addOnFailureListener(this) { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } } + + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + getDynamicLink(false, intent) + } } const val INTENT_ADD_NEW_SERVER = "INTENT_ADD_NEW_SERVER" @@ -135,4 +145,4 @@ fun Context.newServerIntent(): Intent { putExtra(INTENT_ADD_NEW_SERVER, true) flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK } -} \ No newline at end of file +} diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 6e103d1302..b26db01616 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -124,6 +124,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { } override fun onResume() { + getDeepLink() // WIDECHAT - cleanup any titles set by other fragments; clear any previous search if (Constants.WIDECHAT) { (activity as AppCompatActivity?)?.supportActionBar?.setDisplayShowTitleEnabled(false) @@ -142,10 +143,8 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - viewModel = ViewModelProviders.of(this, factory).get(ChatRoomsViewModel::class.java) subscribeUi() - setupToolbar() setupFab() getDeepLink() @@ -524,10 +523,8 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { SharedPreferenceHelper.remove(Constants.DEEP_LINK) TimberLogger.debug("Retrieved deep link on ChatRooms : $deepLink") - if(deepLink.isNullOrBlank() || deepLink.equals("null")){ + if(deepLink.isNullOrBlank() || deepLink.equals("null")) { return - } else { - Toast.makeText(context, "Deep link : $deepLink", Toast.LENGTH_SHORT).show() } val uri = Uri.parse(deepLink) From 60459832c1efc76ac3ab20d4f3b6a9086e429ab9 Mon Sep 17 00:00:00 2001 From: Peter Lepeska Date: Thu, 24 Jan 2019 16:12:48 -0500 Subject: [PATCH 08/16] refactor of dynamic link receiving code --- .../domain/model/DeepLinkInfo.kt | 94 +++++++++++++ .../domain/model/LoginDeepLinkInfo.kt | 40 ------ .../presentation/LoginOptionsPresenter.kt | 4 +- .../loginoptions/ui/LoginOptionsFragment.kt | 11 +- .../presentation/AuthenticationNavigator.kt | 36 ++++- .../presentation/AuthenticationPresenter.kt | 5 + .../server/presentation/ServerPresenter.kt | 4 +- .../server/ui/ServerFragment.kt | 17 ++- .../ui/AuthenticationActivity.kt | 125 ++++++++++-------- .../android/chatrooms/ui/ChatRoomsFragment.kt | 26 ++-- .../chat/rocket/android/helper/Constants.kt | 2 +- .../main/presentation/MainNavigator.kt | 5 +- .../main/presentation/MainPresenter.kt | 3 +- .../rocket/android/main/ui/MainActivity.kt | 29 +++- 14 files changed, 254 insertions(+), 147 deletions(-) create mode 100644 app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt delete mode 100644 app/src/main/java/chat/rocket/android/authentication/domain/model/LoginDeepLinkInfo.kt diff --git a/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt b/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt new file mode 100644 index 0000000000..526fc8fb57 --- /dev/null +++ b/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt @@ -0,0 +1,94 @@ +package chat.rocket.android.authentication.domain.model + +import android.annotation.SuppressLint +import android.content.Intent +import android.net.Uri +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize +import timber.log.Timber + +// see https://rocket.chat/docs/developer-guides/deeplink/ for documentation + +@SuppressLint("ParcelCreator") +@Parcelize +data class DeepLinkInfo( + val url: String, + val userId: String?, + val token: String?, + val rid: String?, + val roomType: String?, + val roomName: String? +) : Parcelable + +fun Uri.getDeepLinkInfo(): DeepLinkInfo? { + return if (isAuthenticationDeepLink()) { + val host = getQueryParameter("host") + val url = if (host.startsWith("http")) host else "https://$host" + val userId = getQueryParameter("userId") + val token = getQueryParameter("token") + try { + DeepLinkInfo(url, userId, token, null, null, null) + } catch (ex: Exception) { + Timber.d(ex, "Error parsing auth deeplink") + null + } + } else if (isCustomSchemeRoomLink()) { + val hostValue = getQueryParameter("host") + val url = if (hostValue.startsWith("http")) hostValue else "https://$hostValue" + val rid = getQueryParameter("rid") + val pathValue = getQueryParameter("path") + val pathSplit = pathValue.split("/") + val roomType = pathSplit[0] + val roomName = pathSplit[1] + try { + DeepLinkInfo(url, null, null, rid, roomType, roomName) + } catch (ex: Exception) { + Timber.d(ex, "Error parsing custom scheme room link") + null + } + } else if (isWebSchemeRoomLink()) { + val url = "https://$host" + val pathSplit = path.split("/") + val roomType = pathSplit[1] + val roomName = pathSplit[2] + try { + DeepLinkInfo(url, null, null, null, roomType, roomName) + } catch (ex: Exception) { + Timber.d(ex, "Error parsing login deeplink") + null + } + } else null +} + +fun Intent.isSupportedLink(): Boolean { + return (action == Intent.ACTION_VIEW && data != null && + (data.isDynamicLink() || data.isAuthenticationDeepLink() || + data.isCustomSchemeRoomLink() || data.isWebSchemeRoomLink())) +} + +fun Uri.isDynamicLink(): Boolean { + return (host != null && host.contains("page.link", ignoreCase = true)) +} + +private inline fun Uri.isAuthenticationDeepLink(): Boolean { + if (host == "auth") + return true + else if (host == "go.rocket.chat" && path == "/auth") + return true + return false +} + +private inline fun Uri.isCustomSchemeRoomLink(): Boolean { + if (scheme.startsWith("http") && + host == "room") + return true + return false +} + +private inline fun Uri.isWebSchemeRoomLink(): Boolean { + val roomType = path.split("/")[1] + if (scheme.startsWith("http") && + (roomType == "channel" || roomType == "group" || roomType == "direct")) + return true + return false +} \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/authentication/domain/model/LoginDeepLinkInfo.kt b/app/src/main/java/chat/rocket/android/authentication/domain/model/LoginDeepLinkInfo.kt deleted file mode 100644 index 769f3e6757..0000000000 --- a/app/src/main/java/chat/rocket/android/authentication/domain/model/LoginDeepLinkInfo.kt +++ /dev/null @@ -1,40 +0,0 @@ -package chat.rocket.android.authentication.domain.model - -import android.annotation.SuppressLint -import android.content.Intent -import android.net.Uri -import android.os.Parcelable -import kotlinx.android.parcel.Parcelize -import timber.log.Timber - -@SuppressLint("ParcelCreator") -@Parcelize -data class LoginDeepLinkInfo( - val url: String, - val userId: String?, - val token: String? -) : Parcelable - -fun Intent.getLoginDeepLinkInfo(): LoginDeepLinkInfo? { - val uri = data - return if (action == Intent.ACTION_VIEW && uri != null && uri.isAuthenticationDeepLink()) { - val host = uri.getQueryParameter("host") - val url = if (host.startsWith("http")) host else "https://$host" - val userId = uri.getQueryParameter("userId") - val token = uri.getQueryParameter("token") - try { - LoginDeepLinkInfo(url, userId, token) - } catch (ex: Exception) { - Timber.d(ex, "Error parsing login deeplink") - null - } - } else null -} - -private inline fun Uri.isAuthenticationDeepLink(): Boolean { - if (host == "auth") - return true - else if (host == "go.rocket.chat" && path == "/auth") - return true - return false -} \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/authentication/loginoptions/presentation/LoginOptionsPresenter.kt b/app/src/main/java/chat/rocket/android/authentication/loginoptions/presentation/LoginOptionsPresenter.kt index 3ee9795c86..34d7d85530 100644 --- a/app/src/main/java/chat/rocket/android/authentication/loginoptions/presentation/LoginOptionsPresenter.kt +++ b/app/src/main/java/chat/rocket/android/authentication/loginoptions/presentation/LoginOptionsPresenter.kt @@ -2,7 +2,7 @@ package chat.rocket.android.authentication.loginoptions.presentation import chat.rocket.android.analytics.AnalyticsManager import chat.rocket.android.analytics.event.AuthenticationEvent -import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.infrastructure.LocalRepository @@ -89,7 +89,7 @@ class LoginOptionsPresenter @Inject constructor( doAuthentication(TYPE_LOGIN_SAML) } - fun authenticateWithDeepLink(deepLinkInfo: LoginDeepLinkInfo) { + fun authenticateWithDeepLink(deepLinkInfo: DeepLinkInfo) { val serverUrl = deepLinkInfo.url setupConnectionInfo(serverUrl) if (deepLinkInfo.userId != null && deepLinkInfo.token != null) { diff --git a/app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt b/app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt index 55903cdb34..077dbf5be3 100644 --- a/app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt +++ b/app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt @@ -15,7 +15,7 @@ import androidx.fragment.app.Fragment import chat.rocket.android.R import chat.rocket.android.analytics.AnalyticsManager import chat.rocket.android.analytics.event.ScreenViewEvent -import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.loginoptions.presentation.LoginOptionsPresenter import chat.rocket.android.authentication.loginoptions.presentation.LoginOptionsView import chat.rocket.android.authentication.ui.AuthenticationActivity @@ -59,7 +59,6 @@ private const val SAML_SERVICE_BUTTON_COLOR = "saml_service_button_color" private const val TOTAL_SOCIAL_ACCOUNTS = "total_social_accounts" private const val IS_LOGIN_FORM_ENABLED = "is_login_form_enabled" private const val IS_NEW_ACCOUNT_CREATION_ENABLED = "is_new_account_creation_enabled" -private const val DEEP_LINK_INFO = "deep-link-info" internal const val REQUEST_CODE_FOR_OAUTH = 1 internal const val REQUEST_CODE_FOR_CAS = 2 @@ -91,7 +90,7 @@ fun newInstance( totalSocialAccountsEnabled: Int = 0, isLoginFormEnabled: Boolean, isNewAccountCreationEnabled: Boolean, - deepLinkInfo: LoginDeepLinkInfo? = null + deepLinkInfo: DeepLinkInfo? = null ): Fragment { return LoginOptionsFragment().apply { arguments = Bundle(23).apply { @@ -120,7 +119,7 @@ fun newInstance( putInt(TOTAL_SOCIAL_ACCOUNTS, totalSocialAccountsEnabled) putBoolean(IS_LOGIN_FORM_ENABLED, isLoginFormEnabled) putBoolean(IS_NEW_ACCOUNT_CREATION_ENABLED, isNewAccountCreationEnabled) - putParcelable(DEEP_LINK_INFO, deepLinkInfo) + putParcelable(Constants.DEEP_LINK_INFO, deepLinkInfo) } } } @@ -155,7 +154,7 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView { private var totalSocialAccountsEnabled = 0 private var isLoginFormEnabled = false private var isNewAccountCreationEnabled = false - private var deepLinkInfo: LoginDeepLinkInfo? = null + private var deepLinkInfo: DeepLinkInfo? = null // WIDECHAT - replace the RC login screen with our welcome and login buttons view private var auth_fragment: Int = R.layout.fragment_authentication_widechat_login_options @@ -195,7 +194,7 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView { totalSocialAccountsEnabled = bundle.getInt(TOTAL_SOCIAL_ACCOUNTS) isLoginFormEnabled = bundle.getBoolean(IS_LOGIN_FORM_ENABLED) isNewAccountCreationEnabled = bundle.getBoolean(IS_NEW_ACCOUNT_CREATION_ENABLED) - deepLinkInfo = bundle.getParcelable(DEEP_LINK_INFO) + deepLinkInfo = bundle.getParcelable(Constants.DEEP_LINK_INFO) } } diff --git a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt index b303f8876b..4d4f52c637 100644 --- a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt +++ b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt @@ -3,19 +3,30 @@ package chat.rocket.android.authentication.presentation import android.content.Intent import chat.rocket.android.R import chat.rocket.android.analytics.event.ScreenViewEvent -import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.ui.AuthenticationActivity +import chat.rocket.android.helper.Constants import chat.rocket.android.main.ui.MainActivity import chat.rocket.android.server.ui.changeServerIntent import chat.rocket.android.util.extensions.addFragmentBackStack import chat.rocket.android.util.extensions.toPreviousView import chat.rocket.android.webview.ui.webViewIntent +import chat.rocket.common.util.ifNull class AuthenticationNavigator(internal val activity: AuthenticationActivity) { + public var savedDeepLinkInfo: DeepLinkInfo? = null - fun toSignInToYourServer() { + fun saveDeepLinkInfo(deepLinkInfo: DeepLinkInfo) { + savedDeepLinkInfo = deepLinkInfo + } + fun toOnBoarding() { + activity.addFragmentBackStack(ScreenViewEvent.OnBoarding.screenName, R.id.fragment_container) { + chat.rocket.android.authentication.onboarding.ui.newInstance() + } + } + fun toSignInToYourServer(deepLinkInfo: DeepLinkInfo? = null) { activity.addFragmentBackStack(ScreenViewEvent.Server.screenName, R.id.fragment_container) { - chat.rocket.android.authentication.server.ui.newInstance() + chat.rocket.android.authentication.server.ui.newInstance(deepLinkInfo) } } @@ -45,7 +56,7 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) { totalSocialAccountsEnabled: Int = 0, isLoginFormEnabled: Boolean = true, isNewAccountCreationEnabled: Boolean = true, - deepLinkInfo: LoginDeepLinkInfo? = null + deepLinkInfo: DeepLinkInfo? = null ) { activity.addFragmentBackStack( ScreenViewEvent.LoginOptions.screenName, @@ -128,12 +139,25 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) { } fun toChatList() { - activity.startActivity(Intent(activity, MainActivity::class.java)) - activity.finish() + savedDeepLinkInfo?.let { + toChatList(it) + } .ifNull { + activity.startActivity(Intent(activity, MainActivity::class.java)) + activity.finish() + } + savedDeepLinkInfo = null } fun toChatList(serverUrl: String) { activity.startActivity(activity.changeServerIntent(serverUrl)) activity.finish() } + + fun toChatList(deepLinkInfo: DeepLinkInfo) { + activity.startActivity(Intent(activity, MainActivity::class.java).also { + it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + it.putExtra(Constants.DEEP_LINK_INFO, deepLinkInfo) + }) + activity.finish() + } } diff --git a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationPresenter.kt b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationPresenter.kt index af3020e071..cbe91d8c62 100644 --- a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationPresenter.kt +++ b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationPresenter.kt @@ -1,5 +1,6 @@ package chat.rocket.android.authentication.presentation +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.server.domain.GetAccountInteractor @@ -52,5 +53,9 @@ class AuthenticationPresenter @Inject constructor( fun privacyPolicy(toolbarTitle: String) = serverInteractor.get()?.let { navigator.toWebPage(it.privacyPolicyUrl(), toolbarTitle) } + fun saveDeepLinkInfo(deepLinkInfo: DeepLinkInfo) = navigator.saveDeepLinkInfo(deepLinkInfo) + fun toOnBoarding() = navigator.toOnBoarding() + fun toSignInToYourServer(deepLinkInfo: DeepLinkInfo? = null) = navigator.toSignInToYourServer(deepLinkInfo) fun toChatList() = navigator.toChatList() + fun toChatList(deepLinkInfo: DeepLinkInfo) = navigator.toChatList(deepLinkInfo) } \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt b/app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt index d294506ff4..2770be9398 100644 --- a/app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt +++ b/app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt @@ -1,6 +1,6 @@ package chat.rocket.android.authentication.server.presentation -import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.core.behaviours.showMessage import chat.rocket.android.core.lifecycle.CancelStrategy @@ -79,7 +79,7 @@ class ServerPresenter @Inject constructor( } } - fun deepLink(deepLinkInfo: LoginDeepLinkInfo) { + fun deepLink(deepLinkInfo: DeepLinkInfo) { connectToServer(deepLinkInfo.url) { navigator.toLoginOptions(deepLinkInfo.url, deepLinkInfo = deepLinkInfo) } diff --git a/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt b/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt index adeebc8d20..bde6f37317 100644 --- a/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt +++ b/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt @@ -20,10 +20,11 @@ import chat.rocket.android.BuildConfig import chat.rocket.android.R import chat.rocket.android.analytics.AnalyticsManager import chat.rocket.android.analytics.event.ScreenViewEvent -import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.server.presentation.ServerPresenter import chat.rocket.android.authentication.server.presentation.ServerView import chat.rocket.android.authentication.ui.AuthenticationActivity +import chat.rocket.android.helper.Constants import chat.rocket.android.helper.KeyboardHelper import chat.rocket.android.util.extension.asObservable import chat.rocket.android.util.extensions.hintContent @@ -42,16 +43,20 @@ import kotlinx.android.synthetic.main.fragment_authentication_server.* import okhttp3.HttpUrl import javax.inject.Inject -fun newInstance() = ServerFragment() - -private const val DEEP_LINK_INFO = "DeepLinkInfo" +fun newInstance(deepLinkInfo: DeepLinkInfo?): ServerFragment { + val fragment = ServerFragment() + val args = Bundle() + args.putParcelable(Constants.DEEP_LINK_INFO, deepLinkInfo) + fragment.setArguments(args) + return fragment +} class ServerFragment : Fragment(), ServerView { @Inject lateinit var presenter: ServerPresenter @Inject lateinit var analyticsManager: AnalyticsManager - private var deepLinkInfo: LoginDeepLinkInfo? = null + private var deepLinkInfo: DeepLinkInfo? = null private var protocol = "https://" private var isDomainAppended = false private var appendedText = "" @@ -66,7 +71,7 @@ class ServerFragment : Fragment(), ServerView { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) AndroidSupportInjection.inject(this) - deepLinkInfo = arguments?.getParcelable(DEEP_LINK_INFO) + deepLinkInfo = arguments?.getParcelable(Constants.DEEP_LINK_INFO) } override fun onCreateView( diff --git a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt index 82f12ad19b..6850a07054 100644 --- a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt +++ b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt @@ -6,13 +6,14 @@ import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import chat.rocket.android.R import chat.rocket.android.analytics.event.ScreenViewEvent -import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo -import chat.rocket.android.authentication.domain.model.getLoginDeepLinkInfo +import chat.rocket.android.authentication.domain.model.DeepLinkInfo +import chat.rocket.android.authentication.domain.model.getDeepLinkInfo +import chat.rocket.android.authentication.domain.model.isDynamicLink +import chat.rocket.android.authentication.domain.model.isSupportedLink import chat.rocket.android.authentication.presentation.AuthenticationPresenter import chat.rocket.android.helper.Constants import chat.rocket.android.helper.SharedPreferenceHelper @@ -40,10 +41,55 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { super.onCreate(savedInstanceState) setContentView(R.layout.activity_authentication) setupToolbar() - loadCredentials() - getDynamicLink(false, intent) + + processIncomingIntent(intent) + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + intent?.let { + processIncomingIntent(it) + } + } + + private fun processIncomingIntent(intent: Intent) { + if (intent.isSupportedLink()) { + val uri = intent.data + if (uri.isDynamicLink()) { + resolveDynamicLink(intent) + } else { + uri.getDeepLinkInfo()?.let{ + routeDeepLink(it) + } .ifNull { + routeNoLink() + } + } + } else { + routeNoLink() + } + } + + private fun resolveDynamicLink(intent: Intent) { + FirebaseDynamicLinks.getInstance() + .getDynamicLink(intent) + .addOnSuccessListener(this) { pendingDynamicLinkData -> + var deepLink: Uri? = null + if (pendingDynamicLinkData != null) { + deepLink = pendingDynamicLinkData.link + } + + TimberLogger.debug("Resolved DeepLink:" + deepLink.toString()) + deepLink?.getDeepLinkInfo()?.let{ + routeDeepLink(it) + } + } + .addOnFailureListener(this) { + e -> TimberLogger.debug("getDynamicLink:onFailure : $e") + routeNoLink() + } } + private fun setupToolbar() { with(toolbar) { setSupportActionBar(this) @@ -75,67 +121,30 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { return super.onOptionsItemSelected(item) } - private fun loadCredentials() { - intent.getLoginDeepLinkInfo()?.let { - showServerFragment(it) - }.ifNull { - val newServer = intent.getBooleanExtra(INTENT_ADD_NEW_SERVER, false) - presenter.loadCredentials(newServer) { isAuthenticated -> + private fun routeDeepLink(deepLinkInfo: DeepLinkInfo) { + if (Constants.WIDECHAT) + presenter.loadCredentials(false) { isAuthenticated -> if (isAuthenticated) { - getDynamicLink(true, intent) + presenter.toChatList(deepLinkInfo) } else { - showOnBoardingFragment() + presenter.saveDeepLinkInfo(deepLinkInfo) + presenter.toOnBoarding() } } - } + else + presenter.toSignInToYourServer(deepLinkInfo) } - private fun showOnBoardingFragment() { - addFragment( - ScreenViewEvent.OnBoarding.screenName, - R.id.fragment_container, - allowStateLoss = true - ) { - chat.rocket.android.authentication.onboarding.ui.newInstance() - } - } - - private fun showServerFragment(deepLinkInfo: LoginDeepLinkInfo) { - addFragment( - ScreenViewEvent.Server.screenName, - R.id.fragment_container, - allowStateLoss = true - ) { - chat.rocket.android.authentication.server.ui.newInstance() + private fun routeNoLink() { + val newServer = intent.getBooleanExtra(INTENT_ADD_NEW_SERVER, false) + presenter.loadCredentials(newServer) { isAuthenticated -> + if (isAuthenticated) { + presenter.toChatList() + } else { + presenter.toOnBoarding() + } } } - - private fun showChatList() { - presenter.toChatList() - } - - private fun getDynamicLink(authenticated: Boolean = false, intent: Intent) { - FirebaseDynamicLinks.getInstance() - .getDynamicLink(intent) - .addOnSuccessListener(this) { pendingDynamicLinkData -> - var deepLink: Uri? = null - if (pendingDynamicLinkData != null) { - deepLink = pendingDynamicLinkData.link - } - - TimberLogger.debug("DeepLink:" + deepLink.toString()) - SharedPreferenceHelper.putString(Constants.DEEP_LINK, deepLink.toString()) - if (authenticated) { - showChatList() - } - } - .addOnFailureListener(this) { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } - } - - override fun onNewIntent(intent: Intent) { - super.onNewIntent(intent) - getDynamicLink(false, intent) - } } const val INTENT_ADD_NEW_SERVER = "INTENT_ADD_NEW_SERVER" diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index b26db01616..346f8ed262 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -46,6 +46,7 @@ import javax.inject.Inject import android.graphics.Color import android.net.Uri import android.widget.* +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.chatrooms.adapter.model.RoomUiModel import chat.rocket.android.helper.UserHelper import chat.rocket.android.profile.ui.ProfileFragment @@ -90,15 +91,16 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { private var searchCloseButton: ImageView? = null private var profileButton: SimpleDraweeView? = null private var onlineStatusButton:ImageView?=null - private var deepLink: String? = null + private var deepLinkInfo: DeepLinkInfo? = null // handles that recurring connection status bug in widechat private var currentlyConnected: Boolean? = false companion object { - fun newInstance(chatRoomId: String? = null): ChatRoomsFragment { + fun newInstance(chatRoomId: String? = null, deepLinkInfo: DeepLinkInfo? = null): ChatRoomsFragment { return ChatRoomsFragment().apply { arguments = Bundle(1).apply { putString(BUNDLE_CHAT_ROOM_ID, chatRoomId) + putParcelable(Constants.DEEP_LINK_INFO, deepLinkInfo) } } } @@ -115,6 +117,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { presenter.loadChatRoom(it) chatRoomId = null } + deepLinkInfo = bundle.getParcelable(Constants.DEEP_LINK_INFO) } } @@ -124,7 +127,6 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { } override fun onResume() { - getDeepLink() // WIDECHAT - cleanup any titles set by other fragments; clear any previous search if (Constants.WIDECHAT) { (activity as AppCompatActivity?)?.supportActionBar?.setDisplayShowTitleEnabled(false) @@ -147,7 +149,9 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { subscribeUi() setupToolbar() setupFab() - getDeepLink() + deepLinkInfo?.let { + processDeepLink(it) + } analyticsManager.logScreenView(ScreenViewEvent.ChatRooms) } @@ -517,19 +521,9 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { } } - private fun getDeepLink() { - - deepLink = SharedPreferenceHelper.getString(Constants.DEEP_LINK, "null") - SharedPreferenceHelper.remove(Constants.DEEP_LINK) - TimberLogger.debug("Retrieved deep link on ChatRooms : $deepLink") - - if(deepLink.isNullOrBlank() || deepLink.equals("null")) { - return - } - - val uri = Uri.parse(deepLink) - val username = uri.lastPathSegment + public fun processDeepLink(deepLinkInfo: DeepLinkInfo) { + val username = deepLinkInfo.roomName username.ifNotNullNorEmpty { val localRooms = viewModel.getChatRoomOfUsernameDB(username!!) val filteredLocalRooms = localRooms.filter { itemHolder -> itemHolder.data is RoomUiModel && (itemHolder.data as RoomUiModel).username == username } diff --git a/app/src/main/java/chat/rocket/android/helper/Constants.kt b/app/src/main/java/chat/rocket/android/helper/Constants.kt index 6206f901bb..6d5127ad6a 100644 --- a/app/src/main/java/chat/rocket/android/helper/Constants.kt +++ b/app/src/main/java/chat/rocket/android/helper/Constants.kt @@ -16,7 +16,7 @@ object Constants { const val WIDECHAT = true const val WIDECHAT_DEV = false - const val DEEP_LINK = "deep_link" + const val DEEP_LINK_INFO = "deep_link_info" } object ChatRoomsSortOrder { diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainNavigator.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainNavigator.kt index c149448922..6b9161654a 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainNavigator.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainNavigator.kt @@ -1,6 +1,7 @@ package chat.rocket.android.main.presentation import chat.rocket.android.R +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.ui.newServerIntent import chat.rocket.android.chatroom.ui.chatRoomIntent import chat.rocket.android.chatrooms.ui.ChatRoomsFragment @@ -18,9 +19,9 @@ import chat.rocket.android.webview.adminpanel.ui.AdminPanelWebViewFragment class MainNavigator(internal val activity: MainActivity) { - fun toChatList(chatRoomId: String? = null) { + fun toChatList(chatRoomId: String? = null, deepLinkInfo: DeepLinkInfo? = null) { activity.addFragment(TAG_CHAT_ROOMS_FRAGMENT, R.id.fragment_container) { - ChatRoomsFragment.newInstance(chatRoomId) + ChatRoomsFragment.newInstance(chatRoomId, deepLinkInfo) } } diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt index 0637ec1a95..dd2e56b436 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt @@ -10,6 +10,7 @@ import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat.startActivity import chat.rocket.android.R +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.db.DatabaseManagerFactory @@ -106,7 +107,7 @@ class MainPresenter @Inject constructor( private var settings: PublicSettings = getSettingsInteractor.get(serverInteractor.get()!!) private val userDataChannel = Channel() - fun toChatList(chatRoomId: String? = null) = navigator.toChatList(chatRoomId) + fun toChatList(chatRoomId: String? = null, deepLinkInfo: DeepLinkInfo? = null) = navigator.toChatList(chatRoomId, deepLinkInfo) fun openDirectMessageChatRoom(username: String) { diff --git a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt index acf3c0f58c..e858888b2a 100644 --- a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt +++ b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt @@ -5,6 +5,7 @@ import android.Manifest import android.app.Activity import android.app.AlertDialog import android.app.ProgressDialog +import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import androidx.annotation.IdRes @@ -20,6 +21,7 @@ import androidx.work.OneTimeWorkRequestBuilder import androidx.work.WorkManager import chat.rocket.android.BuildConfig import chat.rocket.android.R +import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.contacts.worker.ContactSyncWorker import chat.rocket.android.main.adapter.AccountsAdapter import chat.rocket.android.main.adapter.Selector @@ -36,6 +38,7 @@ import chat.rocket.android.util.extensions.rotateBy import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.invalidateFirebaseToken import chat.rocket.common.model.UserStatus +import chat.rocket.common.util.ifNull import dagger.android.AndroidInjection import dagger.android.AndroidInjector import dagger.android.DispatchingAndroidInjector @@ -73,6 +76,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, private var expanded = false private val headerLayout by lazy { view_navigation.getHeaderView(0) } private var chatRoomId: String? = null + private var deepLinkInfo: DeepLinkInfo? = null private var progressDialog: ProgressDialog? = null private val PERMISSIONS_REQUEST_RW_CONTACTS = 0 @@ -88,6 +92,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, refreshPushToken() syncContacts() chatRoomId = intent.getStringExtra(INTENT_CHAT_ROOM_ID) + deepLinkInfo = intent.getParcelableExtra(Constants.DEEP_LINK_INFO) presenter.clearNotificationsForChatroom(chatRoomId) presenter.connect() @@ -104,6 +109,21 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, } } + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + intent?.let { + var deepLinkInfo = it.getParcelableExtra(Constants.DEEP_LINK_INFO) + if (deepLinkInfo != null) { + val chatRoomsFragment = supportFragmentManager.findFragmentByTag(TAG_CHAT_ROOMS_FRAGMENT) as ChatRoomsFragment + chatRoomsFragment?.let { + it.processDeepLink(deepLinkInfo) + } .ifNull { + isFragmentAdded = false + } + } + } + } + override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) outState?.putBoolean(CURRENT_STATE, isFragmentAdded) @@ -122,15 +142,10 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, super.onResume() syncContacts() if (!isFragmentAdded) { - presenter.toChatList(chatRoomId) + presenter.toChatList(chatRoomId, deepLinkInfo) + deepLinkInfo = null isFragmentAdded = true } - - - var myFrag = supportFragmentManager.findFragmentByTag("ChatRoomsFragment") as ChatRoomsFragment? - myFrag?.getDeepLink() - Timber.d("####### EAR >> this is myFrag to string fwiw...") - Timber.d(myFrag.toString()) } override fun onDestroy() { From 66aebd5e5cf67c32ba54ba9b76a2563582d02184 Mon Sep 17 00:00:00 2001 From: Peter Lepeska Date: Fri, 25 Jan 2019 08:04:25 -0500 Subject: [PATCH 09/16] fix from code review --- .../rocket/android/authentication/domain/model/DeepLinkInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt b/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt index 526fc8fb57..3ae397667d 100644 --- a/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt +++ b/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt @@ -79,7 +79,7 @@ private inline fun Uri.isAuthenticationDeepLink(): Boolean { } private inline fun Uri.isCustomSchemeRoomLink(): Boolean { - if (scheme.startsWith("http") && + if (scheme.startsWith("rocketchat") && host == "room") return true return false From e084463b54748a9210030deaab0f5cf20f164891 Mon Sep 17 00:00:00 2001 From: Peter Lepeska Date: Fri, 25 Jan 2019 08:18:15 -0500 Subject: [PATCH 10/16] fix --- .../java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 346f8ed262..4ad9e6c7a7 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -152,6 +152,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { deepLinkInfo?.let { processDeepLink(it) } + deepLinkInfo = null analyticsManager.logScreenView(ScreenViewEvent.ChatRooms) } From 1fde8409c2793391d9330e3fc96c184b869b87b9 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Fri, 25 Jan 2019 12:12:36 -0500 Subject: [PATCH 11/16] add dagger injection for DynamicLinksForFirebase --- .../dynamiclinks/DynamicLinksForFirebase.kt | 13 ++++ .../android/app/RocketChatApplication.kt | 3 - .../ui/AuthenticationActivity.kt | 53 ++++++++------ .../android/chatrooms/ui/ChatRoomsFragment.kt | 2 +- .../rocket/android/dagger/module/AppModule.kt | 7 ++ .../android/dynamiclinks/DynamicLinks.kt | 11 +++ .../main/presentation/MainPresenter.kt | 73 ++++++++++--------- .../rocket/android/main/ui/MainActivity.kt | 2 - .../dynamiclinks/DynamicLinksForFirebase.kt | 70 ++++++++++++++++++ 9 files changed, 171 insertions(+), 63 deletions(-) create mode 100644 app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt create mode 100644 app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt create mode 100644 app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt diff --git a/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt b/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt new file mode 100644 index 0000000000..fc1baad372 --- /dev/null +++ b/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt @@ -0,0 +1,13 @@ +package chat.rocket.android.dynamiclinks + +import android.content.Context +import android.content.Intent +import android.net.Uri +import javax.inject.Inject + +class DynamicLinksForFirebase @Inject constructor(private val context: Context) : DynamicLinks { + + override fun getDynamicLink(intent: Intent) : Uri? { return null} + + override fun createDynamicLink(username: String, server: String) : String? { return null } +} diff --git a/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt b/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt index c4c9e172d2..8574f665bd 100644 --- a/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt +++ b/app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt @@ -32,7 +32,6 @@ import chat.rocket.core.internal.rest.getCustomEmojis import com.facebook.drawee.backends.pipeline.DraweeConfig import com.facebook.drawee.backends.pipeline.Fresco import com.facebook.imagepipeline.core.ImagePipelineConfig -import com.google.firebase.FirebaseApp import com.jakewharton.threetenabp.AndroidThreeTen import dagger.android.DispatchingAndroidInjector import dagger.android.HasActivityInjector @@ -100,8 +99,6 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje AndroidThreeTen.init(this) - FirebaseApp.initializeApp(this) - setupFabric(this) setupFresco() setupTimber() diff --git a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt index 6850a07054..baf9fe4c22 100644 --- a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt +++ b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt @@ -9,18 +9,15 @@ import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import chat.rocket.android.R -import chat.rocket.android.analytics.event.ScreenViewEvent import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.authentication.domain.model.getDeepLinkInfo import chat.rocket.android.authentication.domain.model.isDynamicLink import chat.rocket.android.authentication.domain.model.isSupportedLink import chat.rocket.android.authentication.presentation.AuthenticationPresenter +import chat.rocket.android.dynamiclinks.DynamicLinksForFirebase import chat.rocket.android.helper.Constants -import chat.rocket.android.helper.SharedPreferenceHelper import chat.rocket.android.util.TimberLogger -import chat.rocket.android.util.extensions.addFragment import chat.rocket.common.util.ifNull -import com.google.firebase.dynamiclinks.FirebaseDynamicLinks import dagger.android.AndroidInjection import dagger.android.AndroidInjector import dagger.android.DispatchingAndroidInjector @@ -34,6 +31,8 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector @Inject lateinit var presenter: AuthenticationPresenter + @Inject + lateinit var dynamicLinksManager: DynamicLinksForFirebase val job = Job() override fun onCreate(savedInstanceState: Bundle?) { @@ -70,25 +69,37 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { } private fun resolveDynamicLink(intent: Intent) { - FirebaseDynamicLinks.getInstance() - .getDynamicLink(intent) - .addOnSuccessListener(this) { pendingDynamicLinkData -> - var deepLink: Uri? = null - if (pendingDynamicLinkData != null) { - deepLink = pendingDynamicLinkData.link - } - - TimberLogger.debug("Resolved DeepLink:" + deepLink.toString()) - deepLink?.getDeepLinkInfo()?.let{ - routeDeepLink(it) - } - } - .addOnFailureListener(this) { - e -> TimberLogger.debug("getDynamicLink:onFailure : $e") - routeNoLink() - } + var dynamicLink: Uri? = null + dynamicLink = dynamicLinksManager.getDynamicLink(intent) + + dynamicLink?.getDeepLinkInfo()?.let { + routeDeepLink(it) + } } +// +// +// +// +// FirebaseDynamicLinks.getInstance() +// .getDynamicLink(intent) +// .addOnSuccessListener(this) { pendingDynamicLinkData -> +// var deepLink: Uri? = null +// if (pendingDynamicLinkData != null) { +// deepLink = pendingDynamicLinkData.link +// } +// +// TimberLogger.debug("Resolved DeepLink:" + deepLink.toString()) +// deepLink?.getDeepLinkInfo()?.let{ +// routeDeepLink(it) +// } +// } +// .addOnFailureListener(this) { +// e -> TimberLogger.debug("getDynamicLink:onFailure : $e") +// routeNoLink() +// } +// } + private fun setupToolbar() { with(toolbar) { diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 4ad9e6c7a7..6c562e2372 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -522,7 +522,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { } } - public fun processDeepLink(deepLinkInfo: DeepLinkInfo) { + fun processDeepLink(deepLinkInfo: DeepLinkInfo) { val username = deepLinkInfo.roomName username.ifNotNullNorEmpty { diff --git a/app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt b/app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt index 1a54df6d41..50bc37f749 100644 --- a/app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt +++ b/app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt @@ -19,6 +19,7 @@ import chat.rocket.android.dagger.qualifier.ForAuthentication import chat.rocket.android.dagger.qualifier.ForMessages import chat.rocket.android.db.DatabaseManager import chat.rocket.android.db.DatabaseManagerFactory +import chat.rocket.android.dynamiclinks.DynamicLinksForFirebase import chat.rocket.android.helper.MessageParser import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.SharedPreferencesLocalRepository @@ -378,6 +379,12 @@ class AppModule { return AnswersAnalytics() } + @Provides + @Singleton + fun provideDynamicLinkForFirebase(context: Application): DynamicLinksForFirebase { + return DynamicLinksForFirebase(context) + } + @Provides @Singleton fun provideGoogleAnalyticsForFirebase(context: Application): GoogleAnalyticsForFirebase { diff --git a/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt b/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt new file mode 100644 index 0000000000..f23cc9cc74 --- /dev/null +++ b/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt @@ -0,0 +1,11 @@ +package chat.rocket.android.dynamiclinks + +import android.content.Intent +import android.net.Uri + +interface DynamicLinks { + + fun getDynamicLink(intent: Intent) : Uri? + + fun createDynamicLink(username: String, server: String) : String? +} diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt index dd2e56b436..f178656f1c 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt @@ -2,13 +2,6 @@ package chat.rocket.android.main.presentation import android.content.Context import android.content.Intent -import android.net.Uri -import android.view.LayoutInflater -import android.widget.EditText -import android.widget.TextView -import android.widget.Toast -import androidx.appcompat.app.AlertDialog -import androidx.core.content.ContextCompat.startActivity import chat.rocket.android.R import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor @@ -16,6 +9,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.db.DatabaseManagerFactory import chat.rocket.android.db.DatabaseManager import chat.rocket.android.db.model.ChatRoomEntity +import chat.rocket.android.dynamiclinks.DynamicLinksForFirebase import chat.rocket.android.emoji.Emoji import chat.rocket.android.emoji.EmojiRepository import chat.rocket.android.emoji.Fitzpatrick @@ -58,9 +52,6 @@ import chat.rocket.common.model.roomTypeOf import chat.rocket.core.model.ChatRoom import chat.rocket.core.model.Myself import chat.rocket.common.model.RoomType -import com.google.firebase.dynamiclinks.DynamicLink -import com.google.firebase.dynamiclinks.FirebaseDynamicLinks -import com.google.firebase.dynamiclinks.ShortDynamicLink import kotlinx.coroutines.experimental.channels.Channel import kotlinx.coroutines.experimental.CommonPool import kotlinx.coroutines.experimental.launch @@ -99,6 +90,9 @@ class MainPresenter @Inject constructor( tokenView = view, navigator = navigator ) { + @Inject + lateinit var dynamicLinksManager : DynamicLinksForFirebase + private val currentServer = serverInteractor.get()!! private val manager = managerFactory.create(currentServer) private val dbManager = dbManagerFactory.create(currentServer) @@ -333,32 +327,39 @@ class MainPresenter @Inject constructor( val account = getAccountInteractor.get(server)!! val userName = account.userName - FirebaseDynamicLinks.getInstance().createDynamicLink() - .setLink(Uri.parse("$server/direct/$userName")) - .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) - .setAndroidParameters( - DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) - .setSocialMetaTagParameters( - DynamicLink.SocialMetaTagParameters.Builder() - .setTitle(userName) - .setDescription("Chat with $userName on " + context.getString(R.string.widechat_server_url)) - .build()) - .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) - .addOnSuccessListener { result -> - val link = result.shortLink.toString() - Toast.makeText(context, link, Toast.LENGTH_SHORT).show() - - with(Intent(Intent.ACTION_SEND)) { - type = "text/plain" - putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) - putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") - context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) - } - - }.addOnFailureListener { - // Error - Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() - } +// FirebaseDynamicLinks.getInstance().createDynamicLink() +// .setLink(Uri.parse("$server/direct/$userName")) +// .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) +// .setAndroidParameters( +// DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) +// .setSocialMetaTagParameters( +// DynamicLink.SocialMetaTagParameters.Builder() +// .setTitle(userName) +// .setDescription("Chat with $userName on " + context.getString(R.string.widechat_server_url)) +// .build()) +// .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) +// .addOnSuccessListener { result -> +// val link = result.shortLink.toString() +// Toast.makeText(context, link, Toast.LENGTH_SHORT).show() +// +// with(Intent(Intent.ACTION_SEND)) { +// type = "text/plain" +// putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) +// putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") +// context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) +// } +// +// }.addOnFailureListener { +// // Error +// Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() +// } + val link = dynamicLinksManager.createDynamicLink(userName, server) + with(Intent(Intent.ACTION_SEND)) { + type = "text/plain" + putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) + putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") + context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) + } } } diff --git a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt index e858888b2a..332fcdf808 100644 --- a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt +++ b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt @@ -137,8 +137,6 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, override fun onResume() { supportFragmentManager.popBackStackImmediate("contactsFragment", 1) - Timber.d("########### EAR >> just hit onResume in main activity...") - super.onResume() syncContacts() if (!isFragmentAdded) { diff --git a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt new file mode 100644 index 0000000000..0efb51ee83 --- /dev/null +++ b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt @@ -0,0 +1,70 @@ +package chat.rocket.android.dynamiclinks + +import android.content.Context +import android.content.Intent +import android.net.Uri +import chat.rocket.android.util.TimberLogger +import chat.rocket.android.R +import com.google.firebase.dynamiclinks.DynamicLink +import com.google.firebase.dynamiclinks.FirebaseDynamicLinks +import com.google.firebase.dynamiclinks.ShortDynamicLink +import javax.inject.Inject + +import kotlinx.coroutines.experimental.runBlocking + +// DEBUG +import android.widget.Toast + +class DynamicLinksForFirebase @Inject constructor(private val context: Context) : + DynamicLinks { + + private var deepLink: Uri? = null + private var newDeepLink: String? = null + + override fun getDynamicLink(intent: Intent) : Uri? { + + runBlocking { + + FirebaseDynamicLinks.getInstance() + .getDynamicLink(intent) + .addOnSuccessListener { pendingDynamicLinkData -> + if (pendingDynamicLinkData != null) { + deepLink = pendingDynamicLinkData.link + } + + TimberLogger.debug("DeepLink:" + deepLink.toString()) + } + .addOnFailureListener { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } + } + return deepLink + } + + override fun createDynamicLink(username: String, server: String ) : String? { + + runBlocking { + + FirebaseDynamicLinks.getInstance().createDynamicLink() + .setLink(Uri.parse("$server/direct/$username")) + .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) + .setAndroidParameters( + DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) + .setSocialMetaTagParameters( + DynamicLink.SocialMetaTagParameters.Builder() + .setTitle(username) + .setDescription("Chat with $username on " + context.getString(R.string.widechat_server_url)) + .build()) + .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) + .addOnSuccessListener { result -> + newDeepLink = result.shortLink.toString() + Toast.makeText(context, newDeepLink, Toast.LENGTH_SHORT).show() + + }.addOnFailureListener { + // Error + Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() + } + } + return newDeepLink + } +} + + From a7dd9588a79befb12761886386ec25e0393763f6 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Fri, 25 Jan 2019 12:54:55 -0500 Subject: [PATCH 12/16] debug --- .../ui/AuthenticationActivity.kt | 11 +++-- .../dynamiclinks/DynamicLinksForFirebase.kt | 42 +++++++++---------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt index baf9fe4c22..d90ac82c76 100644 --- a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt +++ b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt @@ -26,6 +26,9 @@ import kotlinx.android.synthetic.main.app_bar.* import kotlinx.coroutines.experimental.Job import javax.inject.Inject +// Test +import com.google.firebase.dynamiclinks.FirebaseDynamicLinks + class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { @Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector @@ -77,10 +80,10 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { } } -// -// -// -// + + + + // FirebaseDynamicLinks.getInstance() // .getDynamicLink(intent) // .addOnSuccessListener(this) { pendingDynamicLinkData -> diff --git a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt index 0efb51ee83..240f922a10 100644 --- a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt +++ b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt @@ -33,6 +33,9 @@ class DynamicLinksForFirebase @Inject constructor(private val context: Context) } TimberLogger.debug("DeepLink:" + deepLink.toString()) +// deepLink?.context.getDeepLinkInfo()?.let { +// context.routeDeepLink(it) +// } } .addOnFailureListener { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } } @@ -41,28 +44,25 @@ class DynamicLinksForFirebase @Inject constructor(private val context: Context) override fun createDynamicLink(username: String, server: String ) : String? { - runBlocking { - - FirebaseDynamicLinks.getInstance().createDynamicLink() - .setLink(Uri.parse("$server/direct/$username")) - .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) - .setAndroidParameters( - DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) - .setSocialMetaTagParameters( - DynamicLink.SocialMetaTagParameters.Builder() - .setTitle(username) - .setDescription("Chat with $username on " + context.getString(R.string.widechat_server_url)) - .build()) - .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) - .addOnSuccessListener { result -> - newDeepLink = result.shortLink.toString() - Toast.makeText(context, newDeepLink, Toast.LENGTH_SHORT).show() + FirebaseDynamicLinks.getInstance().createDynamicLink() + .setLink(Uri.parse("$server/direct/$username")) + .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) + .setAndroidParameters( + DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) + .setSocialMetaTagParameters( + DynamicLink.SocialMetaTagParameters.Builder() + .setTitle(username) + .setDescription("Chat with $username on " + context.getString(R.string.widechat_server_url)) + .build()) + .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) + .addOnSuccessListener { result -> + newDeepLink = result.shortLink.toString() + Toast.makeText(context, newDeepLink, Toast.LENGTH_SHORT).show() - }.addOnFailureListener { - // Error - Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() - } - } + }.addOnFailureListener { + // Error + Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() + } return newDeepLink } } From 7ca0f5a8d015504037d0f9401dad6211110c7d37 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Fri, 25 Jan 2019 16:03:37 -0500 Subject: [PATCH 13/16] add dagger to deepLinks code --- .../ui/AuthenticationActivity.kt | 38 +++--------------- .../android/chatrooms/ui/ChatRoomsFragment.kt | 2 - .../android/dynamiclinks/DynamicLinks.kt | 4 +- .../main/presentation/MainPresenter.kt | 40 ++++--------------- .../rocket/android/main/ui/MainActivity.kt | 10 +---- .../dynamiclinks/DynamicLinksForFirebase.kt | 21 +++------- 6 files changed, 23 insertions(+), 92 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt index d90ac82c76..c07b438f4e 100644 --- a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt +++ b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt @@ -16,7 +16,6 @@ import chat.rocket.android.authentication.domain.model.isSupportedLink import chat.rocket.android.authentication.presentation.AuthenticationPresenter import chat.rocket.android.dynamiclinks.DynamicLinksForFirebase import chat.rocket.android.helper.Constants -import chat.rocket.android.util.TimberLogger import chat.rocket.common.util.ifNull import dagger.android.AndroidInjection import dagger.android.AndroidInjector @@ -26,9 +25,6 @@ import kotlinx.android.synthetic.main.app_bar.* import kotlinx.coroutines.experimental.Job import javax.inject.Inject -// Test -import com.google.firebase.dynamiclinks.FirebaseDynamicLinks - class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { @Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector @@ -72,38 +68,14 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { } private fun resolveDynamicLink(intent: Intent) { - var dynamicLink: Uri? = null - dynamicLink = dynamicLinksManager.getDynamicLink(intent) - - dynamicLink?.getDeepLinkInfo()?.let { - routeDeepLink(it) + var deepLinkCallback = { returnedUri: Uri? -> + returnedUri?.getDeepLinkInfo()?.let{ + routeDeepLink(it) + } } + dynamicLinksManager.getDynamicLink(intent, deepLinkCallback) } - - - - -// FirebaseDynamicLinks.getInstance() -// .getDynamicLink(intent) -// .addOnSuccessListener(this) { pendingDynamicLinkData -> -// var deepLink: Uri? = null -// if (pendingDynamicLinkData != null) { -// deepLink = pendingDynamicLinkData.link -// } -// -// TimberLogger.debug("Resolved DeepLink:" + deepLink.toString()) -// deepLink?.getDeepLinkInfo()?.let{ -// routeDeepLink(it) -// } -// } -// .addOnFailureListener(this) { -// e -> TimberLogger.debug("getDynamicLink:onFailure : $e") -// routeNoLink() -// } -// } - - private fun setupToolbar() { with(toolbar) { setSupportActionBar(this) diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 6c562e2372..2e91a80b18 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -44,7 +44,6 @@ import javax.inject.Inject // WIDECHAT import android.graphics.Color -import android.net.Uri import android.widget.* import chat.rocket.android.authentication.domain.model.DeepLinkInfo import chat.rocket.android.chatrooms.adapter.model.RoomUiModel @@ -52,7 +51,6 @@ import chat.rocket.android.helper.UserHelper import chat.rocket.android.profile.ui.ProfileFragment import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.settings.ui.SettingsFragment -import chat.rocket.android.util.TimberLogger import chat.rocket.android.util.extensions.avatarUrl import com.facebook.drawee.view.SimpleDraweeView import kotlinx.android.synthetic.main.app_bar.* diff --git a/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt b/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt index f23cc9cc74..2576c663c3 100644 --- a/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt +++ b/app/src/main/java/chat/rocket/android/dynamiclinks/DynamicLinks.kt @@ -5,7 +5,7 @@ import android.net.Uri interface DynamicLinks { - fun getDynamicLink(intent: Intent) : Uri? + fun getDynamicLink(intent: Intent, deepLinkCallback: (Uri?) -> Unit? ) - fun createDynamicLink(username: String, server: String) : String? + fun createDynamicLink(username: String, server: String, deepLinkCallback: (String?) -> Unit?) } diff --git a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt index f178656f1c..41e8170ac3 100644 --- a/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt +++ b/app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt @@ -327,39 +327,15 @@ class MainPresenter @Inject constructor( val account = getAccountInteractor.get(server)!! val userName = account.userName -// FirebaseDynamicLinks.getInstance().createDynamicLink() -// .setLink(Uri.parse("$server/direct/$userName")) -// .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) -// .setAndroidParameters( -// DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) -// .setSocialMetaTagParameters( -// DynamicLink.SocialMetaTagParameters.Builder() -// .setTitle(userName) -// .setDescription("Chat with $userName on " + context.getString(R.string.widechat_server_url)) -// .build()) -// .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) -// .addOnSuccessListener { result -> -// val link = result.shortLink.toString() -// Toast.makeText(context, link, Toast.LENGTH_SHORT).show() -// -// with(Intent(Intent.ACTION_SEND)) { -// type = "text/plain" -// putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) -// putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") -// context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) -// } -// -// }.addOnFailureListener { -// // Error -// Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() -// } - val link = dynamicLinksManager.createDynamicLink(userName, server) - with(Intent(Intent.ACTION_SEND)) { - type = "text/plain" - putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) - putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $link") - context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) + var deepLinkCallback = { returnedString: String? -> + with(Intent(Intent.ACTION_SEND)) { + type = "text/plain" + putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_check_this_out)) + putExtra(Intent.EXTRA_TEXT, "Default Invitation Text : $returnedString") + context.startActivity(Intent.createChooser(this, context.getString(R.string.msg_share_using))) + } } + dynamicLinksManager.createDynamicLink(userName, server, deepLinkCallback) } } diff --git a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt index 332fcdf808..9711a515fd 100644 --- a/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt +++ b/app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt @@ -22,6 +22,8 @@ import androidx.work.WorkManager import chat.rocket.android.BuildConfig import chat.rocket.android.R import chat.rocket.android.authentication.domain.model.DeepLinkInfo +import chat.rocket.android.chatrooms.ui.ChatRoomsFragment +import chat.rocket.android.chatrooms.ui.TAG_CHAT_ROOMS_FRAGMENT import chat.rocket.android.contacts.worker.ContactSyncWorker import chat.rocket.android.main.adapter.AccountsAdapter import chat.rocket.android.main.adapter.Selector @@ -49,17 +51,9 @@ import kotlinx.android.synthetic.main.app_bar.* import kotlinx.android.synthetic.main.nav_header.view.* import javax.inject.Inject -// TEST -import chat.rocket.android.chatrooms.ui.TAG_CHAT_ROOMS_FRAGMENT -import chat.rocket.android.chatrooms.ui.ChatRoomsFragment - - // WIDECHAT import chat.rocket.android.helper.Constants -// test -import timber.log.Timber - private const val CURRENT_STATE = "current_state" class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, diff --git a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt index 240f922a10..c0694b9760 100644 --- a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt +++ b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt @@ -10,20 +10,17 @@ import com.google.firebase.dynamiclinks.FirebaseDynamicLinks import com.google.firebase.dynamiclinks.ShortDynamicLink import javax.inject.Inject -import kotlinx.coroutines.experimental.runBlocking - // DEBUG import android.widget.Toast -class DynamicLinksForFirebase @Inject constructor(private val context: Context) : + +class DynamicLinksForFirebase @Inject constructor(private var context: Context) : DynamicLinks { private var deepLink: Uri? = null private var newDeepLink: String? = null - override fun getDynamicLink(intent: Intent) : Uri? { - - runBlocking { + override fun getDynamicLink(intent: Intent, deepLinkCallback: (Uri?) -> Unit?) { FirebaseDynamicLinks.getInstance() .getDynamicLink(intent) @@ -31,18 +28,12 @@ class DynamicLinksForFirebase @Inject constructor(private val context: Context) if (pendingDynamicLinkData != null) { deepLink = pendingDynamicLinkData.link } - - TimberLogger.debug("DeepLink:" + deepLink.toString()) -// deepLink?.context.getDeepLinkInfo()?.let { -// context.routeDeepLink(it) -// } + deepLinkCallback(deepLink) } .addOnFailureListener { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } - } - return deepLink } - override fun createDynamicLink(username: String, server: String ) : String? { + override fun createDynamicLink(username: String, server: String, deepLinkCallback: (String?) -> Unit? ) { FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("$server/direct/$username")) @@ -58,12 +49,12 @@ class DynamicLinksForFirebase @Inject constructor(private val context: Context) .addOnSuccessListener { result -> newDeepLink = result.shortLink.toString() Toast.makeText(context, newDeepLink, Toast.LENGTH_SHORT).show() + deepLinkCallback(newDeepLink) }.addOnFailureListener { // Error Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() } - return newDeepLink } } From 122735d813746b0a04f34a37e83f385e5ec18a33 Mon Sep 17 00:00:00 2001 From: erosenthal Date: Fri, 25 Jan 2019 16:54:52 -0500 Subject: [PATCH 14/16] cleanup and handle foss --- .../dynamiclinks/DynamicLinksForFirebase.kt | 8 ++- .../ui/AuthenticationActivity.kt | 7 ++- .../dynamiclinks/DynamicLinksForFirebase.kt | 57 +++++++++---------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt b/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt index fc1baad372..84c64b5263 100644 --- a/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt +++ b/app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt @@ -7,7 +7,11 @@ import javax.inject.Inject class DynamicLinksForFirebase @Inject constructor(private val context: Context) : DynamicLinks { - override fun getDynamicLink(intent: Intent) : Uri? { return null} + override fun getDynamicLink(intent: Intent, deepLinkCallback: (Uri?) -> Unit? ) { + deepLinkCallback(null) + } - override fun createDynamicLink(username: String, server: String) : String? { return null } + override fun createDynamicLink(username: String, server: String, deepLinkCallback: (String?) -> Unit?) { + deepLinkCallback(null) + } } diff --git a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt index c07b438f4e..6627f7be1d 100644 --- a/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt +++ b/app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt @@ -69,9 +69,12 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { private fun resolveDynamicLink(intent: Intent) { var deepLinkCallback = { returnedUri: Uri? -> - returnedUri?.getDeepLinkInfo()?.let{ + if (returnedUri == null) { + routeNoLink() + } else { + returnedUri?.getDeepLinkInfo()?.let { routeDeepLink(it) - } + } } } dynamicLinksManager.getDynamicLink(intent, deepLinkCallback) } diff --git a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt index c0694b9760..ca039a3e8d 100644 --- a/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt +++ b/app/src/play/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt @@ -13,7 +13,6 @@ import javax.inject.Inject // DEBUG import android.widget.Toast - class DynamicLinksForFirebase @Inject constructor(private var context: Context) : DynamicLinks { @@ -22,39 +21,39 @@ class DynamicLinksForFirebase @Inject constructor(private var context: Context) override fun getDynamicLink(intent: Intent, deepLinkCallback: (Uri?) -> Unit?) { - FirebaseDynamicLinks.getInstance() - .getDynamicLink(intent) - .addOnSuccessListener { pendingDynamicLinkData -> - if (pendingDynamicLinkData != null) { - deepLink = pendingDynamicLinkData.link - } - deepLinkCallback(deepLink) - } - .addOnFailureListener { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } + FirebaseDynamicLinks.getInstance() + .getDynamicLink(intent) + .addOnSuccessListener { pendingDynamicLinkData -> + if (pendingDynamicLinkData != null) { + deepLink = pendingDynamicLinkData.link + } + deepLinkCallback(deepLink) + } + .addOnFailureListener { e -> TimberLogger.debug("getDynamicLink:onFailure : $e") } } override fun createDynamicLink(username: String, server: String, deepLinkCallback: (String?) -> Unit? ) { FirebaseDynamicLinks.getInstance().createDynamicLink() - .setLink(Uri.parse("$server/direct/$username")) - .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) - .setAndroidParameters( - DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) - .setSocialMetaTagParameters( - DynamicLink.SocialMetaTagParameters.Builder() - .setTitle(username) - .setDescription("Chat with $username on " + context.getString(R.string.widechat_server_url)) - .build()) - .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) - .addOnSuccessListener { result -> - newDeepLink = result.shortLink.toString() - Toast.makeText(context, newDeepLink, Toast.LENGTH_SHORT).show() - deepLinkCallback(newDeepLink) - - }.addOnFailureListener { - // Error - Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() - } + .setLink(Uri.parse("$server/direct/$username")) + .setDomainUriPrefix("https://" + context.getString(R.string.widechat_deeplink_host)) + .setAndroidParameters( + DynamicLink.AndroidParameters.Builder(context.getString(R.string.widechat_package_name)).build()) + .setSocialMetaTagParameters( + DynamicLink.SocialMetaTagParameters.Builder() + .setTitle(username) + .setDescription("Chat with $username on " + context.getString(R.string.widechat_server_url)) + .build()) + .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT) + .addOnSuccessListener { result -> + newDeepLink = result.shortLink.toString() + Toast.makeText(context, newDeepLink, Toast.LENGTH_SHORT).show() + deepLinkCallback(newDeepLink) + + }.addOnFailureListener { + // Error + Toast.makeText(context, "Error dynamic link", Toast.LENGTH_SHORT).show() + } } } From e2967e09478a917e146966642075614f7172bdaa Mon Sep 17 00:00:00 2001 From: Peter Lepeska Date: Sun, 27 Jan 2019 18:25:25 -0500 Subject: [PATCH 15/16] updates from code review --- .../domain/model/DeepLinkInfo.kt | 3 +++ .../presentation/AuthenticationNavigator.kt | 27 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt b/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt index 3ae397667d..ac0dd47f29 100644 --- a/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt +++ b/app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt @@ -70,6 +70,7 @@ fun Uri.isDynamicLink(): Boolean { return (host != null && host.contains("page.link", ignoreCase = true)) } +// Authentication deep link defined here: https://rocket.chat/docs/developer-guides/deeplink/#authentication private inline fun Uri.isAuthenticationDeepLink(): Boolean { if (host == "auth") return true @@ -78,6 +79,7 @@ private inline fun Uri.isAuthenticationDeepLink(): Boolean { return false } +// Custom scheme room deep link defined here: https://rocket.chat/docs/developer-guides/deeplink/#channel--group--dm private inline fun Uri.isCustomSchemeRoomLink(): Boolean { if (scheme.startsWith("rocketchat") && host == "room") @@ -85,6 +87,7 @@ private inline fun Uri.isCustomSchemeRoomLink(): Boolean { return false } +// http(s) scheme deep link not yet documented. Ex: https://viasatconnect.com/direct/testuser1 private inline fun Uri.isWebSchemeRoomLink(): Boolean { val roomType = path.split("/")[1] if (scheme.startsWith("http") && diff --git a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt index 4d4f52c637..4613532a30 100644 --- a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt +++ b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt @@ -138,26 +138,23 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) { activity.overridePendingTransition(R.anim.slide_up, R.anim.hold) } - fun toChatList() { - savedDeepLinkInfo?.let { - toChatList(it) - } .ifNull { - activity.startActivity(Intent(activity, MainActivity::class.java)) - activity.finish() - } - savedDeepLinkInfo = null - } - fun toChatList(serverUrl: String) { activity.startActivity(activity.changeServerIntent(serverUrl)) activity.finish() } - fun toChatList(deepLinkInfo: DeepLinkInfo) { - activity.startActivity(Intent(activity, MainActivity::class.java).also { - it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) - it.putExtra(Constants.DEEP_LINK_INFO, deepLinkInfo) - }) + fun toChatList(passedDeepLinkInfo: DeepLinkInfo) { + val deepLinkInfo = if (passedDeepLinkInfo != null) passedDeepLinkInfo else savedDeepLinkInfo + savedDeepLinkInfo = null + + if (deepLinkInfo != null) { + activity.startActivity(Intent(activity, MainActivity::class.java).also { + it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + it.putExtra(Constants.DEEP_LINK_INFO, deepLinkInfo) + }) + } else { + activity.startActivity(Intent(activity, MainActivity::class.java)) + } activity.finish() } } From 8f5818c095cb402bb9c28a76de581fecc233ac44 Mon Sep 17 00:00:00 2001 From: Peter Lepeska Date: Mon, 28 Jan 2019 09:48:23 -0500 Subject: [PATCH 16/16] fix --- .../authentication/presentation/AuthenticationNavigator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt index 4613532a30..474162b4d7 100644 --- a/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt +++ b/app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt @@ -143,7 +143,7 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) { activity.finish() } - fun toChatList(passedDeepLinkInfo: DeepLinkInfo) { + fun toChatList(passedDeepLinkInfo: DeepLinkInfo? = null) { val deepLinkInfo = if (passedDeepLinkInfo != null) passedDeepLinkInfo else savedDeepLinkInfo savedDeepLinkInfo = null