mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Bump org.jlleitschuh.gradle.ktlint from 11.0.0 to 11.4.2
Also run ./gradlew ktlintFormat to follow new format.
This commit is contained in:
@@ -5,7 +5,7 @@ plugins {
|
||||
id("org.jetbrains.kotlin.kapt") version kotlinVersion apply (false)
|
||||
id("org.jetbrains.kotlin.android.extensions") version kotlinVersion apply (false)
|
||||
id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply (false)
|
||||
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
|
||||
id("org.jlleitschuh.gradle.ktlint") version "11.4.2"
|
||||
}
|
||||
|
||||
apply {
|
||||
|
||||
@@ -39,6 +39,7 @@ open class BaseUserInterfaceTest {
|
||||
private lateinit var prefs: Preferences
|
||||
private lateinit var fixtures: HabitFixtures
|
||||
private lateinit var cache: HabitCardListCache
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
|
||||
@@ -153,18 +153,22 @@ open class BaseViewTest : BaseAndroidTest() {
|
||||
var filename = filename
|
||||
var dir = getSDCardDir("test-screenshots")
|
||||
if (dir == null) dir = AndroidDirFinder(targetContext).getFilesDir("test-screenshots")
|
||||
if (dir == null) throw RuntimeException(
|
||||
if (dir == null) {
|
||||
throw RuntimeException(
|
||||
"Could not find suitable dir for screenshots"
|
||||
)
|
||||
}
|
||||
filename = filename.replace("\\.png$".toRegex(), "$suffix.png")
|
||||
val absolutePath = String.format("%s/%s", dir.absolutePath, filename)
|
||||
val parent = File(absolutePath).parentFile
|
||||
if (!parent.exists() && !parent.mkdirs()) throw RuntimeException(
|
||||
if (!parent.exists() && !parent.mkdirs()) {
|
||||
throw RuntimeException(
|
||||
String.format(
|
||||
"Could not create dir: %s",
|
||||
parent.absolutePath
|
||||
)
|
||||
)
|
||||
}
|
||||
val out = FileOutputStream(absolutePath)
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
|
||||
return absolutePath
|
||||
|
||||
@@ -44,7 +44,7 @@ class ScoreChartTest : BaseViewTest() {
|
||||
habit = habit,
|
||||
firstWeekday = prefs.firstWeekdayInt,
|
||||
spinnerPosition = 0,
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
view = ScoreChart(targetContext).apply {
|
||||
setScores(state.scores)
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.junit.runner.RunWith
|
||||
@MediumTest
|
||||
class StreakChartTest : BaseViewTest() {
|
||||
private lateinit var view: StreakChart
|
||||
|
||||
@Before
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
@@ -48,7 +48,7 @@ class FrequencyCardViewTest : BaseViewTest() {
|
||||
FrequencyCardPresenter.buildState(
|
||||
habit = habit,
|
||||
firstWeekday = 0,
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
)
|
||||
measureView(view, 800f, 600f)
|
||||
|
||||
@@ -49,7 +49,7 @@ class HistoryCardViewTest : BaseViewTest() {
|
||||
HistoryCardPresenter.buildState(
|
||||
habit = habit,
|
||||
firstWeekday = SUNDAY,
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
)
|
||||
measureView(view, 800f, 600f)
|
||||
|
||||
@@ -51,7 +51,7 @@ class OverviewCardViewTest : BaseViewTest() {
|
||||
scoreYearDiff = 0.74f,
|
||||
totalCount = 44,
|
||||
color = PaletteColor(7),
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
)
|
||||
measureView(view, 800f, 300f)
|
||||
|
||||
@@ -49,7 +49,7 @@ class ScoreCardViewTest : BaseViewTest() {
|
||||
habit = habit,
|
||||
firstWeekday = 0,
|
||||
spinnerPosition = 0,
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
)
|
||||
measureView(view, 800f, 600f)
|
||||
|
||||
@@ -48,7 +48,7 @@ class StreakCardViewTest : BaseViewTest() {
|
||||
StreakCardState(
|
||||
bestStreaks = habit.streaks.getBest(10),
|
||||
color = habit.color,
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
)
|
||||
measureView(view, 800f, 600f)
|
||||
|
||||
@@ -53,7 +53,7 @@ class SubtitleCardViewTest : BaseViewTest() {
|
||||
isNumerical = false,
|
||||
question = "Did you meditate this morning?",
|
||||
reminder = Reminder(8, 30, EVERY_DAY),
|
||||
theme = LightTheme(),
|
||||
theme = LightTheme()
|
||||
)
|
||||
)
|
||||
measureView(view, 800f, 200f)
|
||||
|
||||
@@ -119,7 +119,7 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() {
|
||||
"Wake up early",
|
||||
"Meditate",
|
||||
"Read books",
|
||||
"Track time",
|
||||
"Track time"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.io.IOException
|
||||
@MediumTest
|
||||
class CheckmarkWidgetViewTest : BaseViewTest() {
|
||||
private lateinit var view: CheckmarkWidgetView
|
||||
|
||||
@Before
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
@@ -60,7 +60,7 @@ class AndroidCanvas : Canvas {
|
||||
y1.toDp(),
|
||||
x2.toDp(),
|
||||
y2.toDp(),
|
||||
paint,
|
||||
paint
|
||||
)
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class AndroidCanvas : Canvas {
|
||||
text,
|
||||
x.toDp(),
|
||||
y.toDp() + 0.6f * mHeight,
|
||||
textPaint,
|
||||
textPaint
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class AndroidCanvas : Canvas {
|
||||
y: Double,
|
||||
width: Double,
|
||||
height: Double,
|
||||
cornerRadius: Double,
|
||||
cornerRadius: Double
|
||||
) {
|
||||
paint.style = Paint.Style.FILL
|
||||
innerCanvas.drawRoundRect(
|
||||
@@ -93,7 +93,7 @@ class AndroidCanvas : Canvas {
|
||||
(y + height).toDp(),
|
||||
cornerRadius.toDp(),
|
||||
cornerRadius.toDp(),
|
||||
paint,
|
||||
paint
|
||||
)
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class AndroidCanvas : Canvas {
|
||||
y.toDp(),
|
||||
(x + width).toDp(),
|
||||
(y + height).toDp(),
|
||||
paint,
|
||||
paint
|
||||
)
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class AndroidCanvas : Canvas {
|
||||
centerY: Double,
|
||||
radius: Double,
|
||||
startAngle: Double,
|
||||
swipeAngle: Double,
|
||||
swipeAngle: Double
|
||||
) {
|
||||
paint.style = Paint.Style.FILL
|
||||
innerCanvas.drawArc(
|
||||
@@ -159,14 +159,14 @@ class AndroidCanvas : Canvas {
|
||||
-startAngle.toFloat(),
|
||||
-swipeAngle.toFloat(),
|
||||
true,
|
||||
paint,
|
||||
paint
|
||||
)
|
||||
}
|
||||
|
||||
override fun fillCircle(
|
||||
centerX: Double,
|
||||
centerY: Double,
|
||||
radius: Double,
|
||||
radius: Double
|
||||
) {
|
||||
paint.style = Paint.Style.FILL
|
||||
innerCanvas.drawCircle(centerX.toDp(), centerY.toDp(), radius.toDp(), paint)
|
||||
|
||||
@@ -33,7 +33,7 @@ import kotlin.math.max
|
||||
*/
|
||||
class AndroidDataView(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
attrs: AttributeSet? = null
|
||||
) : AndroidView<DataView>(context, attrs),
|
||||
GestureDetector.OnGestureListener,
|
||||
ValueAnimator.AnimatorUpdateListener {
|
||||
@@ -60,7 +60,7 @@ class AndroidDataView(
|
||||
e1: MotionEvent?,
|
||||
e2: MotionEvent?,
|
||||
dx: Float,
|
||||
dy: Float,
|
||||
dy: Float
|
||||
): Boolean {
|
||||
if (abs(dx) > abs(dy)) {
|
||||
val parent = parent
|
||||
@@ -82,7 +82,7 @@ class AndroidDataView(
|
||||
e1: MotionEvent?,
|
||||
e2: MotionEvent?,
|
||||
velocityX: Float,
|
||||
velocityY: Float,
|
||||
velocityY: Float
|
||||
): Boolean {
|
||||
scroller.fling(
|
||||
scroller.currX,
|
||||
@@ -140,8 +140,11 @@ class AndroidDataView(
|
||||
// e.getPointerId.
|
||||
return false
|
||||
}
|
||||
if (isSingleTap) view?.onClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
else view?.onLongClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
if (isSingleTap) {
|
||||
view?.onClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
} else {
|
||||
view?.onLongClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ fun Color.toInt(): Int {
|
||||
(255 * this.alpha).roundToInt(),
|
||||
(255 * this.red).roundToInt(),
|
||||
(255 * this.green).roundToInt(),
|
||||
(255 * this.blue).roundToInt(),
|
||||
(255 * this.blue).roundToInt()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import android.util.AttributeSet
|
||||
|
||||
open class AndroidView<T : View>(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
attrs: AttributeSet? = null
|
||||
) : android.view.View(context, attrs) {
|
||||
|
||||
var view: T? = null
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.isoron.uhabits.inject.ActivityScope
|
||||
class AndroidThemeSwitcher
|
||||
constructor(
|
||||
@ActivityContext val context: Context,
|
||||
preferences: Preferences,
|
||||
preferences: Preferences
|
||||
) : ThemeSwitcher(preferences) {
|
||||
|
||||
override var currentTheme: Theme = LightTheme()
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.isoron.uhabits.utils.startActivitySafely
|
||||
class AboutScreen(
|
||||
private val activity: AboutActivity,
|
||||
private val intents: IntentFactory,
|
||||
private val prefs: Preferences,
|
||||
private val prefs: Preferences
|
||||
) {
|
||||
|
||||
private var developerCountdown = 5
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.isoron.uhabits.utils.setupToolbar
|
||||
@SuppressLint("ViewConstructor")
|
||||
class AboutView(
|
||||
context: Context,
|
||||
private val screen: AboutScreen,
|
||||
private val screen: AboutScreen
|
||||
) : FrameLayout(context) {
|
||||
|
||||
private var binding = AboutBinding.inflate(LayoutInflater.from(context))
|
||||
@@ -43,7 +43,7 @@ class AboutView(
|
||||
toolbar = binding.toolbar,
|
||||
color = PaletteColor(11),
|
||||
title = resources.getString(R.string.about),
|
||||
theme = currentTheme(),
|
||||
theme = currentTheme()
|
||||
)
|
||||
val version = resources.getString(R.string.version_n)
|
||||
binding.tvContributors.setOnClickListener { screen.showCodeContributorsWebsite() }
|
||||
|
||||
@@ -48,22 +48,22 @@ class FrequencyPickerDialog(
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.every_x_days),
|
||||
contentView.everyXDaysContainer,
|
||||
contentView.everyXDaysContainer
|
||||
)
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.x_times_per_week),
|
||||
contentView.xTimesPerWeekContainer,
|
||||
contentView.xTimesPerWeekContainer
|
||||
)
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.x_times_per_month),
|
||||
contentView.xTimesPerMonthContainer,
|
||||
contentView.xTimesPerMonthContainer
|
||||
)
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.x_times_per_y_days),
|
||||
contentView.xTimesPerYDaysContainer,
|
||||
contentView.xTimesPerYDaysContainer
|
||||
)
|
||||
|
||||
contentView.everyDayRadioButton.setOnClickListener {
|
||||
@@ -124,7 +124,8 @@ class FrequencyPickerDialog(
|
||||
val parts = str.split("%d")
|
||||
for (i in parts.indices) {
|
||||
container.addView(
|
||||
TextView(activity).apply { text = parts[i].trim() }, 2 * i + 1,
|
||||
TextView(activity).apply { text = parts[i].trim() },
|
||||
2 * i + 1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
theme = themeSwitcher.currentTheme,
|
||||
today = DateUtils.getTodayWithOffset().toLocalDate(),
|
||||
onDateClickedListener = onDateClickedListener ?: object : OnDateClickedListener {},
|
||||
padding = 10.0,
|
||||
padding = 10.0
|
||||
)
|
||||
dataView = AndroidDataView(requireContext(), null)
|
||||
dataView.view = chart!!
|
||||
|
||||
@@ -181,8 +181,9 @@ class FrequencyChart : ScrollableChart {
|
||||
rect[0f, 0f, baseSize.toFloat()] = baseSize.toFloat()
|
||||
rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j)
|
||||
val i = localeWeekdayList[j] % 7
|
||||
if (values != null)
|
||||
if (values != null) {
|
||||
drawMarker(canvas, rect, values[i], weekDaysInMonth[i])
|
||||
}
|
||||
rect.offset(0f, rowHeight)
|
||||
}
|
||||
drawFooter(canvas, rect, date)
|
||||
@@ -196,13 +197,15 @@ class FrequencyChart : ScrollableChart {
|
||||
rect.centerY() - 0.1f * em,
|
||||
pText!!
|
||||
)
|
||||
if (date[Calendar.MONTH] == 1) canvas.drawText(
|
||||
if (date[Calendar.MONTH] == 1) {
|
||||
canvas.drawText(
|
||||
dfYear!!.format(time),
|
||||
rect.centerX(),
|
||||
rect.centerY() + 0.9f * em,
|
||||
pText!!
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawGrid(canvas: Canvas, rGrid: RectF?) {
|
||||
val nRows = 7
|
||||
|
||||
@@ -148,8 +148,12 @@ class RingView : View {
|
||||
pRing!!.color = inactiveColor!!
|
||||
activeCanvas.drawArc(rect!!, angle - 90, 360 - angle, true, pRing!!)
|
||||
if (thickness > 0) {
|
||||
if (isTransparencyEnabled) pRing!!.xfermode = XFERMODE_CLEAR else pRing!!.color =
|
||||
if (isTransparencyEnabled) {
|
||||
pRing!!.xfermode = XFERMODE_CLEAR
|
||||
} else {
|
||||
pRing!!.color =
|
||||
backgroundColor!!
|
||||
}
|
||||
rect!!.inset(thickness, thickness)
|
||||
activeCanvas.drawArc(rect!!, 0f, 360f, true, pRing!!)
|
||||
pRing!!.xfermode = null
|
||||
|
||||
@@ -94,7 +94,7 @@ class ListHabitsRootView @Inject constructor(
|
||||
title = resources.getString(R.string.main_activity_title),
|
||||
color = PaletteColor(17),
|
||||
displayHomeAsUpEnabled = false,
|
||||
theme = currentTheme(),
|
||||
theme = currentTheme()
|
||||
)
|
||||
addView(rootView, MATCH_PARENT, MATCH_PARENT)
|
||||
listAdapter.setListView(listView)
|
||||
|
||||
@@ -96,7 +96,7 @@ class ListHabitsScreen
|
||||
private val colorPickerFactory: ColorPickerDialogFactory,
|
||||
private val behavior: Lazy<ListHabitsBehavior>,
|
||||
private val preferences: Preferences,
|
||||
private val rootView: Lazy<ListHabitsRootView>,
|
||||
private val rootView: Lazy<ListHabitsRootView>
|
||||
) : CommandRunner.Listener,
|
||||
ListHabitsBehavior.Screen,
|
||||
ListHabitsMenuBehavior.Screen,
|
||||
@@ -321,8 +321,11 @@ class ListHabitsScreen
|
||||
private fun onExportDB() {
|
||||
taskRunner.execute(
|
||||
exportDBFactory.create { filename ->
|
||||
if (filename != null) activity.showSendFileScreen(filename)
|
||||
else activity.showMessage(activity.resources.getString(R.string.could_not_export))
|
||||
if (filename != null) {
|
||||
activity.showSendFileScreen(filename)
|
||||
} else {
|
||||
activity.showMessage(activity.resources.getString(R.string.could_not_export))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -60,8 +60,11 @@ abstract class ButtonPanelView<T : View>(
|
||||
repeat(buttonCount) { buttons.add(createButton()) }
|
||||
|
||||
removeAllViews()
|
||||
if (reverse) buttons.reversed().forEach { addView(it) }
|
||||
else buttons.forEach { addView(it) }
|
||||
if (reverse) {
|
||||
buttons.reversed().forEach { addView(it) }
|
||||
} else {
|
||||
buttons.forEach { addView(it) }
|
||||
}
|
||||
setupButtons()
|
||||
requestLayout()
|
||||
}
|
||||
|
||||
@@ -100,13 +100,19 @@ class CheckmarkButtonView(
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (preferences.isShortToggleEnabled) performToggle()
|
||||
else onEdit()
|
||||
if (preferences.isShortToggleEnabled) {
|
||||
performToggle()
|
||||
} else {
|
||||
onEdit()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View): Boolean {
|
||||
if (preferences.isShortToggleEnabled) onEdit()
|
||||
else performToggle()
|
||||
if (preferences.isShortToggleEnabled) {
|
||||
onEdit()
|
||||
} else {
|
||||
performToggle()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -140,8 +146,11 @@ class CheckmarkButtonView(
|
||||
paint.color = when (value) {
|
||||
YES_MANUAL, YES_AUTO, SKIP -> color
|
||||
NO -> {
|
||||
if (preferences.areQuestionMarksEnabled) mediumContrastColor
|
||||
else lowContrastColor
|
||||
if (preferences.areQuestionMarksEnabled) {
|
||||
mediumContrastColor
|
||||
} else {
|
||||
lowContrastColor
|
||||
}
|
||||
}
|
||||
else -> lowContrastColor
|
||||
}
|
||||
@@ -149,8 +158,11 @@ class CheckmarkButtonView(
|
||||
SKIP -> R.string.fa_skipped
|
||||
NO -> R.string.fa_times
|
||||
UNKNOWN -> {
|
||||
if (preferences.areQuestionMarksEnabled) R.string.fa_question
|
||||
else R.string.fa_times
|
||||
if (preferences.areQuestionMarksEnabled) {
|
||||
R.string.fa_question
|
||||
} else {
|
||||
R.string.fa_times
|
||||
}
|
||||
}
|
||||
else -> R.string.fa_check
|
||||
}
|
||||
|
||||
@@ -156,10 +156,11 @@ class HabitCardListController @Inject constructor(
|
||||
}
|
||||
|
||||
private fun notifyListener() {
|
||||
if (activeMode is SelectionMode)
|
||||
if (activeMode is SelectionMode) {
|
||||
selectionMenu.get().onSelectionChange()
|
||||
else
|
||||
} else {
|
||||
selectionMenu.get().onSelectionFinish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,6 @@ class HabitCardView(
|
||||
}
|
||||
|
||||
private fun copyAttributesFrom(h: Habit) {
|
||||
|
||||
fun getActiveColor(habit: Habit): Int {
|
||||
return when (habit.isArchived) {
|
||||
true -> sres.getColor(R.attr.contrast60)
|
||||
@@ -271,7 +270,6 @@ class HabitCardView(
|
||||
}
|
||||
|
||||
private fun updateBackground(isSelected: Boolean) {
|
||||
|
||||
val background = when (isSelected) {
|
||||
true -> R.drawable.selected_box
|
||||
false -> R.drawable.ripple
|
||||
|
||||
@@ -124,15 +124,20 @@ class HeaderView(
|
||||
rect.set(0f, 0f, width, height)
|
||||
rect.offset(canvas.width.toFloat() - dp(3.0f), 0f)
|
||||
|
||||
if (isReversed) rect.offset(-(index + 1) * width, 0f)
|
||||
else rect.offset((index - buttonCount) * width, 0f)
|
||||
if (isReversed) {
|
||||
rect.offset(-(index + 1) * width, 0f)
|
||||
} else {
|
||||
rect.offset((index - buttonCount) * width, 0f)
|
||||
}
|
||||
|
||||
if (isRTL()) rect.set(
|
||||
if (isRTL()) {
|
||||
rect.set(
|
||||
canvas.width - rect.right,
|
||||
rect.top,
|
||||
canvas.width - rect.left,
|
||||
rect.bottom
|
||||
)
|
||||
}
|
||||
|
||||
val y1 = rect.centerY() - 0.25 * em
|
||||
val y2 = rect.centerY() + 1.25 * em
|
||||
|
||||
@@ -88,7 +88,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
habit = habit,
|
||||
habitList = habitList,
|
||||
preferences = preferences,
|
||||
screen = screen,
|
||||
screen = screen
|
||||
)
|
||||
|
||||
view = ShowHabitView(this)
|
||||
@@ -99,13 +99,13 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
habitList = habitList,
|
||||
screen = screen,
|
||||
system = HabitsDirFinder(AndroidDirFinder(this)),
|
||||
taskRunner = appComponent.taskRunner,
|
||||
taskRunner = appComponent.taskRunner
|
||||
)
|
||||
|
||||
menu = ShowHabitMenu(
|
||||
activity = this,
|
||||
presenter = menuPresenter,
|
||||
preferences = preferences,
|
||||
preferences = preferences
|
||||
)
|
||||
|
||||
view.setListener(presenter)
|
||||
@@ -150,7 +150,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
ShowHabitPresenter.buildState(
|
||||
habit = habit,
|
||||
preferences = preferences,
|
||||
theme = themeSwitcher.currentTheme,
|
||||
theme = themeSwitcher.currentTheme
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuPresenter
|
||||
class ShowHabitMenu(
|
||||
val activity: ShowHabitActivity,
|
||||
val presenter: ShowHabitMenuPresenter,
|
||||
val preferences: Preferences,
|
||||
val preferences: Preferences
|
||||
) {
|
||||
fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
activity.menuInflater.inflate(R.menu.show_habit, menu)
|
||||
|
||||
@@ -39,7 +39,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
|
||||
binding.toolbar,
|
||||
title = data.title,
|
||||
color = data.color,
|
||||
theme = data.theme,
|
||||
theme = data.theme
|
||||
)
|
||||
binding.subtitleCard.setState(data.subtitle)
|
||||
binding.overviewCard.setState(data.overview)
|
||||
|
||||
@@ -63,7 +63,7 @@ class BarCardView(context: Context, attrs: AttributeSet) : LinearLayout(context,
|
||||
parent: AdapterView<*>?,
|
||||
view: View?,
|
||||
position: Int,
|
||||
id: Long,
|
||||
id: Long
|
||||
) {
|
||||
presenter.onBoolSpinnerPosition(position)
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class BarCardView(context: Context, attrs: AttributeSet) : LinearLayout(context,
|
||||
parent: AdapterView<*>?,
|
||||
view: View?,
|
||||
position: Int,
|
||||
id: Long,
|
||||
id: Long
|
||||
) {
|
||||
presenter.onNumericalSpinnerPosition(position)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class HistoryCardView(context: Context, attrs: AttributeSet) : LinearLayout(cont
|
||||
series = state.series,
|
||||
defaultSquare = state.defaultSquare,
|
||||
notesIndicators = state.notesIndicators,
|
||||
firstWeekday = state.firstWeekday,
|
||||
firstWeekday = state.firstWeekday
|
||||
)
|
||||
binding.chart.postInvalidate()
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class SubtitleCardView(context: Context, attrs: AttributeSet) : LinearLayout(con
|
||||
binding.frequencyLabel.text = formatFrequency(
|
||||
state.frequency.numerator,
|
||||
state.frequency.denominator,
|
||||
resources,
|
||||
resources
|
||||
)
|
||||
binding.questionLabel.setTextColor(color)
|
||||
binding.questionLabel.text = state.question
|
||||
|
||||
@@ -40,7 +40,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||
toolbar = binding.toolbar,
|
||||
title = resources.getString(R.string.settings),
|
||||
color = PaletteColor(11),
|
||||
theme = themeSwitcher.currentTheme,
|
||||
theme = themeSwitcher.currentTheme
|
||||
)
|
||||
setContentView(binding.root)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class EditSettingActivity : AppCompatActivity() {
|
||||
val habits = app.component.habitList.getFiltered(
|
||||
HabitMatcher(
|
||||
isArchivedAllowed = false,
|
||||
isCompletedAllowed = true,
|
||||
isCompletedAllowed = true
|
||||
)
|
||||
)
|
||||
AndroidThemeSwitcher(this, app.component.preferences).apply()
|
||||
@@ -43,7 +43,7 @@ class EditSettingActivity : AppCompatActivity() {
|
||||
context = this,
|
||||
habitList = app.component.habitList,
|
||||
onSave = controller::onSave,
|
||||
args = args,
|
||||
args = args
|
||||
)
|
||||
setContentView(view)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class EditSettingRootView(
|
||||
title = resources.getString(R.string.app_name),
|
||||
color = PaletteColor(11),
|
||||
displayHomeAsUpEnabled = false,
|
||||
theme = currentTheme(),
|
||||
theme = currentTheme()
|
||||
)
|
||||
populateHabitSpinner()
|
||||
binding.habitSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
@@ -69,7 +69,7 @@ class EditSettingRootView(
|
||||
val habit = habitList.getByPosition(binding.habitSpinner.selectedItemPosition)
|
||||
val action = mapSpinnerPositionToAction(
|
||||
isNumerical = habit.isNumerical,
|
||||
itemPosition = binding.actionSpinner.selectedItemPosition,
|
||||
itemPosition = binding.actionSpinner.selectedItemPosition
|
||||
)
|
||||
onSave(habit, action)
|
||||
}
|
||||
|
||||
@@ -27,22 +27,34 @@ class AndroidCursor(private val cursor: android.database.Cursor) : Cursor {
|
||||
override fun moveToNext() = cursor.moveToNext()
|
||||
|
||||
override fun getInt(index: Int): Int? {
|
||||
return if (cursor.isNull(index)) null
|
||||
else cursor.getInt(index)
|
||||
return if (cursor.isNull(index)) {
|
||||
null
|
||||
} else {
|
||||
cursor.getInt(index)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLong(index: Int): Long? {
|
||||
return if (cursor.isNull(index)) null
|
||||
else cursor.getLong(index)
|
||||
return if (cursor.isNull(index)) {
|
||||
null
|
||||
} else {
|
||||
cursor.getLong(index)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDouble(index: Int): Double? {
|
||||
return if (cursor.isNull(index)) null
|
||||
else cursor.getDouble(index)
|
||||
return if (cursor.isNull(index)) {
|
||||
null
|
||||
} else {
|
||||
cursor.getDouble(index)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getString(index: Int): String? {
|
||||
return if (cursor.isNull(index)) null
|
||||
else cursor.getString(index)
|
||||
return if (cursor.isNull(index)) {
|
||||
null
|
||||
} else {
|
||||
cursor.getString(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.io.File
|
||||
|
||||
class AndroidDatabase(
|
||||
private val db: SQLiteDatabase,
|
||||
override val file: File?,
|
||||
override val file: File?
|
||||
) : Database {
|
||||
|
||||
override fun beginTransaction() = db.beginTransaction()
|
||||
@@ -45,7 +45,7 @@ class AndroidDatabase(
|
||||
tableName: String,
|
||||
values: Map<String, Any?>,
|
||||
where: String,
|
||||
vararg params: String,
|
||||
vararg params: String
|
||||
): Int {
|
||||
val contValues = mapToContentValues(values)
|
||||
return db.update(tableName, contValues, where, params)
|
||||
@@ -59,7 +59,7 @@ class AndroidDatabase(
|
||||
override fun delete(
|
||||
tableName: String,
|
||||
where: String,
|
||||
vararg params: String,
|
||||
vararg params: String
|
||||
) {
|
||||
db.delete(tableName, where, params)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class AndroidDatabaseOpener @Inject constructor() : DatabaseOpener {
|
||||
db = SQLiteDatabase.openDatabase(
|
||||
file.absolutePath,
|
||||
null,
|
||||
SQLiteDatabase.OPEN_READWRITE,
|
||||
SQLiteDatabase.OPEN_READWRITE
|
||||
),
|
||||
file = file
|
||||
)
|
||||
|
||||
@@ -25,5 +25,6 @@ import dagger.Provides
|
||||
@Module
|
||||
class ActivityContextModule(
|
||||
@get:Provides
|
||||
@get:ActivityContext val context: Context
|
||||
@get:ActivityContext
|
||||
val context: Context
|
||||
)
|
||||
|
||||
@@ -26,5 +26,6 @@ import dagger.Provides
|
||||
class AppContextModule(
|
||||
@get:Provides
|
||||
@get:AppContext
|
||||
@param:AppContext val context: Context
|
||||
@param:AppContext
|
||||
val context: Context
|
||||
)
|
||||
|
||||
@@ -53,8 +53,9 @@ class IntentParser
|
||||
var timestamp = intent.getLongExtra("timestamp", today)
|
||||
timestamp = DateUtils.getStartOfDay(timestamp)
|
||||
|
||||
if (timestamp < 0 || timestamp > today)
|
||||
if (timestamp < 0 || timestamp > today) {
|
||||
throw IllegalArgumentException("timestamp is not valid")
|
||||
}
|
||||
|
||||
return Timestamp(timestamp)
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ class AndroidNotificationTray
|
||||
timestamp: Timestamp,
|
||||
disableSound: Boolean = false
|
||||
): Notification {
|
||||
|
||||
val addRepetitionAction = Action(
|
||||
R.drawable.ic_action_check,
|
||||
context.getString(R.string.yes),
|
||||
@@ -146,8 +145,9 @@ class AndroidNotificationTray
|
||||
.addAction(removeRepetitionAction)
|
||||
}
|
||||
|
||||
if (!disableSound)
|
||||
if (!disableSound) {
|
||||
builder.setSound(ringtoneManager.getURI())
|
||||
}
|
||||
|
||||
if (SDK_INT < Build.VERSION_CODES.S) {
|
||||
val snoozeAction = Action(
|
||||
|
||||
@@ -61,8 +61,9 @@ class RingtoneManager
|
||||
"pref_ringtone_uri",
|
||||
defaultRingtoneUri.toString()
|
||||
)!!
|
||||
if (prefRingtoneUri.isNotEmpty())
|
||||
if (prefRingtoneUri.isNotEmpty()) {
|
||||
ringtoneUri = Uri.parse(prefRingtoneUri)
|
||||
}
|
||||
|
||||
return ringtoneUri
|
||||
}
|
||||
|
||||
@@ -103,7 +103,9 @@ class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener {
|
||||
if (snoozeValues[position] >= 0) {
|
||||
reminderController!!.onSnoozeDelayPicked(habit!!, snoozeValues[position])
|
||||
finish()
|
||||
} else showTimePicker()
|
||||
} else {
|
||||
showTimePicker()
|
||||
}
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
|
||||
@@ -27,7 +27,7 @@ import javax.inject.Inject
|
||||
class ExportDBTaskFactory
|
||||
@Inject constructor(
|
||||
@AppContext private val context: Context,
|
||||
private val system: AndroidDirFinder,
|
||||
private val system: AndroidDirFinder
|
||||
) {
|
||||
fun create(listener: ExportDBTask.Listener) = ExportDBTask(context, system, listener)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import javax.inject.Inject
|
||||
class ImportDataTaskFactory
|
||||
@Inject constructor(
|
||||
private val importer: GenericImporter,
|
||||
private val modelFactory: ModelFactory,
|
||||
private val modelFactory: ModelFactory
|
||||
) {
|
||||
fun create(file: File, listener: ImportDataTask.Listener) =
|
||||
ImportDataTask(importer, modelFactory, file, listener)
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Contract
|
||||
|
||||
object AttributeSetUtils {
|
||||
const val ISORON_NAMESPACE = "http://isoron.org/android"
|
||||
|
||||
@JvmStatic
|
||||
fun getAttribute(
|
||||
context: Context,
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.text.SimpleDateFormat
|
||||
|
||||
object DatabaseUtils {
|
||||
private var opener: HabitsDatabaseOpener? = null
|
||||
|
||||
@JvmStatic
|
||||
fun getDatabaseFile(context: Context): File {
|
||||
val databaseFilename = databaseFilename
|
||||
|
||||
@@ -61,7 +61,6 @@ fun RelativeLayout.addBelow(
|
||||
height: Int = WRAP_CONTENT,
|
||||
applyCustomRules: (params: RelativeLayout.LayoutParams) -> Unit = {}
|
||||
) {
|
||||
|
||||
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply {
|
||||
addRule(BELOW, subject.id)
|
||||
applyCustomRules(this)
|
||||
@@ -75,7 +74,6 @@ fun RelativeLayout.addAtBottom(
|
||||
width: Int = MATCH_PARENT,
|
||||
height: Int = WRAP_CONTENT
|
||||
) {
|
||||
|
||||
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply {
|
||||
addRule(ALIGN_PARENT_BOTTOM)
|
||||
}
|
||||
@@ -88,7 +86,6 @@ fun RelativeLayout.addAtTop(
|
||||
width: Int = MATCH_PARENT,
|
||||
height: Int = WRAP_CONTENT
|
||||
) {
|
||||
|
||||
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply {
|
||||
addRule(ALIGN_PARENT_TOP)
|
||||
}
|
||||
@@ -159,7 +156,7 @@ fun Activity.restartWithFade(cls: Class<*>?) {
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
startActivity(Intent(this, cls))
|
||||
},
|
||||
500,
|
||||
500
|
||||
) // HACK: Let the menu disappear first
|
||||
}
|
||||
|
||||
@@ -168,7 +165,7 @@ fun View.setupToolbar(
|
||||
title: String,
|
||||
color: PaletteColor,
|
||||
theme: Theme,
|
||||
displayHomeAsUpEnabled: Boolean = true,
|
||||
displayHomeAsUpEnabled: Boolean = true
|
||||
) {
|
||||
toolbar.elevation = InterfaceUtils.dpToPixels(context, 2f)
|
||||
val res = StyledResources(context)
|
||||
|
||||
@@ -147,11 +147,12 @@ abstract class BaseWidget(val context: Context, val id: Int, val stacked: Boolea
|
||||
|
||||
protected val preferedBackgroundAlpha: Int
|
||||
get() {
|
||||
return if (stacked)
|
||||
return if (stacked) {
|
||||
255
|
||||
else
|
||||
} else {
|
||||
prefs.widgetOpacity
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
val app = context.applicationContext as HabitsApplication
|
||||
|
||||
@@ -33,7 +33,7 @@ open class CheckmarkWidget(
|
||||
context: Context,
|
||||
widgetId: Int,
|
||||
protected val habit: Habit,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, widgetId, stacked) {
|
||||
|
||||
override val defaultHeight: Int = 125
|
||||
|
||||
@@ -23,7 +23,10 @@ import android.content.Context
|
||||
class CheckmarkWidgetProvider : BaseWidgetProvider() {
|
||||
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||
val habits = getHabitsFromWidgetId(id)
|
||||
return if (habits.size == 1) CheckmarkWidget(context, id, habits[0])
|
||||
else StackWidget(context, id, StackWidgetType.CHECKMARK, habits)
|
||||
return if (habits.size == 1) {
|
||||
CheckmarkWidget(context, id, habits[0])
|
||||
} else {
|
||||
StackWidget(context, id, StackWidgetType.CHECKMARK, habits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.isoron.uhabits.widgets.views.EmptyWidgetView
|
||||
class EmptyWidget(
|
||||
context: Context,
|
||||
widgetId: Int,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, widgetId, stacked) {
|
||||
override val defaultHeight: Int = 200
|
||||
override val defaultWidth: Int = 200
|
||||
|
||||
@@ -33,7 +33,7 @@ class FrequencyWidget(
|
||||
widgetId: Int,
|
||||
private val habit: Habit,
|
||||
private val firstWeekday: Int,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, widgetId, stacked) {
|
||||
override val defaultHeight: Int = 200
|
||||
override val defaultWidth: Int = 200
|
||||
|
||||
@@ -24,12 +24,15 @@ import android.content.Context
|
||||
class FrequencyWidgetProvider : BaseWidgetProvider() {
|
||||
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||
val habits = getHabitsFromWidgetId(id)
|
||||
return if (habits.size == 1) FrequencyWidget(
|
||||
return if (habits.size == 1) {
|
||||
FrequencyWidget(
|
||||
context,
|
||||
id,
|
||||
habits[0],
|
||||
preferences.firstWeekdayInt
|
||||
)
|
||||
else StackWidget(context, id, StackWidgetType.FREQUENCY, habits)
|
||||
} else {
|
||||
StackWidget(context, id, StackWidgetType.FREQUENCY, habits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class HistoryWidget(
|
||||
context: Context,
|
||||
id: Int,
|
||||
private val habit: Habit,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, id, stacked) {
|
||||
|
||||
override val defaultHeight: Int = 250
|
||||
@@ -53,7 +53,7 @@ class HistoryWidget(
|
||||
val model = HistoryCardPresenter.buildState(
|
||||
habit = habit,
|
||||
firstWeekday = prefs.firstWeekday,
|
||||
theme = WidgetTheme(),
|
||||
theme = WidgetTheme()
|
||||
)
|
||||
(widgetView.dataView as AndroidDataView).apply {
|
||||
val historyChart = (this.view as HistoryChart)
|
||||
@@ -75,7 +75,7 @@ class HistoryWidget(
|
||||
firstWeekday = prefs.firstWeekday,
|
||||
series = listOf(),
|
||||
defaultSquare = HistoryChart.Square.OFF,
|
||||
notesIndicators = listOf(),
|
||||
notesIndicators = listOf()
|
||||
)
|
||||
}
|
||||
).apply {
|
||||
|
||||
@@ -23,11 +23,14 @@ import android.content.Context
|
||||
class HistoryWidgetProvider : BaseWidgetProvider() {
|
||||
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||
val habits = getHabitsFromWidgetId(id)
|
||||
return if (habits.size == 1) HistoryWidget(
|
||||
return if (habits.size == 1) {
|
||||
HistoryWidget(
|
||||
context,
|
||||
id,
|
||||
habits[0]
|
||||
)
|
||||
else StackWidget(context, id, StackWidgetType.HISTORY, habits)
|
||||
} else {
|
||||
StackWidget(context, id, StackWidgetType.HISTORY, habits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class ScoreWidget(
|
||||
context: Context,
|
||||
id: Int,
|
||||
private val habit: Habit,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, id, stacked) {
|
||||
override val defaultHeight: Int = 300
|
||||
override val defaultWidth: Int = 300
|
||||
@@ -46,7 +46,7 @@ class ScoreWidget(
|
||||
habit = habit,
|
||||
firstWeekday = prefs.firstWeekdayInt,
|
||||
spinnerPosition = prefs.scoreCardSpinnerPosition,
|
||||
theme = WidgetTheme(),
|
||||
theme = WidgetTheme()
|
||||
)
|
||||
val widgetView = view as GraphWidgetView
|
||||
widgetView.setBackgroundAlpha(preferedBackgroundAlpha)
|
||||
|
||||
@@ -23,7 +23,10 @@ import android.content.Context
|
||||
class ScoreWidgetProvider : BaseWidgetProvider() {
|
||||
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||
val habits = getHabitsFromWidgetId(id)
|
||||
return if (habits.size == 1) ScoreWidget(context, id, habits[0])
|
||||
else StackWidget(context, id, StackWidgetType.SCORE, habits)
|
||||
return if (habits.size == 1) {
|
||||
ScoreWidget(context, id, habits[0])
|
||||
} else {
|
||||
StackWidget(context, id, StackWidgetType.SCORE, habits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class StackWidget(
|
||||
widgetId: Int,
|
||||
private val widgetType: StackWidgetType,
|
||||
private val habits: List<Habit>,
|
||||
stacked: Boolean = true,
|
||||
stacked: Boolean = true
|
||||
) : BaseWidget(context, widgetId, stacked) {
|
||||
override val defaultHeight: Int = 0
|
||||
override val defaultWidth: Int = 0
|
||||
|
||||
@@ -34,7 +34,7 @@ class StreakWidget(
|
||||
context: Context,
|
||||
id: Int,
|
||||
private val habit: Habit,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, id, stacked) {
|
||||
override val defaultHeight: Int = 200
|
||||
override val defaultWidth: Int = 200
|
||||
|
||||
@@ -23,7 +23,10 @@ import android.content.Context
|
||||
class StreakWidgetProvider : BaseWidgetProvider() {
|
||||
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||
val habits = getHabitsFromWidgetId(id)
|
||||
return if (habits.size == 1) StreakWidget(context, id, habits[0])
|
||||
else StackWidget(context, id, StackWidgetType.STREAKS, habits)
|
||||
return if (habits.size == 1) {
|
||||
StreakWidget(context, id, habits[0])
|
||||
} else {
|
||||
StackWidget(context, id, StackWidgetType.STREAKS, habits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class TargetWidget(
|
||||
context: Context,
|
||||
id: Int,
|
||||
private val habit: Habit,
|
||||
stacked: Boolean = false,
|
||||
stacked: Boolean = false
|
||||
) : BaseWidget(context, id, stacked) {
|
||||
override val defaultHeight: Int = 200
|
||||
override val defaultWidth: Int = 200
|
||||
@@ -53,7 +53,7 @@ class TargetWidget(
|
||||
val data = TargetCardPresenter.buildState(
|
||||
habit = habit,
|
||||
firstWeekday = prefs.firstWeekdayInt,
|
||||
theme = WidgetTheme(),
|
||||
theme = WidgetTheme()
|
||||
)
|
||||
chart.setColor(WidgetTheme().color(habit.color).toInt())
|
||||
chart.setTargets(data.targets)
|
||||
|
||||
@@ -23,7 +23,10 @@ import android.content.Context
|
||||
class TargetWidgetProvider : BaseWidgetProvider() {
|
||||
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||
val habits = getHabitsFromWidgetId(id)
|
||||
return if (habits.size == 1) TargetWidget(context, id, habits[0])
|
||||
else StackWidget(context, id, StackWidgetType.TARGET, habits)
|
||||
return if (habits.size == 1) {
|
||||
TargetWidget(context, id, habits[0])
|
||||
} else {
|
||||
StackWidget(context, id, StackWidgetType.TARGET, habits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@ class CheckmarkWidgetView : HabitWidgetView {
|
||||
private val text: String
|
||||
get() = if (isNumerical) {
|
||||
(max(0, entryValue) / 1000.0).toShortString()
|
||||
} else when (entryState) {
|
||||
} else {
|
||||
when (entryState) {
|
||||
YES_MANUAL, YES_AUTO -> resources.getString(R.string.fa_check)
|
||||
SKIP -> resources.getString(R.string.fa_skipped)
|
||||
UNKNOWN -> {
|
||||
@@ -112,6 +113,7 @@ class CheckmarkWidgetView : HabitWidgetView {
|
||||
NO -> resources.getString(R.string.fa_times)
|
||||
else -> resources.getString(R.string.fa_times)
|
||||
}
|
||||
}
|
||||
|
||||
override val innerLayoutId: Int
|
||||
get() = R.layout.widget_checkmark
|
||||
|
||||
@@ -31,7 +31,7 @@ enum class Font {
|
||||
|
||||
data class ScreenLocation(
|
||||
val x: Double,
|
||||
val y: Double,
|
||||
val y: Double
|
||||
)
|
||||
|
||||
interface Canvas {
|
||||
|
||||
@@ -23,7 +23,7 @@ data class Color(
|
||||
val red: Double,
|
||||
val green: Double,
|
||||
val blue: Double,
|
||||
val alpha: Double,
|
||||
val alpha: Double
|
||||
) {
|
||||
val luminosity: Double
|
||||
get() {
|
||||
|
||||
@@ -29,7 +29,7 @@ enum class DayOfWeek(val daysSinceSunday: Int) {
|
||||
WEDNESDAY(3),
|
||||
THURSDAY(4),
|
||||
FRIDAY(5),
|
||||
SATURDAY(6),
|
||||
SATURDAY(6)
|
||||
}
|
||||
|
||||
data class LocalDate(val daysSince2000: Int) {
|
||||
@@ -155,7 +155,6 @@ val nonLeapOffset = arrayOf(
|
||||
)
|
||||
|
||||
private fun daysSince2000(year: Int, month: Int, day: Int): Int {
|
||||
|
||||
var result = 365 * (year - 2000)
|
||||
result += ceil((year - 2000) / 4.0).toInt()
|
||||
result -= ceil((year - 2000) / 100.0).toInt()
|
||||
|
||||
@@ -37,7 +37,7 @@ import kotlin.math.roundToInt
|
||||
|
||||
class JavaCanvas(
|
||||
val image: BufferedImage,
|
||||
val pixelScale: Double = 2.0,
|
||||
val pixelScale: Double = 2.0
|
||||
) : Canvas {
|
||||
|
||||
override fun toImage(): Image {
|
||||
@@ -131,7 +131,7 @@ class JavaCanvas(
|
||||
y: Double,
|
||||
width: Double,
|
||||
height: Double,
|
||||
cornerRadius: Double,
|
||||
cornerRadius: Double
|
||||
) {
|
||||
g2d.fill(
|
||||
RoundRectangle2D.Double(
|
||||
@@ -140,7 +140,7 @@ class JavaCanvas(
|
||||
toPixel(width).toDouble(),
|
||||
toPixel(height).toDouble(),
|
||||
toPixel(cornerRadius).toDouble(),
|
||||
toPixel(cornerRadius).toDouble(),
|
||||
toPixel(cornerRadius).toDouble()
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -194,9 +194,8 @@ class JavaCanvas(
|
||||
centerY: Double,
|
||||
radius: Double,
|
||||
startAngle: Double,
|
||||
swipeAngle: Double,
|
||||
swipeAngle: Double
|
||||
) {
|
||||
|
||||
g2d.fillArc(
|
||||
toPixel(centerX - radius),
|
||||
toPixel(centerY - radius),
|
||||
|
||||
@@ -33,8 +33,11 @@ class JavaResourceFile(val path: String) : ResourceFile {
|
||||
get() {
|
||||
val mainPath = Paths.get("assets/main/$path")
|
||||
val testPath = Paths.get("assets/test/$path")
|
||||
return if (Files.exists(mainPath)) mainPath
|
||||
else testPath
|
||||
return if (Files.exists(mainPath)) {
|
||||
mainPath
|
||||
} else {
|
||||
testPath
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun exists(): Boolean {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.HabitList
|
||||
|
||||
data class ArchiveHabitsCommand(
|
||||
val habitList: HabitList,
|
||||
val selected: List<Habit>,
|
||||
val selected: List<Habit>
|
||||
) : Command {
|
||||
override fun run() {
|
||||
for (h in selected) h.isArchived = true
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.PaletteColor
|
||||
data class ChangeHabitColorCommand(
|
||||
val habitList: HabitList,
|
||||
val selected: List<Habit>,
|
||||
val newColor: PaletteColor,
|
||||
val newColor: PaletteColor
|
||||
) : Command {
|
||||
override fun run() {
|
||||
for (h in selected) h.color = newColor
|
||||
|
||||
@@ -27,7 +27,7 @@ import javax.inject.Inject
|
||||
@AppScope
|
||||
open class CommandRunner
|
||||
@Inject constructor(
|
||||
private val taskRunner: TaskRunner,
|
||||
private val taskRunner: TaskRunner
|
||||
) {
|
||||
private val listeners: LinkedList<Listener> = LinkedList()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.ModelFactory
|
||||
data class CreateHabitCommand(
|
||||
val modelFactory: ModelFactory,
|
||||
val habitList: HabitList,
|
||||
val model: Habit,
|
||||
val model: Habit
|
||||
) : Command {
|
||||
override fun run() {
|
||||
val habit = modelFactory.buildHabit()
|
||||
|
||||
@@ -28,7 +28,7 @@ data class CreateRepetitionCommand(
|
||||
val habit: Habit,
|
||||
val timestamp: Timestamp,
|
||||
val value: Int,
|
||||
val notes: String,
|
||||
val notes: String
|
||||
) : Command {
|
||||
override fun run() {
|
||||
val entries = habit.originalEntries
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.HabitList
|
||||
|
||||
data class DeleteHabitsCommand(
|
||||
val habitList: HabitList,
|
||||
val selected: List<Habit>,
|
||||
val selected: List<Habit>
|
||||
) : Command {
|
||||
override fun run() {
|
||||
for (h in selected) habitList.remove(h)
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.HabitNotFoundException
|
||||
data class EditHabitCommand(
|
||||
val habitList: HabitList,
|
||||
val habitId: Long,
|
||||
val modified: Habit,
|
||||
val modified: Habit
|
||||
) : Command {
|
||||
override fun run() {
|
||||
val habit = habitList.getById(habitId) ?: throw HabitNotFoundException()
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.HabitList
|
||||
|
||||
data class UnarchiveHabitsCommand(
|
||||
val habitList: HabitList,
|
||||
val selected: List<Habit>,
|
||||
val selected: List<Habit>
|
||||
) : Command {
|
||||
override fun run() {
|
||||
for (h in selected) h.isArchived = false
|
||||
|
||||
@@ -35,7 +35,7 @@ interface Database {
|
||||
tableName: String,
|
||||
values: Map<String, Any?>,
|
||||
where: String,
|
||||
vararg params: String,
|
||||
vararg params: String
|
||||
): Int
|
||||
|
||||
fun insert(tableName: String, values: Map<String, Any?>): Long?
|
||||
|
||||
@@ -41,7 +41,7 @@ class JdbcDatabase(private val connection: Connection) : Database {
|
||||
tableName: String,
|
||||
values: Map<String, Any?>,
|
||||
where: String,
|
||||
vararg params: String,
|
||||
vararg params: String
|
||||
): Int {
|
||||
return try {
|
||||
val fields = ArrayList<String?>()
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.io.InputStream
|
||||
import java.util.Locale
|
||||
|
||||
class MigrationHelper(
|
||||
private val db: Database,
|
||||
private val db: Database
|
||||
) {
|
||||
fun migrateTo(newVersion: Int) {
|
||||
try {
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.LinkedList
|
||||
|
||||
class Repository<T>(
|
||||
private val klass: Class<T>,
|
||||
private val db: Database,
|
||||
private val db: Database
|
||||
) {
|
||||
/**
|
||||
* Returns the record that has the id provided. If no record is found, returns null.
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.InputStream
|
||||
import java.util.ArrayList
|
||||
|
||||
internal class Tokenizer(
|
||||
private val mStream: InputStream,
|
||||
private val mStream: InputStream
|
||||
) {
|
||||
private var mIsNext = false
|
||||
private var mCurrent = 0
|
||||
|
||||
@@ -30,14 +30,14 @@ class GenericImporter
|
||||
loopDBImporter: LoopDBImporter,
|
||||
rewireDBImporter: RewireDBImporter,
|
||||
tickmateDBImporter: TickmateDBImporter,
|
||||
habitBullCSVImporter: HabitBullCSVImporter,
|
||||
habitBullCSVImporter: HabitBullCSVImporter
|
||||
) : AbstractImporter() {
|
||||
|
||||
var importers: List<AbstractImporter> = listOf(
|
||||
loopDBImporter,
|
||||
rewireDBImporter,
|
||||
tickmateDBImporter,
|
||||
habitBullCSVImporter,
|
||||
habitBullCSVImporter
|
||||
)
|
||||
|
||||
override fun canHandle(file: File): Boolean {
|
||||
|
||||
@@ -48,7 +48,7 @@ class HabitBullCSVImporter
|
||||
@Inject constructor(
|
||||
private val habitList: HabitList,
|
||||
private val modelFactory: ModelFactory,
|
||||
logging: Logging,
|
||||
logging: Logging
|
||||
) : AbstractImporter() {
|
||||
|
||||
private val logger = logging.getLogger("HabitBullCSVImporter")
|
||||
@@ -98,7 +98,7 @@ class HabitBullCSVImporter
|
||||
val formats = listOf(
|
||||
DateFormat.getDateInstance(DateFormat.SHORT),
|
||||
SimpleDateFormat("yyyy-MM-dd", Locale.US),
|
||||
SimpleDateFormat("MM/dd/yyyy", Locale.US),
|
||||
SimpleDateFormat("MM/dd/yyyy", Locale.US)
|
||||
)
|
||||
var parsedDate: Date? = null
|
||||
for (fmt in formats) {
|
||||
@@ -116,7 +116,7 @@ class HabitBullCSVImporter
|
||||
return Timestamp.from(
|
||||
parsedCalendar[YEAR],
|
||||
parsedCalendar[MONTH],
|
||||
parsedCalendar[DAY_OF_MONTH],
|
||||
parsedCalendar[DAY_OF_MONTH]
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class LoopDBImporter
|
||||
@AppScope val modelFactory: ModelFactory,
|
||||
@AppScope val opener: DatabaseOpener,
|
||||
@AppScope val runner: CommandRunner,
|
||||
@AppScope logging: Logging,
|
||||
@AppScope logging: Logging
|
||||
) : AbstractImporter() {
|
||||
|
||||
private val logger = logging.getLogger("LoopDBImporter")
|
||||
|
||||
@@ -125,7 +125,7 @@ class RewireDBImporter
|
||||
try {
|
||||
c = db.query(
|
||||
"select distinct date from checkins where habit_id=? and type=2",
|
||||
rewireHabitId.toString(),
|
||||
rewireHabitId.toString()
|
||||
)
|
||||
if (!c.moveToNext()) return
|
||||
do {
|
||||
@@ -147,7 +147,7 @@ class RewireDBImporter
|
||||
try {
|
||||
c = db.query(
|
||||
"select time, active_days from reminders where habit_id=? limit 1",
|
||||
rewireHabitId.toString(),
|
||||
rewireHabitId.toString()
|
||||
)
|
||||
if (!c.moveToNext()) return
|
||||
val rewireReminder = c.getInt(0)!!
|
||||
|
||||
@@ -72,7 +72,7 @@ class TickmateDBImporter @Inject constructor(
|
||||
try {
|
||||
c = db.query(
|
||||
"select distinct year, month, day from ticks where _track_id=?",
|
||||
tickmateTrackId.toString(),
|
||||
tickmateTrackId.toString()
|
||||
)
|
||||
if (!c.moveToNext()) return
|
||||
do {
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.core.models
|
||||
data class Entry(
|
||||
val timestamp: Timestamp,
|
||||
val value: Int,
|
||||
val notes: String = "",
|
||||
val notes: String = ""
|
||||
) {
|
||||
companion object {
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ open class EntryList {
|
||||
open fun recomputeFrom(
|
||||
originalEntries: EntryList,
|
||||
frequency: Frequency,
|
||||
isNumerical: Boolean,
|
||||
isNumerical: Boolean
|
||||
) {
|
||||
clear()
|
||||
val original = originalEntries.getKnown()
|
||||
@@ -167,7 +167,7 @@ open class EntryList {
|
||||
*/
|
||||
fun buildEntriesFromInterval(
|
||||
original: List<Entry>,
|
||||
intervals: List<Interval>,
|
||||
intervals: List<Interval>
|
||||
): List<Entry> {
|
||||
val result = arrayListOf<Entry>()
|
||||
if (original.isEmpty()) return result
|
||||
@@ -246,7 +246,7 @@ open class EntryList {
|
||||
|
||||
fun buildIntervals(
|
||||
freq: Frequency,
|
||||
entries: List<Entry>,
|
||||
entries: List<Entry>
|
||||
): ArrayList<Interval> {
|
||||
val filtered = entries.filter { it.value == YES_MANUAL }
|
||||
val num = freq.numerator
|
||||
@@ -294,21 +294,22 @@ open class EntryList {
|
||||
fun List<Entry>.groupedSum(
|
||||
truncateField: DateUtils.TruncateField,
|
||||
firstWeekday: Int = Calendar.SATURDAY,
|
||||
isNumerical: Boolean,
|
||||
isNumerical: Boolean
|
||||
): List<Entry> {
|
||||
return this.map { (timestamp, value) ->
|
||||
if (isNumerical) {
|
||||
if (value == SKIP)
|
||||
if (value == SKIP) {
|
||||
Entry(timestamp, 0)
|
||||
else
|
||||
} else {
|
||||
Entry(timestamp, max(0, value))
|
||||
}
|
||||
} else {
|
||||
Entry(timestamp, if (value == YES_MANUAL) 1000 else 0)
|
||||
}
|
||||
}.groupBy { entry ->
|
||||
entry.timestamp.truncate(
|
||||
truncateField,
|
||||
firstWeekday,
|
||||
firstWeekday
|
||||
)
|
||||
}.entries.map { (timestamp, entries) ->
|
||||
Entry(timestamp, entries.sumOf { it.value })
|
||||
@@ -333,7 +334,7 @@ fun List<Entry>.countSkippedDays(
|
||||
}.groupBy { entry ->
|
||||
entry.timestamp.truncate(
|
||||
truncateField,
|
||||
firstWeekday,
|
||||
firstWeekday
|
||||
)
|
||||
}.entries.map { (timestamp, entries) ->
|
||||
Entry(timestamp, entries.sumOf { it.value })
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.isoron.uhabits.core.models
|
||||
|
||||
data class Frequency(
|
||||
var numerator: Int,
|
||||
var denominator: Int,
|
||||
var denominator: Int
|
||||
) {
|
||||
init {
|
||||
if (numerator == denominator) {
|
||||
|
||||
@@ -39,7 +39,7 @@ data class Habit(
|
||||
val computedEntries: EntryList,
|
||||
val originalEntries: EntryList,
|
||||
val scores: ScoreList,
|
||||
val streaks: StreakList,
|
||||
val streaks: StreakList
|
||||
) {
|
||||
init {
|
||||
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
|
||||
@@ -78,7 +78,7 @@ data class Habit(
|
||||
computedEntries.recomputeFrom(
|
||||
originalEntries = originalEntries,
|
||||
frequency = frequency,
|
||||
isNumerical = isNumerical,
|
||||
isNumerical = isNumerical
|
||||
)
|
||||
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
@@ -94,13 +94,13 @@ data class Habit(
|
||||
targetValue = targetValue,
|
||||
computedEntries = computedEntries,
|
||||
from = from,
|
||||
to = to,
|
||||
to = to
|
||||
)
|
||||
|
||||
streaks.recompute(
|
||||
computedEntries,
|
||||
from,
|
||||
to,
|
||||
to
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ data class HabitMatcher(
|
||||
val isArchivedAllowed: Boolean = false,
|
||||
val isReminderRequired: Boolean = false,
|
||||
val isCompletedAllowed: Boolean = true,
|
||||
val isEnteredAllowed: Boolean = true,
|
||||
val isEnteredAllowed: Boolean = true
|
||||
) {
|
||||
fun matches(habit: Habit): Boolean {
|
||||
if (!isArchivedAllowed && habit.isArchived) return false
|
||||
@@ -36,7 +36,7 @@ data class HabitMatcher(
|
||||
@JvmField
|
||||
val WITH_ALARM = HabitMatcher(
|
||||
isArchivedAllowed = true,
|
||||
isReminderRequired = true,
|
||||
isReminderRequired = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ interface ModelFactory {
|
||||
scores = scores,
|
||||
streaks = streaks,
|
||||
originalEntries = buildOriginalEntries(),
|
||||
computedEntries = buildComputedEntries(),
|
||||
computedEntries = buildComputedEntries()
|
||||
)
|
||||
}
|
||||
fun buildComputedEntries(): EntryList
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.utils.DateUtils
|
||||
data class Reminder(
|
||||
val hour: Int,
|
||||
val minute: Int,
|
||||
val days: WeekdayList,
|
||||
val days: WeekdayList
|
||||
) {
|
||||
val timeInMillis: Long
|
||||
get() = DateUtils.getUpcomingTimeInMillis(hour, minute)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user