Search in sources :

Example 1 with LinearTimePickerView

use of me.jfenn.timedatepickers.views.LinearTimePickerView in project Alarmio by TheAndroidMaster.

the class ThemePreferenceData method bindViewHolder.

@Override
public void bindViewHolder(final ViewHolder holder) {
    holder.themeSpinner.setAdapter(ArrayAdapter.createFromResource(holder.itemView.getContext(), R.array.array_themes, R.layout.support_simple_spinner_dropdown_item));
    int theme = ((Alarmio) holder.itemView.getContext().getApplicationContext()).getActivityTheme();
    holder.themeSpinner.setOnItemSelectedListener(null);
    holder.themeSpinner.setSelection(theme);
    holder.sunriseAutoSwitch.setVisibility(theme == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
    holder.sunriseLayout.setVisibility(theme == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
    holder.themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        Integer selection = null;

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (selection != null) {
                PreferenceData.THEME.setValue(adapterView.getContext(), i);
                holder.sunriseAutoSwitch.setVisibility(i == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
                holder.sunriseLayout.setVisibility(i == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
                ((Alarmio) holder.itemView.getContext().getApplicationContext()).updateTheme();
            } else
                selection = i;
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    final SunriseView.SunriseListener listener = new SunriseView.SunriseListener() {

        @Override
        public void onSunriseChanged(int sunrise, int sunset) {
            Calendar sunriseCalendar = Calendar.getInstance();
            sunriseCalendar.set(Calendar.HOUR_OF_DAY, sunrise);
            sunriseCalendar.set(Calendar.MINUTE, 0);
            holder.sunriseTextView.setText(FormatUtils.formatShort(holder.getContext(), new Date(sunriseCalendar.getTimeInMillis())));
            Calendar sunsetCalendar = Calendar.getInstance();
            sunsetCalendar.set(Calendar.HOUR_OF_DAY, sunset);
            sunsetCalendar.set(Calendar.MINUTE, 0);
            holder.sunsetTextView.setText(FormatUtils.formatShort(holder.getContext(), new Date(sunsetCalendar.getTimeInMillis())));
        }
    };
    holder.sunriseAutoSwitch.setOnCheckedChangeListener(null);
    holder.sunriseAutoSwitch.setChecked(holder.getAlarmio().isDayAuto());
    holder.sunriseAutoSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            PreferenceData.DAY_AUTO.setValue(holder.getContext(), b);
            if (b && ContextCompat.checkSelfPermission(holder.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                holder.getAlarmio().requestPermissions(Manifest.permission.ACCESS_COARSE_LOCATION);
                holder.sunriseAutoSwitch.setChecked(false);
            } else {
                holder.sunriseView.invalidate();
                listener.onSunriseChanged(holder.getAlarmio().getDayStart(), holder.getAlarmio().getDayEnd());
            }
            holder.getAlarmio().updateTheme();
        }
    });
    holder.sunriseView.setListener(listener);
    listener.onSunriseChanged(holder.getAlarmio().getDayStart(), holder.getAlarmio().getDayEnd());
    holder.sunriseTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!holder.getAlarmio().isDayAuto()) {
                new AestheticTimeSheetPickerDialog(view.getContext(), holder.getAlarmio().getDayStart(), 0).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                    @Override
                    public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                        int dayEnd = holder.getAlarmio().getDayEnd();
                        if (view.getHourOfDay() < dayEnd) {
                            PreferenceData.DAY_START.setValue(holder.getContext(), view.getHourOfDay());
                            holder.sunriseView.invalidate();
                            listener.onSunriseChanged(view.getHourOfDay(), dayEnd);
                            holder.getAlarmio().updateTheme();
                        }
                    }

                    @Override
                    public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                    }
                }).show();
            }
        }
    });
    holder.sunsetTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!holder.getAlarmio().isDayAuto()) {
                new AestheticTimeSheetPickerDialog(view.getContext(), holder.getAlarmio().getDayEnd(), 0).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                    @Override
                    public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                        int dayStart = holder.getAlarmio().getDayStart();
                        if (view.getHourOfDay() > dayStart) {
                            PreferenceData.DAY_END.setValue(holder.getContext(), view.getHourOfDay());
                            holder.sunriseView.invalidate();
                            listener.onSunriseChanged(dayStart, view.getHourOfDay());
                            holder.getAlarmio().updateTheme();
                        }
                    }

                    @Override
                    public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                    }
                }).show();
            }
        }
    });
    Aesthetic.Companion.get().textColorSecondary().take(1).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer textColorSecondary) throws Exception {
            holder.themeSpinner.setSupportBackgroundTintList(ColorStateList.valueOf(textColorSecondary));
        }
    });
    Aesthetic.Companion.get().colorCardViewBackground().take(1).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer colorForeground) throws Exception {
            holder.themeSpinner.setPopupBackgroundDrawable(new ColorDrawable(colorForeground));
        }
    });
}
Also used : Alarmio(james.alarmio.Alarmio) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) Calendar(java.util.Calendar) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) View(android.view.View) SunriseView(james.alarmio.views.SunriseView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Date(java.util.Date) ColorDrawable(android.graphics.drawable.ColorDrawable) PickerDialog(me.jfenn.timedatepickers.dialogs.PickerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) AdapterView(android.widget.AdapterView) SunriseView(james.alarmio.views.SunriseView) CompoundButton(android.widget.CompoundButton) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView)

Example 2 with LinearTimePickerView

use of me.jfenn.timedatepickers.views.LinearTimePickerView in project Alarmio by TheAndroidMaster.

the class HomeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_home, container, false);
    viewPager = view.findViewById(R.id.viewPager);
    tabLayout = view.findViewById(R.id.tabLayout);
    timePager = view.findViewById(R.id.timePager);
    bottomSheet = view.findViewById(R.id.bottomSheet);
    timeIndicator = view.findViewById(R.id.pageIndicator);
    background = view.findViewById(R.id.background);
    overlay = view.findViewById(R.id.overlay);
    menu = view.findViewById(R.id.fabsMenu);
    stopwatchFab = view.findViewById(R.id.stopwatchFab);
    timerFab = view.findViewById(R.id.timerFab);
    alarmFab = view.findViewById(R.id.alarmFab);
    behavior = BottomSheetBehavior.from(bottomSheet);
    behavior.setHideable(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

            private int statusBarHeight = -1;

            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_COLLAPSED)
                    bottomSheet.setPadding(0, 0, 0, 0);
                else if (newState == BottomSheetBehavior.STATE_EXPANDED) {
                    if (statusBarHeight < 0)
                        statusBarHeight = ConversionUtils.getStatusBarHeight(getContext());
                    bottomSheet.setPadding(0, statusBarHeight, 0, 0);
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                if (statusBarHeight < 0)
                    statusBarHeight = ConversionUtils.getStatusBarHeight(getContext());
                bottomSheet.setPadding(0, (int) (slideOffset * statusBarHeight), 0, 0);
            }
        });
    }
    pagerAdapter = new SimplePagerAdapter(getChildFragmentManager(), new AlarmsFragment(), new SettingsFragment());
    viewPager.setAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if (tab.getPosition() > 0) {
                shouldCollapseBack = behavior.getState() != BottomSheetBehavior.STATE_EXPANDED;
                behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            } else {
                setClockFragments();
                if (shouldCollapseBack) {
                    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    shouldCollapseBack = false;
                }
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    setClockFragments();
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            behavior.setPeekHeight(view.getMeasuredHeight() / 2);
            view.findViewById(R.id.timeContainer).setLayoutParams(new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, view.getMeasuredHeight() / 2));
        }
    });
    colorPrimarySubscription = Aesthetic.Companion.get().colorPrimary().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            bottomSheet.setBackgroundColor(integer);
            overlay.setBackgroundColor(integer);
        }
    });
    colorAccentSubscription = Aesthetic.Companion.get().colorAccent().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            menu.setMenuButtonColor(integer);
            int color = ContextCompat.getColor(getContext(), getAlarmio().getActivityTheme() == Alarmio.THEME_AMOLED ? R.color.textColorPrimary : R.color.textColorPrimaryNight);
            menu.getMenuButton().setColorFilter(color);
            stopwatchFab.setColorFilter(color);
            timerFab.setColorFilter(color);
            alarmFab.setColorFilter(color);
            stopwatchFab.setBackgroundColor(integer);
            timerFab.setBackgroundColor(integer);
            alarmFab.setBackgroundColor(integer);
        }
    });
    textColorPrimarySubscription = Aesthetic.Companion.get().textColorPrimary().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            stopwatchFab.setTitleTextColor(integer);
            timerFab.setTitleTextColor(integer);
            alarmFab.setTitleTextColor(integer);
        }
    });
    textColorPrimaryInverseSubscription = Aesthetic.Companion.get().textColorPrimaryInverse().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            alarmFab.setTitleBackgroundColor(integer);
            stopwatchFab.setTitleBackgroundColor(integer);
            timerFab.setTitleBackgroundColor(integer);
        }
    });
    stopwatchFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            menu.collapseImmediately();
            getFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_up_sheet, R.anim.slide_out_up_sheet, R.anim.slide_in_down_sheet, R.anim.slide_out_down_sheet).replace(R.id.fragment, new StopwatchFragment()).addToBackStack(null).commit();
        }
    });
    timerFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new TimerDialog(getContext(), getFragmentManager()).show();
            menu.collapse();
        }
    });
    alarmFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new AestheticTimeSheetPickerDialog(view.getContext()).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                @Override
                public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                    AlarmManager manager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE);
                    AlarmData alarm = getAlarmio().newAlarm();
                    alarm.time.set(Calendar.HOUR_OF_DAY, view.getHourOfDay());
                    alarm.time.set(Calendar.MINUTE, view.getMinute());
                    alarm.setEnabled(getContext(), manager, true);
                    getAlarmio().onAlarmsChanged();
                }

                @Override
                public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                }
            }).show();
            menu.collapse();
        }
    });
    menu.setMenuListener(new FABsMenuListener() {

        @Override
        public void onMenuExpanded(FABsMenu fabsMenu) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.FOREGROUND_SERVICE) != PackageManager.PERMISSION_GRANTED)
                    requestPermissions(new String[] { Manifest.permission.FOREGROUND_SERVICE }, 0);
                else
                    fabsMenu.collapseImmediately();
            }
        }
    });
    return view;
}
Also used : FABsMenuListener(jahirfiquitiva.libs.fabsmenu.FABsMenuListener) SimplePagerAdapter(james.alarmio.adapters.SimplePagerAdapter) FABsMenu(jahirfiquitiva.libs.fabsmenu.FABsMenu) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) Consumer(io.reactivex.functions.Consumer) TabLayout(com.google.android.material.tabs.TabLayout) ViewTreeObserver(android.view.ViewTreeObserver) TimerDialog(james.alarmio.dialogs.TimerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) ImageView(android.widget.ImageView) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) View(android.view.View) PageIndicatorView(james.alarmio.views.PageIndicatorView) PickerDialog(me.jfenn.timedatepickers.dialogs.PickerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) AlarmManager(android.app.AlarmManager) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) AlarmData(james.alarmio.data.AlarmData) Nullable(androidx.annotation.Nullable)

Example 3 with LinearTimePickerView

use of me.jfenn.timedatepickers.views.LinearTimePickerView in project Alarmio by TheAndroidMaster.

the class AlarmsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (getItemViewType(position) == 0) {
        final TimerViewHolder timerHolder = (TimerViewHolder) holder;
        if (timerHolder.runnable != null)
            timerHolder.handler.removeCallbacks(timerHolder.runnable);
        timerHolder.runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    TimerData timer = getTimer(timerHolder.getAdapterPosition());
                    String text = FormatUtils.formatMillis(timer.getRemainingMillis());
                    timerHolder.time.setText(text.substring(0, text.length() - 3));
                    timerHolder.progress.update(1 - ((float) timer.getRemainingMillis() / timer.getDuration()));
                    timerHolder.handler.postDelayed(this, 1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        timerHolder.stop.setColorFilter(textColorPrimary);
        timerHolder.stop.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                TimerData timer = getTimer(timerHolder.getAdapterPosition());
                alarmio.removeTimer(timer);
            }
        });
        timerHolder.handler.post(timerHolder.runnable);
    } else {
        final AlarmViewHolder alarmHolder = (AlarmViewHolder) holder;
        final boolean isExpanded = position == expandedPosition;
        AlarmData alarm = getAlarm(position);
        alarmHolder.name.setFocusable(isExpanded);
        alarmHolder.name.setEnabled(isExpanded);
        alarmHolder.name.clearFocus();
        alarmHolder.nameUnderline.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
        alarmHolder.name.setText(alarm.getName(alarmio));
        alarmHolder.name.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                getAlarm(alarmHolder.getAdapterPosition()).setName(alarmio, alarmHolder.name.getText().toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        alarmHolder.enable.setOnCheckedChangeListener(null);
        alarmHolder.enable.setChecked(alarm.isEnabled);
        alarmHolder.enable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                getAlarm(alarmHolder.getAdapterPosition()).setEnabled(alarmio, alarmManager, b);
            }
        });
        alarmHolder.time.setText(FormatUtils.formatShort(alarmio, alarm.time.getTime()));
        alarmHolder.time.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                new AestheticTimeSheetPickerDialog(view.getContext(), alarm.time.get(Calendar.HOUR_OF_DAY), alarm.time.get(Calendar.MINUTE)).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                    @Override
                    public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                        AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                        alarm.time.set(Calendar.HOUR_OF_DAY, view.getHourOfDay());
                        alarm.time.set(Calendar.MINUTE, view.getMinute());
                        alarm.setTime(alarmio, alarmManager, alarm.time.getTimeInMillis());
                        alarmHolder.time.setText(FormatUtils.formatShort(alarmio, alarm.time.getTime()));
                    }

                    @Override
                    public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                    }
                }).show();
            }
        });
        alarmHolder.indicators.setVisibility(isExpanded ? View.GONE : View.VISIBLE);
        if (isExpanded) {
            alarmHolder.repeat.setOnCheckedChangeListener(null);
            alarmHolder.repeat.setChecked(alarm.isRepeat());
            alarmHolder.repeat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                    for (int i = 0; i < 7; i++) {
                        alarm.days[i] = b;
                    }
                    alarm.setDays(alarmio, alarm.days);
                    Transition transition = new AutoTransition();
                    transition.setDuration(150);
                    TransitionManager.beginDelayedTransition(recycler, transition);
                    notifyDataSetChanged();
                }
            });
            alarmHolder.days.setVisibility(alarm.isRepeat() ? View.VISIBLE : View.GONE);
            DaySwitch.OnCheckedChangeListener listener = new DaySwitch.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(DaySwitch daySwitch, boolean b) {
                    AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                    alarm.days[alarmHolder.days.indexOfChild(daySwitch)] = b;
                    alarm.setDays(alarmio, alarm.days);
                    if (!alarm.isRepeat())
                        notifyItemChanged(alarmHolder.getAdapterPosition());
                }
            };
            for (int i = 0; i < 7; i++) {
                DaySwitch daySwitch = (DaySwitch) alarmHolder.days.getChildAt(i);
                daySwitch.setChecked(alarm.days[i]);
                daySwitch.setOnCheckedChangeListener(listener);
                switch(i) {
                    case 0:
                    case 6:
                        daySwitch.setText("S");
                        break;
                    case 1:
                        daySwitch.setText("M");
                        break;
                    case 2:
                    case 4:
                        daySwitch.setText("T");
                        break;
                    case 3:
                        daySwitch.setText("W");
                        break;
                    case 5:
                        daySwitch.setText("F");
                }
            }
            alarmHolder.ringtoneImage.setImageResource(alarm.hasSound() ? R.drawable.ic_ringtone : R.drawable.ic_ringtone_disabled);
            alarmHolder.ringtoneImage.setAlpha(alarm.hasSound() ? 1 : 0.333f);
            alarmHolder.ringtoneText.setText(alarm.hasSound() ? alarm.getSound().getName() : alarmio.getString(R.string.title_sound_none));
            alarmHolder.ringtone.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    SoundChooserDialog dialog = new SoundChooserDialog();
                    dialog.setListener(new SoundChooserListener() {

                        @Override
                        public void onSoundChosen(SoundData sound) {
                            int position = alarmHolder.getAdapterPosition();
                            AlarmData alarm = getAlarm(position);
                            alarm.setSound(alarmio, sound);
                            notifyItemChanged(position);
                        }
                    });
                    dialog.show(fragmentManager, null);
                }
            });
            AnimatedVectorDrawableCompat vibrateDrawable = AnimatedVectorDrawableCompat.create(alarmio, alarm.isVibrate ? R.drawable.ic_vibrate_to_none : R.drawable.ic_none_to_vibrate);
            alarmHolder.vibrateImage.setImageDrawable(vibrateDrawable);
            alarmHolder.vibrateImage.setAlpha(alarm.isVibrate ? 1 : 0.333f);
            alarmHolder.vibrate.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                    alarm.setVibrate(alarmio, !alarm.isVibrate);
                    AnimatedVectorDrawableCompat vibrateDrawable = AnimatedVectorDrawableCompat.create(alarmio, alarm.isVibrate ? R.drawable.ic_none_to_vibrate : R.drawable.ic_vibrate_to_none);
                    if (vibrateDrawable != null) {
                        alarmHolder.vibrateImage.setImageDrawable(vibrateDrawable);
                        vibrateDrawable.start();
                    } else
                        alarmHolder.vibrateImage.setImageResource(alarm.isVibrate ? R.drawable.ic_vibrate : R.drawable.ic_vibrate_none);
                    alarmHolder.vibrateImage.animate().alpha(alarm.isVibrate ? 1 : 0.333f).setDuration(250).start();
                    if (alarm.isVibrate)
                        view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                }
            });
        } else {
            alarmHolder.repeatIndicator.setAlpha(alarm.isRepeat() ? 1 : 0.333f);
            alarmHolder.soundIndicator.setAlpha(alarm.hasSound() ? 1 : 0.333f);
            alarmHolder.vibrateIndicator.setAlpha(alarm.isVibrate ? 1 : 0.333f);
        }
        alarmHolder.expandImage.animate().rotationX(isExpanded ? 180 : 0).start();
        alarmHolder.delete.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
        alarmHolder.delete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                new AlertDialog(view.getContext()).setContent(alarmio.getString(R.string.msg_delete_confirmation, alarm.getName(alarmio))).setListener(new AlertDialog.Listener() {

                    @Override
                    public void onDismiss(AlertDialog dialog, boolean ok) {
                        if (ok)
                            alarmio.removeAlarm(getAlarm(alarmHolder.getAdapterPosition()));
                    }
                }).show();
            }
        });
        alarmHolder.repeat.setTextColor(textColorPrimary);
        alarmHolder.delete.setTextColor(textColorPrimary);
        alarmHolder.ringtoneImage.setColorFilter(textColorPrimary);
        alarmHolder.vibrateImage.setColorFilter(textColorPrimary);
        alarmHolder.expandImage.setColorFilter(textColorPrimary);
        alarmHolder.repeatIndicator.setColorFilter(textColorPrimary);
        alarmHolder.soundIndicator.setColorFilter(textColorPrimary);
        alarmHolder.vibrateIndicator.setColorFilter(textColorPrimary);
        alarmHolder.nameUnderline.setBackgroundColor(textColorPrimary);
        int visibility = isExpanded ? View.VISIBLE : View.GONE;
        if (visibility != alarmHolder.extra.getVisibility()) {
            alarmHolder.extra.setVisibility(visibility);
            Aesthetic.Companion.get().colorPrimary().take(1).subscribe(new Consumer<Integer>() {

                @Override
                public void accept(Integer integer) throws Exception {
                    ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), isExpanded ? integer : colorForeground, isExpanded ? colorForeground : integer);
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            alarmHolder.itemView.setBackgroundColor((int) animation.getAnimatedValue());
                        }
                    });
                    animator.addListener(new Animator.AnimatorListener() {

                        @Override
                        public void onAnimationStart(Animator animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            alarmHolder.itemView.setBackgroundColor(isExpanded ? colorForeground : Color.TRANSPARENT);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {
                        }
                    });
                    animator.start();
                }
            });
            ValueAnimator animator = ValueAnimator.ofFloat(isExpanded ? 0 : ConversionUtils.dpToPx(2), isExpanded ? ConversionUtils.dpToPx(2) : 0);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    ViewCompat.setElevation(alarmHolder.itemView, (float) animation.getAnimatedValue());
                }
            });
            animator.start();
        } else {
            alarmHolder.itemView.setBackgroundColor(isExpanded ? colorForeground : Color.TRANSPARENT);
            ViewCompat.setElevation(alarmHolder.itemView, isExpanded ? ConversionUtils.dpToPx(2) : 0);
        }
        alarmHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                expandedPosition = isExpanded ? -1 : alarmHolder.getAdapterPosition();
                Transition transition = new AutoTransition();
                transition.setDuration(250);
                TransitionManager.beginDelayedTransition(recycler, transition);
                notifyDataSetChanged();
            }
        });
    }
}
Also used : AlertDialog(james.alarmio.dialogs.AlertDialog) SoundChooserListener(james.alarmio.interfaces.SoundChooserListener) ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SoundData(james.alarmio.data.SoundData) DaySwitch(james.alarmio.views.DaySwitch) AutoTransition(androidx.transition.AutoTransition) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) ImageView(android.widget.ImageView) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) View(android.view.View) ProgressLineView(james.alarmio.views.ProgressLineView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SoundChooserDialog(james.alarmio.dialogs.SoundChooserDialog) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) TimerData(james.alarmio.data.TimerData) PickerDialog(me.jfenn.timedatepickers.dialogs.PickerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) AutoTransition(androidx.transition.AutoTransition) Transition(androidx.transition.Transition) AnimatedVectorDrawableCompat(androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat) CompoundButton(android.widget.CompoundButton) AlarmData(james.alarmio.data.AlarmData) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView)

Aggregations

View (android.view.View)3 AestheticTimeSheetPickerDialog (james.alarmio.dialogs.AestheticTimeSheetPickerDialog)3 PickerDialog (me.jfenn.timedatepickers.dialogs.PickerDialog)3 LinearTimePickerView (me.jfenn.timedatepickers.views.LinearTimePickerView)3 CompoundButton (android.widget.CompoundButton)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AlarmData (james.alarmio.data.AlarmData)2 Animator (android.animation.Animator)1 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 AlarmManager (android.app.AlarmManager)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 ViewTreeObserver (android.view.ViewTreeObserver)1 AdapterView (android.widget.AdapterView)1 Nullable (androidx.annotation.Nullable)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AutoTransition (androidx.transition.AutoTransition)1