Skip to content

Commit 97884da

Browse files
committed
Still working out the oddities of the staggered update-and-replace RecycleView pattern on Android
1 parent a1d8cb3 commit 97884da

13 files changed

Lines changed: 377 additions & 242 deletions

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/BasicFileProvider.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,22 @@ else if(curFileIndex > lastFileIndex) {
367367
return mcResult;
368368
}
369369

370+
public int getFolderChildCount(String folderDocId) throws FileNotFoundException {
371+
if(updateDocsQueryFilesList || docsQueryFilesList == null) {
372+
final File parent = getFileForDocId(folderDocId);
373+
if(customFileFilter != null) {
374+
docsQueryFilesList = parent.listFiles(customFileFilter);
375+
}
376+
else {
377+
docsQueryFilesList = parent.listFiles();
378+
}
379+
if(customFolderSort != null) {
380+
docsQueryFilesList = customFolderSort.sortFileItemsList(docsQueryFilesList);
381+
}
382+
}
383+
return docsQueryFilesList.length;
384+
}
385+
370386
@Override
371387
public ParcelFileDescriptor openDocument(final String documentId, final String mode,
372388
CancellationSignal signal) throws FileNotFoundException {

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/CustomExceptionInterface.java

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
This program (the AndroidFilePickerLight library) is free software written by
3+
Maxie Dion Schmidt: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
The complete license provided with source distributions of this library is
14+
available at the following link:
15+
https://github.com/maxieds/AndroidFilePickerLight
16+
*/
17+
18+
package com.maxieds.androidfilepickerlightlibrary;
19+
20+
import android.graphics.drawable.Drawable;
21+
22+
public class CustomThemeBuilder {
23+
24+
private static final String LOGTAG = CustomThemeBuilder.class.getSimpleName();
25+
26+
public static CustomThemeBuilder getDefaultsInstance() {
27+
return null;
28+
}
29+
30+
public CustomThemeBuilder setPickerTitleText(String titleText) {
31+
return this;
32+
}
33+
34+
public CustomThemeBuilder setNavBarPrefixText(String prefixText) {
35+
return this;
36+
}
37+
38+
public CustomThemeBuilder setDoneActionButtonText(String btnText) {
39+
return this;
40+
}
41+
42+
public CustomThemeBuilder setCancelActionButtonText(String btnText) {
43+
return this;
44+
}
45+
46+
public CustomThemeBuilder setDoneActionButtonIcon(Drawable checkMark) {
47+
return this;
48+
}
49+
50+
public CustomThemeBuilder setCancelActionButtonIcon(Drawable xMark) {
51+
return this;
52+
}
53+
54+
public static final int COLOR_PRIMARY = 0;
55+
public static final int COLOR_PRIMARY_DARK = 1;
56+
public static final int COLOR_PRIMARY_VERY_DARK = 2;
57+
public static final int COLOR_ACCENT = 3;
58+
public static final int COLOR_ACCENT_MEDIUM = 4;
59+
public static final int COLOR_ACCENT_LIGHT = 5;
60+
public static final int COLOR_TOOLBAR_BG = 6;
61+
public static final int COLOR_TOOLBAR_FG = 7;
62+
63+
public CustomThemeBuilder setThemeColors(int[] colorsList) {
64+
return this;
65+
}
66+
67+
public CustomThemeBuilder useThemeGradientBackgrounds(boolean enable) {
68+
return this;
69+
}
70+
71+
public CustomThemeBuilder setActivityToolbarIcon(Drawable customIcon) {
72+
return this;
73+
}
74+
75+
// Should be 16x16 pixels and compressed with the WEBP format to save resources:
76+
public CustomThemeBuilder setDefaultFolderIcon(Drawable folderIcon) {
77+
return this;
78+
}
79+
80+
// Should be 16x16 pixels and compressed with the WEBP format to save resources:
81+
public CustomThemeBuilder setDefaultFileIcon(Drawable folderIcon) {
82+
return this;
83+
}
84+
85+
// Should be 16x16 pixels and compressed with the WEBP format to save resources:
86+
public CustomThemeBuilder setDefaultHidenFileIcon(Drawable folderIcon) {
87+
return this;
88+
}
89+
90+
// TODO: setup / configure the stock directory path nav btn icons
91+
// (excluding any custom file type icons, which the user can supply
92+
// via a separate interface ... )
93+
94+
public CustomThemeBuilder makeTheme() {
95+
return this; // should fill in defaults not defined by the client code
96+
}
97+
98+
}

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/DisplayAdapters.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ This program (the AndroidFilePickerLight library) is free software written by
1717

1818
package com.maxieds.androidfilepickerlightlibrary;
1919

20-
import android.content.Context;
2120
import android.util.Log;
2221
import android.view.GestureDetector;
2322
import android.view.LayoutInflater;
@@ -47,18 +46,29 @@ public FileListAdapter(List<String> nextFileListData, List<DisplayTypes.FileType
4746
this.fileListData.addAll(nextFileListData);
4847
this.fileItemsData = new ArrayList<DisplayTypes.FileType>();
4948
this.fileItemsData.addAll(nextFileItemsData);
50-
this.setHasStableIds(false); // TODO ???
51-
notifyDataSetChanged();
49+
this.setHasStableIds(true); // TODO ???
5250
}
5351

54-
public void reloadDataSets(List<String> nextDataSet, List<DisplayTypes.FileType> nextFileItemsData) {
52+
public void reloadDataSets(List<String> nextDataSet, List<DisplayTypes.FileType> nextFileItemsData, boolean notifyAdapter) {
53+
//DisplayFragments.getInstance().getMainRecyclerView().setLayoutFrozen(true);
54+
int fileItemsListSize = fileListData.size();
5555
fileListData.clear();
5656
fileListData.addAll(nextDataSet);
5757
fileItemsData.clear();
5858
fileItemsData.addAll(nextFileItemsData);
59-
notifyDataSetChanged();
59+
//DisplayFragments.getInstance().getMainRecyclerView().setLayoutFrozen(false);
60+
//notifyItemRangeRemoved(0, fileItemsListSize);
61+
if(notifyAdapter) {
62+
notifyDataSetChanged();
63+
}
64+
}
65+
66+
public void reloadDataSets(List<String> nextDataSet, List<DisplayTypes.FileType> nextFileItemsData) {
67+
reloadDataSets(nextDataSet, nextFileItemsData, true);
6068
}
6169

70+
private static final int VIEW_TYPE_FILE_ITEM = 0;
71+
6272
@Override
6373
public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
6474
//Log.i(LOGTAG,"onCreateViewHolder");
@@ -98,10 +108,16 @@ public int getItemCount() {
98108
return fileListData.size();
99109
}
100110

101-
//@Override
102-
//public long getItemId(int posIndex) {
103-
// return posIndex;
104-
//}
111+
@Override
112+
public long getItemId(int posIndex) {
113+
return fileItemsData.get(posIndex).getLayoutContainer().hashCode();
114+
//return posIndex;
115+
}
116+
117+
@Override
118+
public int getItemViewType(int posIndex) {
119+
return posIndex;
120+
}
105121

106122
}
107123

@@ -197,7 +213,7 @@ else if(DisplayFragments.getInstance().curSelectionCount >= DisplayFragments.get
197213
@Override
198214
public void onClick(View v) {
199215
Log.i(LOGTAG, "onClick");
200-
int fileItemPosIndex = DisplayFragments.getInstance().findFileItemIndexByLayout(v);
216+
int fileItemPosIndex = DisplayFragments.RecyclerViewUtils.findFileItemIndexByLayout(v);
201217
if(fileItemPosIndex < 0) {
202218
return;
203219
}
@@ -214,7 +230,7 @@ public void onClick(View v) {
214230
@Override
215231
public boolean onLongClick(View v) {
216232
Log.i(LOGTAG, "onLongClick");
217-
int fileItemPosIndex = DisplayFragments.getInstance().findFileItemIndexByLayout(v);
233+
int fileItemPosIndex = DisplayFragments.RecyclerViewUtils.findFileItemIndexByLayout(v);
218234
if(fileItemPosIndex < 0) {
219235
return false;
220236
}

0 commit comments

Comments
 (0)