Skip to content

Commit

Permalink
Merge pull request #2
Browse files Browse the repository at this point in the history
Merge for v1.3.0
  • Loading branch information
lucka-me authored May 11, 2023
2 parents 8921e6d + cfe3608 commit 5ffdf13
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 41 deletions.
6 changes: 6 additions & 0 deletions .tokeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.xml
*.md
*.bat
*.pro

/gradlew
24 changes: 12 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "labs.lucka.refrain"
minSdk 28
targetSdk 33
versionCode 4
versionName "1.2.0"
versionCode 5
versionName "1.3.0"
vectorDrawables {
useSupportLibrary true
}
Expand Down Expand Up @@ -47,19 +47,19 @@ android {
}

dependencies {
implementation 'androidx.activity:activity-compose:1.6.1'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation "androidx.compose.material:material-icons-extended:1.3.1"
implementation 'androidx.activity:activity-compose:1.7.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation "androidx.compose.material:material-icons-extended:1.4.3"
implementation 'androidx.compose.material3:material3:1.0.1'
implementation "androidx.compose.ui:ui:1.3.3"
implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"
implementation 'androidx.core:core-ktx:1.9.0'
implementation "androidx.compose.ui:ui:1.4.3"
implementation "androidx.compose.ui:ui-tooling-preview:1.4.3"
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.datastore:datastore-preferences:1.0.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation "com.google.accompanist:accompanist-permissions:$accompanist_version"
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version"
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.google.android.material:material:1.9.0'

debugImplementation "androidx.compose.ui:ui-tooling:1.3.3"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.3.3"
debugImplementation "androidx.compose.ui:ui-tooling:1.4.3"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.4.3"
}
8 changes: 5 additions & 3 deletions app/src/main/java/labs/lucka/refrain/service/TraceService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import labs.lucka.refrain.service.appender.FileAppender
import labs.lucka.refrain.MainActivity
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

class TraceService : Service() {

Expand Down Expand Up @@ -120,26 +121,27 @@ class TraceService : Service() {
return
}
val now = LocalDateTime.now().atZone(ZoneId.systemDefault())
val displayName = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"))
appenders.clear()
if (preferencesDataStore.data.map { it[Keys.outputFormat.csv] != false }.first()) {
val appender = FileAppender.Builder(FileAppender.FileType.CSV).build()
if (!appender.prepare(contentResolver, outputTree, now)) {
if (!appender.prepare(contentResolver, outputTree, displayName)) {
mainExecutor.execute { notifyStart(false) }
return
}
appenders.add(appender)
}
if (preferencesDataStore.data.map { it[Keys.outputFormat.gpx] == true }.first()) {
val appender = FileAppender.Builder(FileAppender.FileType.GPX).build()
if (!appender.prepare(contentResolver, outputTree, now)) {
if (!appender.prepare(contentResolver, outputTree, displayName)) {
mainExecutor.execute { notifyStart(false) }
return
}
appenders.add(appender)
}
if (preferencesDataStore.data.map { it[Keys.outputFormat.kml] == true }.first()) {
val appender = FileAppender.Builder(FileAppender.FileType.KML).build()
if (!appender.prepare(contentResolver, outputTree, now)) {
if (!appender.prepare(contentResolver, outputTree, displayName)) {
mainExecutor.execute { notifyStart(false) }
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.ContentResolver
import android.location.Location
import androidx.documentfile.provider.DocumentFile
import java.io.PrintWriter
import java.time.ZonedDateTime

class CSVFileAppender : FileAppender {
override fun append(location: Location) {
Expand All @@ -20,9 +19,8 @@ class CSVFileAppender : FileAppender {
writer.close()
}

override fun prepare(contentResolver: ContentResolver, tree: DocumentFile, dateTime: ZonedDateTime) : Boolean {
val timestamp = dateTime.toInstant().toEpochMilli()
val document = tree.createFile("text/csv", "$timestamp") ?: return false
override fun prepare(contentResolver: ContentResolver, tree: DocumentFile, displayName: String) : Boolean {
val document = tree.createFile("text/csv", displayName) ?: return false
val outputStream = contentResolver.openOutputStream(document.uri) ?: return false
writer = PrintWriter(outputStream)
writer.println("timestamp,provider,longitude,latitude,altitude,bearing,speed,accuracy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package labs.lucka.refrain.service.appender
import android.content.ContentResolver
import android.location.Location
import androidx.documentfile.provider.DocumentFile
import java.time.ZonedDateTime

interface FileAppender {

Expand All @@ -23,6 +22,6 @@ interface FileAppender {

fun append(location: Location)
fun finish()
fun prepare(contentResolver: ContentResolver, tree: DocumentFile, dateTime: ZonedDateTime): Boolean
fun prepare(contentResolver: ContentResolver, tree: DocumentFile, displayName: String): Boolean
fun split()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.documentfile.provider.DocumentFile
import java.io.PrintWriter
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.*

Expand All @@ -30,17 +29,17 @@ class GPXFileAppender : FileAppender {
writer.close()
}

override fun prepare(contentResolver: ContentResolver, tree: DocumentFile, dateTime: ZonedDateTime) : Boolean {
val timestamp = dateTime.toInstant().toEpochMilli()
override fun prepare(contentResolver: ContentResolver, tree: DocumentFile, displayName: String) : Boolean {
val now = LocalDateTime.now().atZone(ZoneId.systemDefault())
// The MIME type will not be recognized correctly
val document = tree
.createFile("application/gpx+xml", "$timestamp.gpx") ?: return false
.createFile("application/gpx+xml", "$displayName.gpx") ?: return false
val outputStream = contentResolver.openOutputStream(document.uri) ?: return false
writer = PrintWriter(outputStream)
writer.println("""<?xml version="1.0" encoding="UTF-8"?>""")
writer.println("""<gpx xmlns="http://www.topografix.com/GPX/1/1">""")
writer.println(""" <metadata>""")
writer.println(""" <time>${dateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)}</time>""")
writer.println(""" <time>${now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)}</time>""")
writer.println(""" </metadata>""")
writer.println(""" <trk>""")
writer.println(""" <trkseg>""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.ContentResolver
import android.location.Location
import androidx.documentfile.provider.DocumentFile
import java.io.PrintWriter
import java.time.ZonedDateTime

class KMLFileAppender : FileAppender {
override fun append(location: Location) {
Expand All @@ -21,16 +20,15 @@ class KMLFileAppender : FileAppender {
writer.close()
}

override fun prepare(contentResolver: ContentResolver, tree: DocumentFile, dateTime: ZonedDateTime) : Boolean {
val timestamp = dateTime.toInstant().toEpochMilli()
override fun prepare(contentResolver: ContentResolver, tree: DocumentFile, displayName: String) : Boolean {
val document = tree
.createFile("application/vnd.google-earth.kml+xml", "$timestamp") ?: return false
.createFile("application/vnd.google-earth.kml+xml", displayName) ?: return false
val outputStream = contentResolver.openOutputStream(document.uri) ?: return false
writer = PrintWriter(outputStream)
writer.println("""<?xml version="1.0" encoding="UTF-8"?>""")
writer.println("""<kml xmlns="http://www.opengis.net/kml/2.2">""")
writer.println(""" <Document>""")
writer.println(""" <name>$timestamp.kml</name>""")
writer.println(""" <name>$displayName.kml</name>""")
writer.println(""" <Placemark>""")
writer.println(""" <LineString>""")
writer.println(""" <coordinates>""")
Expand Down
34 changes: 28 additions & 6 deletions app/src/main/java/labs/lucka/refrain/ui/card/OutputPathCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
Expand All @@ -20,10 +21,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.documentfile.provider.DocumentFile
import labs.lucka.refrain.R
import labs.lucka.refrain.common.preferences.Keys
import labs.lucka.refrain.ui.compose.Label
import labs.lucka.refrain.ui.compose.rememberPreference
import java.net.URLDecoder

@Composable
fun OutputPathCard(mutable: Boolean) {
Expand All @@ -48,12 +51,31 @@ fun OutputPathCard(mutable: Boolean) {
Icons.Filled.Folder,
style = MaterialTheme.typography.titleLarge
)
Text(text = path.ifEmpty { stringResource(R.string.output_path_description) })
if (mutable) {
TextButton(onClick = { documentTreeLauncher.launch(Uri.parse(path)) }) {
Text(
stringResource(if (path.isEmpty()) R.string.output_path_select else R.string.output_path_change)
)
if (path.isEmpty()) {
Text(text = stringResource(R.string.output_path_description))
} else {
val decodedPath = URLDecoder.decode(path, "UTF-8")
Text(text = decodedPath.substring(decodedPath.lastIndexOf(':') + 1))
}
Row {
if (path.isNotEmpty()) {
TextButton(
onClick = {
val tree = DocumentFile.fromTreeUri(context, Uri.parse(path)) ?: return@TextButton
val intent = Intent(Intent.ACTION_VIEW, tree.uri)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
) {
Text(stringResource(R.string.output_path_open))
}
}
if (mutable) {
TextButton(onClick = { documentTreeLauncher.launch(Uri.parse(path)) }) {
Text(
stringResource(if (path.isEmpty()) R.string.output_path_select else R.string.output_path_change)
)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<string name="output_format_gpx">GPX</string>
<string name="output_format_kml">KML</string>
<string name="output_path">输出目录</string>
<string name="output_path_open">打开</string>
<string name="output_path_description">请选择Refrain保存轨迹文件的目录。</string>
<string name="output_path_select">选择</string>
<string name="output_path_change">更改</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<string name="output_path">Output Path</string>
<string name="output_path_description">Please selected a folder to where Refrain saves the trace files.</string>
<string name="output_path_open">Open</string>
<string name="output_path_select">Select</string>
<string name="output_path_change">Change</string>

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
org.gradle.unsafe.configuration-cache=tue
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jan 20 23:37:28 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 5ffdf13

Please sign in to comment.