🫣 Fix and disable rules

Making ktlint happier.
This commit is contained in:
Igor Escodro
2024-06-04 17:41:55 -04:00
parent c59100d256
commit fd929a8fd7
28 changed files with 133 additions and 75 deletions

View File

@ -6,3 +6,4 @@ ktlint_standard_property-naming = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_class-signature = disabled

View File

@ -23,9 +23,9 @@ fun getDataStore(producePath: () -> String): DataStore<Preferences> =
if (::dataStore.isInitialized) {
dataStore
} else {
PreferenceDataStoreFactory.createWithPath(
produceFile = { producePath().toPath() },
).also { dataStore = it }
PreferenceDataStoreFactory
.createWithPath(produceFile = { producePath().toPath() })
.also { dataStore = it }
}
}

View File

@ -13,7 +13,8 @@ import kotlinx.datetime.toLocalDateTime
*/
val dateTimeAdapter = object : ColumnAdapter<LocalDateTime, Long> {
override fun decode(databaseValue: Long): LocalDateTime =
Instant.fromEpochMilliseconds(databaseValue)
Instant
.fromEpochMilliseconds(databaseValue)
.toLocalDateTime(TimeZone.currentSystemDefault())
override fun encode(value: LocalDateTime): Long =

View File

@ -60,7 +60,8 @@ internal class TaskDaoImpl(private val databaseProvider: DatabaseProvider) : Tas
}
override suspend fun findAllTasksWithDueDate(): List<Task> =
taskQueries.selectAllTasksWithDueDate(mapper = ::Task)
taskQueries
.selectAllTasksWithDueDate(mapper = ::Task)
.asFlow()
.mapToList(Dispatchers.IO)
.first()

View File

@ -26,21 +26,19 @@ internal class TaskWithCategoryDaoImpl(
private val taskWithCategoryQueries: TaskWithCategoryQueries
get() = databaseProvider.getInstance().taskWithCategoryQueries
override fun findAllTasksWithCategory(): Flow<List<TaskWithCategory>> {
return taskWithCategoryQueries
override fun findAllTasksWithCategory(): Flow<List<TaskWithCategory>> =
taskWithCategoryQueries
.selectAllTasksWithCategory(mapper = ::SelectAllTasksWithCategory)
.asFlow()
.mapToList(Dispatchers.IO)
.map(selectMapper::toTaskWithCategory)
}
override fun findAllTasksWithCategoryId(categoryId: Long): Flow<List<TaskWithCategory>> =
taskWithCategoryQueries
.selectAllTasksWithCategoryId(
task_category_id = categoryId,
mapper = ::SelectAllTasksWithCategory,
)
.asFlow()
).asFlow()
.mapToList(Dispatchers.IO)
.map(selectMapper::toTaskWithCategory)

View File

@ -25,15 +25,21 @@ internal class IosDriverFactory : DriverFactory {
private fun databaseExists(databaseName: String): Boolean {
val fileManager = NSFileManager.defaultManager
val documentDirectory = NSFileManager.defaultManager.URLsForDirectory(
NSLibraryDirectory,
NSUserDomainMask,
).last() as NSURL
val documentDirectory = NSFileManager
.defaultManager
.URLsForDirectory(
NSLibraryDirectory,
NSUserDomainMask,
).last() as NSURL
val file = documentDirectory
.URLByAppendingPathComponent("$DATABASE_PATH$databaseName")?.path
.URLByAppendingPathComponent("$DATABASE_PATH$databaseName")
?.path
return fileManager.fileExistsAtPath(file ?: "")
}
@Suppress("ktlint:standard:chain-method-continuation")
@OptIn(ExperimentalForeignApi::class)
private fun UIColor.toHex(): String {
val components: CPointer<DoubleVarOf<CGFloat>>? = CGColorGetComponents(CGColor)

View File

@ -48,7 +48,8 @@ class RescheduleFutureAlarms(
private fun rescheduleFutureTask(task: Task) {
val futureTime = task.dueDate
?.toInstant(TimeZone.currentSystemDefault())?.toEpochMilliseconds() ?: return
?.toInstant(TimeZone.currentSystemDefault())
?.toEpochMilliseconds() ?: return
alarmInteractor.schedule(task, futureTime)
logger.debug { "Task '${task.title} rescheduled to '${task.dueDate}" }
}

View File

@ -16,6 +16,7 @@ class LoadCompletedTasks(private val repository: TaskWithCategoryRepository) {
* @return observable to be subscribe
*/
operator fun invoke(): Flow<List<TaskWithCategory>> =
repository.findAllTasksWithCategory()
repository
.findAllTasksWithCategory()
.map { list -> list.filter { item -> item.task.completed } }
}

View File

@ -12,7 +12,8 @@ internal class LoadUncompletedTasksImpl(
override fun invoke(categoryId: Long?): Flow<List<TaskWithCategory>> =
if (categoryId == null) {
repository.findAllTasksWithCategory()
repository
.findAllTasksWithCategory()
.map { list -> list.filterNot { item -> item.task.completed } }
} else {
repository.findAllTasksWithCategoryId(categoryId)

View File

@ -21,9 +21,11 @@ internal class LoadCompletedTasksByPeriodImpl(
* Gets completed tasks in Tracker format for the last month.
*/
override operator fun invoke(): Flow<List<TaskWithCategory>> =
repository.findAllTasksWithCategory()
repository
.findAllTasksWithCategory()
.map { list ->
list.filter { item -> item.task.completed }
list
.filter { item -> item.task.completed }
.filter(::filterByLastMonth)
}

View File

@ -50,8 +50,11 @@ internal class RescheduleFutureAlarmsTest {
@Test
fun test_if_future_alarms_are_rescheduled() = runTest {
val futureCalendar = dateTimeProvider.getCurrentInstant()
.plus(15.days).toLocalDateTime(TimeZone.currentSystemDefault())
val futureCalendar = dateTimeProvider
.getCurrentInstant()
.plus(15.days)
.toLocalDateTime(TimeZone.currentSystemDefault())
val task1 = Task(id = 1, title = "Task 1", dueDate = futureCalendar)
val task2 = Task(id = 2, title = "Task 2")
val task3 = Task(id = 3, title = "Task 3", dueDate = futureCalendar)
@ -71,8 +74,11 @@ internal class RescheduleFutureAlarmsTest {
@Test
fun test_if_completed_tasks_are_not_rescheduled() = runTest {
val futureCalendar = dateTimeProvider.getCurrentInstant()
.plus(15.days).toLocalDateTime(TimeZone.currentSystemDefault())
val futureCalendar = dateTimeProvider
.getCurrentInstant()
.plus(15.days)
.toLocalDateTime(TimeZone.currentSystemDefault())
val task1 = Task(id = 1, completed = true, title = "Task 1", dueDate = futureCalendar)
val task2 = Task(id = 2, completed = true, title = "Task 2", dueDate = futureCalendar)
val task3 = Task(id = 3, completed = true, title = "Task 3", dueDate = futureCalendar)
@ -92,11 +98,15 @@ internal class RescheduleFutureAlarmsTest {
@Test
fun test_if_uncompleted_tasks_on_the_past_are_ignored() = runTest {
val pastCalendar = dateTimeProvider.getCurrentInstant()
.minus(15.days).toLocalDateTime(TimeZone.currentSystemDefault())
val pastCalendar = dateTimeProvider
.getCurrentInstant()
.minus(15.days)
.toLocalDateTime(TimeZone.currentSystemDefault())
val futureCalendar = dateTimeProvider.getCurrentInstant()
.plus(15.days).toLocalDateTime(TimeZone.currentSystemDefault())
val futureCalendar = dateTimeProvider
.getCurrentInstant()
.plus(15.days)
.toLocalDateTime(TimeZone.currentSystemDefault())
val task1 = Task(id = 1, title = "Title", dueDate = pastCalendar)
val task2 = Task(id = 2, title = "Title", dueDate = pastCalendar)
@ -117,8 +127,11 @@ internal class RescheduleFutureAlarmsTest {
@Test
fun test_if_missed_repeating_alarms_are_rescheduled() = runTest {
val pastCalendar = dateTimeProvider.getCurrentInstant()
.minus(1.days).toLocalDateTime(TimeZone.currentSystemDefault())
val pastCalendar = dateTimeProvider
.getCurrentInstant()
.minus(1.days)
.toLocalDateTime(TimeZone.currentSystemDefault())
val task = Task(
id = 1,
title = "lost",

View File

@ -107,8 +107,10 @@ internal class ScheduleNextAlarmTest {
require(result != null)
val assertCalendar = calendar.toInstant(TimeZone.currentSystemDefault())
.plus(1.hours).toLocalDateTime(TimeZone.currentSystemDefault())
val assertCalendar = calendar
.toInstant(TimeZone.currentSystemDefault())
.plus(1.hours)
.toLocalDateTime(TimeZone.currentSystemDefault())
assertEquals(assertCalendar, result.dueDate)
}
@ -127,7 +129,8 @@ internal class ScheduleNextAlarmTest {
require(result != null)
val assertCalendar = calendar.toInstant(TimeZone.currentSystemDefault())
val assertCalendar = calendar
.toInstant(TimeZone.currentSystemDefault())
.plus(DateTimePeriod(days = 1), TimeZone.currentSystemDefault())
.toLocalDateTime(TimeZone.currentSystemDefault())
@ -148,7 +151,8 @@ internal class ScheduleNextAlarmTest {
require(result != null)
val assertCalendar = calendar.toInstant(TimeZone.currentSystemDefault())
val assertCalendar = calendar
.toInstant(TimeZone.currentSystemDefault())
.plus(DateTimePeriod(days = 7), TimeZone.currentSystemDefault())
.toLocalDateTime(TimeZone.currentSystemDefault())
@ -169,7 +173,8 @@ internal class ScheduleNextAlarmTest {
require(result != null)
val assertCalendar = calendar.toInstant(TimeZone.currentSystemDefault())
val assertCalendar = calendar
.toInstant(TimeZone.currentSystemDefault())
.plus(DateTimePeriod(months = 1), TimeZone.currentSystemDefault())
.toLocalDateTime(TimeZone.currentSystemDefault())
@ -190,7 +195,8 @@ internal class ScheduleNextAlarmTest {
require(result != null)
val assertCalendar = calendar.toInstant(TimeZone.currentSystemDefault())
val assertCalendar = calendar
.toInstant(TimeZone.currentSystemDefault())
.plus(DateTimePeriod(years = 1), TimeZone.currentSystemDefault())
.toLocalDateTime(TimeZone.currentSystemDefault())
@ -213,8 +219,10 @@ internal class ScheduleNextAlarmTest {
@Test
fun test_if_missed_repeating_alarm_is_set_on_future() = runTest {
val pastCalendar = datetimeProvider.getCurrentInstant()
.minus(5.hours).toLocalDateTime(TimeZone.currentSystemDefault())
val pastCalendar = datetimeProvider
.getCurrentInstant()
.minus(5.hours)
.toLocalDateTime(TimeZone.currentSystemDefault())
val task = baseTask.copy(
dueDate = pastCalendar,
@ -229,8 +237,10 @@ internal class ScheduleNextAlarmTest {
require(result != null)
val assertCalendar = pastCalendar.toInstant(TimeZone.currentSystemDefault())
.plus(5.hours).toLocalDateTime(TimeZone.currentSystemDefault())
val assertCalendar = pastCalendar
.toInstant(TimeZone.currentSystemDefault())
.plus(5.hours)
.toLocalDateTime(TimeZone.currentSystemDefault())
assertEquals(assertCalendar, result.dueDate)
}

View File

@ -50,7 +50,9 @@ internal class SnoozeAlarmTest {
snoozeAlarmUseCase(baseTask.id, snoozeTime)
val calendarAssert = calendarProvider.getCurrentInstant().plus(snoozeTime.minutes)
val calendarAssert = calendarProvider
.getCurrentInstant()
.plus(snoozeTime.minutes)
.toLocalDateTime(TimeZone.currentSystemDefault())
val result = alarmInteractor.getAlarmTime(baseTask.id)

View File

@ -77,7 +77,8 @@ internal class UpdateAlarmTest {
val taskId = 123L
val alarm = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
val alarmInterval = AlarmInterval.WEEKLY
val task = TaskFactory.createTask()
val task = TaskFactory
.createTask()
.copy(id = taskId, dueDate = alarm, alarmInterval = alarmInterval)
// When the function to set the alarm and interval is called

View File

@ -13,7 +13,10 @@ internal class CategoryRepositoryFake : CategoryRepository {
val id = if (category.id == 0L && categoryMap.isEmpty()) {
1
} else if (category.id == 0L) {
categoryMap.entries.maxByOrNull { it.key }?.key?.plus(1) ?: 1
categoryMap.entries
.maxByOrNull { it.key }
?.key
?.plus(1) ?: 1
} else {
category.id
}

View File

@ -14,7 +14,8 @@ internal class SearchRepositoryFake(
TaskWithCategoryRepositoryFake(taskRepository, categoryRepository)
override suspend fun findTaskByName(query: String): Flow<List<TaskWithCategory>> =
taskWithCategoryRepository.findAllTasksWithCategory()
taskWithCategoryRepository
.findAllTasksWithCategory()
.map { list: List<TaskWithCategory> ->
list.filter { taskWithCategory ->
taskWithCategory.task.title.contains(query)

View File

@ -9,7 +9,10 @@ internal class TaskRepositoryFake : TaskRepository {
override suspend fun insertTask(task: Task): Long {
val id = if (task.id == 0L) {
taskMap.entries.maxByOrNull { it.key }?.key?.plus(1) ?: 1
taskMap.entries
.maxByOrNull { it.key }
?.key
?.plus(1) ?: 1
} else {
task.id
}

View File

@ -13,7 +13,8 @@ internal class TaskWithCategoryRepositoryFake(
override fun findAllTasksWithCategory(): Flow<List<TaskWithCategory>> =
flow {
val tasks = taskRepository.findAllTasks()
val tasks = taskRepository
.findAllTasks()
.map { task -> TaskWithCategory(task, findCategory(task.categoryId)) }
emit(tasks)
@ -21,7 +22,8 @@ internal class TaskWithCategoryRepositoryFake(
override fun findAllTasksWithCategoryId(categoryId: Long): Flow<List<TaskWithCategory>> =
flow {
val tasks = taskRepository.findAllTasks()
val tasks = taskRepository
.findAllTasks()
.map { task -> TaskWithCategory(task, findCategory(task.categoryId)) }
.filter { it.category?.id == categoryId }

View File

@ -87,15 +87,14 @@ internal class AndroidTaskNotification(
}
}
private fun buildPendingIntent(taskId: Long): PendingIntent {
return TaskStackBuilder.create(context).run {
private fun buildPendingIntent(taskId: Long): PendingIntent =
TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(AndroidDestinations.taskDetail(taskId))
getPendingIntent(
REQUEST_CODE_OPEN_TASK,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
}
}
private suspend fun getCompleteAction(task: Task): NotificationCompat.Action {
val actionTitle = getString(Res.string.notification_action_completed)

View File

@ -89,9 +89,10 @@ internal class IosNotificationScheduler : NotificationScheduler {
override fun updateTaskNotification(task: Task) {
NSLog("Updating notification with id '${task.title}'")
val time = task.dueDate?.toInstant(
TimeZone.currentSystemDefault(),
)?.toEpochMilliseconds() ?: return
val time = task.dueDate
?.toInstant(
TimeZone.currentSystemDefault(),
)?.toEpochMilliseconds() ?: return
scheduleTaskNotification(task, time)
}

View File

@ -10,9 +10,8 @@ internal class IosAlarmPermission : AlarmPermission {
override fun hasExactAlarmPermission(): Boolean =
true // iOS does not have exact alarm permission
override fun openExactAlarmPermissionScreen() {
override fun openExactAlarmPermissionScreen() =
throw UnsupportedOperationException("iOS does not have exact alarm permission")
}
override fun openAppSettings() {
UIApplication.sharedApplication.openURL(NSURL(string = UIApplicationOpenSettingsURLString))

View File

@ -70,7 +70,10 @@ internal class TaskListGlanceWidget : GlanceAppWidget() {
AlkaaGlanceTheme {
Column(
modifier = GlanceModifier.appWidgetBackground().fillMaxSize().then(background)
modifier = GlanceModifier
.appWidgetBackground()
.fillMaxSize()
.then(background)
.padding(8.dp),
) {
Row(
@ -80,7 +83,8 @@ internal class TaskListGlanceWidget : GlanceAppWidget() {
Image(
provider = ImageProvider(R.drawable.ic_alkaa_icon),
contentDescription = context.getString(R.string.glance_app_icon_content_description),
modifier = GlanceModifier.size(32.dp)
modifier = GlanceModifier
.size(32.dp)
.clickable(actionStartActivity(AndroidDestinations.homeIntent())),
)
Spacer(modifier = GlanceModifier.width(12.dp))
@ -148,7 +152,9 @@ internal class TaskListGlanceWidget : GlanceAppWidget() {
@Composable
private fun TaskItem(task: Task, modifier: GlanceModifier = GlanceModifier) {
Row(
modifier = modifier.padding(vertical = 2.dp).fillMaxWidth()
modifier = modifier
.padding(vertical = 2.dp)
.fillMaxWidth()
.clickable(actionStartActivity(AndroidDestinations.taskDetail(task.id))),
verticalAlignment = Alignment.CenterVertically,
) {

View File

@ -19,7 +19,6 @@ internal class AndroidRelativeDateTimeProvider(
DateUtils.MINUTE_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS,
0,
)
.toString()
).toString()
}
}

View File

@ -66,7 +66,8 @@ internal class AlarmSelectionTest {
// Assert that the remove alarm button is shown
val removeAlarmCd = context.getString(R.string.task_detail_cd_icon_remove_alarm)
composeTestRule.onNodeWithContentDescription(removeAlarmCd, useUnmergedTree = true)
composeTestRule
.onNodeWithContentDescription(removeAlarmCd, useUnmergedTree = true)
.assertIsDisplayed()
}
@ -85,7 +86,8 @@ internal class AlarmSelectionTest {
// Click to remove the alarm
val removeAlarmCd = context.getString(R.string.task_detail_cd_icon_remove_alarm)
composeTestRule.onNodeWithContentDescription(removeAlarmCd, useUnmergedTree = true)
composeTestRule
.onNodeWithContentDescription(removeAlarmCd, useUnmergedTree = true)
.performClick()
// Assert that the alarm item is not set again
@ -112,7 +114,8 @@ internal class AlarmSelectionTest {
val alarmArray = context.resources.getStringArray(R.array.task_alarm_repeating)
val repeatIconCd = context.getString(R.string.task_detail_cd_icon_repeat_alarm)
alarmArray.forEach { string ->
composeTestRule.onNodeWithContentDescription(repeatIconCd, useUnmergedTree = true)
composeTestRule
.onNodeWithContentDescription(repeatIconCd, useUnmergedTree = true)
.performClick()
composeTestRule.onAllNodesWithText(string)[0].performClick()
composeTestRule.onAllNodesWithText(string)[0].assertIsDisplayed()

View File

@ -45,9 +45,11 @@ internal class TaskItemTest {
// Assert that the due date time is shown
val hour = calendar.get(Calendar.HOUR).toString()
val minute = calendar.get(Calendar.MINUTE).toString()
composeTestRule.onNodeWithText(text = hour, substring = true, useUnmergedTree = true)
composeTestRule
.onNodeWithText(text = hour, substring = true, useUnmergedTree = true)
.assertExists()
composeTestRule.onNodeWithText(text = minute, substring = true, useUnmergedTree = true)
composeTestRule
.onNodeWithText(text = minute, substring = true, useUnmergedTree = true)
.assertExists()
}
@ -62,7 +64,8 @@ internal class TaskItemTest {
loadItemView(taskWithCategory) {}
// Assert that the title has a single line
composeTestRule.onNodeWithText(text = taskName, useUnmergedTree = true)
composeTestRule
.onNodeWithText(text = taskName, useUnmergedTree = true)
.assertLines(lines = 1)
}

View File

@ -41,11 +41,12 @@ fun DateTimerPicker(
onDateChange: (LocalDateTime) -> Unit,
) {
val now = Clock.System.now()
val displayTime = now.plus(
value = 1,
unit = DateTimeUnit.HOUR,
timeZone = TimeZone.currentSystemDefault(),
).toLocalDateTime(TimeZone.currentSystemDefault())
val displayTime = now
.plus(
value = 1,
unit = DateTimeUnit.HOUR,
timeZone = TimeZone.currentSystemDefault(),
).toLocalDateTime(TimeZone.currentSystemDefault())
val datePickerState = rememberDatePickerState(
initialSelectedDateMillis = now.toEpochMilliseconds(),

View File

@ -54,11 +54,10 @@ internal class LoadUncompletedTasksFake : LoadUncompletedTasks {
throwError = false
}
override fun invoke(categoryId: Long?): Flow<List<TaskWithCategory>> {
return when {
override fun invoke(categoryId: Long?): Flow<List<TaskWithCategory>> =
when {
throwError -> flowOf(list).map { throw IllegalStateException() }
categoryId != null -> flowOf(list.filter { it.category?.id == categoryId })
else -> flowOf(list)
}
}
}

View File

@ -124,7 +124,8 @@ private fun DownloadFeature(
) {
var isDialogOpen by rememberSaveable { mutableStateOf(true) }
DisposableEffect(featureName, setState, onDismiss) {
val request = SplitInstallRequest.newBuilder()
val request = SplitInstallRequest
.newBuilder()
.addModule(featureName)
.build()