Reconsider ViewHolder item ID for tag making

This commit is contained in:
Phillip Hsu 2016-09-07 16:54:41 -07:00
parent e1d858a06a
commit 022153fec1
3 changed files with 18 additions and 9 deletions

View File

@ -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
public void onBind(Alarm 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);
bindSwitch(alarm.isEnabled());
bindDismissButton(alarm);
@ -301,6 +300,6 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
}
private String makeTag(@IdRes int viewId) {
return FragmentTagUtils.makeTag(BaseAlarmViewHolder.class, viewId);
return FragmentTagUtils.makeTag(BaseAlarmViewHolder.class, viewId, getItemId());
}
}

View File

@ -68,7 +68,6 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
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.
mPopupMenu = new PopupMenu(getContext(), mMenuButton);
@ -92,6 +91,10 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
Log.d(TAG, "Binding TimerViewHolder");
// TOneverDO: create before super
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());
bindLabel(timer.label());
bindChronometer(timer);
@ -198,6 +201,6 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
}
private String makeTag(@IdRes int viewId) {
return FragmentTagUtils.makeTag(TimerViewHolder.class, viewId);
return FragmentTagUtils.makeTag(TimerViewHolder.class, viewId, getItemId());
}
}

View File

@ -14,5 +14,12 @@ public final class FragmentTagUtils {
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() {}
}