Rework widgets to support advanced features

pull/610/head
KristianTashkov 5 years ago
parent 545bb8209b
commit d4e451e27b

@ -111,6 +111,17 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".widgets.activities.YesNoCheckmarkWidgetActivity"
android:label="YesNoCheckmarkWidget"
android:noHistory="true"
android:excludeFromRecents="true"
android:theme="@style/Theme.AppCompat.Light.Dialog">
<intent-filter>
<action android:name="org.isoron.uhabits.ACTION_SHOW_YESNO_VALUE_ACTIVITY"/>
</intent-filter>
</activity>
<activity android:name=".notifications.SnoozeDelayPickerActivity" <activity android:name=".notifications.SnoozeDelayPickerActivity"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:launchMode="singleInstance" android:launchMode="singleInstance"

@ -20,14 +20,11 @@
package org.isoron.uhabits.activities.common.dialogs package org.isoron.uhabits.activities.common.dialogs
import android.content.Context import android.content.Context
import android.graphics.BlendMode import android.graphics.Typeface
import android.graphics.BlendModeColorFilter
import android.graphics.PorterDuff
import android.os.Build
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.WindowManager import android.view.WindowManager
import android.widget.Button
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.google.android.material.button.MaterialButton
import org.isoron.androidbase.activities.ActivityContext import org.isoron.androidbase.activities.ActivityContext
import org.isoron.androidbase.utils.InterfaceUtils import org.isoron.androidbase.utils.InterfaceUtils
import org.isoron.uhabits.R import org.isoron.uhabits.R
@ -70,20 +67,16 @@ class CheckmarkOptionPickerFactory
) )
for ((buttonId, buttonValue) in buttonValues) { for ((buttonId, buttonValue) in buttonValues) {
val button = view.findViewById<MaterialButton>(buttonId) val button = view.findViewById<Button>(buttonId)
button.setTypeface(InterfaceUtils.getFontAwesome(context)) var textStyle = Typeface.NORMAL
button.setOnClickListener{ button.setOnClickListener{
callback.onCheckmarkOptionPicked(buttonValue) callback.onCheckmarkOptionPicked(buttonValue)
dialog.dismiss() dialog.dismiss()
} }
if (valuesToButton.containsKey(value) && valuesToButton[value] == buttonId) { if (valuesToButton.containsKey(value) && valuesToButton[value] == buttonId)
val color = context.resources.getColor(R.color.amber_800) textStyle = Typeface.BOLD
if (Build.VERSION.SDK_INT >= 29) {
button.background.colorFilter = BlendModeColorFilter(color, BlendMode.MULTIPLY) button.setTypeface(InterfaceUtils.getFontAwesome(context), textStyle)
} else {
button.background.setColorFilter(color, PorterDuff.Mode.MULTIPLY)
}
}
} }
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)

@ -39,7 +39,7 @@ class IntentParser
fun copyIntentData(source: Intent, destination: Intent) { fun copyIntentData(source: Intent, destination: Intent) {
destination.data = source.data; destination.data = source.data;
destination.putExtra("timestamp", source.getLongExtra("timestamp", DateUtils.getToday().unixTime)) destination.putExtra("timestamp", source.getLongExtra("timestamp", DateUtils.getToday().unixTime))
destination.putExtra("value", source.getIntExtra("value", 0)) destination.putExtra("value", source.getIntExtra("value", -1))
} }
private fun parseHabit(uri: Uri): Habit { private fun parseHabit(uri: Uri): Habit {
@ -60,7 +60,7 @@ class IntentParser
} }
private fun parseValue(intent: Intent): Int { private fun parseValue(intent: Intent): Int {
return intent.getIntExtra("value", 0) return intent.getIntExtra("value", -1)
} }
class CheckmarkIntentData(var habit: Habit, var timestamp: Timestamp, var value: Int) class CheckmarkIntentData(var habit: Habit, var timestamp: Timestamp, var value: Int)

@ -121,8 +121,20 @@ public class WidgetReceiver extends BroadcastReceiver
data.getHabit().getId(), data.getHabit().getId(),
data.getTimestamp().getUnixTime(), data.getTimestamp().getUnixTime(),
data.getValue())); data.getValue()));
controller.setYesNoValue( if (data.getValue() >= 0)
data.getHabit(), data.getTimestamp(), data.getValue()); {
controller.setYesNoValue(
data.getHabit(), data.getTimestamp(), data.getValue());
}
else
{
Intent checkmarkOptionsSelector = new Intent(context, YesNoCheckmarkWidgetActivity.class);
checkmarkOptionsSelector.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
checkmarkOptionsSelector.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
checkmarkOptionsSelector.setAction(YesNoCheckmarkWidgetActivity.ACTION_SHOW_YESNO_VALUE_ACTIVITY);
parser.copyIntentData(intent, checkmarkOptionsSelector);
context.startActivity(checkmarkOptionsSelector);
}
break; break;
} }
} }

@ -19,12 +19,14 @@
package org.isoron.uhabits.widgets package org.isoron.uhabits.widgets
import android.app.* import android.app.PendingIntent
import android.content.* import android.content.Context
import android.view.* import android.view.View
import org.isoron.uhabits.core.models.* import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.utils.* import org.isoron.uhabits.core.models.Checkmark
import org.isoron.uhabits.widgets.views.* import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.utils.PaletteUtils
import org.isoron.uhabits.widgets.views.CheckmarkWidgetView
open class CheckmarkWidget( open class CheckmarkWidget(
context: Context, context: Context,
@ -36,7 +38,12 @@ open class CheckmarkWidget(
return if (habit.isNumerical) { return if (habit.isNumerical) {
pendingIntentFactory.setNumericalValue(context, habit, 10, null) pendingIntentFactory.setNumericalValue(context, habit, 10, null)
} else { } else {
pendingIntentFactory.toggleCheckmark(habit, null) val prefs = (context.applicationContext as HabitsApplication).component.preferences
if (prefs.isAdvancedCheckmarksEnabled) {
pendingIntentFactory.setYesNoValue(habit, null, -1)
} else {
pendingIntentFactory.toggleCheckmark(habit, null)
}
} }
} }

@ -0,0 +1,76 @@
/*
* Copyright (C) 2016-2020 Á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.widgets.activities
import android.app.*
import android.content.*
import android.os.*
import android.view.*
import android.widget.FrameLayout
import org.isoron.uhabits.*
import org.isoron.uhabits.activities.*
import org.isoron.uhabits.activities.common.dialogs.*
import org.isoron.uhabits.core.ui.screens.habits.list.*
import org.isoron.uhabits.core.ui.widgets.*
import org.isoron.uhabits.intents.*
import org.isoron.uhabits.widgets.*
class YesNoCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.CheckmarkOptionsCallback {
private lateinit var behavior: WidgetBehavior
private lateinit var data: IntentParser.CheckmarkIntentData
private lateinit var widgetUpdater: WidgetUpdater
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(FrameLayout(this))
val app = this.applicationContext as HabitsApplication
val component = app.component
val parser = app.component.intentParser
data = parser.parseCheckmarkIntent(intent)
behavior = WidgetBehavior(component.habitList, component.commandRunner, component.notificationTray)
widgetUpdater = component.widgetUpdater
showCheckmarkOptions(this)
}
override fun onCheckmarkOptionPicked(newValue: Int) {
behavior.setYesNoValue(data.habit, data.timestamp, newValue)
widgetUpdater.updateWidgets()
finish()
}
override fun onCheckmarkOptionDismissed() {
finish()
}
private fun showCheckmarkOptions(context: Context) {
val app = this.applicationContext as HabitsApplication
AndroidThemeSwitcher(this, app.component.preferences).apply()
val oldValue = data.habit.checkmarks.getValues(data.timestamp, data.timestamp)[0]
val checkmarkOptionsPickerFactory = CheckmarkOptionPickerFactory(context)
checkmarkOptionsPickerFactory.create(
data.habit.name, data.timestamp.toString(), oldValue, this).show()
}
companion object {
const val ACTION_SHOW_YESNO_VALUE_ACTIVITY = "org.isoron.uhabits.ACTION_SHOW_YESNO_VALUE_ACTIVITY"
}
}

@ -82,11 +82,17 @@ public class CheckmarkWidgetView extends HabitWidgetView {
backgroundPaint.setColor(bgColor); backgroundPaint.setColor(bgColor);
frame.setBackgroundDrawable(background); frame.setBackgroundDrawable(background);
break; break;
case Checkmark.FAILED_EXPLICITLY_NECESSARY:
case Checkmark.FAILED_EXPLICITLY_UNNECESSARY:
case Checkmark.SKIPPED_EXPLICITLY:
bgColor = res.getColor(R.attr.highlightedBackgroundColor);
fgColor = res.getColor(R.attr.mediumContrastTextColor);
setShadowAlpha(0x4f);
break;
case Checkmark.CHECKED_IMPLICITLY: case Checkmark.CHECKED_IMPLICITLY:
case Checkmark.UNCHECKED: case Checkmark.UNCHECKED:
default: default:
getResources().getString(R.string.fa_times);
bgColor = res.getColor(R.attr.cardBgColor); bgColor = res.getColor(R.attr.cardBgColor);
fgColor = res.getColor(R.attr.mediumContrastTextColor); fgColor = res.getColor(R.attr.mediumContrastTextColor);
setShadowAlpha(0x00); setShadowAlpha(0x00);
@ -116,9 +122,12 @@ public class CheckmarkWidgetView extends HabitWidgetView {
switch (checkmarkState) { switch (checkmarkState) {
case Checkmark.CHECKED_EXPLICITLY: case Checkmark.CHECKED_EXPLICITLY:
case Checkmark.CHECKED_IMPLICITLY: case Checkmark.CHECKED_IMPLICITLY:
case Checkmark.FAILED_EXPLICITLY_UNNECESSARY:
return getResources().getString(R.string.fa_check); return getResources().getString(R.string.fa_check);
case Checkmark.SKIPPED_EXPLICITLY:
return getResources().getString(R.string.fa_skipped);
case Checkmark.UNCHECKED: case Checkmark.UNCHECKED:
case Checkmark.FAILED_EXPLICITLY_NECESSARY:
default: default:
return getResources().getString(R.string.fa_times); return getResources().getString(R.string.fa_times);
} }

@ -35,7 +35,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:drawableStart="@drawable/ic_action_check"
android:text="@string/done_button_text" android:text="@string/done_button_text"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />

Loading…
Cancel
Save