be far less aggressive on restoring saved positions

This commit is contained in:
Adrian Ulrich 2016-06-18 12:28:29 +02:00
parent a55f1c795c
commit 161b8855fb
2 changed files with 7 additions and 8 deletions

View File

@ -710,7 +710,6 @@ public class LibraryActivity
.setMessage(delete_message)
.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mPagerAdapter.maintainPosition(); // remember current scrolling position
mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
}
})

View File

@ -443,6 +443,7 @@ public class LibraryPagerAdapter
out.putSerializable("limiter_songs", mSongAdapter.getLimiter());
if (mFilesAdapter != null)
out.putSerializable("limiter_files", mFilesAdapter.getLimiter());
maintainPosition();
return out;
}
@ -588,7 +589,7 @@ public class LibraryPagerAdapter
/**
* Saves the scrolling position of every visible limiter
*/
public void maintainPosition() {
private void maintainPosition() {
for (int i = MAX_ADAPTER_COUNT; --i != -1; ) {
if (mAdapters[i] != null) {
sLruAdapterPos.storePosition(mAdapters[i], mLists[i].getFirstVisiblePosition());
@ -646,15 +647,14 @@ public class LibraryPagerAdapter
break;
}
case MSG_COMMIT_QUERY: {
int pos = 0;
int index = message.arg1;
mAdapters[index].commitQuery(message.obj);
Integer curPos = sLruAdapterPos.getPosition(mAdapters[index]);
// Restore scrolling position if present and valid
Integer curPos = sLruAdapterPos.popPosition(mAdapters[index]);
if (curPos != null && curPos < mLists[index].getCount())
pos = (int)curPos;
mLists[index].setSelection(curPos);
mLists[index].setSelection(pos);
break;
}
case MSG_SAVE_SORT: {
@ -861,8 +861,8 @@ public class LibraryPagerAdapter
public void storePosition(LibraryAdapter adapter, Integer val) {
this.put(_k(adapter), val);
}
public Integer getPosition(LibraryAdapter adapter) {
return this.get(_k(adapter));
public Integer popPosition(LibraryAdapter adapter) {
return this.remove(_k(adapter));
}
/**