Move core sources from jvmMain to commonMain for KMP migration
This commit is contained in:
parent
6f1057f825
commit
d467dd643c
@ -19,9 +19,9 @@
|
||||
|
||||
package org.isoron.uhabits.database
|
||||
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.uhabits.AndroidDirFinder
|
||||
import org.isoron.uhabits.BaseAndroidTest
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
@ -51,6 +51,8 @@ import org.isoron.uhabits.core.models.PaletteColor
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.tasks.TaskRunner
|
||||
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
||||
import org.isoron.uhabits.core.ui.callbacks.CheckMarkDialogCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.NumberPickerCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.OnColorPickedCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
||||
@ -270,7 +272,7 @@ class ListHabitsScreen(
|
||||
override fun showNumberPopup(
|
||||
value: Double,
|
||||
notes: String,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback
|
||||
callback: NumberPickerCallback
|
||||
) {
|
||||
val fm = (context as AppCompatActivity).supportFragmentManager
|
||||
val dialog = NumberDialog()
|
||||
@ -286,7 +288,7 @@ class ListHabitsScreen(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
color: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
callback: CheckMarkDialogCallback
|
||||
) {
|
||||
val theme = rootView.value.currentTheme()
|
||||
val fm = (context as AppCompatActivity).supportFragmentManager
|
||||
|
||||
@ -43,8 +43,9 @@ import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.PaletteColor
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.ui.callbacks.CheckMarkDialogCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.NumberPickerCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuPresenter
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter
|
||||
import org.isoron.uhabits.core.ui.views.OnDateClickedListener
|
||||
@ -174,7 +175,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
override fun showNumberPopup(
|
||||
value: Double,
|
||||
notes: String,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback
|
||||
callback: NumberPickerCallback
|
||||
) {
|
||||
val dialog = NumberDialog()
|
||||
dialog.arguments = Bundle().apply {
|
||||
@ -189,7 +190,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
color: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
callback: CheckMarkDialogCallback
|
||||
) {
|
||||
val theme = view.currentTheme()
|
||||
val dialog = CheckmarkDialog()
|
||||
|
||||
@ -24,8 +24,8 @@ import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.uhabits.AndroidDirFinder
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.utils.DatabaseUtils
|
||||
import java.io.File
|
||||
|
||||
|
||||
@ -28,11 +28,11 @@ import android.content.Context.ALARM_SERVICE
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.platform.time.DateFormats
|
||||
import org.isoron.uhabits.core.AppScope
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.reminders.ReminderScheduler.SchedulerResult
|
||||
import org.isoron.uhabits.core.reminders.ReminderScheduler.SystemScheduler
|
||||
import org.isoron.uhabits.core.utils.DateFormats
|
||||
import org.isoron.uhabits.inject.AppContext
|
||||
import java.util.Date
|
||||
import kotlin.math.min
|
||||
|
||||
@ -22,13 +22,13 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.core.AppScope
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.reminders.ReminderScheduler
|
||||
import org.isoron.uhabits.core.ui.NotificationTray
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.notifications.SnoozeDelayPickerActivity
|
||||
|
||||
@Inject
|
||||
|
||||
@ -22,11 +22,11 @@ import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.util.Log
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import org.isoron.platform.time.DateFormats.Companion.getBackupDateFormat
|
||||
import org.isoron.uhabits.HabitsApplication.Companion.isTestMode
|
||||
import org.isoron.uhabits.HabitsDatabaseOpener
|
||||
import org.isoron.uhabits.core.DATABASE_FILENAME
|
||||
import org.isoron.uhabits.core.DATABASE_VERSION
|
||||
import org.isoron.uhabits.core.utils.DateFormats.Companion.getBackupDateFormat
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
|
||||
@ -21,11 +21,11 @@ package org.isoron.uhabits.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.format.DateFormat
|
||||
import org.isoron.platform.time.DateFormats
|
||||
import org.isoron.platform.time.DayOfWeek
|
||||
import org.isoron.platform.time.JavaLocalDateFormatter
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.models.WeekdayList
|
||||
import org.isoron.uhabits.core.utils.DateFormats
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@ -24,13 +24,13 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.uhabits.core.commands.Command
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.preferences.WidgetPreferences
|
||||
import org.isoron.uhabits.core.tasks.TaskRunner
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.inject.AppContext
|
||||
import org.isoron.uhabits.intents.IntentScheduler
|
||||
|
||||
|
||||
@ -236,6 +236,8 @@ fun getWeekdaySequence(firstWeekday: DayOfWeek): List<DayOfWeek> {
|
||||
}
|
||||
}
|
||||
|
||||
expect fun getFirstWeekdayNumberAccordingToLocale(): Int
|
||||
|
||||
fun countWeekdayOccurrencesInMonth(startOfMonth: LocalDate): Array<Int> {
|
||||
val weekday = (startOfMonth.dayOfWeek.daysSinceSunday + 1) % 7
|
||||
val freq = Array(7) { 0 }
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package org.isoron.uhabits.core.preferences
|
||||
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.platform.io.format
|
||||
import org.isoron.uhabits.core.AppScope
|
||||
|
||||
@AppScope
|
||||
@ -52,11 +53,11 @@ class WidgetPreferences(private val storage: Preferences.Storage) {
|
||||
}
|
||||
|
||||
private fun getHabitIdKey(id: Int): String {
|
||||
return String.format("widget-%06d-habit", id)
|
||||
return format("widget-%06d-habit", id)
|
||||
}
|
||||
|
||||
private fun getSnoozeKey(id: Long): String {
|
||||
return String.format("snooze-%06d", id)
|
||||
return format("snooze-%06d", id.toInt())
|
||||
}
|
||||
|
||||
fun removeSnoozeTime(id: Long) {
|
||||
@ -16,20 +16,8 @@
|
||||
* 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.core.tasks
|
||||
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
|
||||
@Inject
|
||||
class ExportCSVTaskFactory(
|
||||
val habitList: HabitList
|
||||
) {
|
||||
fun create(
|
||||
selectedHabits: List<Habit>,
|
||||
outputDir: String,
|
||||
listener: ExportCSVTask.Listener
|
||||
) = ExportCSVTask(habitList, selectedHabits, outputDir, listener)
|
||||
fun interface ExportCSVListener {
|
||||
fun onExportCSVFinished(archiveFilename: String?)
|
||||
}
|
||||
@ -16,27 +16,20 @@
|
||||
* 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.core.ui.callbacks
|
||||
|
||||
package org.isoron.uhabits.core.utils
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
class DateFormats {
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic fun fromSkeleton(
|
||||
skeleton: String,
|
||||
locale: Locale
|
||||
): SimpleDateFormat {
|
||||
val df = SimpleDateFormat(skeleton, locale)
|
||||
df.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return df
|
||||
}
|
||||
|
||||
@JvmStatic fun getBackupDateFormat(): SimpleDateFormat =
|
||||
fromSkeleton("yyyy-MM-dd HHmmss", Locale.US)
|
||||
}
|
||||
fun interface NumberPickerCallback {
|
||||
fun onNumberPicked(
|
||||
newValue: Double,
|
||||
notes: String
|
||||
)
|
||||
fun onNumberPickerDismissed() {}
|
||||
}
|
||||
|
||||
fun interface CheckMarkDialogCallback {
|
||||
fun onNotesSaved(
|
||||
value: Int,
|
||||
notes: String
|
||||
)
|
||||
fun onNotesDismissed() {}
|
||||
}
|
||||
@ -34,7 +34,8 @@ import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST
|
||||
import org.isoron.uhabits.core.models.NumericalHabitType.AT_MOST
|
||||
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.callbacks.CheckMarkDialogCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.NumberPickerCallback
|
||||
import org.isoron.uhabits.core.ui.views.HistoryChart
|
||||
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.DIMMED
|
||||
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.GREY
|
||||
@ -204,13 +205,13 @@ class HistoryCardPresenter(
|
||||
fun showNumberPopup(
|
||||
value: Double,
|
||||
notes: String,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback
|
||||
callback: NumberPickerCallback
|
||||
)
|
||||
fun showCheckmarkPopup(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
color: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
callback: CheckMarkDialogCallback
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package org.isoron.platform.time
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
class DateFormats {
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic fun fromSkeleton(
|
||||
skeleton: String,
|
||||
locale: Locale
|
||||
): SimpleDateFormat {
|
||||
val df = SimpleDateFormat(skeleton, locale)
|
||||
df.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return df
|
||||
}
|
||||
|
||||
@JvmStatic fun getBackupDateFormat(): SimpleDateFormat =
|
||||
fromSkeleton("yyyy-MM-dd HHmmss", Locale.US)
|
||||
}
|
||||
}
|
||||
@ -1,22 +1,4 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2025 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* 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.core.utils
|
||||
package org.isoron.platform.time
|
||||
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
@ -47,7 +47,7 @@ fun LocalDate.toGregorianCalendar(): GregorianCalendar {
|
||||
return cal
|
||||
}
|
||||
|
||||
fun getFirstWeekdayNumberAccordingToLocale(): Int {
|
||||
actual fun getFirstWeekdayNumberAccordingToLocale(): Int {
|
||||
return GregorianCalendar(Locale.getDefault()).firstDayOfWeek
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package org.isoron.uhabits.core.reminders
|
||||
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.uhabits.core.AppScope
|
||||
import org.isoron.uhabits.core.commands.ChangeHabitColorCommand
|
||||
import org.isoron.uhabits.core.commands.Command
|
||||
@ -28,7 +29,6 @@ import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.models.HabitMatcher
|
||||
import org.isoron.uhabits.core.preferences.WidgetPreferences
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
|
||||
@AppScope
|
||||
@Inject
|
||||
|
||||
@ -29,7 +29,7 @@ class ExportCSVTask(
|
||||
private val habitList: HabitList,
|
||||
private val selectedHabits: List<Habit>,
|
||||
private val outputDir: String,
|
||||
private val listener: Listener
|
||||
private val listener: ExportCSVListener
|
||||
) : Task {
|
||||
private var archiveFilename: String? = null
|
||||
override fun doInBackground() {
|
||||
@ -50,8 +50,4 @@ class ExportCSVTask(
|
||||
override fun onPostExecute() {
|
||||
listener.onExportCSVFinished(archiveFilename)
|
||||
}
|
||||
|
||||
fun interface Listener {
|
||||
fun onExportCSVFinished(archiveFilename: String?)
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,8 @@ import org.isoron.uhabits.core.models.PaletteColor
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.tasks.ExportCSVTask
|
||||
import org.isoron.uhabits.core.tasks.TaskRunner
|
||||
import org.isoron.uhabits.core.ui.callbacks.CheckMarkDialogCallback
|
||||
import org.isoron.uhabits.core.ui.callbacks.NumberPickerCallback
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Inject
|
||||
@ -152,22 +154,6 @@ open class ListHabitsBehavior(
|
||||
fun getCSVOutputDir(): String
|
||||
}
|
||||
|
||||
fun interface NumberPickerCallback {
|
||||
fun onNumberPicked(
|
||||
newValue: Double,
|
||||
notes: String
|
||||
)
|
||||
fun onNumberPickerDismissed() {}
|
||||
}
|
||||
|
||||
fun interface CheckMarkDialogCallback {
|
||||
fun onNotesSaved(
|
||||
value: Int,
|
||||
notes: String
|
||||
)
|
||||
fun onNotesDismissed() {}
|
||||
}
|
||||
|
||||
interface Screen {
|
||||
fun showHabitScreen(h: Habit)
|
||||
fun showIntroScreen()
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package org.isoron.uhabits.core.utils
|
||||
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.platform.time.computeToday
|
||||
import org.isoron.platform.time.setToday
|
||||
import org.isoron.uhabits.core.AppScope
|
||||
|
||||
@ -18,15 +18,15 @@
|
||||
*/
|
||||
package org.isoron.uhabits.core.reminders
|
||||
|
||||
import org.isoron.platform.time.DateUtils
|
||||
import org.isoron.platform.time.DateUtils.removeTimezone
|
||||
import org.isoron.platform.time.DateUtils.setFixedLocalTime
|
||||
import org.isoron.platform.time.DateUtils.setFixedTimeZone
|
||||
import org.isoron.uhabits.core.BaseUnitTest
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.Reminder
|
||||
import org.isoron.uhabits.core.models.WeekdayList
|
||||
import org.isoron.uhabits.core.preferences.WidgetPreferences
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.core.utils.DateUtils.removeTimezone
|
||||
import org.isoron.uhabits.core.utils.DateUtils.setFixedLocalTime
|
||||
import org.isoron.uhabits.core.utils.DateUtils.setFixedTimeZone
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
@ -26,6 +26,7 @@ import org.isoron.uhabits.core.BaseUnitTest
|
||||
import org.isoron.uhabits.core.models.Entry
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.ui.callbacks.NumberPickerCallback
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.kotlin.KArgumentCaptor
|
||||
@ -50,7 +51,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
|
||||
private lateinit var habit1: Habit
|
||||
private lateinit var habit2: Habit
|
||||
|
||||
var picker: KArgumentCaptor<ListHabitsBehavior.NumberPickerCallback> = argumentCaptor()
|
||||
var picker: KArgumentCaptor<NumberPickerCallback> = argumentCaptor()
|
||||
|
||||
private val bugReporter: ListHabitsBehavior.BugReporter = mock()
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user