Skip to content

Commit

Permalink
Add support for location plugins (#772)
Browse files Browse the repository at this point in the history
* Cherry pick location refactor

* Refactor :data:openstreetmaps to :data:locations

* contract, plugin sdk

* Implement serialization, module tweaks

* Include check for out-of-date departures in SearchableItemVM.requestUpdatedSearchable()

* settings for location plugins

* Try not to be too lazy

* more fiddling with the plugin SDK

* add departures in MapView with mock data for debug builds

* change icons

* add boats

* animate departure lazycolumn

* Add MarqueeText for text overflow handling

* Define height for Departures in case there is no map to display

* Don't inclure railway / highway tags for OSM since there will be location plugins for that

* sort by time

* - Apply pre-merge changes to LocationSettings
- Add banner warning about slowed down location search for large search radii

* ditch `showLocationOnMap`

* LocationItem: make `showOpeningSchedule` toggleable

* LocationItem: make Navigation AssistChip work for people that don't have google maps installed

* LocationItem: resolve TODOs

* MapTiles: ditch unused code, animate userIndicator

* Reintroduce departure list

* Add LineColor

* Add osm tag `stars` as `userRating` https://taginfo.openstreetmap.org/keys/stars#overview

* typealias -> import

* Don't add Navigation Chip when there is no way to resolve navigation intents

* Add settings migration

* Set plugin SDK version to 1.2.0-SNAPSHOT

* Deduplicate shared plugin classes, use kotlinx.serialization

* Fix imports

* Use ZonedDateTime for depature times

* Add more line types

* Rewrite location serialization

* Replace street/houseNumber with address

* Add attribution field

* Add plugin config

* Reject location search requests without lat lon parameters

* Add default values to plugin location class

* Don't crash if column value is null

* Add docs comments to LocationCategory values

* Refactor OpeningSchedule as polymorphic

* remove dead corpse *ahem* code

* Split LocationCategory into category and icon

(Also update to Kotlin 2.0, please don't do this at home)

* Add more location icons

* Fix (?) location deserializer

* Add more location icons

* More icons

* Meh

* Add Pub

* Disable Github Maven repo if credentials are missing

* Add location search specific settings to plugin details screen

* Add language parameter

* Unbreak the build

* Refactor plugin SDK (with breaking changes)

* Set plugin SDK version to 2.0.0-SNAPSHOT

* Document SDK breaking changes

* Implement LocationProvider.getQuery

* Add a typesafe cursor API

* Oops I did it again

next time maybe check if the code is actually compiling before pushing

* Add missing return statement

* Fix list serialization

* Departure time UI adjustment

* Use typesafe cursor for weather plugins

* Add userRatingCount and emailAddress fields

* grrr

* Rename and extend LineTypes

* Add default lineType to Departure to fix serialization errors

* Fix refreshing stored plugin locations

* Adapt line name column width to available departures

* Fix plugin settings screen category overlap

* add LocationItem.GenericTransit

* Fix crash during deserialization of locations

* Update SDK docs

* Replace plugin "official" mark with "verified developer" mark

before anyone gets sued

* show 'now' when departure is in less than one minute

* Add typesafe Bundle API

* Implement plugin API changes

* Plugin SDK: Fix refresh result not being returned

* Update docs

* apply alpha to departures that have departured

* better (maybe): reduce saturation instead of alpha

* Add default values for Attribution

* Display attribution

* Rearrange location result layout

* Reduce searchable update interval to 1 minute

* Pass last update time to refresh function

* Change refresh path and ensure that timestamp is only update when the item was updated

* categorize osm location

* Update docs

* Optimize location search

- run providers in parallel
- flatten code

* add experimental address parsing for OSM

* add poi_category_townhall

* Fix popup closing when favorites items are updated

* Revert "Fix popup closing when favorites items are updated"

This reverts commit fc517fd.

* Fork AndroidAddressFormatter to `:libs:address-formatter`

* migrate `:libs:address-formatter` dependencies to version catalog and update them

* also consider addr:{suburb,hamlet} for `Address.city` if city tag is missing

* Move poi strings back to strings.xml

* Update Jetpack Compose

* Move address-formatter back to its original package, add license and readme

* Move address-formatter back to its original package

---------

Co-authored-by: MM20 <[email protected]>
  • Loading branch information
Sir-Photch and MM2-0 authored Jun 14, 2024
1 parent cfe80ff commit 65a9c8c
Show file tree
Hide file tree
Showing 145 changed files with 5,800 additions and 2,195 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,6 @@ fabric.properties
.idea/deploymentTargetDropDown.xml
.idea/deploymentTargetSelector.xml
.idea/copilot
.idea/other.xml
.idea/other.xml

.kotlin
28 changes: 28 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ android {
}
debug {
applicationIdSuffix = ".debug"
isDebuggable = false
isDebuggable = true
}
create("nightly") {
initWith(getByName("release"))
Expand Down Expand Up @@ -166,7 +166,7 @@ dependencies {
implementation(project(":services:global-actions"))
implementation(project(":services:widgets"))
implementation(project(":services:favorites"))
implementation(project(":data:openstreetmaps"))
implementation(project(":data:locations"))
implementation(project(":services:plugins"))
implementation(project(":core:devicepose"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import de.mm20.launcher2.database.databaseModule
import de.mm20.launcher2.debug.initDebugMode
import de.mm20.launcher2.globalactions.globalActionsModule
import de.mm20.launcher2.notifications.notificationsModule
import de.mm20.launcher2.openstreetmaps.openStreetMapsModule
import de.mm20.launcher2.locations.locationsModule
import de.mm20.launcher2.permissions.permissionsModule
import de.mm20.launcher2.data.plugins.dataPluginsModule
import de.mm20.launcher2.devicepose.devicePoseModule
Expand Down Expand Up @@ -87,7 +87,7 @@ class LauncherApplication : Application(), CoroutineScope, ImageLoaderFactory {
websitesModule,
widgetsModule,
wikipediaModule,
openStreetMapsModule,
locationsModule,
servicesTagsModule,
widgetsServiceModule,
dataPluginsModule,
Expand Down
7 changes: 2 additions & 5 deletions app/ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.plugin.compose)
}

android {
Expand Down Expand Up @@ -58,10 +59,6 @@ android {
viewBinding = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}

lint {
abortOnError = false
}
Expand Down Expand Up @@ -141,7 +138,7 @@ dependencies {
implementation(project(":core:crashreporter"))
implementation(project(":data:notifications"))
implementation(project(":data:contacts"))
implementation(project(":data:openstreetmaps"))
implementation(project(":data:locations"))
implementation(project(":core:permissions"))
implementation(project(":data:websites"))
implementation(project(":data:unitconverter"))
Expand Down
101 changes: 101 additions & 0 deletions app/ui/src/main/java/de/mm20/launcher2/ui/component/MarqueeText.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package de.mm20.launcher2.ui.component

import androidx.compose.foundation.MarqueeAnimationMode
import androidx.compose.foundation.MarqueeAnimationMode.Companion.Immediately
import androidx.compose.foundation.MarqueeDefaults
import androidx.compose.foundation.MarqueeSpacing
import androidx.compose.foundation.basicMarquee
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import de.mm20.launcher2.ui.ktx.conditional
import de.mm20.launcher2.ui.ktx.drawFadedEdge

@Composable
fun MarqueeText(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
style: TextStyle = LocalTextStyle.current,
iterations: Int = MarqueeDefaults.Iterations,
animationMode: MarqueeAnimationMode = Immediately,
repeatDelayMillis: Int = MarqueeDefaults.RepeatDelayMillis,
initialDelayMillis: Int = if (animationMode == Immediately) repeatDelayMillis else 0,
spacing: MarqueeSpacing = MarqueeDefaults.Spacing,
velocity: Dp = MarqueeDefaults.Velocity,
fadeLeft: Dp? = null,
fadeRight: Dp? = null,
) {
var textSize by remember { mutableIntStateOf(0) }
var textLayout by remember { mutableStateOf<TextLayoutResult?>(null) }

Text(
text = text,
style = style,
color = color,
fontSize = fontSize,
fontStyle = fontStyle,
fontWeight = fontWeight,
fontFamily = fontFamily,
letterSpacing = letterSpacing,
textDecoration = textDecoration,
textAlign = textAlign,
lineHeight = lineHeight,
softWrap = false,
maxLines = 1,
onTextLayout = { textLayout = it },
modifier = modifier
.onGloballyPositioned { textSize = it.size.width }
.graphicsLayer {
compositingStrategy = CompositingStrategy.Offscreen
}
.conditional(
textLayout != null && textLayout!!.size.width > textSize,
Modifier
.drawWithContent {
drawContent()
if (fadeLeft != null) {
drawFadedEdge(leftEdge = true, fadeLeft)
}
if (fadeRight != null) {
drawFadedEdge(leftEdge = false, fadeRight)
}
}
)
.basicMarquee(
iterations = iterations,
initialDelayMillis = initialDelayMillis,
spacing = spacing,
repeatDelayMillis = repeatDelayMillis,
velocity = velocity
)
)
}
17 changes: 15 additions & 2 deletions app/ui/src/main/java/de/mm20/launcher2/ui/component/RatingBar.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package de.mm20.launcher2.ui.component

import android.icu.text.DecimalFormat
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.StarHalf
import androidx.compose.material.icons.rounded.Star
import androidx.compose.material.icons.rounded.StarOutline
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -25,7 +29,8 @@ fun RatingBar(
rating: Float,
modifier: Modifier = Modifier,
tint: Color = MaterialTheme.colorScheme.primary,
starSize: Dp = 16.dp
starSize: Dp = 16.dp,
ratingCount: Int? = null,
) {
val starRating = round(rating * 10f).toInt()
val fullStars = starRating / 2
Expand All @@ -34,6 +39,7 @@ fun RatingBar(
val iconModifier = Modifier.size(starSize)
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically
) {
for (i in 0 until fullStars) {
Icon(
Expand All @@ -59,11 +65,18 @@ fun RatingBar(
modifier = iconModifier
)
}
Text(
modifier = Modifier.padding(start = 4.dp),
text = DecimalFormat("#.0").format(starRating / 2) +
if (ratingCount == null) "" else " ($ratingCount)",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}

@Preview
@Composable
fun RatingBarPreview() {
RatingBar(0.67f)
RatingBar(0.68f, ratingCount = 263)
}
Loading

0 comments on commit 65a9c8c

Please sign in to comment.