Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Gallery Search #14532

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -35,8 +34,7 @@
import com.owncloud.android.ui.activity.ToolbarActivity;
import com.owncloud.android.ui.adapter.CommonOCFileListAdapterInterface;
import com.owncloud.android.ui.adapter.GalleryAdapter;
import com.owncloud.android.ui.adapter.OCFileListDelegate;
import com.owncloud.android.ui.asynctasks.GallerySearchTask;
import com.owncloud.android.ui.tasks.GallerySearchTask;
import com.owncloud.android.ui.events.ChangeMenuEvent;

import javax.inject.Inject;
Expand All @@ -58,7 +56,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
public static final String REFRESH_SEARCH_EVENT_RECEIVER = "refreshSearchEventReceiver";

private boolean photoSearchQueryRunning = false;
private AsyncTask<Void, Void, GallerySearchTask.Result> photoSearchTask;
private GallerySearchTask photoSearchTask;
private long endDate;
private int limit = 150;
private GalleryAdapter mAdapter;
Expand Down Expand Up @@ -97,6 +95,7 @@ public void onCreate(Bundle savedInstanceState) {
columnSize = maxColumnSizePortrait;
}

initGallerySearchTask();
registerRefreshSearchEventReceiver();
}

Expand Down Expand Up @@ -125,15 +124,6 @@ public void onDestroyView() {
super.onDestroyView();
}

@Override
public void onPause() {
super.onPause();

if (photoSearchTask != null) {
photoSearchTask.cancel(true);
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -256,7 +246,7 @@ private void searchAndDisplay() {
// to avoid reloading the gallery, check if endDate has already a value which is not -1 or 0 (which generally means some kind of reset/init)
endDate = System.currentTimeMillis() / 1000;
this.setPhotoSearchQueryRunning(true);
runGallerySearchTask();
photoSearchTask.execute(endDate, limit);
}
}

Expand Down Expand Up @@ -327,18 +317,18 @@ private void searchAndDisplayAfterChangingFolder() {
//TODO: Fix folder change, it seems it doesn't work at all
this.endDate = System.currentTimeMillis() / 1000;
this.setPhotoSearchQueryRunning(true);
runGallerySearchTask();
photoSearchTask.execute(endDate, limit);
}

private void runGallerySearchTask() {
if (mContainerActivity != null) {
photoSearchTask = new GallerySearchTask(this,
accountManager.getUser(),
mContainerActivity.getStorageManager(),
endDate,
limit)
.execute();
private void initGallerySearchTask() {
if (mContainerActivity == null) {
return;
}

photoSearchTask = new GallerySearchTask(this,
requireContext(),
accountManager.getUser(),
mContainerActivity.getStorageManager());
}

private void loadMoreWhenEndReached(@NonNull RecyclerView recyclerView, int dy) {
Expand Down Expand Up @@ -368,7 +358,7 @@ private void loadMoreWhenEndReached(@NonNull RecyclerView recyclerView, int dy)
}

this.setPhotoSearchQueryRunning(true);
runGallerySearchTask();
photoSearchTask.execute(endDate, limit);
} else if ((totalItemCount - visibleItemCount) <= (lastVisibleItem + MAX_ITEMS_PER_ROW) //no more files in the gallery, retrieve the next ones
&& (totalItemCount - visibleItemCount) > 0) {

Expand All @@ -379,7 +369,7 @@ private void loadMoreWhenEndReached(@NonNull RecyclerView recyclerView, int dy)
// Almost reached the end, continue to load new photos
endDate = lastItemTimestamp;
this.setPhotoSearchQueryRunning(true);
runGallerySearchTask();
photoSearchTask.execute(endDate, limit);
}
}
}
Expand Down
Loading
Loading