mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Signed-off-by: Bogdan Coticopol <bcoticopol@gmail.com>
Minor refactoring on Media Tab.
This commit is contained in:
parent
2bf3a5b142
commit
3ce6a16bd8
2 changed files with 45 additions and 36 deletions
|
@ -24,6 +24,7 @@ package com.owncloud.android.ui.asynctasks;
|
|||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.BuildConfig;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
@ -52,14 +53,11 @@ public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.R
|
|||
private final WeakReference<GalleryFragment> photoFragmentWeakReference;
|
||||
private final FileDataStorageManager storageManager;
|
||||
private final int limit;
|
||||
@Deprecated
|
||||
private final long startDate = 0; // we don't use startDate anymore, only endDate and limit
|
||||
private final long endDate;
|
||||
|
||||
public GallerySearchTask(GalleryFragment photoFragment,
|
||||
User user,
|
||||
FileDataStorageManager storageManager,
|
||||
long startDate,
|
||||
long endDate,
|
||||
int limit) {
|
||||
this.user = user;
|
||||
|
@ -86,19 +84,17 @@ public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.R
|
|||
false,
|
||||
ocCapability);
|
||||
|
||||
|
||||
searchRemoteOperation.setLimit(limit);
|
||||
searchRemoteOperation.setStartDate(startDate);
|
||||
searchRemoteOperation.setEndDate(endDate);
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//workaround to keep SearchRemoteOperation functioning correctly even if we don't actively use startDate
|
||||
searchRemoteOperation.setStartDate(0L);
|
||||
|
||||
if (photoFragment.getContext() != null) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Log_OC.d(this,
|
||||
"Start gallery search with " + dateFormat.format(new Date(startDate * 1000L)) +
|
||||
" - " + dateFormat.format(new Date(endDate * 1000L)) +
|
||||
"Start gallery search since " + dateFormat.format(new Date(endDate * 1000L)) +
|
||||
" with limit: " + limit);
|
||||
|
||||
RemoteOperationResult result = searchRemoteOperation.execute(user, photoFragment.getContext());
|
||||
|
||||
if (result.isSuccess()) {
|
||||
|
@ -136,14 +132,16 @@ public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.R
|
|||
}
|
||||
|
||||
private boolean parseMedia(long startDate, long endDate, List<Object> remoteFiles) {
|
||||
// retrieve all between startDate and endDate
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Log_OC.d(this, "parseMedia - start: " + dateFormat.format(new Date(startDate * 1000L)) + " - " + dateFormat.format(new Date(endDate * 1000L)));
|
||||
|
||||
List<OCFile> localFiles = storageManager.getGalleryItems(startDate * 1000L, endDate * 1000L);
|
||||
|
||||
for (OCFile localFile: localFiles) {
|
||||
Log_OC.d(this, "local file: modified: " + dateFormat.format(new Date(localFile.getModificationTimestamp())) + " path: " + localFile.getRemotePath());
|
||||
if (BuildConfig.DEBUG) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Log_OC.d(this, "parseMedia - start: " + dateFormat.format(new Date(startDate * 1000L)) + " - " + dateFormat.format(new Date(endDate * 1000L)));
|
||||
|
||||
for (OCFile localFile : localFiles) {
|
||||
Log_OC.d(this, "local file: modified: " + dateFormat.format(new Date(localFile.getModificationTimestamp())) + " path: " + localFile.getRemotePath());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, OCFile> localFilesMap = RefreshFolderOperation.prefillLocalFilesMap(null, localFiles);
|
||||
|
@ -152,7 +150,12 @@ public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.R
|
|||
|
||||
for (Object file : remoteFiles) {
|
||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) file);
|
||||
Log_OC.d(this, "remote file: modified: " + dateFormat.format(new Date(ocFile.getModificationTimestamp())) + " path: " + ocFile.getRemotePath());
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Log_OC.d(this, "remote file: modified: " + dateFormat.format(new Date(ocFile.getModificationTimestamp())) + " path: " + ocFile.getRemotePath());
|
||||
}
|
||||
|
||||
OCFile localFile = localFilesMap.remove(ocFile.getRemotePath());
|
||||
|
||||
if (localFile == null) {
|
||||
|
@ -173,16 +176,20 @@ public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.R
|
|||
filesDeleted = localFilesMap.values().size();
|
||||
|
||||
for (OCFile file : localFilesMap.values()) {
|
||||
Log_OC.d(this, "Gallery Sync: File deleted " + file.getRemotePath());
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log_OC.d(this, "Gallery Sync: File deleted " + file.getRemotePath());
|
||||
}
|
||||
|
||||
storageManager.removeFile(file, true, true);
|
||||
}
|
||||
|
||||
Log_OC.d(this, "Gallery search result:" +
|
||||
" new: " + filesAdded +
|
||||
" updated: " + filesUpdated +
|
||||
" deleted: " + filesDeleted +
|
||||
" unchanged: " + unchangedFiles);
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log_OC.d(this, "Gallery search result:" +
|
||||
" new: " + filesAdded +
|
||||
" updated: " + filesUpdated +
|
||||
" deleted: " + filesDeleted +
|
||||
" unchanged: " + unchangedFiles);
|
||||
}
|
||||
final long totalFiles = filesAdded + filesUpdated + filesDeleted + unchangedFiles;
|
||||
return totalFiles <= 0;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.owncloud.android.BuildConfig;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -65,11 +66,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
|
||||
private boolean photoSearchQueryRunning = false;
|
||||
private AsyncTask<Void, Void, GallerySearchTask.Result> photoSearchTask;
|
||||
@Deprecated
|
||||
private long startDate = 0; // we don't use the startDate anymore, we use only endDate and row limit
|
||||
private long endDate;
|
||||
@Deprecated
|
||||
private long daySpan = 30; //not used anymore
|
||||
private int limit = 150;
|
||||
private GalleryAdapter mAdapter;
|
||||
|
||||
|
@ -87,7 +84,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
this.setLoading(value); // link the photoSearchQueryRunning variable with UI progress loading
|
||||
}
|
||||
|
||||
public boolean getPhotoSearchQueryRunning() {
|
||||
public boolean isPhotoSearchQueryRunning() {
|
||||
return this.photoSearchQueryRunning;
|
||||
}
|
||||
|
||||
|
@ -202,7 +199,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setLoading(this.getPhotoSearchQueryRunning());
|
||||
setLoading(this.isPhotoSearchQueryRunning());
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity instanceof FileDisplayActivity) {
|
||||
FileDisplayActivity fileDisplayActivity = ((FileDisplayActivity) activity);
|
||||
|
@ -229,7 +226,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
}
|
||||
|
||||
private void searchAndDisplay() {
|
||||
if (!this.getPhotoSearchQueryRunning() && this.endDate <= 0) {
|
||||
if (!this.isPhotoSearchQueryRunning() && this.endDate <= 0) {
|
||||
// fix an issue when the method is called after loading the gallery and pressing play on a movie (--> endDate <= 0)
|
||||
// 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;
|
||||
|
@ -274,7 +271,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
// Handle item selection
|
||||
if (item.getItemId() == R.id.action_three_dot_icon && !this.getPhotoSearchQueryRunning()
|
||||
if (item.getItemId() == R.id.action_three_dot_icon && !this.isPhotoSearchQueryRunning()
|
||||
&& galleryFragmentBottomSheetDialog != null) {
|
||||
showBottomSheet();
|
||||
return true;
|
||||
|
@ -302,7 +299,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
|
||||
private void searchAndDisplayAfterChangingFolder() {
|
||||
//TODO: Fix folder change, it seems it doesn't work at all
|
||||
this.startDate = 0;
|
||||
this.endDate = System.currentTimeMillis() / 1000;
|
||||
this.setPhotoSearchQueryRunning(true);
|
||||
runGallerySearchTask();
|
||||
|
@ -313,7 +309,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
photoSearchTask = new GallerySearchTask(this,
|
||||
accountManager.getUser(),
|
||||
mContainerActivity.getStorageManager(),
|
||||
startDate,
|
||||
endDate,
|
||||
limit)
|
||||
.execute();
|
||||
|
@ -325,7 +320,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
|
||||
|
||||
// scroll down
|
||||
if (dy > 0 && !this.getPhotoSearchQueryRunning()) {
|
||||
if (dy > 0 && !this.isPhotoSearchQueryRunning()) {
|
||||
int totalItemCount = gridLayoutManager.getItemCount();
|
||||
int lastVisibleItem = gridLayoutManager.findLastCompletelyVisibleItemPosition();
|
||||
int visibleItemCount = gridLayoutManager.getChildCount();
|
||||
|
@ -342,15 +337,22 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
|
||||
// if we have already older media in the gallery then retrieve file in chronological order to fill the gap
|
||||
if (lastItemTimestamp < this.endDate) {
|
||||
Log_OC.d(this,"Gallery swipe: retrieve items to check the chronology");
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log_OC.d(this, "Gallery swipe: retrieve items to check the chronology");
|
||||
}
|
||||
|
||||
this.setPhotoSearchQueryRunning(true);
|
||||
runGallerySearchTask();
|
||||
} else if ((totalItemCount - visibleItemCount) <= (lastVisibleItem + MAX_ITEMS_PER_ROW) //no more files in the gallery, retrieve the next ones
|
||||
&& (totalItemCount - visibleItemCount) > 0) {
|
||||
Log_OC.d(this,"Gallery swipe: retrieve items because end of gallery display");
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log_OC.d(this, "Gallery swipe: retrieve items because end of gallery display");
|
||||
}
|
||||
|
||||
// Almost reached the end, continue to load new photos
|
||||
endDate = lastItemTimestamp;
|
||||
startDate = 0;
|
||||
this.setPhotoSearchQueryRunning(true);
|
||||
runGallerySearchTask();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue