mirror of https://github.com/iSoron/uhabits.git
parent
fd03414607
commit
1d372a8fbb
@ -1,103 +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.receivers
|
|
||||||
|
|
||||||
import android.content.*
|
|
||||||
import android.util.*
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*
|
|
||||||
import org.isoron.uhabits.core.preferences.*
|
|
||||||
import org.isoron.uhabits.core.ui.widgets.*
|
|
||||||
import org.isoron.uhabits.intents.*
|
|
||||||
import org.isoron.uhabits.sync.*
|
|
||||||
|
|
||||||
import dagger.*
|
|
||||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
|
||||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
|
||||||
import org.isoron.uhabits.widgets.activities.NumericalCheckmarkWidgetActivity
|
|
||||||
import android.content.Intent
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Android BroadcastReceiver for Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* All broadcast messages are received and processed by this class.
|
|
||||||
*/
|
|
||||||
class WidgetReceiver : BroadcastReceiver() {
|
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
val app = context.applicationContext as HabitsApplication
|
|
||||||
|
|
||||||
val component = DaggerWidgetReceiver_WidgetComponent
|
|
||||||
.builder()
|
|
||||||
.habitsApplicationComponent(app.component)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val parser = app.component.intentParser
|
|
||||||
val controller = component.widgetController
|
|
||||||
val prefs = app.component.preferences
|
|
||||||
|
|
||||||
if (prefs.isSyncEnabled)
|
|
||||||
context.startService(Intent(context, SyncService::class.java))
|
|
||||||
|
|
||||||
try {
|
|
||||||
val data: IntentParser.CheckmarkIntentData = parser.parseCheckmarkIntent(intent)
|
|
||||||
|
|
||||||
when (intent.action) {
|
|
||||||
ACTION_ADD_REPETITION -> controller.onAddRepetition(data.habit, data.timestamp)
|
|
||||||
|
|
||||||
ACTION_TOGGLE_REPETITION -> controller.onToggleRepetition(data.habit, data.timestamp)
|
|
||||||
|
|
||||||
ACTION_REMOVE_REPETITION -> controller.onRemoveRepetition(data.habit, data.timestamp)
|
|
||||||
|
|
||||||
ACTION_SET_NUMERICAL_VALUE -> {
|
|
||||||
val numberSelectorIntent = Intent(context, NumericalCheckmarkWidgetActivity::class.java)
|
|
||||||
numberSelectorIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
numberSelectorIntent.action = NumericalCheckmarkWidgetActivity.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY
|
|
||||||
parser.copyIntentData(intent,numberSelectorIntent)//give the habit and timestamp data to the numericalCheckmarkWidgetActivity
|
|
||||||
context.startActivity(numberSelectorIntent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: RuntimeException) {
|
|
||||||
Log.e("WidgetReceiver", "could not process intent", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReceiverScope
|
|
||||||
@Component(dependencies = [HabitsApplicationComponent::class])
|
|
||||||
internal interface WidgetComponent {
|
|
||||||
val widgetController: WidgetBehavior
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val ACTION_ADD_REPETITION = "org.isoron.uhabits.ACTION_ADD_REPETITION"
|
|
||||||
|
|
||||||
val ACTION_DISMISS_REMINDER = "org.isoron.uhabits.ACTION_DISMISS_REMINDER"
|
|
||||||
|
|
||||||
val ACTION_REMOVE_REPETITION = "org.isoron.uhabits.ACTION_REMOVE_REPETITION"
|
|
||||||
|
|
||||||
val ACTION_TOGGLE_REPETITION = "org.isoron.uhabits.ACTION_TOGGLE_REPETITION"
|
|
||||||
|
|
||||||
val ACTION_SET_NUMERICAL_VALUE = "org.isoron.uhabits.ACTION_SET_NUMERICAL_VALUE"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package org.isoron.uhabits.widgets
|
|
||||||
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
|
||||||
import org.isoron.uhabits.core.models.Checkmark
|
|
||||||
import org.isoron.uhabits.core.models.Habit
|
|
||||||
import org.isoron.uhabits.receivers.WidgetReceiver
|
|
||||||
import org.isoron.uhabits.receivers.WidgetReceiver.Companion.ACTION_SET_NUMERICAL_VALUE
|
|
||||||
import org.isoron.uhabits.utils.PaletteUtils
|
|
||||||
import org.isoron.uhabits.widgets.activities.NumericalCheckmarkWidgetActivity
|
|
||||||
import org.isoron.uhabits.widgets.views.CheckmarkWidgetView
|
|
||||||
import org.isoron.uhabits.widgets.views.NumericalCheckmarkWidgetView
|
|
||||||
|
|
||||||
class NumericalCheckmarkWidget(context: Context, widgetId: Int, habit: Habit) : CheckmarkWidget(context, widgetId, habit) {
|
|
||||||
|
|
||||||
private lateinit var view: NumericalCheckmarkWidgetView
|
|
||||||
|
|
||||||
override fun getOnClickPendingIntent(context: Context): PendingIntent {
|
|
||||||
return pendingIntentFactory.setNumericalValue(context, habit, 10,null)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun buildView(): View {
|
|
||||||
view = NumericalCheckmarkWidgetView(context)
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun refreshData(v: View) {
|
|
||||||
(v as NumericalCheckmarkWidgetView).apply {
|
|
||||||
setPercentage(habit.scores.todayValue.toFloat())
|
|
||||||
setActiveColor(PaletteUtils.getColor(context, habit.color))
|
|
||||||
setName(habit.name)
|
|
||||||
setCheckmarkValue(habit.checkmarks.todayValue)
|
|
||||||
setCheckmarkState(getCheckmarkState())
|
|
||||||
refresh()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getCheckmarkState():Int{
|
|
||||||
return if(habit.isCompletedToday){
|
|
||||||
Checkmark.CHECKED_EXPLICITLY
|
|
||||||
}else{
|
|
||||||
Checkmark.UNCHECKED
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package org.isoron.uhabits.widgets.views
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.AttributeSet
|
|
||||||
|
|
||||||
import org.isoron.androidbase.utils.StyledResources
|
|
||||||
import org.isoron.uhabits.R
|
|
||||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
|
||||||
import org.isoron.uhabits.activities.habits.list.views.toShortString
|
|
||||||
import org.isoron.uhabits.core.models.Checkmark
|
|
||||||
import org.isoron.uhabits.core.models.Habit
|
|
||||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
|
||||||
|
|
||||||
|
|
||||||
class NumericalCheckmarkWidgetView : CheckmarkWidgetView {
|
|
||||||
|
|
||||||
private var checkmarkState : Int = Checkmark.UNCHECKED
|
|
||||||
|
|
||||||
constructor(context: Context) : super(context) {}
|
|
||||||
|
|
||||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param state the new state/style of the widget, either:
|
|
||||||
* - Checkmark.CHECKED_EXPLICITLY
|
|
||||||
* - Checkmark.CHECKED_IMPLICITLY
|
|
||||||
* - Checkmark.UNCHECKED
|
|
||||||
*/
|
|
||||||
fun setCheckmarkState(state : Int) {
|
|
||||||
checkmarkState = state
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCheckmarkState(): Int {
|
|
||||||
return checkmarkState
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getText(): String {
|
|
||||||
val numberValue : Double = Habit.checkMarkValueToDouble(checkmarkValue)
|
|
||||||
return numberValue.toShortString()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue