@@ -45,33 +45,35 @@ public static class FileListAdapter extends RecyclerView.Adapter<BaseViewHolder>
4545 public FileListAdapter (List <String > nextFileListData , List <DisplayTypes .FileType > nextFileItemsData ) {
4646 this .fileListData = new ArrayList <String >();
4747 this .fileItemsData = new ArrayList <DisplayTypes .FileType >();
48- this .setHasStableIds (false ); // ???
48+ this .setHasStableIds (true );
4949 reloadDataSets (nextFileListData , nextFileItemsData , false );
5050 }
5151
5252 public void reloadDataSets (List <String > nextDataSet , List <DisplayTypes .FileType > nextFileItemsData , boolean notifyAdapter ) {
53- Log .i (LOGTAG , "PREV SIZE = " + fileListData .size () + ", " + nextDataSet .size ());
5453 if (fileListData != nextDataSet ) {
5554 fileListData .clear ();
5655 fileListData .addAll (nextDataSet );
57- //fileListData = nextDataSet;
5856 }
5957 if (fileItemsData != nextFileItemsData ) {
6058 fileItemsData .clear ();
6159 fileItemsData .addAll (nextFileItemsData );
62- //fileItemsData = nextFileItemsData;
6360 }
6461 if (notifyAdapter ) {
6562 notifyDataSetChanged ();
66- //notifyItemRangeInserted(0, nextDataSet.size());
6763 }
68- Log .i (LOGTAG , "POST SIZE = " + fileListData .size ());
6964 }
7065
7166 public void reloadDataSets (List <String > nextDataSet , List <DisplayTypes .FileType > nextFileItemsData ) {
7267 reloadDataSets (nextDataSet , nextFileItemsData , true );
7368 }
7469
70+ public DisplayTypes .FileType getFileItemByIndex (int indexPos ) {
71+ if (indexPos < 0 || indexPos >= fileItemsData .size ()) {
72+ return null ;
73+ }
74+ return fileItemsData .get (indexPos );
75+ }
76+
7577 private static final int VIEW_TYPE_FILE_ITEM = 0 ;
7678
7779 @ Override
@@ -83,29 +85,30 @@ public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
8385
8486 @ Override
8587 public void onBindViewHolder (BaseViewHolder bvHolder , int posIndex ) {
86- bvHolder .getDisplayText ().setText (fileListData .get (posIndex ));
87- //Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- %s", posIndex, bvHolder.getDisplayText().getText()));
88+ bvHolder .setInitialIndexPosition (posIndex );
8889 if (!fileItemsData .isEmpty ()) {
8990 DisplayTypes .FileType fileItem = fileItemsData .get (posIndex );
9091 fileItem .setLayoutContainer (bvHolder .getMainViewLayoutContainer ());
9192 View viewItemContainer = bvHolder .getMainViewLayoutContainer ();
9293 DisplayFragments .FileListItemFragment .resetLayout (viewItemContainer , fileItem , posIndex );
93- }
94+ }
95+ //Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- %s (ADAPTER -> %s) [DATA ITEMS SIZE = %d]", posIndex,
96+ // bvHolder.getDisplayText().getText(), fileListData.get(posIndex), fileItemsData.size()));
9497 }
9598
9699 @ Override
97100 public void onViewRecycled (BaseViewHolder bvHolder ) {
98- //Log.i(LOGTAG,"onViewRecycled: " + bvHolder);
101+ //Log.i(LOGTAG,"onViewRecycled: " + bvHolder + " AT initial INDEX " + bvHolder.getInitialIndexPosition() );
99102 }
100103
101104 @ Override
102105 public void onViewDetachedFromWindow (BaseViewHolder bvHolder ) {
103- //Log.i(LOGTAG,"onViewDetachedFromWindow: " + bvHolder);
106+ //Log.i(LOGTAG,"onViewDetachedFromWindow: " + bvHolder + " AT initial INDEX " + bvHolder.getInitialIndexPosition() );
104107 }
105108
106109 @ Override
107110 public void onViewAttachedToWindow (BaseViewHolder bvHolder ) {
108- //Log.i(LOGTAG,"onViewAttachedToWindow: " + bvHolder);
111+ //Log.i(LOGTAG,"onViewAttachedToWindow: " + bvHolder + " AT initial INDEX " + bvHolder.getInitialIndexPosition() );
109112 }
110113
111114 @ Override
@@ -115,19 +118,12 @@ public int getItemCount() {
115118
116119 @ Override
117120 public long getItemId (int posIndex ) {
118- if (fileItemsData .size () > posIndex && fileItemsData .get (posIndex ).getLayoutContainer () != null ){
119- return fileItemsData .get (posIndex ).getLayoutContainer ().hashCode ();
120- }
121- else if (fileItemsData .size () > posIndex ) {
122- return fileItemsData .get (posIndex ).hashCode ();
123- }
124121 return posIndex ;
125122 }
126123
127124 @ Override
128125 public int getItemViewType (int posIndex ) {
129- //return posIndex;
130- return VIEW_TYPE_FILE_ITEM ;
126+ return posIndex ;
131127 }
132128
133129 }
@@ -164,15 +160,34 @@ public BaseViewHolder(View v) {
164160 v .setOnLongClickListener (this );
165161 displayText = (TextView ) v .findViewById (R .id .fileEntryBaseName );
166162 initIndexPos = -1 ;
167- //setIsRecyclable(false); // ???
163+
168164 }
169165
170166 public TextView getDisplayText () { return displayText ; }
167+ public void setDisplayText (TextView nextDisplayText ) { displayText = nextDisplayText ; }
171168
172169 public int getInitialIndexPosition () { return initIndexPos ; }
170+ public void setInitialIndexPosition (int initIdx ) { initIndexPos = initIdx ; }
173171
174172 public View getMainViewLayoutContainer () { return fileItemContainerView ; }
175173
174+ private static int getPositionForView (View v ) {
175+ DisplayFragments displayCtx = DisplayFragments .getInstance ();
176+ FileChooserRecyclerView mainRV = displayCtx .getMainRecyclerView ();
177+ BaseViewHolder bvHolder = (BaseViewHolder ) mainRV .getChildViewHolder (v );
178+ if (bvHolder == null ) {
179+ return -1 ;
180+ }
181+ return bvHolder .getInitialIndexPosition ();
182+ }
183+
184+ public static DisplayTypes .FileType getFileItemForView (View v ) {
185+ DisplayFragments displayCtx = DisplayFragments .getInstance ();
186+ FileChooserRecyclerView mainRV = displayCtx .getMainRecyclerView ();
187+ DisplayAdapters .FileListAdapter rvAdapter = (DisplayAdapters .FileListAdapter ) mainRV .getAdapter ();
188+ return rvAdapter .getFileItemByIndex (getPositionForView (v ));
189+ }
190+
176191 @ Override
177192 public void onClick (View v ) {
178193 Log .i (LOGTAG , "BaseViewHolder::onClick [RETURNING, DOING NOTHING] ... " );
@@ -181,17 +196,14 @@ public void onClick(View v) {
181196 @ Override
182197 public boolean onLongClick (View v ) {
183198 Log .i (LOGTAG , "BaseViewHolder::onLongClick" );
184- int fileItemPosIndex = DisplayFragments .getInstance ().findFileItemIndexByLayout (v );
185- if (fileItemPosIndex < 0 ) {
186- return false ;
187- }
188- DisplayTypes .FileType fileItem = DisplayFragments .getInstance ().activeFileItemsDataList .get (fileItemPosIndex );
199+ DisplayTypes .FileType fileItem = getFileItemForView (v );
189200 if (fileItem != null && fileItem .isDirectory ()) {
190201 // Recursively descend into the clicked directory location:
191202 DisplayTypes .DirectoryResultContext nextFolder = fileItem .getParentFolderContext ();
192203 if (nextFolder == null ) {
193204 return false ;
194205 }
206+ int fileItemPosIndex = getPositionForView (v );
195207 DisplayTypes .DirectoryResultContext workingFolder = DisplayFragments .getInstance ().pathHistoryStack .peek ();
196208 DisplayFragments .getInstance ().pathHistoryStack .push (nextFolder );
197209 if (workingFolder == null ) {
@@ -282,12 +294,7 @@ else if(DisplayFragments.getInstance().curSelectionCount >= DisplayFragments.get
282294 @ Override
283295 public void onCheckedChanged (CompoundButton btnView , boolean isChecked ) {
284296 CheckBox cbView = (CheckBox ) btnView ;
285- int fileItemPosIndex = DisplayFragments .getInstance ().findFileItemIndexByLayout ((View ) btnView .getParent ());
286- if (fileItemPosIndex < 0 ) {
287- Log .i (LOGTAG , "onCheckedChanged: Unable to find parent view index ..." );
288- return ;
289- }
290- DisplayTypes .FileType fileItem = DisplayFragments .getInstance ().activeFileItemsDataList .get (fileItemPosIndex );
297+ DisplayTypes .FileType fileItem = BaseViewHolder .getFileItemForView ((View ) btnView .getParent ());
291298 if (fileItem != null ) {
292299 performNewFileItemClick (cbView , fileItem );
293300 }
0 commit comments