Persist label change as it is made. Keep AlarmVH expanded as content change occurs.
This commit is contained in:
parent
8171a663bc
commit
abc849c243
@ -38,9 +38,9 @@ public class AlarmsCursorAdapter extends BaseCursorAdapter<Alarm, BaseAlarmViewH
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
// final long stableId = getItemId(position);
|
final long stableId = getItemId(position);
|
||||||
return /*stableId != RecyclerView.NO_ID && stableId == mExpandedId*/
|
return stableId != RecyclerView.NO_ID && stableId == mExpandedId
|
||||||
position == mExpandedPosition
|
// position == mExpandedPosition
|
||||||
? VIEW_TYPE_EXPANDED : VIEW_TYPE_COLLAPSED;
|
? VIEW_TYPE_EXPANDED : VIEW_TYPE_COLLAPSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,10 +50,11 @@ public class AlarmsCursorAdapter extends BaseCursorAdapter<Alarm, BaseAlarmViewH
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
public boolean expand(int position) {
|
public boolean expand(int position) {
|
||||||
final long stableId = getItemId(position);
|
if (position == RecyclerView.NO_POSITION)
|
||||||
if (mExpandedId == stableId) {
|
return false;
|
||||||
|
final long stableId = getItemId(position);
|
||||||
|
if (stableId == RecyclerView.NO_ID || mExpandedId == stableId)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
mExpandedId = stableId;
|
mExpandedId = stableId;
|
||||||
// If we can call this, the item is in view, so we don't need to scroll to it?
|
// If we can call this, the item is in view, so we don't need to scroll to it?
|
||||||
// mScrollHandler.smoothScrollTo(position);
|
// mScrollHandler.smoothScrollTo(position);
|
||||||
|
|||||||
@ -52,6 +52,10 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
private final Drawable mCancelSnoozeDrawable;
|
private final Drawable mCancelSnoozeDrawable;
|
||||||
private final FragmentManager mFragmentManager;
|
private final FragmentManager mFragmentManager;
|
||||||
|
|
||||||
|
// So far, Alarms are the only VH type that requires saving a reference to the listener,
|
||||||
|
// so that they may do extra stuff with it.
|
||||||
|
private final OnListItemInteractionListener<Alarm> mInteractionListener;
|
||||||
|
|
||||||
// These should only be changed from the OnTimeSet callback.
|
// These should only be changed from the OnTimeSet callback.
|
||||||
// If we had initialized these in onBind(), they would be reset to their original values
|
// If we had initialized these in onBind(), they would be reset to their original values
|
||||||
// from the Alarm each time the ViewHolder binds.
|
// from the Alarm each time the ViewHolder binds.
|
||||||
@ -79,6 +83,8 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
AppCompatActivity act = (AppCompatActivity) getContext();
|
AppCompatActivity act = (AppCompatActivity) getContext();
|
||||||
mFragmentManager = act.getSupportFragmentManager();
|
mFragmentManager = act.getSupportFragmentManager();
|
||||||
|
|
||||||
|
mInteractionListener = listener;
|
||||||
|
|
||||||
// Are we recreating this because of a rotation?
|
// Are we recreating this because of a rotation?
|
||||||
// If so, try finding any dialog that was last shown in our backstack,
|
// If so, try finding any dialog that was last shown in our backstack,
|
||||||
// and restore the callback.
|
// and restore the callback.
|
||||||
@ -274,7 +280,12 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
return new AddLabelDialog.OnLabelSetListener() {
|
return new AddLabelDialog.OnLabelSetListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLabelSet(String label) {
|
public void onLabelSet(String label) {
|
||||||
mLabel.setText(label);
|
final Alarm oldAlarm = getAlarm();
|
||||||
|
Alarm newAlarm = oldAlarm.toBuilder()
|
||||||
|
.label(label)
|
||||||
|
.build();
|
||||||
|
oldAlarm.copyMutableFieldsTo(newAlarm);
|
||||||
|
mAlarmController.save(newAlarm);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -295,4 +306,8 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final OnListItemInteractionListener<Alarm> getInteractionListener() {
|
||||||
|
return mInteractionListener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,26 +54,13 @@ public class ExpandedAlarmViewHolder extends BaseAlarmViewHolder {
|
|||||||
listener.onListItemDeleted(getAlarm());
|
listener.onListItemDeleted(getAlarm());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: We can now do method binding instead, because our superclass provides an API
|
||||||
|
// to retrieve the interaction listener.
|
||||||
mOk.setOnClickListener(new View.OnClickListener() {
|
mOk.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final Alarm oldAlarm = getAlarm();
|
createNewAlarmAndWriteToDb();
|
||||||
Alarm newAlarm = Alarm.builder()
|
|
||||||
.hour(oldAlarm.hour()/*TODO*/)
|
|
||||||
.minutes(oldAlarm.minutes()/*TODO*/)
|
|
||||||
.label(mLabel.getText().toString())
|
|
||||||
.ringtone(""/*TODO*/)
|
|
||||||
.vibrates(mVibrate.isChecked())
|
|
||||||
.build();
|
|
||||||
oldAlarm.copyMutableFieldsTo(newAlarm);
|
|
||||||
// ----------------------------------------------
|
|
||||||
// TOneverDO: precede copyMutableFieldsTo()
|
|
||||||
newAlarm.setEnabled(mSwitch.isChecked());
|
|
||||||
for (int i = SUNDAY; i <= SATURDAY; i++) {
|
|
||||||
newAlarm.setRecurring(i, isRecurringDay(i));
|
|
||||||
}
|
|
||||||
// ----------------------------------------------
|
|
||||||
listener.onListItemUpdate(newAlarm, getAdapterPosition());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -204,4 +191,24 @@ public class ExpandedAlarmViewHolder extends BaseAlarmViewHolder {
|
|||||||
// Return the state of this day according to its button
|
// Return the state of this day according to its button
|
||||||
return mDays[pos].isChecked();
|
return mDays[pos].isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createNewAlarmAndWriteToDb() {
|
||||||
|
final Alarm oldAlarm = getAlarm();
|
||||||
|
Alarm newAlarm = Alarm.builder()
|
||||||
|
.hour(oldAlarm.hour()/*TODO*/)
|
||||||
|
.minutes(oldAlarm.minutes()/*TODO*/)
|
||||||
|
.label(mLabel.getText().toString())
|
||||||
|
.ringtone(""/*TODO*/)
|
||||||
|
.vibrates(mVibrate.isChecked())
|
||||||
|
.build();
|
||||||
|
oldAlarm.copyMutableFieldsTo(newAlarm);
|
||||||
|
// ----------------------------------------------
|
||||||
|
// TOneverDO: precede copyMutableFieldsTo()
|
||||||
|
newAlarm.setEnabled(mSwitch.isChecked());
|
||||||
|
for (int i = SUNDAY; i <= SATURDAY; i++) {
|
||||||
|
newAlarm.setRecurring(i, isRecurringDay(i));
|
||||||
|
}
|
||||||
|
// ----------------------------------------------
|
||||||
|
getInteractionListener().onListItemUpdate(newAlarm, getAdapterPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user