Convert SnoozeDelayPickerActivity to kotlin

pull/707/head
Quentin Hibon 5 years ago
parent 99277491c8
commit d5b9fda636

@ -1,123 +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.notifications;
import android.app.*;
import android.graphics.*;
import android.os.*;
import androidx.annotation.Nullable;
import android.text.format.*;
import android.view.*;
import android.widget.*;
import androidx.fragment.app.FragmentActivity;
import com.android.datetimepicker.time.TimePickerDialog;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.inject.*;
import org.isoron.uhabits.receivers.*;
import org.isoron.uhabits.utils.*;
import java.util.*;
import static android.content.ContentUris.parseId;
public class SnoozeDelayPickerActivity extends FragmentActivity
implements AdapterView.OnItemClickListener
{
private Habit habit;
private ReminderController reminderController;
@Nullable
private AlertDialog dialog;
@Override
protected void onCreate(@Nullable Bundle bundle)
{
super.onCreate(bundle);
if (getIntent() == null) finish();
if (getIntent().getData() == null) finish();
HabitsApplication app = (HabitsApplication) getApplicationContext();
HabitsApplicationComponent appComponent = app.getComponent();
reminderController = appComponent.getReminderController();
habit = appComponent.getHabitList().getById(parseId(getIntent().getData()));
if (habit == null) finish();
int theme = R.style.Theme_AppCompat_Light_Dialog_Alert;
dialog = new AlertDialog.Builder(new ContextThemeWrapper(this, theme))
.setTitle(R.string.select_snooze_delay)
.setItems(R.array.snooze_picker_names, null)
.create();
dialog.getListView().setOnItemClickListener(this);
dialog.setOnDismissListener(d -> finish());
dialog.show();
SystemUtils.unlockScreen(this);
}
private void showTimePicker()
{
final Calendar calendar = Calendar.getInstance();
TimePickerDialog dialog = TimePickerDialog.newInstance(
(view, hour, minute) -> {
reminderController.onSnoozeTimePicked(habit, hour, minute);
finish();
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
DateFormat.is24HourFormat(this),
Color.BLUE);
dialog.show(getSupportFragmentManager(), "timePicker");
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
int[] snoozeValues = getResources().getIntArray(R.array.snooze_picker_values);
if (snoozeValues[position] >= 0)
{
reminderController.onSnoozeDelayPicked(habit, snoozeValues[position]);
finish();
}
else showTimePicker();
}
@Override
public void finish()
{
super.finish();
overridePendingTransition(0, 0);
}
@Override
protected void onPause()
{
if (dialog != null) dialog.dismiss();
super.onPause();
}
}

@ -0,0 +1,96 @@
/*
* 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.notifications
import android.app.AlertDialog
import android.content.ContentUris
import android.graphics.Color
import android.os.Bundle
import android.text.format.DateFormat
import android.view.ContextThemeWrapper
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import androidx.fragment.app.FragmentActivity
import com.android.datetimepicker.time.RadialPickerLayout
import com.android.datetimepicker.time.TimePickerDialog
import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.receivers.ReminderController
import org.isoron.uhabits.utils.SystemUtils
import java.util.Calendar
class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener {
private var habit: Habit? = null
private var reminderController: ReminderController? = null
private var dialog: AlertDialog? = null
override fun onCreate(bundle: Bundle?) {
super.onCreate(bundle)
if (intent == null) finish()
if (intent.data == null) finish()
val app = applicationContext as HabitsApplication
val appComponent = app.component
reminderController = appComponent.reminderController
habit = appComponent.habitList.getById(ContentUris.parseId(intent.data))
if (habit == null) finish()
val theme = R.style.Theme_AppCompat_Light_Dialog_Alert
dialog = AlertDialog.Builder(ContextThemeWrapper(this, theme))
.setTitle(R.string.select_snooze_delay)
.setItems(R.array.snooze_picker_names, null)
.create()
dialog!!.listView.onItemClickListener = this
dialog!!.setOnDismissListener { finish() }
dialog!!.show()
SystemUtils.unlockScreen(this)
}
private fun showTimePicker() {
val calendar = Calendar.getInstance()
val dialog = TimePickerDialog.newInstance(
{ view: RadialPickerLayout?, hour: Int, minute: Int ->
reminderController!!.onSnoozeTimePicked(habit, hour, minute)
finish()
},
calendar[Calendar.HOUR_OF_DAY],
calendar[Calendar.MINUTE],
DateFormat.is24HourFormat(this),
Color.BLUE
)
dialog.show(supportFragmentManager, "timePicker")
}
override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
val snoozeValues = resources.getIntArray(R.array.snooze_picker_values)
if (snoozeValues[position] >= 0) {
reminderController!!.onSnoozeDelayPicked(habit, snoozeValues[position])
finish()
} else showTimePicker()
}
override fun finish() {
super.finish()
overridePendingTransition(0, 0)
}
override fun onPause() {
if (dialog != null) dialog!!.dismiss()
super.onPause()
}
}
Loading…
Cancel
Save