mirror of https://github.com/iSoron/uhabits.git
parent
a2a8dc4489
commit
714771fbc3
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
|
||||||
*
|
|
||||||
* 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.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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||||
|
*
|
||||||
|
* 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.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
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
|
||||||
*
|
|
||||||
* 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.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) -> { }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||||
|
*
|
||||||
|
* 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.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 -> }
|
||||||
|
}
|
||||||
|
}
|
@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
|
||||||
*
|
|
||||||
* 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.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||||
|
*
|
||||||
|
* 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.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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue