private void setUpdateIntervalText() {
   Context context = ui.getActivity().getApplicationContext();
   String val;
   long interval = UserPreferences.getUpdateInterval();
   if (interval > 0) {
     int hours = (int) TimeUnit.MILLISECONDS.toHours(interval);
     String hoursStr =
         context.getResources().getQuantityString(R.plurals.time_hours_quantified, hours, hours);
     val =
         String.format(context.getString(R.string.pref_autoUpdateIntervallOrTime_every), hoursStr);
   } else {
     int[] timeOfDay = UserPreferences.getUpdateTimeOfDay();
     if (timeOfDay.length == 2) {
       Calendar cal = new GregorianCalendar();
       cal.set(Calendar.HOUR_OF_DAY, timeOfDay[0]);
       cal.set(Calendar.MINUTE, timeOfDay[1]);
       String timeOfDayStr = DateFormat.getTimeFormat(context).format(cal.getTime());
       val =
           String.format(
               context.getString(R.string.pref_autoUpdateIntervallOrTime_at), timeOfDayStr);
     } else {
       val = context.getString(R.string.pref_smart_mark_as_played_disabled);
     }
   }
   String summary =
       context.getString(R.string.pref_autoUpdateIntervallOrTime_sum)
           + "\n"
           + String.format(context.getString(R.string.pref_current_value), val);
   ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL).setSummary(summary);
 }
  private void showUpdateIntervalTimePreferencesDialog() {
    final Context context = ui.getActivity();

    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(R.string.pref_autoUpdateIntervallOrTime_title);
    builder.content(R.string.pref_autoUpdateIntervallOrTime_message);
    builder.positiveText(R.string.pref_autoUpdateIntervallOrTime_Interval);
    builder.negativeText(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay);
    builder.neutralText(R.string.pref_autoUpdateIntervallOrTime_Disable);
    builder.onPositive(
        (dialog, which) -> {
          AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
          builder1.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_Interval));
          final String[] values =
              context.getResources().getStringArray(R.array.update_intervall_values);
          final String[] entries = getUpdateIntervalEntries(values);
          long currInterval = UserPreferences.getUpdateInterval();
          int checkedItem = -1;
          if (currInterval > 0) {
            String currIntervalStr = String.valueOf(TimeUnit.MILLISECONDS.toHours(currInterval));
            checkedItem = ArrayUtils.indexOf(values, currIntervalStr);
          }
          builder1.setSingleChoiceItems(
              entries,
              checkedItem,
              (dialog1, which1) -> {
                int hours = Integer.parseInt(values[which1]);
                UserPreferences.setUpdateInterval(hours);
                dialog1.dismiss();
                setUpdateIntervalText();
              });
          builder1.setNegativeButton(context.getString(R.string.cancel_label), null);
          builder1.show();
        });
    builder.onNegative(
        (dialog, which) -> {
          int hourOfDay = 7, minute = 0;
          int[] updateTime = UserPreferences.getUpdateTimeOfDay();
          if (updateTime.length == 2) {
            hourOfDay = updateTime[0];
            minute = updateTime[1];
          }
          TimePickerDialog timePickerDialog =
              new TimePickerDialog(
                  context,
                  (view, selectedHourOfDay, selectedMinute) -> {
                    if (view.getTag() == null) { // onTimeSet() may get called twice!
                      view.setTag("TAGGED");
                      UserPreferences.setUpdateTimeOfDay(selectedHourOfDay, selectedMinute);
                      setUpdateIntervalText();
                    }
                  },
                  hourOfDay,
                  minute,
                  DateFormat.is24HourFormat(context));
          timePickerDialog.setTitle(
              context.getString(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay));
          timePickerDialog.show();
        });
    builder.onNeutral(
        (dialog, which) -> {
          UserPreferences.setUpdateInterval(0);
          setUpdateIntervalText();
        });
    builder.show();
  }