Began to add numer picker to checkmark widget

pull/499/head
Thomas Saedt 6 years ago
parent abd9eb51a4
commit 3d039db61c

@ -17,7 +17,7 @@
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<manifest
<manifest xmlns:tools="http://schemas.android.com/tools"
package="org.isoron.uhabits"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="36"
@ -163,6 +163,15 @@
</intent-filter>
</receiver>
<receiver android:name=".receivers.WidgetReceiver">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="org.isoron.uhabits.ACTION_SET_NUMERICAL_VALUE"/>
<data
android:host="org.isoron.uhabits"
android:scheme="content"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>

@ -103,4 +103,15 @@ class PendingIntentFactory
if (timestamp != null) putExtra("timestamp", timestamp)
},
FLAG_UPDATE_CURRENT)
fun setNumericalValue(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_SET_NUMERICAL_VALUE
putExtra("numericalValue",numericalValue);
if (timestamp != null) putExtra("timestamp", timestamp)
},
FLAG_UPDATE_CURRENT)
}

@ -47,7 +47,10 @@ public class WidgetReceiver extends BroadcastReceiver
"org.isoron.uhabits.ACTION_REMOVE_REPETITION";
public static final String ACTION_TOGGLE_REPETITION =
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
public static final String ACTION_SET_NUMERICAL_VALUE =
"org.isoron.uhabits.ACTION_SET_NUMERICAL_VALUE";
@Override
public void onReceive(final Context context, Intent intent)
@ -88,6 +91,11 @@ public class WidgetReceiver extends BroadcastReceiver
controller.onRemoveRepetition(data.getHabit(),
data.getTimestamp());
break;
case ACTION_SET_NUMERICAL_VALUE:
//controller.onToggleRepetition(data.getHabit(),
// data.getTimestamp());
break;
}
}
catch (RuntimeException e)

@ -19,40 +19,38 @@
package org.isoron.uhabits.widgets
import android.app.PendingIntent
import android.content.*
import android.view.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.utils.*
import org.isoron.uhabits.widgets.views.*
class CheckmarkWidget(
open class CheckmarkWidget(
context: Context,
widgetId: Int,
private val habit: Habit
protected val habit: Habit
) : BaseWidget(context, widgetId) {
override fun getOnClickPendingIntent(context: Context) =
pendingIntentFactory.toggleCheckmark(habit, null)
override fun getOnClickPendingIntent(context: Context): PendingIntent{
return pendingIntentFactory.toggleCheckmark(habit, null)
}
override fun refreshData(v: View) {
(v as CheckmarkWidgetView).apply {
setPercentage(habit.scores.todayValue.toFloat())
setActiveColor(PaletteUtils.getColor(context, habit.color))
setName(habit.name)
setCheckmarkValue(habit.checkmarks.todayValue)
refresh()
}
v.setCheckmarkValue(habit.checkmarks.todayValue)
v.refresh()
}
override fun buildView(): CheckmarkWidgetView{
return if (habit.isNumerical) {
NumericalCheckmarkWidgetView(context)
}else{
CheckmarkWidgetView(context)
}
}
override fun buildView(): View = CheckmarkWidgetView(context)
override fun getDefaultHeight() = 125
override fun getDefaultWidth() = 125
}

@ -23,7 +23,13 @@ import android.content.*
class CheckmarkWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
if (habits.size == 1) return CheckmarkWidget(context, id, habits[0])
else return StackWidget(context, id, StackWidgetType.CHECKMARK, habits)
return if (habits.size == 1) {
if (habits[0].isNumerical){
NumericalCheckmarkWidget(context, id, habits[0])
}else {
CheckmarkWidget(context, id, habits[0])
}
}
else StackWidget(context, id, StackWidgetType.CHECKMARK, habits)
}
}

@ -0,0 +1,22 @@
package org.isoron.uhabits.widgets
import android.app.PendingIntent
import android.content.Context
import android.view.View
import org.isoron.uhabits.core.models.Habit
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 {
view.showNumberSelector()
return pendingIntentFactory.setNumericalValue(habit, 10,null)
}
override fun buildView(): View {
view = NumericalCheckmarkWidgetView(context)
return view;
}
}

@ -5,12 +5,16 @@ 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.ui.screens.habits.list.ListHabitsBehavior
class NumericalCheckmarkWidgetView : CheckmarkWidgetView {
private var callBackReciever : CallBackReciever = CallBackReciever()
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
@ -48,4 +52,16 @@ class NumericalCheckmarkWidgetView : CheckmarkWidgetView {
postInvalidate()
}
class CallBackReciever : ListHabitsBehavior.NumberPickerCallback{
override fun onNumberPicked(newValue: Double) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
fun showNumberSelector() {
val numberPickerFactory = NumberPickerFactory(context)
numberPickerFactory.create(1000.0, "This is a test", callBackReciever).show()
}
}

Loading…
Cancel
Save