mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Make usage of BundleSavedState more robust
This commit is contained in:
@@ -20,24 +20,27 @@
|
|||||||
package org.isoron.uhabits.activities.common.views;
|
package org.isoron.uhabits.activities.common.views;
|
||||||
|
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
import android.support.v4.os.*;
|
||||||
|
|
||||||
public class BundleSavedState extends android.support.v4.view.AbsSavedState
|
public class BundleSavedState extends android.support.v4.view.AbsSavedState
|
||||||
{
|
{
|
||||||
public static final Parcelable.Creator<BundleSavedState> CREATOR =
|
public static final Parcelable.Creator<BundleSavedState> CREATOR =
|
||||||
new Parcelable.Creator<BundleSavedState>()
|
ParcelableCompat.newCreator(
|
||||||
{
|
new ParcelableCompatCreatorCallbacks<BundleSavedState>()
|
||||||
@Override
|
|
||||||
public BundleSavedState createFromParcel(Parcel source)
|
|
||||||
{
|
{
|
||||||
return new BundleSavedState(source, getClass().getClassLoader());
|
@Override
|
||||||
}
|
public BundleSavedState createFromParcel(Parcel source,
|
||||||
|
ClassLoader loader)
|
||||||
|
{
|
||||||
|
return new BundleSavedState(source, loader);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BundleSavedState[] newArray(int size)
|
public BundleSavedState[] newArray(int size)
|
||||||
{
|
{
|
||||||
return new BundleSavedState[size];
|
return new BundleSavedState[size];
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
public final Bundle bundle;
|
public final Bundle bundle;
|
||||||
|
|
||||||
@@ -50,7 +53,7 @@ public class BundleSavedState extends android.support.v4.view.AbsSavedState
|
|||||||
public BundleSavedState(Parcel source, ClassLoader loader)
|
public BundleSavedState(Parcel source, ClassLoader loader)
|
||||||
{
|
{
|
||||||
super(source, loader);
|
super(source, loader);
|
||||||
this.bundle = source.readBundle(getClass().getClassLoader());
|
this.bundle = source.readBundle(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ public abstract class ScrollableChart extends View
|
|||||||
@Override
|
@Override
|
||||||
public void onRestoreInstanceState(Parcelable state)
|
public void onRestoreInstanceState(Parcelable state)
|
||||||
{
|
{
|
||||||
|
if(!(state instanceof BundleSavedState))
|
||||||
|
{
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BundleSavedState bss = (BundleSavedState) state;
|
BundleSavedState bss = (BundleSavedState) state;
|
||||||
int x = bss.bundle.getInt("x");
|
int x = bss.bundle.getInt("x");
|
||||||
int y = bss.bundle.getInt("y");
|
int y = bss.bundle.getInt("y");
|
||||||
|
|||||||
@@ -153,6 +153,12 @@ public class HabitCardListView extends RecyclerView
|
|||||||
@Override
|
@Override
|
||||||
protected void onRestoreInstanceState(Parcelable state)
|
protected void onRestoreInstanceState(Parcelable state)
|
||||||
{
|
{
|
||||||
|
if(!(state instanceof BundleSavedState))
|
||||||
|
{
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BundleSavedState bss = (BundleSavedState) state;
|
BundleSavedState bss = (BundleSavedState) state;
|
||||||
dataOffset = bss.bundle.getInt("dataOffset");
|
dataOffset = bss.bundle.getInt("dataOffset");
|
||||||
super.onRestoreInstanceState(bss.getSuperState());
|
super.onRestoreInstanceState(bss.getSuperState());
|
||||||
|
|||||||
Reference in New Issue
Block a user