mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove AndroidDateUtils
This commit is contained in:
@@ -257,12 +257,11 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
binding.reminderDatePicker.visibility = View.GONE
|
||||
binding.reminderDivider.visibility = View.GONE
|
||||
} else {
|
||||
val time = AndroidDateUtils.formatTime(this, reminderHour, reminderMin)
|
||||
val daysArray = reminderDays.toArray()
|
||||
val time = formatTime(this, reminderHour, reminderMin)
|
||||
binding.reminderTimePicker.text = time
|
||||
binding.reminderDatePicker.visibility = View.VISIBLE
|
||||
binding.reminderDivider.visibility = View.VISIBLE
|
||||
binding.reminderDatePicker.text = AndroidDateUtils.formatWeekdayList(this, daysArray)
|
||||
binding.reminderDatePicker.text = reminderDays.toFormattedString(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,8 +92,7 @@ class SubtitleCard(context: Context?, attrs: AttributeSet?) : HabitCard(context,
|
||||
}
|
||||
|
||||
private fun updateReminderText(reminder: Reminder) {
|
||||
binding.reminderLabel.text = AndroidDateUtils.formatTime(context, reminder.hour,
|
||||
reminder.minute)
|
||||
binding.reminderLabel.text = formatTime(context, reminder.hour, reminder.minute)
|
||||
}
|
||||
|
||||
override fun createRefreshTask(): Task {
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.utils;
|
||||
|
||||
import android.content.*;
|
||||
import android.text.format.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AndroidDateUtils
|
||||
{
|
||||
public static String formatTime(Context context, int hours, int minutes)
|
||||
{
|
||||
int reminderMilliseconds = (hours * 60 + minutes) * 60 * 1000;
|
||||
|
||||
Date date = new Date(reminderMilliseconds);
|
||||
java.text.DateFormat df = DateFormat.getTimeFormat(context);
|
||||
df.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String formatWeekdayList(Context context, boolean weekday[])
|
||||
{
|
||||
String shortDayNames[] = org.isoron.uhabits.core.utils.DateUtils.getShortWeekdayNames(Calendar.SATURDAY);
|
||||
String longDayNames[] = org.isoron.uhabits.core.utils.DateUtils.getLongWeekdayNames(Calendar.SATURDAY);
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
int count = 0;
|
||||
int first = 0;
|
||||
boolean isFirst = true;
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
if (weekday[i])
|
||||
{
|
||||
if (isFirst) first = i;
|
||||
else buffer.append(", ");
|
||||
|
||||
buffer.append(shortDayNames[i]);
|
||||
isFirst = false;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1) return longDayNames[first];
|
||||
if (count == 2 && weekday[0] && weekday[1])
|
||||
return context.getString(R.string.weekends);
|
||||
if (count == 5 && !weekday[0] && !weekday[1])
|
||||
return context.getString(R.string.any_weekday);
|
||||
if (count == 7) return context.getString(R.string.any_day);
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,12 @@
|
||||
|
||||
package org.isoron.uhabits.utils
|
||||
|
||||
import android.content.*
|
||||
import android.text.format.DateFormat
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.utils.*
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import java.text.*
|
||||
import java.util.*
|
||||
|
||||
@@ -28,3 +32,33 @@ fun String.toSimpleDataFormat(): SimpleDateFormat {
|
||||
val locale = Locale.getDefault()
|
||||
return DateFormats.fromSkeleton(DateFormat.getBestDateTimePattern(locale, this), locale)
|
||||
}
|
||||
|
||||
fun WeekdayList.toFormattedString(context: Context): String {
|
||||
val shortDayNames = DateUtils.getShortWeekdayNames(Calendar.SATURDAY)
|
||||
val longDayNames = DateUtils.getLongWeekdayNames(Calendar.SATURDAY)
|
||||
val buffer = StringBuilder()
|
||||
var count = 0
|
||||
var first = 0
|
||||
var isFirst = true
|
||||
val array = this.toArray()
|
||||
for (i in 0..6) {
|
||||
if (array[i]) {
|
||||
if (isFirst) first = i else buffer.append(", ")
|
||||
buffer.append(shortDayNames[i])
|
||||
isFirst = false
|
||||
count++
|
||||
}
|
||||
}
|
||||
if (count == 1) return longDayNames[first]
|
||||
if (count == 2 && array[0] && array[1]) return context.getString(R.string.weekends)
|
||||
if (count == 5 && !array[0] && !array[1]) return context.getString(R.string.any_weekday)
|
||||
return if (count == 7) context.getString(R.string.any_day) else buffer.toString()
|
||||
}
|
||||
|
||||
fun formatTime(context: Context, hours: Int, minutes: Int): String? {
|
||||
val reminderMilliseconds = (hours * 60 + minutes) * 60 * 1000L
|
||||
val date = Date(reminderMilliseconds)
|
||||
val df = DateFormat.getTimeFormat(context)
|
||||
df.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return df.format(date)
|
||||
}
|
||||
Reference in New Issue
Block a user