Fixed list state in server tab not being restored correctly.

This commit is contained in:
Felix Ableitner 2014-01-05 23:37:36 +01:00
parent 86ba981c3c
commit 7ace238723

View file

@ -79,9 +79,9 @@ import com.github.nutomic.controldlna.utility.FileArrayAdapter;
*/
public class ServerFragment extends ListFragment implements OnBackPressedListener {
private final String TAG = "ServerFragment";
private final static String TAG = "ServerFragment";
private final String ROOT_DIRECTORY = "0";
private final static String ROOT_DIRECTORY = "0";
/**
* ListView adapter for showing a list of DLNA media servers.
@ -133,7 +133,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
setListAdapter(mFileAdapter);
getFiles(true);
}
getListView().onRestoreInstanceState(mListState.lastElement());
getListView().onRestoreInstanceState(mListState.peek());
}
}
@ -176,8 +177,7 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
mRestoreServer = savedInstanceState.getString("current_server");
mCurrentPath.addAll(savedInstanceState.getStringArrayList("path"));
mListState.addAll(savedInstanceState.getParcelableArrayList("list_state"));
}
else
} else
mListState.push(getListView().onSaveInstanceState());
}
@ -237,10 +237,10 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
*/
private void serverMode() {
setListAdapter(mServerAdapter);
getListView().onRestoreInstanceState(mListState.peek());
mCurrentServer = null;
TextView emptyView = (TextView) getListView().getEmptyView();
emptyView.setText(R.string.device_list_empty);
getListView().onRestoreInstanceState(mListState.pop());
}
/**
@ -291,7 +291,7 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
for (Item i : didl.getItems())
mFileAdapter.add(i);
if (restoreListState)
getListView().onRestoreInstanceState(mListState.peek());
getListView().onRestoreInstanceState(mListState.pop());
else
getListView().setSelectionFromTop(0, 0);
}
@ -322,7 +322,6 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
return false;
mCurrentPath.pop();
mListState.pop();
if (mCurrentPath.empty())
serverMode();
else
@ -359,15 +358,10 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
.getDevice(udn, false) == null) {
mServerAdapter.deviceRemoved(d);
if (d.equals(mCurrentServer)) {
mListState.setSize(2);
mCurrentPath.clear();
mListState.setSize(1);
setListAdapter(mServerAdapter);
getListView().onRestoreInstanceState(mListState.firstElement());
mCurrentServer = null;
TextView emptyView = (TextView) getListView().getEmptyView();
emptyView.setText(R.string.device_list_empty);
serverMode();
}
i--;
}
}
}