mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
Unified search: fix opening non-file results (open in a browser)
Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
c3a1656781
commit
fdf1abd0fd
2 changed files with 27 additions and 18 deletions
|
@ -44,13 +44,14 @@ import com.owncloud.android.lib.common.SearchResultEntry
|
|||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import com.owncloud.android.ui.adapter.UnifiedSearchListAdapter
|
||||
import com.owncloud.android.ui.asynctasks.GetRemoteFileTask
|
||||
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
|
||||
import com.owncloud.android.ui.unifiedsearch.ProviderID
|
||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchSection
|
||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import javax.inject.Inject
|
||||
import android.content.Intent
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
|
||||
/**
|
||||
* Starts query to all capable unified search providers and displays them Opens result in our app, redirect to other
|
||||
|
@ -105,6 +106,13 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
|
|||
.updateActionBarTitleAndHomeButtonByString("\"${query}\"")
|
||||
}
|
||||
}
|
||||
vm.browserUri.observe(this) { uri ->
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
|
||||
startActivity(browserIntent)
|
||||
}
|
||||
vm.file.observe(this) {
|
||||
showFile(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpBinding() {
|
||||
|
@ -148,36 +156,24 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
|
|||
_binding = null
|
||||
}
|
||||
|
||||
private fun showFile(result: GetRemoteFileTask.Result) {
|
||||
private fun showFile(file: OCFile) {
|
||||
activity.let {
|
||||
if (activity is FileDisplayActivity) {
|
||||
val fda = activity as FileDisplayActivity
|
||||
fda.file = result.file
|
||||
fda.file = file
|
||||
fda.showFile("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSearchResultClicked(searchResultEntry: SearchResultEntry) {
|
||||
openFile(searchResultEntry.remotePath())
|
||||
vm.openResult(searchResultEntry)
|
||||
}
|
||||
|
||||
override fun onLoadMoreClicked(providerID: ProviderID) {
|
||||
vm.loadMore(providerID)
|
||||
}
|
||||
|
||||
fun openFile(fileUrl: String) {
|
||||
val user = currentAccountProvider.user
|
||||
val task = GetRemoteFileTask(
|
||||
requireContext(),
|
||||
fileUrl,
|
||||
clientFactory.create(currentAccountProvider.user),
|
||||
FileDataStorageManager(user.toPlatformAccount(), requireContext().contentResolver),
|
||||
user
|
||||
)
|
||||
runner.postQuickTask(task, onResult = this::showFile)
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun onSearchResultChanged(result: List<UnifiedSearchSection>) {
|
||||
Log_OC.d(TAG, "result")
|
||||
|
|
|
@ -30,9 +30,12 @@ import com.nextcloud.client.network.ClientFactory
|
|||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.lib.common.SearchResult
|
||||
import com.owncloud.android.lib.common.SearchResultEntry
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.asynctasks.GetRemoteFileTask
|
||||
import javax.inject.Inject
|
||||
import android.net.Uri
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
class UnifiedSearchViewModel() : ViewModel() {
|
||||
|
@ -74,6 +77,8 @@ class UnifiedSearchViewModel() : ViewModel() {
|
|||
val searchResults = MutableLiveData<List<UnifiedSearchSection>>(mutableListOf())
|
||||
val error: MutableLiveData<String> = MutableLiveData<String>("")
|
||||
val query: MutableLiveData<String> = MutableLiveData()
|
||||
val browserUri: MutableLiveData<Uri> = MutableLiveData()
|
||||
val file: MutableLiveData<OCFile> = MutableLiveData()
|
||||
|
||||
@Inject
|
||||
constructor(
|
||||
|
@ -136,6 +141,15 @@ class UnifiedSearchViewModel() : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
fun openResult(result: SearchResultEntry) {
|
||||
if (result.fileId() != null) {
|
||||
openFile(result.remotePath())
|
||||
} else {
|
||||
val uri = Uri.parse(result.resourceUrl)
|
||||
this.browserUri.value = uri
|
||||
}
|
||||
}
|
||||
|
||||
fun openFile(fileUrl: String) {
|
||||
if (isLoading.value == false) {
|
||||
isLoading.value = true
|
||||
|
@ -213,8 +227,7 @@ class UnifiedSearchViewModel() : ViewModel() {
|
|||
private fun onFileRequestResult(result: GetRemoteFileTask.Result) {
|
||||
isLoading.value = false
|
||||
if (result.success) {
|
||||
// unifiedSearchFragment.showFile(result.file)
|
||||
// (file as MutableLiveData).value = result.file
|
||||
file.value = result.file
|
||||
} else {
|
||||
error.value = "Error showing search result"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue