Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save ktlint rules to project #230

Merged
merged 18 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[*.{kt,kts}]
end_of_line = lf
ij_kotlin_allow_trailing_comma = false
KevinSchildhorn marked this conversation as resolved.
Show resolved Hide resolved
ij_kotlin_allow_trailing_comma_on_call_site = false
KevinSchildhorn marked this conversation as resolved.
Show resolved Hide resolved
ij_kotlin_imports_layout = *
ij_kotlin_indent_before_arrow_on_new_line = false
ij_kotlin_line_break_after_multiline_when_entry = true
ij_kotlin_packages_to_use_import_on_demand = java.util.*,kotlinx.android.synthetic.**
indent_size = 4
indent_style = space
insert_final_newline = true
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = 8
ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 4
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
ktlint_code_style = android_studio
ktlint_enum_entry_name_casing = upper_or_camel_cases
ktlint_function_naming_ignore_when_annotated_with = [unset]
ktlint_function_signature_body_expression_wrapping = default
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
ktlint_ignore_back_ticked_identifier = false
max_line_length = 100
KevinSchildhorn marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 4 additions & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ android {
if (releaseEnabled) {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}
Expand Down
12 changes: 10 additions & 2 deletions android/src/main/java/co/touchlab/droidcon/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ class MainActivity : ComponentActivity(), KoinComponent {

private fun askNotificationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
} else if (false && shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
if (
ContextCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) {
} else if (
false &&
shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)
) {
// TODO: display an educational UI explaining to the user the features that will be enabled
// by them granting the POST_NOTIFICATION permission. This UI should provide the user
// "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class MainApp : Application() {
single<Context> { this@MainApp }
single<Class<out Activity>> { MainActivity::class.java }
single<SharedPreferences> {
get<Context>().getSharedPreferences("DROIDCON_SETTINGS_2023", Context.MODE_PRIVATE)
get<Context>().getSharedPreferences(
"DROIDCON_SETTINGS_2023",
Context.MODE_PRIVATE
)
}
single<ObservableSettings> { SharedPreferencesSettings(delegate = get()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class DefaultFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)

if (message.data.isNotEmpty() && message.data[Notification.Keys.notificationType] == Notification.Values.refreshDataType) {
if (
message.data.isNotEmpty() &&
message.data[Notification.Keys.notificationType] == Notification.Values.refreshDataType
) {
MainScope().launch {
notificationService.handleNotification(
Notification.Remote.RefreshData
Expand All @@ -32,7 +35,10 @@ class DefaultFirebaseMessagingService : FirebaseMessagingService() {

// If we have notification, we're running in foreground and should show it ourselves.
val originalNotification = message.notification ?: return
val notification = NotificationCompat.Builder(this, message.notification?.channelId ?: "")
val notification = NotificationCompat.Builder(
this,
message.notification?.channelId ?: ""
)
.setContentTitle(originalNotification.title)
.setContentText(originalNotification.body)
.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class NotificationLocalizedStringFactory(
) : NotificationSchedulingService.LocalizedStringFactory {

override fun reminderTitle(roomName: String?): String {
val ending = roomName?.let { context.getString(R.string.notification_reminder_title_in_room, it) } ?: ""
val ending = roomName?.let {
context.getString(R.string.notification_reminder_title_in_room, it)
} ?: ""
return context.getString(R.string.notification_reminder_title_base, ending)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,32 @@ class NotificationLocalizedStringFactory(
) : NotificationSchedulingService.LocalizedStringFactory {

override fun reminderTitle(roomName: String?): String {
val ending = roomName?.let { NSString.stringWithFormat(bundle.localizedStringForKey("Notification.Reminder.Title.InRoom", null, null).convertParametersForPrintf(), it.cstr) } ?: ""
return NSString.stringWithFormat(bundle.localizedStringForKey("Notification.Reminder.Title.Base", null, null).convertParametersForPrintf(), ending.cstr)
val ending = roomName?.let {
NSString.stringWithFormat(
bundle.localizedStringForKey("Notification.Reminder.Title.InRoom", null, null)
.convertParametersForPrintf(),
it.cstr
)
} ?: ""
return NSString.stringWithFormat(
bundle.localizedStringForKey(
"Notification.Reminder.Title.Base",
null,
null
).convertParametersForPrintf(),
ending.cstr
)
}

override fun reminderBody(sessionTitle: String): String {
return NSString.stringWithFormat(bundle.localizedStringForKey("Notification.Reminder.Body", null, null).convertParametersForPrintf(), sessionTitle.cstr)
return NSString.stringWithFormat(
bundle.localizedStringForKey(
"Notification.Reminder.Body",
null,
null
).convertParametersForPrintf(),
sessionTitle.cstr
)
}

override fun feedbackTitle(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class IOSDateFormatter : DateFormatter {
private val monthWithDay: NSDateFormatter by lazy {
NSDateFormatter().also {
val dateTemplate = "MMM d"
it.dateFormat = NSDateFormatter.dateFormatFromTemplate(dateTemplate, 0.toULong(), NSLocale.currentLocale)!!
it.dateFormat = NSDateFormatter.dateFormatFromTemplate(
dateTemplate,
0.toULong(),
NSLocale.currentLocale
)!!
}
}

Expand All @@ -30,7 +34,11 @@ class IOSDateFormatter : DateFormatter {
private val timeOnlyNoPeriod: NSDateFormatter by lazy {
NSDateFormatter().also {
val dateTemplate = "hh:mm"
it.dateFormat = NSDateFormatter.dateFormatFromTemplate(dateTemplate, 0.toULong(), NSLocale.currentLocale)!!
it.dateFormat = NSDateFormatter.dateFormatFromTemplate(
dateTemplate,
0.toULong(),
NSLocale.currentLocale
)!!
}
}

Expand All @@ -40,15 +48,18 @@ class IOSDateFormatter : DateFormatter {
override fun timeOnly(dateTime: LocalDateTime) =
dateTime.date()?.let { timeOnly.stringFromDate(it) }

override fun timeOnlyInterval(fromDateTime: LocalDateTime, toDateTime: LocalDateTime) = interval(
fromDateTime.date()?.let { timeOnlyNoPeriod.stringFromDate(it) },
toDateTime.date()?.let { timeOnly.stringFromDate(it) }
)
override fun timeOnlyInterval(fromDateTime: LocalDateTime, toDateTime: LocalDateTime) =
interval(
fromDateTime.date()?.let { timeOnlyNoPeriod.stringFromDate(it) },
toDateTime.date()?.let { timeOnly.stringFromDate(it) }
)

private fun LocalDate.date() = NSCalendar.currentCalendar.dateFromComponents(toNSDateComponents())
private fun LocalDate.date() =
NSCalendar.currentCalendar.dateFromComponents(toNSDateComponents())

private fun LocalDateTime.date() =
NSCalendar.currentCalendar.dateFromComponents(toNSDateComponents()) // TODOKPG - Pretty sure this is device time zone, might be OK. Just for local formating
// TODOKPG - Pretty sure this is device time zone, might be OK. Just for local formating
NSCalendar.currentCalendar.dateFromComponents(toNSDateComponents())

private fun interval(from: String?, to: String?) = listOfNotNull(from, to).joinToString(" – ")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ internal actual fun PlatformSwitchApp() {
val context = LocalContext.current
Button(
onClick = {
val intent = context.packageManager.getLaunchIntentForPackage(Constants.SisterApp.androidPackageName)
val intent =
context
.packageManager
.getLaunchIntentForPackage(Constants.SisterApp.androidPackageName)
if (intent != null) {
context.startActivity(intent)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package co.touchlab.droidcon.ui.util

import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.window.Dialog as AndroidXComposeDialog
import androidx.compose.ui.window.DialogProperties

@OptIn(ExperimentalComposeUiApi::class)
@Composable
internal actual fun Dialog(dismiss: () -> Unit, content: @Composable () -> Unit) {
AndroidXComposeDialog(
onDismissRequest = dismiss,
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false, usePlatformDefaultWidth = false),
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformDefaultWidth = false
),
) {
content()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ import co.touchlab.droidcon.ui.theme.Dimensions
// platforms and on each platform we need to get the drawable according to provided name.
@SuppressLint("ComposableNaming", "DiscouragedApi")
@Composable
internal actual fun __LocalImage(imageResourceName: String, modifier: Modifier, contentDescription: String?) {
internal actual fun __LocalImage(
imageResourceName: String,
modifier: Modifier,
contentDescription: String?
) {
val context = LocalContext.current
val imageRes = context.resources.getIdentifier(imageResourceName, "drawable", context.packageName).takeIf { it != 0 }
val imageRes =
context.resources.getIdentifier(imageResourceName, "drawable", context.packageName)
.takeIf { it != 0 }
if (imageRes != null) {
androidx.compose.foundation.Image(
modifier = modifier,
Expand All @@ -36,7 +42,10 @@ internal actual fun __LocalImage(imageResourceName: String, modifier: Modifier,
)
} else {
Row(
modifier = modifier.background(MaterialTheme.colorScheme.primary, RoundedCornerShape(Dimensions.Padding.half)),
modifier = modifier.background(
MaterialTheme.colorScheme.primary,
RoundedCornerShape(Dimensions.Padding.half)
),
verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier.weight(1f))
Expand All @@ -46,7 +55,11 @@ internal actual fun __LocalImage(imageResourceName: String, modifier: Modifier,
modifier = Modifier.padding(Dimensions.Padding.half),
tint = Color.White
)
Text("Image not supported", modifier = Modifier.padding(Dimensions.Padding.default), color = Color.White)
Text(
"Image not supported",
modifier = Modifier.padding(Dimensions.Padding.default),
color = Color.White
)
Spacer(modifier = Modifier.weight(1f))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ internal fun BottomNavigationView(viewModel: ApplicationViewModel, modifier: Mod
NavigationBar {
viewModel.tabs.forEach { tab ->
val (title, icon) = when (tab) {
ApplicationViewModel.Tab.Schedule -> "Schedule" to Icons.Filled.CalendarMonth
ApplicationViewModel.Tab.Schedule ->
"Schedule" to Icons.Filled.CalendarMonth
// FIXME: Was originally "My agenda" but then it doesn't seem to fit.
ApplicationViewModel.Tab.MyAgenda -> "Agenda" to Icons.Filled.Schedule
ApplicationViewModel.Tab.Venue -> "Venue" to Icons.Filled.Map
ApplicationViewModel.Tab.Sponsors -> "Sponsors" to Icons.Filled.LocalFireDepartment
ApplicationViewModel.Tab.Sponsors ->
"Sponsors" to Icons.Filled.LocalFireDepartment
ApplicationViewModel.Tab.Settings -> "Settings" to Icons.Filled.Settings
}
NavigationBarItem(
Expand All @@ -66,11 +68,13 @@ internal fun BottomNavigationView(viewModel: ApplicationViewModel, modifier: Mod
title = "Droidcon NYC 2024",
emptyText = "Sessions could not be loaded.",
)

ApplicationViewModel.Tab.MyAgenda -> SessionListView(
viewModel = viewModel.agenda,
title = "Agenda",
emptyText = "Add sessions to your agenda from session detail in schedule.",
)

ApplicationViewModel.Tab.Venue -> VenueView()
ApplicationViewModel.Tab.Sponsors -> SponsorsView(viewModel.sponsors)
ApplicationViewModel.Tab.Settings -> SettingsView(viewModel.settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ internal fun SettingsView(viewModel: SettingsViewModel) {
}

@Composable
internal fun IconTextSwitchRow(text: String, image: ImageVector, checked: MutableObservableProperty<Boolean>) {
internal fun IconTextSwitchRow(
text: String,
image: ImageVector,
checked: MutableObservableProperty<Boolean>
) {
val isChecked by checked.observeAsState()
Row(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
internal expect fun __LocalImage(imageResourceName: String, modifier: Modifier, contentDescription: String?)
internal expect fun __LocalImage(
imageResourceName: String,
modifier: Modifier,
contentDescription: String?
)

@Composable
internal fun LocalImage(imageResourceName: String, modifier: Modifier = Modifier, contentDescription: String? = null) {
internal fun LocalImage(
imageResourceName: String,
modifier: Modifier = Modifier,
contentDescription: String? = null
) {
__LocalImage(imageResourceName, modifier, contentDescription)
}
Loading
Loading