Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f110327 authored by Paul Sliwowski's avatar Paul Sliwowski
Browse files

Fix expanding and scrolling in AlarmClockFragment.

Bug: 11007039
Change-Id: I195c98190c8264a4e226b9ea32b8d0cec11c6c8d
(cherry picked from commit 7870ba87)
parent c202c87b
Loading
Loading
Loading
Loading
+12 −22
Original line number Diff line number Diff line
@@ -615,24 +615,6 @@ public class AlarmClockFragment extends DeskClockFragment implements
        if (alarmPosition >= 0) {
            mAdapter.setNewAlarm(alarmId);
            mAlarmsList.smoothScrollToPositionFromTop(alarmPosition, 0);

            final int firstPositionId = mAlarmsList.getFirstVisiblePosition();
            final int childId = alarmPosition - firstPositionId;

            // We need to expand the first view item because bindView may have been called
            // before setNewAlarm took effect. In that case, the newly created alarm will not be
            // expanded.
            final View view = mAlarmsList.getChildAt(childId);
            if (view != null) {
                // The view may be null if it isn't visible yet. In that case, the above call to
                // setNewAlarm() will make sure it's expanded when it comes into view.
                Object tag = view.getTag();
                if (tag != null && tag instanceof AlarmItemAdapter.ItemHolder) {
                    mAdapter.expandAlarm((AlarmItemAdapter.ItemHolder) tag, true);
                } else {
                    Log.e("Unable to get ItemHolder for view at id "+childId);
                }
            }
        } else {
            // Trying to display a deleted alarm should only happen from a missed notification for
            // an alarm that has been marked deleted after use.
@@ -1153,13 +1135,15 @@ public class AlarmClockFragment extends DeskClockFragment implements

            if (expanded) {
                expandAlarm(itemHolder, false);
            } else {
                collapseAlarm(itemHolder, false);
            }

            itemHolder.alarmItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (isAlarmExpanded(alarm)) {
                        collapseAlarm(itemHolder);
                        collapseAlarm(itemHolder, true);
                    } else {
                        expandAlarm(itemHolder, true);
                    }
@@ -1523,7 +1507,7 @@ public class AlarmClockFragment extends DeskClockFragment implements
            return mExpanded.contains(alarm.id);
        }

        private void collapseAlarm(final ItemHolder itemHolder) {
        private void collapseAlarm(final ItemHolder itemHolder, boolean animate) {
            mExpanded.remove(itemHolder.alarm.id);

            // Save the starting height so we can animate from this value.
@@ -1533,6 +1517,13 @@ public class AlarmClockFragment extends DeskClockFragment implements
            itemHolder.alarmItem.setBackgroundResource(mBackgroundColor);
            itemHolder.expandArea.setVisibility(View.GONE);

            if (!animate) {
                // Set the "end" layout and don't do the animation.
                itemHolder.arrow.setRotation(0);
                itemHolder.hairLine.setTranslationY(0);
                return;
            }

            // Add an onPreDrawListener, which gets called after measurement but before the draw.
            // This way we can check the height we need to animate to before any drawing.
            // Note the series of events:
@@ -1765,6 +1756,7 @@ public class AlarmClockFragment extends DeskClockFragment implements

                    // Add alarm to db
                    Alarm newAlarm = Alarm.addAlarm(cr, alarm);
                    mScrollToAlarmId = newAlarm.id;

                    // Create and add instance to db
                    if (newAlarm.enabled) {
@@ -1779,8 +1771,6 @@ public class AlarmClockFragment extends DeskClockFragment implements
                if (alarm.enabled && instance != null) {
                    AlarmUtils.popAlarmSetToast(context, instance.getAlarmTime().getTimeInMillis());
                }
                mAdapter.setNewAlarm(alarm.id);
                scrollToAlarm(alarm.id);
            }
        };
        updateTask.execute();