diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialog.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialog.kt
similarity index 62%
rename from uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialog.java
rename to uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialog.kt
index a36cac195..cf6248600 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialog.java
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialog.kt
@@ -16,24 +16,20 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
+package org.isoron.uhabits.activities.common.dialogs
-package org.isoron.uhabits.activities.common.dialogs;
-
-import org.isoron.uhabits.core.models.*;
-import org.isoron.uhabits.core.ui.callbacks.*;
-import org.isoron.uhabits.utils.*;
+import com.android.colorpicker.ColorPickerDialog
+import org.isoron.uhabits.core.ui.callbacks.OnColorPickedCallback
+import org.isoron.uhabits.utils.toPaletteColor
/**
* Dialog that allows the user to choose a color.
*/
-public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
-{
- public void setListener(OnColorPickedCallback callback)
- {
- super.setOnColorSelectedListener(c ->
- {
- PaletteColor pc = PaletteUtilsKt.toPaletteColor(c, getContext());
- callback.onColorPicked(pc);
- });
+class ColorPickerDialog : ColorPickerDialog() {
+ fun setListener(callback: OnColorPickedCallback) {
+ super.setOnColorSelectedListener { c: Int ->
+ val pc = c.toPaletteColor(context!!)
+ callback.onColorPicked(pc)
+ }
}
}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialogFactory.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialogFactory.java
deleted file mode 100644
index d06272d63..000000000
--- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialogFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2016-2021 Álinson Santos Xavier
- *
- * 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 .
- */
-
-package org.isoron.uhabits.activities.common.dialogs;
-
-import android.content.*;
-
-import org.isoron.uhabits.R;
-import org.isoron.uhabits.core.models.*;
-import org.isoron.uhabits.inject.*;
-import org.isoron.uhabits.utils.*;
-
-import javax.inject.*;
-
-@ActivityScope
-public class ColorPickerDialogFactory
-{
- private final Context context;
-
- @Inject
- public ColorPickerDialogFactory(@ActivityContext Context context)
- {
- this.context = context;
- }
-
- public ColorPickerDialog create(PaletteColor color)
- {
- ColorPickerDialog dialog = new ColorPickerDialog();
- StyledResources res = new StyledResources(context);
- int androidColor = PaletteUtilsKt.toThemedAndroidColor(color, context);
-
- dialog.initialize(R.string.color_picker_default_title, res.getPalette(),
- androidColor, 4, com.android.colorpicker.ColorPickerDialog.SIZE_SMALL);
-
- return dialog;
- }
-}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialogFactory.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialogFactory.kt
new file mode 100644
index 000000000..ac393d506
--- /dev/null
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ColorPickerDialogFactory.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016-2021 Álinson Santos Xavier
+ *
+ * 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 .
+ */
+package org.isoron.uhabits.activities.common.dialogs
+
+import android.content.Context
+import org.isoron.uhabits.R
+import org.isoron.uhabits.core.models.PaletteColor
+import org.isoron.uhabits.inject.ActivityContext
+import org.isoron.uhabits.inject.ActivityScope
+import org.isoron.uhabits.utils.StyledResources
+import org.isoron.uhabits.utils.toThemedAndroidColor
+import javax.inject.Inject
+
+@ActivityScope
+class ColorPickerDialogFactory @Inject constructor(@param:ActivityContext private val context: Context) {
+ fun create(color: PaletteColor): ColorPickerDialog {
+ val dialog = ColorPickerDialog()
+ val res = StyledResources(context)
+ val androidColor = color.toThemedAndroidColor(context)
+ dialog.initialize(
+ R.string.color_picker_default_title,
+ res.getPalette(),
+ androidColor,
+ 4,
+ com.android.colorpicker.ColorPickerDialog.SIZE_SMALL
+ )
+ return dialog
+ }
+}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmDeleteDialog.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmDeleteDialog.kt
similarity index 52%
rename from uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmDeleteDialog.java
rename to uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmDeleteDialog.kt
index 7309f27d5..bac6180b2 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmDeleteDialog.java
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmDeleteDialog.kt
@@ -16,39 +16,34 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
+package org.isoron.uhabits.activities.common.dialogs
-package org.isoron.uhabits.activities.common.dialogs;
-
-import android.content.*;
-import android.content.res.*;
-
-import androidx.annotation.*;
-import androidx.appcompat.app.*;
-
-import org.isoron.uhabits.R;
-import org.isoron.uhabits.core.ui.callbacks.*;
-import org.isoron.uhabits.inject.*;
+import android.content.Context
+import android.content.DialogInterface
+import androidx.appcompat.app.AlertDialog
+import org.isoron.uhabits.R
+import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback
+import org.isoron.uhabits.inject.ActivityContext
/**
* Dialog that asks the user confirmation before executing a delete operation.
*/
-public class ConfirmDeleteDialog extends AlertDialog
-{
- public ConfirmDeleteDialog(@ActivityContext Context context,
- @NonNull OnConfirmedCallback callback,
- int quantity)
- {
- super(context);
- Resources res = context.getResources();
- setTitle(res.getQuantityString(R.plurals.delete_habits_title, quantity));
- setMessage(res.getQuantityString(R.plurals.delete_habits_message, quantity));
- setButton(BUTTON_POSITIVE,
- res.getString(R.string.yes),
- (dialog, which) -> callback.onConfirmed()
- );
- setButton(BUTTON_NEGATIVE,
- res.getString(R.string.no),
- (dialog, which) -> { }
- );
+class ConfirmDeleteDialog(
+ @ActivityContext context: Context,
+ callback: OnConfirmedCallback,
+ quantity: Int
+) : AlertDialog(context) {
+ init {
+ val res = context.resources
+ setTitle(res.getQuantityString(R.plurals.delete_habits_title, quantity))
+ setMessage(res.getQuantityString(R.plurals.delete_habits_message, quantity))
+ setButton(
+ BUTTON_POSITIVE,
+ res.getString(R.string.yes)
+ ) { dialog: DialogInterface?, which: Int -> callback.onConfirmed() }
+ setButton(
+ BUTTON_NEGATIVE,
+ res.getString(R.string.no)
+ ) { dialog: DialogInterface?, which: Int -> }
}
}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmSyncKeyDialog.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmSyncKeyDialog.java
deleted file mode 100644
index 337823e5f..000000000
--- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmSyncKeyDialog.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2016-2021 Álinson Santos Xavier
- *
- * 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 .
- */
-
-package org.isoron.uhabits.activities.common.dialogs;
-
-import android.content.*;
-import android.content.res.*;
-
-import androidx.annotation.*;
-import androidx.appcompat.app.*;
-
-import org.isoron.uhabits.*;
-import org.isoron.uhabits.core.ui.callbacks.*;
-import org.isoron.uhabits.inject.*;
-
-public class ConfirmSyncKeyDialog extends AlertDialog
-{
- public ConfirmSyncKeyDialog(@ActivityContext Context context,
- @NonNull OnConfirmedCallback callback)
- {
- super(context);
- setTitle(R.string.device_sync);
- Resources res = context.getResources();
- setMessage(res.getString(R.string.sync_confirm));
- setButton(BUTTON_POSITIVE,
- res.getString(R.string.yes),
- (dialog, which) -> callback.onConfirmed()
- );
- setButton(BUTTON_NEGATIVE,
- res.getString(R.string.no),
- (dialog, which) -> { }
- );
- }
-}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmSyncKeyDialog.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmSyncKeyDialog.kt
new file mode 100644
index 000000000..b50ed50be
--- /dev/null
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/ConfirmSyncKeyDialog.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016-2021 Álinson Santos Xavier
+ *
+ * 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 .
+ */
+package org.isoron.uhabits.activities.common.dialogs
+
+import android.content.Context
+import android.content.DialogInterface
+import androidx.appcompat.app.AlertDialog
+import org.isoron.uhabits.R
+import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback
+import org.isoron.uhabits.inject.ActivityContext
+
+class ConfirmSyncKeyDialog(
+ @ActivityContext context: Context,
+ callback: OnConfirmedCallback
+) : AlertDialog(context) {
+ init {
+ setTitle(R.string.device_sync)
+ val res = context.resources
+ setMessage(res.getString(R.string.sync_confirm))
+ setButton(
+ BUTTON_POSITIVE,
+ res.getString(R.string.yes)
+ ) { dialog: DialogInterface?, which: Int -> callback.onConfirmed() }
+ setButton(
+ BUTTON_NEGATIVE,
+ res.getString(R.string.no)
+ ) { dialog: DialogInterface?, which: Int -> }
+ }
+}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/WeekdayPickerDialog.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/WeekdayPickerDialog.java
deleted file mode 100644
index 4d40cc386..000000000
--- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/WeekdayPickerDialog.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2016-2021 Álinson Santos Xavier
- *
- * 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 .
- */
-
-package org.isoron.uhabits.activities.common.dialogs;
-
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AppCompatDialogFragment;
-
-import org.isoron.uhabits.R;
-import org.isoron.uhabits.core.models.WeekdayList;
-import org.isoron.uhabits.core.utils.DateUtils;
-
-import java.util.Calendar;
-
-/**
- * Dialog that allows the user to pick one or more days of the week.
- */
-public class WeekdayPickerDialog extends AppCompatDialogFragment implements
- DialogInterface.OnMultiChoiceClickListener,
- DialogInterface.OnClickListener
-{
- private static final String KEY_SELECTED_DAYS = "selectedDays";
- private boolean[] selectedDays;
-
- private OnWeekdaysPickedListener listener;
-
- @Override
- public void onClick(DialogInterface dialog, int which, boolean isChecked)
- {
- selectedDays[which] = isChecked;
- }
-
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- if(savedInstanceState != null){
- selectedDays = savedInstanceState.getBooleanArray(KEY_SELECTED_DAYS);
- }
- }
-
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBooleanArray(KEY_SELECTED_DAYS, selectedDays);
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- if (listener != null)
- listener.onWeekdaysSet(new WeekdayList(selectedDays));
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState)
- {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder
- .setTitle(R.string.select_weekdays)
- .setMultiChoiceItems(DateUtils.getLongWeekdayNames(Calendar.SATURDAY),
- selectedDays,
- this)
- .setPositiveButton(android.R.string.yes, this)
- .setNegativeButton(android.R.string.cancel, (dialog, which) -> {
- dismiss();
- });
-
- return builder.create();
- }
-
- public void setListener(OnWeekdaysPickedListener listener)
- {
- this.listener = listener;
- }
-
- public void setSelectedDays(WeekdayList days)
- {
- this.selectedDays = days.toArray();
- }
-
- public interface OnWeekdaysPickedListener
- {
- void onWeekdaysSet(WeekdayList days);
- }
-}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/WeekdayPickerDialog.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/WeekdayPickerDialog.kt
new file mode 100644
index 000000000..6e1f8cf28
--- /dev/null
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/WeekdayPickerDialog.kt
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2016-2021 Álinson Santos Xavier
+ *
+ * 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 .
+ */
+package org.isoron.uhabits.activities.common.dialogs
+
+import android.app.Dialog
+import android.content.DialogInterface
+import android.content.DialogInterface.OnMultiChoiceClickListener
+import android.os.Bundle
+import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatDialogFragment
+import org.isoron.uhabits.R
+import org.isoron.uhabits.core.models.WeekdayList
+import org.isoron.uhabits.core.utils.DateUtils
+import java.util.Calendar
+
+/**
+ * Dialog that allows the user to pick one or more days of the week.
+ */
+class WeekdayPickerDialog :
+ AppCompatDialogFragment(),
+ OnMultiChoiceClickListener,
+ DialogInterface.OnClickListener {
+ private var selectedDays: BooleanArray? = null
+ private var listener: OnWeekdaysPickedListener? = null
+ override fun onClick(dialog: DialogInterface, which: Int, isChecked: Boolean) {
+ selectedDays!![which] = isChecked
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ if (savedInstanceState != null) {
+ selectedDays = savedInstanceState.getBooleanArray(KEY_SELECTED_DAYS)
+ }
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ outState.putBooleanArray(KEY_SELECTED_DAYS, selectedDays)
+ }
+
+ override fun onClick(dialog: DialogInterface, which: Int) {
+ if (listener != null) listener!!.onWeekdaysSet(WeekdayList(selectedDays))
+ }
+
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val builder = AlertDialog.Builder(
+ activity!!
+ )
+ builder
+ .setTitle(R.string.select_weekdays)
+ .setMultiChoiceItems(
+ DateUtils.getLongWeekdayNames(Calendar.SATURDAY),
+ selectedDays,
+ this
+ )
+ .setPositiveButton(android.R.string.yes, this)
+ .setNegativeButton(
+ android.R.string.cancel
+ ) { _: DialogInterface?, _: Int -> dismiss() }
+ return builder.create()
+ }
+
+ fun setListener(listener: OnWeekdaysPickedListener?) {
+ this.listener = listener
+ }
+
+ fun setSelectedDays(days: WeekdayList) {
+ selectedDays = days.toArray()
+ }
+
+ fun interface OnWeekdaysPickedListener {
+ fun onWeekdaysSet(days: WeekdayList)
+ }
+
+ companion object {
+ private const val KEY_SELECTED_DAYS = "selectedDays"
+ }
+}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitActivity.kt
index 5e7aab70a..80adad0c7 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitActivity.kt
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitActivity.kt
@@ -197,7 +197,8 @@ class EditHabitActivity : AppCompatActivity() {
binding.reminderDatePicker.setOnClickListener {
val dialog = WeekdayPickerDialog()
- dialog.setListener { days ->
+
+ dialog.setListener { days: WeekdayList ->
reminderDays = days
if (reminderDays.isEmpty) reminderDays = WeekdayList.EVERY_DAY
populateReminder()