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

Commit 80fc6e3f authored by Sam Blitzstein's avatar Sam Blitzstein
Browse files

Fix crash and excessive alarm creation from quick settings access.

Crash was from the convertView not having an ItemHolder tag
The intent to create a new alarm wasn't getting removed after use.

Bug: 10506871
Change-Id: I27ba36661a84092fbc99681d3190e2f2cedd37cb
parent 1601e013
Loading
Loading
Loading
Loading
+15 −7
Original line number Original line Diff line number Diff line
@@ -232,6 +232,8 @@ public class AlarmClockFragment extends DeskClockFragment implements
            // An external app asked us to create a blank alarm.
            // An external app asked us to create a blank alarm.
            asyncAddAlarm();
            asyncAddAlarm();
        }
        }
        // Remove the CREATE_NEW extra now that we've processed it.
        intent.removeExtra(Alarms.ALARM_CREATE_NEW);


        TimePickerDialog tpd = (TimePickerDialog) getActivity().getFragmentManager().
        TimePickerDialog tpd = (TimePickerDialog) getActivity().getFragmentManager().
                findFragmentByTag(AlarmUtils.FRAG_TAG_TIME_PICKER);
                findFragmentByTag(AlarmUtils.FRAG_TAG_TIME_PICKER);
@@ -536,9 +538,12 @@ public class AlarmClockFragment extends DeskClockFragment implements
            if (convertView == null) {
            if (convertView == null) {
                v = newView(mContext, getCursor(), parent);
                v = newView(mContext, getCursor(), parent);
            } else {
            } else {
                // TODO temporary hack to prevent the convertView from not having stuff we need.
                boolean badConvertView = convertView.findViewById(R.id.digital_clock) == null;
                // Do a translation check to test for animation. Change this to something more
                // Do a translation check to test for animation. Change this to something more
                // reliable and robust in the future.
                // reliable and robust in the future.
                if (convertView.getTranslationX() != 0 || convertView.getTranslationY() != 0) {
                if (convertView.getTranslationX() != 0 || convertView.getTranslationY() != 0 ||
                        badConvertView) {
                    // view was animated, reset
                    // view was animated, reset
                    v = newView(mContext, getCursor(), parent);
                    v = newView(mContext, getCursor(), parent);
                } else {
                } else {
@@ -552,7 +557,11 @@ public class AlarmClockFragment extends DeskClockFragment implements
        @Override
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            final View view = mFactory.inflate(R.layout.alarm_time, parent, false);
            final View view = mFactory.inflate(R.layout.alarm_time, parent, false);
            setNewHolder(view);
            return view;
        }


        private void setNewHolder(View view) {
            // standard view holder optimization
            // standard view holder optimization
            final ItemHolder holder = new ItemHolder();
            final ItemHolder holder = new ItemHolder();
            holder.alarmItem = (LinearLayout) view.findViewById(R.id.alarm_item);
            holder.alarmItem = (LinearLayout) view.findViewById(R.id.alarm_item);
@@ -590,18 +599,17 @@ public class AlarmClockFragment extends DeskClockFragment implements
            holder.ringtone = (TextView) view.findViewById(R.id.choose_ringtone);
            holder.ringtone = (TextView) view.findViewById(R.id.choose_ringtone);


            view.setTag(holder);
            view.setTag(holder);
            return view;
        }
        }


        @Override
        @Override
        public void bindView(View view, Context context, final Cursor cursor) {
        public void bindView(View view, Context context, final Cursor cursor) {
            final Alarm alarm = new Alarm(cursor);
            final Alarm alarm = new Alarm(cursor);
            final ItemHolder itemHolder = (ItemHolder) view.getTag();
            Object tag = view.getTag();
            if (itemHolder == null) {
            if (tag == null) {
                // TODO I was seeing NPE here a few times but unable to repro now, keep this check
                // The view was converted but somehow lost its tag.
                // in to hopefully see it again soon.
                setNewHolder(view);
                Log.wtf("itemholder is null?? alarm:"+alarm.toString());
            }
            }
            final ItemHolder itemHolder = (ItemHolder) tag;
            itemHolder.alarm = alarm;
            itemHolder.alarm = alarm;


            // We must unset the listener first because this maybe a recycled view so changing the
            // We must unset the listener first because this maybe a recycled view so changing the