Fixed list state in server tab not being restored correctly.
This commit is contained in:
parent
86ba981c3c
commit
7ace238723
1 changed files with 14 additions and 20 deletions
|
@ -79,9 +79,9 @@ import com.github.nutomic.controldlna.utility.FileArrayAdapter;
|
||||||
*/
|
*/
|
||||||
public class ServerFragment extends ListFragment implements OnBackPressedListener {
|
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.
|
* ListView adapter for showing a list of DLNA media servers.
|
||||||
|
@ -133,7 +133,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
||||||
setListAdapter(mFileAdapter);
|
setListAdapter(mFileAdapter);
|
||||||
getFiles(true);
|
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");
|
mRestoreServer = savedInstanceState.getString("current_server");
|
||||||
mCurrentPath.addAll(savedInstanceState.getStringArrayList("path"));
|
mCurrentPath.addAll(savedInstanceState.getStringArrayList("path"));
|
||||||
mListState.addAll(savedInstanceState.getParcelableArrayList("list_state"));
|
mListState.addAll(savedInstanceState.getParcelableArrayList("list_state"));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
mListState.push(getListView().onSaveInstanceState());
|
mListState.push(getListView().onSaveInstanceState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,10 +237,10 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
||||||
*/
|
*/
|
||||||
private void serverMode() {
|
private void serverMode() {
|
||||||
setListAdapter(mServerAdapter);
|
setListAdapter(mServerAdapter);
|
||||||
getListView().onRestoreInstanceState(mListState.peek());
|
|
||||||
mCurrentServer = null;
|
mCurrentServer = null;
|
||||||
TextView emptyView = (TextView) getListView().getEmptyView();
|
TextView emptyView = (TextView) getListView().getEmptyView();
|
||||||
emptyView.setText(R.string.device_list_empty);
|
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())
|
for (Item i : didl.getItems())
|
||||||
mFileAdapter.add(i);
|
mFileAdapter.add(i);
|
||||||
if (restoreListState)
|
if (restoreListState)
|
||||||
getListView().onRestoreInstanceState(mListState.peek());
|
getListView().onRestoreInstanceState(mListState.pop());
|
||||||
else
|
else
|
||||||
getListView().setSelectionFromTop(0, 0);
|
getListView().setSelectionFromTop(0, 0);
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,6 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mCurrentPath.pop();
|
mCurrentPath.pop();
|
||||||
mListState.pop();
|
|
||||||
if (mCurrentPath.empty())
|
if (mCurrentPath.empty())
|
||||||
serverMode();
|
serverMode();
|
||||||
else
|
else
|
||||||
|
@ -359,15 +358,10 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
||||||
.getDevice(udn, false) == null) {
|
.getDevice(udn, false) == null) {
|
||||||
mServerAdapter.deviceRemoved(d);
|
mServerAdapter.deviceRemoved(d);
|
||||||
if (d.equals(mCurrentServer)) {
|
if (d.equals(mCurrentServer)) {
|
||||||
|
mListState.setSize(2);
|
||||||
mCurrentPath.clear();
|
mCurrentPath.clear();
|
||||||
mListState.setSize(1);
|
serverMode();
|
||||||
setListAdapter(mServerAdapter);
|
|
||||||
getListView().onRestoreInstanceState(mListState.firstElement());
|
|
||||||
mCurrentServer = null;
|
|
||||||
TextView emptyView = (TextView) getListView().getEmptyView();
|
|
||||||
emptyView.setText(R.string.device_list_empty);
|
|
||||||
}
|
}
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue