cleaned up numerical widget code

pull/499/head
thomas 6 years ago
parent 26d91a2d1d
commit 6daee8c5bb

@ -114,14 +114,4 @@ class PendingIntentFactory
if (timestamp != null) putExtra("timestamp", timestamp)
},
FLAG_UPDATE_CURRENT)
fun saveNumericalValue(habit: Habit, numericalValue: Int, timestamp: Long?): PendingIntent =
PendingIntent.getBroadcast(
context, 2,
Intent(context, WidgetReceiver::class.java).apply {
data = Uri.parse(habit.uriString)
action = WidgetReceiver.ACTION_SAVE_NUMERICAL_VALUE
putExtra("numericalValue",numericalValue);
if (timestamp != null) putExtra("timestamp", timestamp)
},
FLAG_UPDATE_CURRENT)
}

@ -19,7 +19,6 @@ import org.isoron.uhabits.widgets.WidgetUpdater
class NumericalCheckmarkWidgetActivity : Activity() {
//private var activityComponent : NumericalCheckmarkWidgetActivityComponent? = null
private lateinit var behavior : NumericalCheckmarkWidgetBehavior
private var data: IntentParser.CheckmarkIntentData? = null
private lateinit var widgetUpdater : WidgetUpdater
@ -68,7 +67,7 @@ class NumericalCheckmarkWidgetActivity : Activity() {
}
companion object{
val ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY = "org.isoron.uhabits.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY"
const val ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY = "org.isoron.uhabits.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY"
}
}

@ -1,37 +0,0 @@
package org.isoron.uhabits.widgets.activities;
import android.content.Context;
import org.isoron.androidbase.AppContext;
import org.isoron.androidbase.AppContextModule;
import org.isoron.uhabits.HabitsModule;
import org.isoron.uhabits.core.AppScope;
import org.isoron.uhabits.core.commands.CommandRunner;
import org.isoron.uhabits.core.models.HabitList;
import org.isoron.uhabits.core.preferences.Preferences;
import org.isoron.uhabits.core.tasks.TaskRunner;
import org.isoron.uhabits.core.ui.widgets.NumericalCheckmarkWidgetBehavior;
import org.isoron.uhabits.tasks.AndroidTaskRunner;
import dagger.Component;
@AppScope
@Component(modules = {
AppContextModule.class,
HabitsModule.class,
AndroidTaskRunner.class,
})
public interface NumericalCheckmarkWidgetActivityComponent {
NumericalCheckmarkWidgetBehavior getNumericalCheckmarkWidgetBehavior();
CommandRunner getCommandRunner();
@AppContext
Context getContext();
HabitList getHabitList();
Preferences getPreferences();
TaskRunner getTaskRunner();
}

@ -1,105 +0,0 @@
/*
* Copyright (C) 2016 Á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.core.commands;
import android.support.annotation.NonNull;
import org.isoron.uhabits.core.models.Habit;
import org.isoron.uhabits.core.models.HabitList;
import org.isoron.uhabits.core.models.HabitNotFoundException;
/**
* Command to update a habit.
*/
public class UpdateHabitCommand extends Command
{
@NonNull
private HabitList list;
@NonNull
final Habit habit;
public UpdateHabitCommand(@NonNull HabitList list,
@NonNull Habit habit)
{
super();
this.list = list;
this.habit = habit;
}
@Override
public void execute()
{
list.update(habit);
}
@NonNull
public Habit getHabit()
{
return habit;
}
@Override
@NonNull
public Record toRecord()
{
return new Record(this);
}
@Override
public void undo()
{
throw new RuntimeException("Update command cannot be undone");
}
public static class Record
{
@NonNull
public String id;
@NonNull
public String event = "Update";
public long habit;
public Record(@NonNull UpdateHabitCommand command)
{
id = command.getId();
Long habitId = command.habit.getId();
if (habitId == null) throw new RuntimeException("Habit not saved");
this.habit = habitId;
}
public UpdateHabitCommand toCommand(@NonNull HabitList habitList)
{
Habit h = habitList.getById(habit);
if (h == null) throw new HabitNotFoundException();
UpdateHabitCommand command;
command = new UpdateHabitCommand(
habitList, h);
command.setId(id);
return command;
}
}
}

@ -69,11 +69,4 @@ public class WidgetBehavior extends BaseWidgetBehavior
new ToggleRepetitionCommand(getHabitList(), habit, timestamp),
habit.getId());
}
public void updateWidget(@NonNull Habit habit)
{
getCommandRunner().execute(
new UpdateHabitCommand(getHabitList(), habit),
habit.getId());
}
}

Loading…
Cancel
Save