|
@@ -23,7 +23,10 @@
|
|
|
|
|
|
package com.owncloud.android.ui.fragment;
|
|
|
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.IntentFilter;
|
|
|
import android.content.res.Configuration;
|
|
|
import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
@@ -54,6 +57,7 @@ import javax.inject.Inject;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
@@ -64,6 +68,8 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|
|
private static final int MAX_ITEMS_PER_ROW = 10;
|
|
|
private static final String FRAGMENT_TAG_BOTTOM_SHEET = "data";
|
|
|
|
|
|
+ public static final String REFRESH_SEARCH_EVENT_RECEIVER = "refreshSearchEventReceiver";
|
|
|
+
|
|
|
private boolean photoSearchQueryRunning = false;
|
|
|
private AsyncTask<Void, Void, GallerySearchTask.Result> photoSearchTask;
|
|
|
private long endDate;
|
|
@@ -103,6 +109,28 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|
|
} else {
|
|
|
columnSize = maxColumnSizePortrait;
|
|
|
}
|
|
|
+
|
|
|
+ registerRefreshSearchEventReceiver();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void registerRefreshSearchEventReceiver() {
|
|
|
+ IntentFilter filter = new IntentFilter(REFRESH_SEARCH_EVENT_RECEIVER);
|
|
|
+ LocalBroadcastManager.getInstance(requireContext()).registerReceiver(refreshSearchEventReceiver, filter);
|
|
|
+ }
|
|
|
+
|
|
|
+ private final BroadcastReceiver refreshSearchEventReceiver = new BroadcastReceiver() {
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ if (getActivity() instanceof FileDisplayActivity fileDisplayActivity) {
|
|
|
+ fileDisplayActivity.startPhotoSearch(R.id.nav_gallery);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroyView() {
|
|
|
+ LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(refreshSearchEventReceiver);
|
|
|
+ super.onDestroyView();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -200,10 +228,9 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|
|
@Override
|
|
|
public void onResume() {
|
|
|
super.onResume();
|
|
|
+
|
|
|
setLoading(this.isPhotoSearchQueryRunning());
|
|
|
- final FragmentActivity activity = getActivity();
|
|
|
- if (activity instanceof FileDisplayActivity) {
|
|
|
- FileDisplayActivity fileDisplayActivity = ((FileDisplayActivity) activity);
|
|
|
+ if (getActivity() instanceof FileDisplayActivity fileDisplayActivity) {
|
|
|
fileDisplayActivity.updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_gallery));
|
|
|
fileDisplayActivity.setMainFabVisible(false);
|
|
|
}
|
|
@@ -247,7 +274,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|
|
setEmptyListMessage(SearchType.GALLERY_SEARCH);
|
|
|
}
|
|
|
|
|
|
- if(!emptySearch) {
|
|
|
+ if (!emptySearch) {
|
|
|
this.showAllGalleryItems();
|
|
|
}
|
|
|
|
|
@@ -317,8 +344,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|
|
}
|
|
|
|
|
|
private void loadMoreWhenEndReached(@NonNull RecyclerView recyclerView, int dy) {
|
|
|
- if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
|
|
|
- GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
|
|
|
+ if (recyclerView.getLayoutManager() instanceof GridLayoutManager gridLayoutManager) {
|
|
|
|
|
|
// scroll down
|
|
|
if (dy > 0 && !this.isPhotoSearchQueryRunning()) {
|