Skip to content

Commit

Permalink
build: Updated libraries, collections, new backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Sep 23, 2022
1 parent f0cbfc1 commit d27a1b0
Show file tree
Hide file tree
Showing 71 changed files with 392 additions and 351 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

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

15 changes: 0 additions & 15 deletions .idea/git_toolbox_prj.xml

This file was deleted.

8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
plugins {
id(Plugins.APPLICATION)
id(Plugins.KOTLIN_ANDROID)
id(Plugins.SERIALIZATION)
id(Plugins.ABOUT_LIBRARIES)
}

Expand All @@ -39,8 +40,8 @@ android {
applicationId = App.APP_ID

//have to be specified explicitly for FDroid to work
versionCode = 1020000 // 1x major . 2x minor . 2x path . 2x build diff
versionName = "1.2.0"
versionCode = 1020100 // 1x major . 2x minor . 2x path . 2x build diff
versionName = "1.2.1"
require(versionCode == App.VERSION_CODE)
require(versionName == App.VERSION_NAME)

Expand Down Expand Up @@ -102,6 +103,7 @@ android {
composeOptions {
kotlinCompilerExtensionVersion = Versions.COMPOSE_COMPILER
}
namespace = "cz.lastaapps.menza"
}

dependencies {
Expand Down Expand Up @@ -134,6 +136,8 @@ dependencies {
initCompose()

implementation(Libs.KOTLINX_DATETIME)
implementation(Libs.KOTLINX_COLLECTION)
implementation(Libs.KOTLIN_SERIALIZATION_JSON)
implementation(Libs.COIL_COMPOSE_COMPLETE)
implementation(Libs.ABOUT_LIBRARIES_CORE)

Expand Down
40 changes: 39 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,42 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
-renamesourcefileattribute SourceFile
-renamesourcefileattribute SourceFile


# Kodein
-keep, allowobfuscation, allowoptimization class org.kodein.type.TypeReference
-keep, allowobfuscation, allowoptimization class org.kodein.type.JVMAbstractTypeToken$Companion$WrappingTest

-keep, allowobfuscation, allowoptimization class * extends org.kodein.type.TypeReference
-keep, allowobfuscation, allowoptimization class * extends org.kodein.type.JVMAbstractTypeToken$Companion$WrappingTest



# Serialization
# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="cz.lastaapps.menza">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/cz/lastaapps/menza/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class App : Application(), ImageLoaderFactory, DIAware {
memoryCachePolicy(CachePolicy.ENABLED)
networkCachePolicy(CachePolicy.ENABLED)
networkObserverEnabled(true)
logger(DebugLogger())
if (BuildConfig.DEBUG)
logger(DebugLogger())
diskCache {
with(DiskCache.Builder()) {
maxSizeBytes(1024 * 1024 * 32) // 32 MB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ import cz.lastaapps.entity.info.Email
import cz.lastaapps.entity.info.PhoneNumber
import cz.lastaapps.menza.R
import cz.lastaapps.menza.ui.root.locals.LocalSnackbarProvider
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.launch

@Composable
fun ContactList(
contact: List<Contact>,
contact: ImmutableList<Contact>,
modifier: Modifier = Modifier,
) {
if (contact.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import cz.lastaapps.entity.menza.MenzaId
import cz.lastaapps.entity.menza.MenzaLocation
import cz.lastaapps.entity.menza.Message
import cz.lastaapps.storage.repo.*
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -78,19 +80,19 @@ class InfoViewModel constructor(
}
}

fun getMessage(menzaId: MenzaId): Flow<List<Message>> {
return messageRepo.getMessage(menzaId)
fun getMessage(menzaId: MenzaId): Flow<ImmutableList<Message>> {
return messageRepo.getMessage(menzaId).map { it.toImmutableList() }
}

fun getContacts(menzaId: MenzaId): Flow<List<Contact>> {
return contactsRepo.getContactsForMenza(menzaId)
fun getContacts(menzaId: MenzaId): Flow<ImmutableList<Contact>> {
return contactsRepo.getContactsForMenza(menzaId).map { it.toImmutableList() }
}

fun getLocation(menzaId: MenzaId): Flow<List<MenzaLocation>> {
return locationRepo.getMenzaLocation(menzaId)
fun getLocation(menzaId: MenzaId): Flow<ImmutableList<MenzaLocation>> {
return locationRepo.getMenzaLocation(menzaId).map { it.toImmutableList() }
}

fun getOpeningHours(menzaId: MenzaId): Flow<List<OpeningLocation>> {
fun getOpeningHours(menzaId: MenzaId): Flow<ImmutableList<OpeningLocation>> {
return openingHoursRepo.getForMenza(menzaId).map { input ->
val places = mutableMapOf<String, MutableList<OpeningHours>>()
input.forEach {
Expand Down Expand Up @@ -133,8 +135,8 @@ class InfoViewModel constructor(
}
}
combined.map { pair ->
OpeningLocation(pair.first, pair.second)
OpeningLocation(pair.first, pair.second.toImmutableList())
}
}
}.map { it.toImmutableList() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ import cz.lastaapps.entity.menza.Coordinates
import cz.lastaapps.entity.menza.MenzaLocation
import cz.lastaapps.menza.R
import cz.lastaapps.menza.ui.root.locals.LocalSnackbarProvider
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.launch

@Composable
fun AddressList(
locations: List<MenzaLocation>,
locations: ImmutableList<MenzaLocation>,
modifier: Modifier = Modifier,
) {
if (locations.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cz.lastaapps.entity.menza.Message
import cz.lastaapps.menza.R
import kotlinx.collections.immutable.ImmutableList

@Composable
fun MessageList(
messages: List<Message>,
messages: ImmutableList<Message>,
modifier: Modifier = Modifier,
) {
if (messages.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cz.lastaapps.entity.LocalTime
import cz.lastaapps.menza.R
import kotlinx.collections.immutable.ImmutableList
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalTime
import kotlinx.datetime.toJavaLocalTime
import java.time.format.DateTimeFormatter
import java.time.format.TextStyle
import java.util.*

@Composable
fun OpeningHoursList(
data: List<OpeningLocation>,
data: ImmutableList<OpeningLocation>,
modifier: Modifier = Modifier,
) {
if (data.isNotEmpty()) {
Expand Down Expand Up @@ -96,8 +98,8 @@ fun OpeningHoursLocationUI(
}
Column {
data.list.forEach {
val start = it.startTime.toJavaLocalDate().format(formatter)
val end = it.endTime.toJavaLocalDate().format(formatter)
val start = it.startTime.toJavaLocalTime().format(formatter)
val end = it.endTime.toJavaLocalTime().format(formatter)
Text("$start - $end")
}
}
Expand All @@ -111,10 +113,6 @@ fun OpeningHoursLocationUI(
}
}

private fun LocalTime.toJavaLocalDate(): java.time.LocalTime {
return java.time.LocalTime.of(hours, minutes, seconds)
}

data class OpeningInterval(
val startDay: DayOfWeek,
val endDay: DayOfWeek,
Expand All @@ -123,4 +121,4 @@ data class OpeningInterval(
val comment: String?,
)

data class OpeningLocation(val name: String, val list: List<OpeningInterval>)
data class OpeningLocation(val name: String, val list: ImmutableList<OpeningInterval>)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import cz.lastaapps.menza.BuildConfig
import cz.lastaapps.menza.R
import cz.lastaapps.menza.ui.dests.others.ReportDialog
import cz.lastaapps.menza.ui.dests.others.sendReport
import kotlinx.collections.immutable.ImmutableList
import java.time.format.DateTimeFormatter

@Composable
Expand Down Expand Up @@ -100,7 +101,10 @@ private fun NoContent() {
}

@Composable
private fun Content(crashes: List<Pair<Long, Crash>>, onItemSelected: (Pair<Long, Crash>) -> Unit) {
private fun Content(
crashes: ImmutableList<Pair<Long, Crash>>,
onItemSelected: (Pair<Long, Crash>) -> Unit
) {
Text(
stringResource(R.string.crash_title),
style = MaterialTheme.typography.headlineMedium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import cz.lastaapps.crash.CrashDatabase
import cz.lastaapps.crash.entity.Crash
import cz.lastaapps.crash.entity.ErrorSeverity
import cz.lastaapps.crash.entity.ReportState
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -39,11 +42,11 @@ class CrashesViewModel constructor(
private val database: CrashDatabase,
) : ViewModel() {

val errors: StateFlow<List<Pair<Long, Crash>>> get() = mErrors
private val mErrors = MutableStateFlow<List<Pair<Long, Crash>>>(emptyList())
val errors: StateFlow<ImmutableList<Pair<Long, Crash>>> get() = mErrors
private val mErrors = MutableStateFlow<ImmutableList<Pair<Long, Crash>>>(persistentListOf())

val unreported: StateFlow<List<Pair<Long, Crash>>> get() = mUnreported
private val mUnreported = MutableStateFlow<List<Pair<Long, Crash>>>(emptyList())
val unreported: StateFlow<ImmutableList<Pair<Long, Crash>>> get() = mUnreported
private val mUnreported = MutableStateFlow<ImmutableList<Pair<Long, Crash>>>(persistentListOf())

val hasErrors: StateFlow<Boolean> get() = mHasErrors
private val mHasErrors = MutableStateFlow(false)
Expand All @@ -62,15 +65,15 @@ class CrashesViewModel constructor(
database.crashQueries.getCrashes() { id: Long, date: ZonedDateTime, severity: ErrorSeverity, message: String?, trace: String, reported: ReportState ->
id to Crash(date, severity, message, trace, reported)
}.asFlow().mapToList(coroutineContext).collectLatest {
mErrors.emit(it)
mErrors.emit(it.toImmutableList())
mHasErrors.emit(it.isNotEmpty())
}
}
viewModelScope.launch(Dispatchers.IO) {
database.crashQueries.getUnreported { id: Long, date: ZonedDateTime, severity: ErrorSeverity, message: String?, trace: String, reported: ReportState ->
id to Crash(date, severity, message, trace, reported)
}.asFlow().mapToList(coroutineContext).collectLatest {
mUnreported.emit(it)
mUnreported.emit(it.toImmutableList())
}
}
viewModelScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.entity.Library
import cz.lastaapps.menza.R
import kotlinx.collections.immutable.ImmutableList
import org.lighthousegames.logging.logging

@Composable
fun LibraryList(
libraries: List<Library>,
libraries: ImmutableList<Library>,
onLibrarySelected: (Library?) -> Unit,
modifier: Modifier = Modifier,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import com.mikepenz.aboutlibraries.util.withContext
import cz.lastaapps.menza.ui.root.UseSplitLayout
import cz.lastaapps.menza.ui.root.locals.LocalWindowWidth
import cz.lastaapps.menza.ui.root.locals.WindowSizeClass
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

@Composable
fun LicenseLayout() {
Expand All @@ -57,7 +59,7 @@ fun LicenseLayout() {

val libraryList = remember(libraries) {
// to filter out wrongly named libraries
libraries!!.libraries.filter { !it.name.startsWith("$") }
libraries!!.libraries.filter { !it.name.startsWith("$") }.toImmutableList()
}

when (LocalWindowWidth.current) {
Expand Down Expand Up @@ -87,7 +89,7 @@ fun LicenseLayout() {

@Composable
fun LicenseLayoutCompact(
libraries: List<Library>,
libraries: ImmutableList<Library>,
selectedLibrary: Library?,
onLibrarySelected: (Library?) -> Unit,
) {
Expand All @@ -108,7 +110,7 @@ fun LicenseLayoutCompact(

@Composable
fun LicenseLayoutMedium(
libraries: List<Library>,
libraries: ImmutableList<Library>,
selectedLibrary: Library?,
onLibrarySelected: (Library?) -> Unit,
) = LicenseLayoutExpanded(
Expand All @@ -119,7 +121,7 @@ fun LicenseLayoutMedium(

@Composable
fun LicenseLayoutExpanded(
libraries: List<Library>,
libraries: ImmutableList<Library>,
selectedLibrary: Library?,
onLibrarySelected: (Library?) -> Unit,
) {
Expand Down
Loading

0 comments on commit d27a1b0

Please sign in to comment.