mirror of https://github.com/iSoron/uhabits.git
parent
84523869e8
commit
fdd9346d1c
Before Width: | Height: | Size: 543 B After Width: | Height: | Size: 620 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Álinson Santos Xavier
|
||||
*
|
||||
* 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 .
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.common.dialogs
|
||||
|
||||
import android.content.*
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
import androidx.appcompat.app.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
import javax.inject.*
|
||||
|
||||
|
||||
class CheckmarkOptionPickerFactory
|
||||
@Inject constructor(
|
||||
@ActivityContext private val context: Context
|
||||
) {
|
||||
fun create(habit: Habit,
|
||||
habitTimestamp: String,
|
||||
value: Int,
|
||||
callback: ListHabitsBehavior.CheckmarkOptionsCallback): AlertDialog {
|
||||
|
||||
var habitColor = PaletteUtils.getColor(context, habit.color)
|
||||
val res = StyledResources(context)
|
||||
|
||||
val titleTextView = TextView(context)
|
||||
titleTextView.setText(habit.name)
|
||||
titleTextView.setTextSize(20F)
|
||||
titleTextView.setPadding(20, 30, 20, 30);
|
||||
titleTextView.setTextColor(res.getColor(R.attr.highContrastReverseTextColor))
|
||||
titleTextView.setBackgroundColor(habitColor)
|
||||
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val view = inflater.inflate(R.layout.checkmark_option_picker_dialog, null)
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setView(view)
|
||||
.setCustomTitle(titleTextView)
|
||||
.setOnDismissListener{
|
||||
callback.onCheckmarkOptionDismissed()
|
||||
}
|
||||
.create()
|
||||
|
||||
val buttonValues = mapOf(
|
||||
R.id.yes_button to Checkmark.CHECKED_EXPLICITLY,
|
||||
R.id.skip_button to Checkmark.SKIPPED,
|
||||
R.id.no_button to Checkmark.UNCHECKED_EXPLICITLY,
|
||||
R.id.clear_button to Checkmark.UNCHECKED
|
||||
)
|
||||
val valuesToButton = mapOf(
|
||||
Checkmark.CHECKED_EXPLICITLY to R.id.yes_button,
|
||||
Checkmark.SKIPPED to R.id.skip_button ,
|
||||
Checkmark.UNCHECKED_EXPLICITLY to R.id.no_button
|
||||
)
|
||||
|
||||
for ((buttonId, buttonValue) in buttonValues) {
|
||||
val button = view.findViewById<Button>(buttonId)
|
||||
button.setOnClickListener{
|
||||
callback.onCheckmarkOptionPicked(buttonValue)
|
||||
dialog.dismiss()
|
||||
}
|
||||
button.isPressed = (
|
||||
valuesToButton.containsKey(value) &&
|
||||
valuesToButton[value] == buttonId)
|
||||
button.typeface = InterfaceUtils.getFontAwesome(context)
|
||||
button.background.setTint(habitColor)
|
||||
}
|
||||
|
||||
val questionTextView = view.findViewById<TextView>(R.id.choose_checkmark_question_textview)
|
||||
var question = context.resources.getString(R.string.default_checkmark_option_question)
|
||||
if (habit.question.isNotEmpty()) {
|
||||
question = habit.question.trim('?')
|
||||
}
|
||||
val questionFullText = context.resources.getString(
|
||||
R.string.choose_checkmark_question, question, habitTimestamp)
|
||||
questionTextView.text = questionFullText
|
||||
questionTextView.setTextColor(habitColor)
|
||||
|
||||
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
|
||||
return dialog
|
||||
}
|
||||
}
|
@ -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.*
|
||||
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, data.timestamp.toString(), oldValue, this).show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ACTION_SHOW_YESNO_VALUE_ACTIVITY = "org.isoron.uhabits.ACTION_SHOW_YESNO_VALUE_ACTIVITY"
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="5dp"
|
||||
android:paddingVertical="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/choose_checkmark_question_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/default_checkmark_option_question"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/yes_button"
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/yes_button_text"
|
||||
android:textColor="?attr/highContrastReverseTextColor"
|
||||
app:cornerRadius="0dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/no_button"
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/no_button_text"
|
||||
android:textColor="?attr/highContrastReverseTextColor"
|
||||
app:cornerRadius="0dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/skip_button"
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/skip_button_text"
|
||||
android:textColor="?attr/highContrastReverseTextColor"
|
||||
app:cornerRadius="0dp" />
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/clear_button"
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/delete_button_text"
|
||||
android:textColor="?attr/highContrastReverseTextColor"
|
||||
app:cornerRadius="0dp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
Loading…
Reference in new issue