mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 14:45:47 +03:00
Merge pull request #9972 from nextcloud/fix/search-loading
Fix search loading animation and display
This commit is contained in:
commit
138d3a03a9
5 changed files with 96 additions and 85 deletions
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 12 KiB |
|
@ -235,38 +235,6 @@ public class ExtendedListFragment extends Fragment implements
|
|||
}
|
||||
});
|
||||
|
||||
final View mSearchEditFrame = searchView
|
||||
.findViewById(androidx.appcompat.R.id.search_edit_frame);
|
||||
|
||||
ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
|
||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
int oldVisibility = -1;
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
|
||||
int currentVisibility = mSearchEditFrame.getVisibility();
|
||||
|
||||
if (currentVisibility != oldVisibility) {
|
||||
if (currentVisibility == View.VISIBLE) {
|
||||
setEmptyListMessage(SearchType.REGULAR_FILTER);
|
||||
} else {
|
||||
if (MainApp.isOnlyOnDevice()) {
|
||||
setMessageForEmptyList(R.string.file_list_empty_headline,
|
||||
R.string.file_list_empty_on_device,
|
||||
R.drawable.ic_list_empty_folder,
|
||||
true);
|
||||
} else {
|
||||
setEmptyListMessage(SearchType.NO_SEARCH);
|
||||
}
|
||||
}
|
||||
|
||||
oldVisibility = currentVisibility;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
LinearLayout searchBar = searchView.findViewById(R.id.search_bar);
|
||||
searchBar.setLayoutTransition(new LayoutTransition());
|
||||
}
|
||||
|
|
|
@ -77,7 +77,6 @@ import com.owncloud.android.ui.activity.FileActivity;
|
|||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.activity.FolderPickerActivity;
|
||||
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
|
||||
import com.owncloud.android.ui.activity.ToolbarActivity;
|
||||
import com.owncloud.android.ui.activity.UploadFilesActivity;
|
||||
import com.owncloud.android.ui.adapter.OCFileListAdapter;
|
||||
import com.owncloud.android.ui.dialog.ChooseRichDocumentsTemplateDialogFragment;
|
||||
|
@ -1384,7 +1383,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
return mAdapter;
|
||||
}
|
||||
|
||||
private void setTitle() {
|
||||
protected void setTitle() {
|
||||
// set title
|
||||
|
||||
if (getActivity() instanceof FileDisplayActivity && currentSearchType != null) {
|
||||
|
@ -1428,7 +1427,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private void setEmptyView(SearchEvent event) {
|
||||
protected void setEmptyView(SearchEvent event) {
|
||||
if (event != null) {
|
||||
switch (event.getSearchType()) {
|
||||
case FILE_SEARCH:
|
||||
|
@ -1556,56 +1555,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
remoteOperation = new GetSharesRemoteOperation();
|
||||
}
|
||||
|
||||
remoteOperationAsyncTask = new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
setTitle();
|
||||
if (getContext() != null && !isCancelled()) {
|
||||
RemoteOperationResult remoteOperationResult = remoteOperation.execute(
|
||||
currentUser.toPlatformAccount(), getContext());
|
||||
|
||||
FileDataStorageManager storageManager = null;
|
||||
if (mContainerActivity != null && mContainerActivity.getStorageManager() != null) {
|
||||
storageManager = mContainerActivity.getStorageManager();
|
||||
}
|
||||
|
||||
if (remoteOperationResult.isSuccess() && remoteOperationResult.getResultData() != null
|
||||
&& !isCancelled() && searchFragment) {
|
||||
searchEvent = event;
|
||||
|
||||
if (remoteOperationResult.getResultData() == null || ((List) remoteOperationResult.getResultData()).isEmpty()) {
|
||||
setEmptyView(event);
|
||||
} else {
|
||||
mAdapter.setData(((RemoteOperationResult<List>) remoteOperationResult).getResultData(),
|
||||
currentSearchType,
|
||||
storageManager,
|
||||
mFile,
|
||||
true);
|
||||
}
|
||||
|
||||
final ToolbarActivity fileDisplayActivity = (ToolbarActivity) getActivity();
|
||||
if (fileDisplayActivity != null) {
|
||||
fileDisplayActivity.runOnUiThread(() -> {
|
||||
if (fileDisplayActivity != null) {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return remoteOperationResult.isSuccess();
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean bool) {
|
||||
if (!isCancelled()) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
remoteOperationAsyncTask = new OCFileListSearchAsyncTask(mContainerActivity, this, remoteOperation, currentUser, event);
|
||||
|
||||
remoteOperationAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.os.AsyncTask
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.ui.events.SearchEvent
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class OCFileListSearchAsyncTask(
|
||||
containerActivity: FileFragment.ContainerActivity,
|
||||
fragment: OCFileListFragment,
|
||||
private val remoteOperation: RemoteOperation<List<Any>>,
|
||||
private val currentUser: User,
|
||||
private val event: SearchEvent
|
||||
) : AsyncTask<Void, Void, Boolean>() {
|
||||
private val activityReference: WeakReference<FileFragment.ContainerActivity> = WeakReference(containerActivity)
|
||||
private val fragmentReference: WeakReference<OCFileListFragment> = WeakReference(fragment)
|
||||
|
||||
private val fileDataStorageManager: FileDataStorageManager?
|
||||
get() = activityReference.get()?.storageManager
|
||||
|
||||
private fun RemoteOperationResult<out Any>.hasSuccessfulResult() = this.isSuccess && this.resultData != null
|
||||
|
||||
override fun onPreExecute() {
|
||||
fragmentReference.get()?.let { fragment ->
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
fragment.isLoading = true
|
||||
fragment.setEmptyListLoadingMessage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun doInBackground(vararg voids: Void): Boolean {
|
||||
val fragment = fragmentReference.get()
|
||||
if (fragment?.context == null || isCancelled) {
|
||||
return java.lang.Boolean.FALSE
|
||||
}
|
||||
|
||||
fragment.setTitle()
|
||||
val remoteOperationResult = remoteOperation.execute(
|
||||
currentUser.toPlatformAccount(), fragment.context
|
||||
)
|
||||
if (remoteOperationResult.hasSuccessfulResult() && !isCancelled && fragment.searchFragment) {
|
||||
fragment.searchEvent = event
|
||||
if (remoteOperationResult.resultData.isNullOrEmpty()) {
|
||||
fragment.setEmptyView(event)
|
||||
} else {
|
||||
fragment.mAdapter.setData(
|
||||
remoteOperationResult.resultData,
|
||||
fragment.currentSearchType,
|
||||
fileDataStorageManager,
|
||||
fragment.mFile,
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
return remoteOperationResult.isSuccess
|
||||
}
|
||||
|
||||
override fun onPostExecute(bool: Boolean) {
|
||||
fragmentReference.get()?.let { fragment ->
|
||||
fragment.isLoading = false
|
||||
if (!isCancelled) {
|
||||
fragment.mAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
DO NOT TOUCH; GENERATED BY DRONE
|
||||
<span class="mdl-layout-title">Lint Report: 93 warnings</span>
|
||||
<span class="mdl-layout-title">Lint Report: 92 warnings</span>
|
||||
|
|
Loading…
Reference in a new issue