Skip to content

Commit

Permalink
Merge pull request #170 from WideChat/ear_proto_profile_update_deeplink
Browse files Browse the repository at this point in the history
Profile update button link in CCT, with deep link to logout after the redirect from SSO
  • Loading branch information
ear-dev authored Feb 11, 2019
2 parents e4200f3 + 20873b2 commit 60f6c28
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 6 deletions.
14 changes: 13 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@
<activity
android:name=".main.ui.MainActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"/>
android:windowSoftInputMode="adjustResize|stateAlwaysHidden">

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />

<data
android:host="profile.update"
android:scheme="connect" />
</intent-filter>
</activity>

<activity
android:name=".webview.ui.WebViewActivity"
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import javax.inject.Inject

// WIDECHAT
import chat.rocket.android.helper.Constants
import androidx.core.net.toUri

private const val CURRENT_STATE = "current_state"

Expand Down Expand Up @@ -130,9 +131,13 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,

override fun onResume() {
supportFragmentManager.popBackStackImmediate("contactsFragment", 1)

super.onResume()
//syncContacts()

if (intent?.data == "connect://profile.update".toUri()) {
presenter.logout()
return
}

if (!isFragmentAdded) {
presenter.toChatList(chatRoomId, deepLinkInfo)
deepLinkInfo = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import kotlinx.coroutines.experimental.withContext
import java.util.*
import javax.inject.Inject

// WIDECHAT
import chat.rocket.core.internal.rest.getAccessToken

class ProfilePresenter @Inject constructor(
private val view: ProfileView,
private val strategy: CancelStrategy,
Expand Down Expand Up @@ -59,6 +62,9 @@ class ProfilePresenter @Inject constructor(
private val client: RocketChatClient = factory.create(serverUrl)
private val user = userHelper.user()

// WIDECHAT
var currentAccessToken: String? = null

fun loadUserProfile() {
launchUI(strategy) {
view.showLoading()
Expand All @@ -77,6 +83,23 @@ class ProfilePresenter @Inject constructor(
}
}

// WIDECHAT
fun setUpdateUrl(updatePath: String?, onClickCallback: (String?) -> Unit?) {
launchUI(strategy) {
try {
withContext(DefaultDispatcher) {
setupConnectionInfo(serverUrl)
refreshServerAccounts()
checkForCustomOauthAccount(serverUrl)
}
retryIO { currentAccessToken = client.getAccessToken(customOauthServiceName.toString())}
onClickCallback("${widechatCustomOauthHost}${updatePath}${currentAccessToken}")
} catch (ex: Exception) {
view.showMessage(ex)
}
}
}

fun updateUserProfile(email: String, name: String, username: String) {
launchUI(strategy) {
view.showLoading()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import javax.inject.Inject

// WIDECHAT
import chat.rocket.android.helper.Constants
import chat.rocket.android.util.extensions.openTabbedUrl
import kotlinx.android.synthetic.main.app_bar.* // need this for back button in setupToolbar
import kotlinx.android.synthetic.main.fragment_profile_widechat.*

Expand Down Expand Up @@ -269,7 +270,16 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {

if (Constants.WIDECHAT) {
widechat_view_dim.setOnClickListener { hideUpdateAvatarOptions() }
edit_profile_button.setOnClickListener { showToast("Edit Profile Button Clicked") }

var onClickCallback = {url: String? ->
edit_profile_button.setOnClickListener { view: View ->
view.openTabbedUrl(url)
}
edit_profile_button.setBackgroundResource(R.drawable.widechat_update_profile_button)
}

presenter.setUpdateUrl(getString(R.string.widechat_sso_profile_update_path), onClickCallback)

delete_account_button.setOnClickListener { showToast("Delete Account Button Clicked") }
} else {
view_dim.setOnClickListener { hideUpdateAvatarOptions() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ abstract class CheckServerPresenter constructor(
internal var isLoginFormEnabled = false
internal var isNewAccountCreationEnabled = false

// WIDECHAT
internal var widechatCustomOauthHost: String? = null

internal fun setupConnectionInfo(serverUrl: String) {
currentServer = serverUrl
client = factory.create(serverUrl)
Expand Down Expand Up @@ -200,6 +203,21 @@ abstract class CheckServerPresenter constructor(
}
}

// WIDECHAT
internal suspend fun checkForCustomOauthAccount(serverUrl: String) {
try {
val services = retryIO("settingsOauth()") {
client.settingsOauth().services
}

if (services.isNotEmpty()) {
checkEnabledCustomOauthAccounts(services, serverUrl)
}
} catch (exception: RocketChatException) {
Timber.e(exception)
}
}

/**
* Logout the user from the current server.
*
Expand Down Expand Up @@ -378,6 +396,7 @@ abstract class CheckServerPresenter constructor(
getServiceNameColor(serviceMap)
val serviceButtonColor = getServiceButtonColor(serviceMap)

widechatCustomOauthHost = host
if (customOauthServiceName != null &&
host != null &&
authorizePath != null &&
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/chat/rocket/android/util/extensions/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fun View.openTabbedUrl(url: String?) {
val tabsbuilder = CustomTabsIntent.Builder()
tabsbuilder.setToolbarColor(ResourcesCompat.getColor(context.resources, R.color.colorPrimary, context.theme))
val customTabsIntent = tabsbuilder.build()
// WIDECHAT NOTE: - Use chrome if they have it.
customTabsIntent.intent.setPackage("com.android.chrome")
try {
customTabsIntent.launchUrl(context, uri)
} catch (ex: Exception) {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/drawable/widechat_update_profile_button_grey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#21000000" />
<corners android:radius="100dp"/>
</shape>
<padding android:left="0dp"
android:bottom="4dp"
android:right="0dp"
android:top="4dp"/>
</item>

<item android:right="0dp" android:left="0dp" android:bottom="2dp">
<shape>
<solid android:color="@color/icon_grey"/>
<corners android:radius="100dp"/>
</shape>

<padding android:left="0dp"
android:bottom="4dp"
android:right="0dp"
android:top="4dp"/>
</item>

</layer-list>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_profile_widechat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
android:layout_marginTop="32dp"
android:layout_marginStart="@dimen/screen_edge_left_and_right_margins"
android:layout_marginEnd="@dimen/screen_edge_left_and_right_margins"
android:background="@drawable/widechat_update_profile_button"
android:background="@drawable/widechat_update_profile_button_grey"
android:textColor="@color/colorWhite"
android:text="@string/edit_profile" />

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<string name="default_protocol" translatable="false">https://</string>
<string name="server_hint_url" translatable="false">viasatconnect.com</string>
<string name="widechat_server_url" translatable="false">viasatconnect.com</string>
<string name="widechat_sso_profile_update_path" translatable="false">/federation/custom/ViasatConnectProfile.jsp?access_token=</string>
<string name="widechat_deeplink_host" translatable="false">viasatconnect.page.link</string>
<string name="widechat_package_name" translatable="false">chat.veranda.android</string>
<!--WIDECHAT deal with these strings!!-->

<!--WIDECHAT deal with these strings??-->
<string name="community_server_url" translatable="false">open.rocket.chat</string>
<string name="create_server_url" translatable="false">cloud.rocket.chat/trial</string>
<string name="play_store_link" translatable="false">https://play.google.com/store/apps/details?id=chat.rocket.android</string>
Expand Down

0 comments on commit 60f6c28

Please sign in to comment.