Reconsider ViewHolder item ID for tag making
This commit is contained in:
parent
e1d858a06a
commit
022153fec1
@ -114,17 +114,16 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Are we recreating this because of a rotation?
|
|
||||||
// If so, try finding any dialog that was last shown in our backstack,
|
|
||||||
// and restore the callback.
|
|
||||||
mAddLabelDialogController.tryRestoreCallback(makeTag(R.id.label));
|
|
||||||
mTimePickerDialogController.tryRestoreCallback(makeTag(R.id.time));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBind(Alarm alarm) {
|
public void onBind(Alarm alarm) {
|
||||||
super.onBind(alarm);
|
super.onBind(alarm);
|
||||||
|
// Items that are not in view will not be bound. If in one orientation the item was in view
|
||||||
|
// and in another it is out of view, then the callback for that item will not be restored
|
||||||
|
// for the new orientation.
|
||||||
|
mAddLabelDialogController.tryRestoreCallback(makeTag(R.id.label));
|
||||||
|
mTimePickerDialogController.tryRestoreCallback(makeTag(R.id.time));
|
||||||
bindTime(alarm);
|
bindTime(alarm);
|
||||||
bindSwitch(alarm.isEnabled());
|
bindSwitch(alarm.isEnabled());
|
||||||
bindDismissButton(alarm);
|
bindDismissButton(alarm);
|
||||||
@ -301,6 +300,6 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String makeTag(@IdRes int viewId) {
|
private String makeTag(@IdRes int viewId) {
|
||||||
return FragmentTagUtils.makeTag(BaseAlarmViewHolder.class, viewId);
|
return FragmentTagUtils.makeTag(BaseAlarmViewHolder.class, viewId, getItemId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,6 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
|||||||
mController.updateLabel(label);
|
mController.updateLabel(label);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mAddLabelDialogController.tryRestoreCallback(makeTag(R.id.label));
|
|
||||||
|
|
||||||
// The item layout is inflated in the super ctor, so we can safely reference our views.
|
// The item layout is inflated in the super ctor, so we can safely reference our views.
|
||||||
mPopupMenu = new PopupMenu(getContext(), mMenuButton);
|
mPopupMenu = new PopupMenu(getContext(), mMenuButton);
|
||||||
@ -92,6 +91,10 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
|||||||
Log.d(TAG, "Binding TimerViewHolder");
|
Log.d(TAG, "Binding TimerViewHolder");
|
||||||
// TOneverDO: create before super
|
// TOneverDO: create before super
|
||||||
mController = new TimerController(timer, mAsyncTimersTableUpdateHandler);
|
mController = new TimerController(timer, mAsyncTimersTableUpdateHandler);
|
||||||
|
// Items that are not in view will not be bound. If in one orientation the item was in view
|
||||||
|
// and in another it is out of view, then the callback for that item will not be restored
|
||||||
|
// for the new orientation.
|
||||||
|
mAddLabelDialogController.tryRestoreCallback(makeTag(R.id.label));
|
||||||
Log.d(TAG, "timer.label() = " + timer.label());
|
Log.d(TAG, "timer.label() = " + timer.label());
|
||||||
bindLabel(timer.label());
|
bindLabel(timer.label());
|
||||||
bindChronometer(timer);
|
bindChronometer(timer);
|
||||||
@ -198,6 +201,6 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String makeTag(@IdRes int viewId) {
|
private String makeTag(@IdRes int viewId) {
|
||||||
return FragmentTagUtils.makeTag(TimerViewHolder.class, viewId);
|
return FragmentTagUtils.makeTag(TimerViewHolder.class, viewId, getItemId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,5 +14,12 @@ public final class FragmentTagUtils {
|
|||||||
return cls.getName() + ":" + viewId;
|
return cls.getName() + ":" + viewId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A version suitable for our ViewHolders.
|
||||||
|
*/
|
||||||
|
public static String makeTag(Class<?> cls, @IdRes int viewId, long itemId) {
|
||||||
|
return makeTag(cls, viewId) + ":" + itemId;
|
||||||
|
}
|
||||||
|
|
||||||
private FragmentTagUtils() {}
|
private FragmentTagUtils() {}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user