You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hmm, I might be able to also have a look, but might not find the time before the weekend to give it a try but would also have thought that onSaveInstanceState/onRestoreInstanceState might be the way to deal with it. The CAB is still there it "just" looses all menu items. funny thing is that when you select further list items after the rotation the menu appears again. So maybe there is a listener that need to be called / event to be thrown. Tricky one :(
@tobiasKaminsky do you store any information about the selected items e.g.: in onSaveInstanceState()?
Todo so add two methods to the FileListListAdapter
privatestaticfinalStringSELECTION_KEY = "multiFileSelectionsKey";
publicvoidrestoreSelectionState(BundlesavedInstanceState){
if (savedInstanceState == null) {
return;
}
long[] selectionState = savedInstanceState.getLongArray(SELECTION_KEY);
mSelection.clear();
if(selectionState != null){
for (longid : selectionState) {
mSelection.put(id, true);
}
}
}
publicvoidsaveSelectionState(BundleoutState) {
ArrayList<Integer> selectionState = newArrayList<Integer>();
for (Map.Entry<Integer, Boolean> entry : mSelection.entrySet()){
if (entry.getValue()){
selectionState.add(entry.getKey());
}
}
// convert to promitive long arraylong[] selectionStatePrimitive = newlong[selectionState.size()];
inti = 0;
for (Longid : selectionState) {
selectionStatePrimitive[i++] = id.longValue();
}
outState.putLongArray(SELECTION_KEY, selectionStatePrimitive);
}
Your solution has some another possible issues. On rotation the list of files will be synced again and so there is a chance new items will be added and the position is of selected items will change. So because your the adapter has stable Ids you can save this Ids to the mSelection HastMap. Then you have to adapt getCheckedItemPositions and getCheckedItems. getCheckedItemPositions can be remove because you never use this. getCheckedItems has than to iterate over all files and check if there id is in the mSelection HastMap. And adapt getView for check the id is in mSelection. not the position.
Another improvement is to replace the HashMap with a HashSet, because you never check for the boolean value to be false.
Then you have to change also all calls to removeSelection and setNewSelection to pass the id instead of the position e.g.: OCFileListFragment.java#L352
Many thanks for your help!
As I am currently busy right now, maybe you want to try this by yourself and if it works create a patch or create a PR from your repository to this branch?
@tobiasKaminsky my solution wasn't rigth. The main reason for this problem is that the ActionMenu wasn't updated after rotation after the directory was set. Here is a PR #1714
Activity
AndyScherzinger commentedon Mar 13, 2016
@tobiasKaminsky Hah, i already opened an issue for this a while ago 😄
tobiasKaminsky commentedon Mar 14, 2016
emilsjolander/StickyListHeaders#255
There seems to be a solution, but I cannot get it to work :/
AndyScherzinger commentedon Mar 14, 2016
Hmm, I might be able to also have a look, but might not find the time before the weekend to give it a try but would also have thought that onSaveInstanceState/onRestoreInstanceState might be the way to deal with it. The CAB is still there it "just" looses all menu items. funny thing is that when you select further list items after the rotation the menu appears again. So maybe there is a listener that need to be called / event to be thrown. Tricky one :(
DavidWiesner commentedon Jun 1, 2016
The problem could be that the
getCheckedItemCount()inupdateActionsMenu()return 0 after rotating the device. Thats happen when theChoiceModeis modified in code (see: http://stackoverflow.com/a/24301175)One solution could be remove
getCheckedItemCount()call and use the AdaptersgetCheckedItems().size()count.tobiasKaminsky commentedon Jun 2, 2016
@DavidWiesner I tried it, but now all selected items get removed. Before the change only the action menu vanished...
DavidWiesner commentedon Jun 3, 2016
@tobiasKaminsky do you store any information about the selected items e.g.: in
onSaveInstanceState()?Todo so add two methods to the
FileListListAdapterThen call
mAdapter.saveSelectionState(outState)inOCFileListFragment::onSaveInstanceStateandmAdapter.restoreSelectionState(savedInstanceState)inonActivityCreated.Your solution has some another possible issues. On rotation the list of files will be synced again and so there is a chance new items will be added and the position is of selected items will change. So because your the adapter has stable Ids you can save this Ids to the
mSelectionHastMap. Then you have to adaptgetCheckedItemPositionsandgetCheckedItems.getCheckedItemPositionscan be remove because you never use this.getCheckedItemshas than to iterate over all files and check if there id is in themSelectionHastMap. And adaptgetViewfor check the id is inmSelection. not the position.Another improvement is to replace the HashMap with a HashSet, because you never check for the boolean value to be false.
So you will have something like this:
Then you have to change also all calls to
removeSelectionandsetNewSelectionto pass the id instead of the position e.g.: OCFileListFragment.java#L352tobiasKaminsky commentedon Jun 3, 2016
Many thanks for your help!
As I am currently busy right now, maybe you want to try this by yourself and if it works create a patch or create a PR from your repository to this branch?
davivel commentedon Jun 13, 2016
In a fast test, this seems fixed now in #1176; will mark it as ready to test so that QA have a real look.
DavidWiesner commentedon Jun 14, 2016
@tobiasKaminsky my solution wasn't rigth. The main reason for this problem is that the ActionMenu wasn't updated after rotation after the directory was set. Here is a PR #1714
jesmrec commentedon Jun 28, 2016
Fixed!
davivel commentedon Jul 5, 2016
Great :)