-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
251 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.17 KB
(120%)
uhabits-android/src/androidTest/assets/views/widgets/CheckmarkWidget/render.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.55 KB
(120%)
...ts-android/src/androidTest/assets/views/widgets/CheckmarkWidgetView/checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.39 KB
(110%)
...android/src/androidTest/assets/views/widgets/CheckmarkWidgetView/large_size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+43 Bytes
(100%)
uhabits-android/src/androidTest/assets/views/widgets/FrequencyWidget/render.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+672 Bytes
(100%)
uhabits-android/src/androidTest/assets/views/widgets/HistoryWidget/render.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.58 KB
(110%)
uhabits-android/src/androidTest/assets/views/widgets/ScoreWidget/render.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+932 Bytes
(110%)
uhabits-android/src/androidTest/assets/views/widgets/TargetWidget/render.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.isoron.uhabits.activities.common.dialogs | ||
|
||
import android.app.Dialog | ||
import android.os.Bundle | ||
import android.text.method.DigitsKeyListener | ||
import android.view.KeyEvent | ||
import android.view.LayoutInflater | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatDialogFragment | ||
import org.isoron.uhabits.HabitsApplication | ||
import org.isoron.uhabits.R | ||
import org.isoron.uhabits.core.models.Entry | ||
import org.isoron.uhabits.databinding.CheckmarkPopupBinding | ||
import org.isoron.uhabits.utils.InterfaceUtils | ||
import org.isoron.uhabits.utils.requestFocusWithKeyboard | ||
import org.isoron.uhabits.utils.sres | ||
import java.text.DecimalFormat | ||
import java.text.DecimalFormatSymbols | ||
import java.text.NumberFormat | ||
import java.text.ParseException | ||
|
||
class NumberDialog : AppCompatDialogFragment() { | ||
|
||
var onToggle: (Double, String) -> Unit = { _, _ -> } | ||
var onDismiss: () -> Unit = {} | ||
|
||
private var originalNotes: String = "" | ||
private var originalValue: Double = 0.0 | ||
private lateinit var view: CheckmarkPopupBinding | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val appComponent = (requireActivity().application as HabitsApplication).component | ||
val prefs = appComponent.preferences | ||
view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context)) | ||
arrayOf(view.yesBtn, view.skipBtn).forEach { | ||
it.setTextColor(requireArguments().getInt("color")) | ||
} | ||
arrayOf(view.noBtn, view.unknownBtn).forEach { | ||
it.setTextColor(view.root.sres.getColor(R.attr.contrast60)) | ||
} | ||
arrayOf(view.yesBtn, view.noBtn, view.skipBtn, view.unknownBtn).forEach { | ||
it.typeface = InterfaceUtils.getFontAwesome(requireContext()) | ||
} | ||
if (!prefs.isSkipEnabled) view.skipBtnNumber.visibility = View.GONE | ||
view.numberButtons.visibility = View.VISIBLE | ||
fixDecimalSeparator(view) | ||
originalNotes = requireArguments().getString("notes")!! | ||
originalValue = requireArguments().getDouble("value") | ||
view.notes.setText(originalNotes) | ||
view.value.setText( | ||
when { | ||
originalValue < 0.01 -> "0" | ||
else -> DecimalFormat("#.##").format(originalValue) | ||
} | ||
) | ||
view.value.setOnKeyListener { _, keyCode, event -> | ||
if (event.action == MotionEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { | ||
save() | ||
return@setOnKeyListener true | ||
} | ||
return@setOnKeyListener false | ||
} | ||
view.saveBtn.setOnClickListener { | ||
save() | ||
} | ||
view.skipBtnNumber.setOnClickListener { | ||
view.value.setText((Entry.SKIP.toDouble() / 1000).toString()) | ||
save() | ||
} | ||
view.notes.setOnEditorActionListener { v, actionId, event -> | ||
save() | ||
true | ||
} | ||
view.value.requestFocusWithKeyboard() | ||
val dialog = Dialog(requireContext()) | ||
dialog.setContentView(view.root) | ||
dialog.window?.apply { | ||
setBackgroundDrawableResource(android.R.color.transparent) | ||
} | ||
dialog.setOnDismissListener { onDismiss() } | ||
return dialog | ||
} | ||
|
||
private fun fixDecimalSeparator(view: CheckmarkPopupBinding) { | ||
// https://stackoverflow.com/a/34256139 | ||
val separator = DecimalFormatSymbols.getInstance().decimalSeparator | ||
view.value.keyListener = DigitsKeyListener.getInstance("0123456789$separator") | ||
} | ||
|
||
fun save() { | ||
var value = originalValue | ||
try { | ||
val numberFormat = NumberFormat.getInstance() | ||
val valueStr = view.value.text.toString() | ||
value = numberFormat.parse(valueStr)!!.toDouble() | ||
} catch (e: ParseException) { | ||
// NOP | ||
} | ||
val notes = view.notes.text.toString() | ||
onToggle(value, notes) | ||
requireDialog().dismiss() | ||
} | ||
} |
Oops, something went wrong.