@ -1,5 +1,5 @@
|
||||
org.gradle.parallel=false
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms2048m -Xmx2048m -XX:MaxPermSize=2048m
|
||||
org.gradle.jvmargs=-Xms2048m -Xmx2048m
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
@ -0,0 +1,119 @@
|
||||
package org.isoron.uhabits.activities.common.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import org.isoron.platform.gui.toInt
|
||||
import org.isoron.platform.time.JavaLocalDateFormatter
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||
import org.isoron.uhabits.core.models.PaletteColor
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
||||
import org.isoron.uhabits.core.ui.views.Theme
|
||||
import org.isoron.uhabits.databinding.CheckmarkDialogBinding
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.InterfaceUtils
|
||||
import org.isoron.uhabits.utils.StyledResources
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
class CheckmarkDialog
|
||||
@Inject constructor(
|
||||
@ActivityContext private val context: Context,
|
||||
private val preferences: Preferences,
|
||||
) : View.OnClickListener {
|
||||
|
||||
private lateinit var binding: CheckmarkDialogBinding
|
||||
private lateinit var fontAwesome: Typeface
|
||||
private val allButtons = mutableListOf<Button>()
|
||||
private var selectedButton: Button? = null
|
||||
|
||||
fun create(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
date: LocalDate,
|
||||
paletteColor: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback,
|
||||
theme: Theme,
|
||||
): AlertDialog {
|
||||
binding = CheckmarkDialogBinding.inflate(LayoutInflater.from(context))
|
||||
fontAwesome = InterfaceUtils.getFontAwesome(context)!!
|
||||
binding.etNotes.append(notes)
|
||||
setUpButtons(selectedValue, theme.color(paletteColor).toInt())
|
||||
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setView(binding.root)
|
||||
.setTitle(JavaLocalDateFormatter(Locale.getDefault()).longFormat(date))
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
val newValue = when (selectedButton?.id) {
|
||||
R.id.yesBtn -> YES_MANUAL
|
||||
R.id.noBtn -> NO
|
||||
R.id.skippedBtn -> SKIP
|
||||
else -> UNKNOWN
|
||||
}
|
||||
callback.onNotesSaved(newValue, binding.etNotes.text.toString())
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ ->
|
||||
callback.onNotesDismissed()
|
||||
}
|
||||
.setOnDismissListener {
|
||||
callback.onNotesDismissed()
|
||||
}
|
||||
.create()
|
||||
|
||||
dialog.setOnShowListener {
|
||||
binding.etNotes.requestFocus()
|
||||
dialog.window?.setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
}
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
private fun setUpButtons(value: Int, color: Int) {
|
||||
val sres = StyledResources(context)
|
||||
val mediumContrastColor = sres.getColor(R.attr.contrast60)
|
||||
setButtonAttrs(binding.yesBtn, color)
|
||||
setButtonAttrs(binding.noBtn, mediumContrastColor)
|
||||
setButtonAttrs(binding.skippedBtn, color, visible = preferences.isSkipEnabled)
|
||||
setButtonAttrs(binding.questionBtn, mediumContrastColor, visible = preferences.areQuestionMarksEnabled)
|
||||
when (value) {
|
||||
UNKNOWN -> if (preferences.areQuestionMarksEnabled) {
|
||||
binding.questionBtn.performClick()
|
||||
} else {
|
||||
binding.noBtn.performClick()
|
||||
}
|
||||
SKIP -> binding.skippedBtn.performClick()
|
||||
YES_MANUAL -> binding.yesBtn.performClick()
|
||||
YES_AUTO, NO -> binding.noBtn.performClick()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setButtonAttrs(button: Button, color: Int, visible: Boolean = true) {
|
||||
button.apply {
|
||||
visibility = if (visible) View.VISIBLE else View.GONE
|
||||
typeface = fontAwesome
|
||||
setTextColor(color)
|
||||
setOnClickListener(this@CheckmarkDialog)
|
||||
}
|
||||
allButtons.add(button)
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
allButtons.forEach {
|
||||
if (v?.id == it.id) {
|
||||
it.isSelected = true
|
||||
selectedButton = it
|
||||
} else it.isSelected = false
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/>
|
||||
</vector>
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#333333"
|
||||
android:alpha="0.6">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/>
|
||||
</vector>
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
|
||||
</vector>
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#333333"
|
||||
android:alpha="0.6">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
|
||||
</vector>
|
Before Width: | Height: | Size: 155 B |
Before Width: | Height: | Size: 338 B |
Before Width: | Height: | Size: 266 B |
Before Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 492 B |
Before Width: | Height: | Size: 563 B |
Before Width: | Height: | Size: 249 B |
Before Width: | Height: | Size: 304 B |
Before Width: | Height: | Size: 354 B |
Before Width: | Height: | Size: 111 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 240 B |
Before Width: | Height: | Size: 237 B |
Before Width: | Height: | Size: 234 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 618 B |
Before Width: | Height: | Size: 111 B |
Before Width: | Height: | Size: 214 B |
Before Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 289 B |
Before Width: | Height: | Size: 319 B |
Before Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 183 B |
Before Width: | Height: | Size: 196 B |
Before Width: | Height: | Size: 90 B |
Before Width: | Height: | Size: 694 B |
Before Width: | Height: | Size: 207 B |
Before Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 182 B |
Before Width: | Height: | Size: 177 B |
Before Width: | Height: | Size: 182 B |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 435 B |
Before Width: | Height: | Size: 140 B |
Before Width: | Height: | Size: 338 B |
Before Width: | Height: | Size: 323 B |
Before Width: | Height: | Size: 488 B |
Before Width: | Height: | Size: 541 B |
Before Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 279 B |
Before Width: | Height: | Size: 267 B |
Before Width: | Height: | Size: 296 B |
Before Width: | Height: | Size: 103 B |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 317 B |