Skip to content

Commit

Permalink
Opening app with DeepLink, solving login problems
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelplazaspalacio committed Oct 16, 2023
1 parent 824514b commit 64dd8b5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class AuthenticationViewModel(
private val _legacyWebfingerHost = MediatorLiveData<Event<UIResult<String>>>()
val legacyWebfingerHost: LiveData<Event<UIResult<String>>> = _legacyWebfingerHost

var launchedFromDeepLink = false

fun getLegacyWebfingerHost(
webfingerLookupServer: String,
webfingerUsername: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import com.owncloud.android.presentation.security.SecurityEnforced
import com.owncloud.android.presentation.settings.SettingsActivity
import com.owncloud.android.providers.ContextProvider
import com.owncloud.android.providers.MdmProvider
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog
import com.owncloud.android.utils.CONFIGURATION_OAUTH2_OPEN_ID_PROMPT
import com.owncloud.android.utils.CONFIGURATION_OAUTH2_OPEN_ID_SCOPE
Expand Down Expand Up @@ -117,6 +118,7 @@ class LoginActivity : AppCompatActivity(), SslUntrustedCertDialog.OnSslUntrusted
} // else, let it go, or taking screenshots & testing will not be possible

// Get values from intent
handleDeepLink()
loginAction = intent.getByteExtra(EXTRA_ACTION, ACTION_CREATE)
authTokenType = intent.getStringExtra(KEY_AUTH_TOKEN_TYPE)
userAccount = intent.getParcelableExtra(EXTRA_ACCOUNT)
Expand Down Expand Up @@ -188,6 +190,24 @@ class LoginActivity : AppCompatActivity(), SslUntrustedCertDialog.OnSslUntrusted
initLiveDataObservers()
}

private fun handleDeepLink() {
if (intent.data != null) {
authenticationViewModel.launchedFromDeepLink = true
if (com.owncloud.android.presentation.authentication.AccountUtils.getAccounts(baseContext).isNotEmpty()) {
launchFileDisplayActivity()
} else {
showMessageInSnackbar(message = baseContext.getString(R.string.no_user_logged_for_deep_link))
}
}
}

private fun launchFileDisplayActivity() {
val newIntent = Intent(this, FileDisplayActivity::class.java)
newIntent.data = intent.data
startActivity(newIntent)
finish()
}

private fun initLiveDataObservers() {
// LiveData observers
authenticationViewModel.legacyWebfingerHost.observe(this) { event ->
Expand Down Expand Up @@ -217,8 +237,11 @@ class LoginActivity : AppCompatActivity(), SslUntrustedCertDialog.OnSslUntrusted
authenticationViewModel.accountDiscovery.observe(this) {
if (it.peekContent() is UIResult.Success) {
notifyDocumentsProviderRoots(applicationContext)

finish()
if (authenticationViewModel.launchedFromDeepLink) {
launchFileDisplayActivity()
} else {
finish()
}
} else {
binding.authStatusText.run {
text = context.getString(R.string.login_account_preparing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.owncloud.android.presentation.files.operations

import android.net.Uri
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.ViewModel
Expand Down Expand Up @@ -287,4 +288,7 @@ class FileOperationsViewModel(
}
}
}

fun handleDeepLink(uri: Uri) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class FileDisplayActivity : FileActivity(),

localBroadcastManager = LocalBroadcastManager.getInstance(this)

handleDeepLink()

/// Load of saved instance state
if (savedInstanceState != null) {
Timber.d(savedInstanceState.toString())
Expand Down Expand Up @@ -1782,6 +1784,13 @@ class FileDisplayActivity : FileActivity(),
)
}

private fun handleDeepLink() {
intent.data?.let { uri ->
fileOperationsViewModel.handleDeepLink(uri)
intent.data = null
}
}

companion object {
private const val TAG_LIST_OF_FILES = "LIST_OF_FILES"
private const val TAG_LIST_OF_SPACES = "LIST_OF_SPACES"
Expand Down
3 changes: 3 additions & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,7 @@
<string name="tab_label_ascii">Text</string>
<string name="apply_to_all_conflicts">Apply to all %1$s conflicts</string>

<!-- DeepLinks -->
<string name="no_user_logged_for_deep_link">You need a logged user to open the link</string>

</resources>

0 comments on commit 64dd8b5

Please sign in to comment.