Skip to content

Commit

Permalink
rebased onto latest branch
Browse files Browse the repository at this point in the history
Signed-off-by: tobiaskaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Mar 13, 2018
1 parent 674ccb3 commit fc0e389
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private ArrayList<OCFile> mFilesAll = new ArrayList<>();
private boolean mJustFolders;
private boolean mHideItemOptions;
private long lastTimestamp;

private boolean gridView = false;
private boolean multiSelect = false;
private HashSet<OCFile> checkedFiles;
Expand Down Expand Up @@ -512,18 +514,20 @@ private void searchForLocalFileInDefaultPath(OCFile file) {
}

public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType,
FileDataStorageManager storageManager, OCFile folder) {
FileDataStorageManager storageManager, OCFile folder, boolean clear) {
if (storageManager != null && mStorageManager == null) {
mStorageManager = storageManager;
}
mFiles.clear();
if (clear) {
mFiles.clear();
}

// early exit
if (objects.size() > 0 && mStorageManager != null) {
if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
parseShares(objects);
} else {
parseVirtuals(objects, searchType);
parseVirtuals(objects, searchType, clear);
}
}

Expand Down Expand Up @@ -586,7 +590,7 @@ private void parseShares(ArrayList<Object> objects) {
mStorageManager.saveShares(shares);
}

private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType, boolean clear) {
VirtualFolderType type;
boolean onlyImages = false;
switch (searchType) {
Expand All @@ -596,13 +600,16 @@ private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.Searc
case PHOTO_SEARCH:
type = VirtualFolderType.PHOTOS;
onlyImages = true;
lastTimestamp = ((RemoteFile) objects.get(objects.size() - 1)).getModifiedTimestamp() / 1000;
break;
default:
type = VirtualFolderType.NONE;
break;
}

mStorageManager.deleteVirtuals(type);
if (clear) {
mStorageManager.deleteVirtuals(type);
}

ArrayList<ContentValues> contentValues = new ArrayList<>();

Expand All @@ -613,15 +620,15 @@ private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.Searc
try {
ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);

if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
if ((!onlyImages || MimeTypeUtil.isImage(ocFile)) && !mFiles.contains(ocFile)) {
mFiles.add(ocFile);
}

ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());

contentValues.add(cv);
contentValues.add(cv);
}
} catch (RemoteOperationFailedException e) {
Log_OC.e(TAG, "Error saving file with parent" + e.getMessage(), e);
}
Expand Down Expand Up @@ -679,6 +686,14 @@ public Filter getFilter() {
return mFilesFilter;
}

public void resetLastTimestamp() {
lastTimestamp = -1;
}

public long getLastTimestamp() {
return lastTimestamp;
}

private class FilesFilter extends Filter {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
private boolean searchFragment = false;
private SearchEvent searchEvent;
private AsyncTask remoteOperationAsyncTask;
private AbsListView.OnScrollListener onScrollChangeListener;
private RecyclerView.OnScrollListener onScrollChangeListener;
private boolean photoSearchQueryRunning;
private boolean photoSearchNoNew = false;
private RemoteOperation remoteOperation;
Expand Down Expand Up @@ -205,27 +205,6 @@ public void onCreate(Bundle savedInstanceState) {

searchFragment = currentSearchType != null;

onScrollChangeListener = new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
Log_OC.d("SCROLL", getListView().getFirstVisiblePosition() + " / " + mAdapter.getCount());
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log_OC.d("SCROLL", firstVisibleItem + " / " + totalItemCount);

if ((totalItemCount - visibleItemCount) <= (firstVisibleItem + 5)) {
// Almost reached the end, continue to load new activities
Log_OC.d("SCROLL", "load next");

if ((totalItemCount - visibleItemCount) > 0) {
search();
}
}
}
};

if (isGridViewPreferred(getCurrentFile())) {
switchToGridView();
}
Expand Down Expand Up @@ -298,6 +277,29 @@ public void run() {
setChoiceModeAsMultipleModal(savedInstanceState);
}

onScrollChangeListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();

// scroll down
if (dy > 0 && !photoSearchQueryRunning) {
int visibleItemCount = gridLayoutManager.getChildCount();
int totalItemCount = gridLayoutManager.getItemCount();
int firstVisibleItem = gridLayoutManager.findFirstCompletelyVisibleItemPosition();

if ((totalItemCount - visibleItemCount) <= (firstVisibleItem + 5)) {
// Almost reached the end, continue to load new photos
if ((totalItemCount - visibleItemCount) > 0) {
searchAndDisplay();
}
}
}
}
}
};

Log_OC.i(TAG, "onCreateView() end");
return v;
}
Expand Down Expand Up @@ -1433,6 +1435,7 @@ public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {

getActivity().getIntent().removeExtra(OCFileListFragment.SEARCH_EVENT);
getArguments().putParcelable(OCFileListFragment.SEARCH_EVENT, null);
getRecyclerView().clearOnScrollListeners();

setFabEnabled(true);
}
Expand Down Expand Up @@ -1547,21 +1550,18 @@ public void run() {
remoteOperation = new GetRemoteSharesOperation();
}

search();
searchAndDisplay();

getListView().setOnScrollListener(onScrollChangeListener);
getRecyclerView().setOnScrollListener(onScrollChangeListener);
}

// TODO refactor, can only used for photo search atm
private void search() {
private void searchAndDisplay() {
if (!photoSearchQueryRunning && !photoSearchNoNew) {
remoteOperationAsyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
if (getContext() != null && !isCancelled()) {
photoSearchQueryRunning = true;
Log_OC.d("SCROLL", "re-run search");

final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());

int limit = -1;
Expand Down
6 changes: 3 additions & 3 deletions src/main/res/layout/grid_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">

<ImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/standard_list_item_size"
android:layout_height="@dimen/standard_list_item_size"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/folder"
android:contentDescription="@string/thumbnail"/>
Expand Down

0 comments on commit fc0e389

Please sign in to comment.