Skip to content

Commit

Permalink
Merge pull request #377 from joeloewi7178/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
joeloewi7178 authored Mar 12, 2024
2 parents ee601ea + 135a22c commit 7a87121
Show file tree
Hide file tree
Showing 70 changed files with 1,301 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_push_development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v4.1.1

- name: set up JDK 17
uses: actions/setup-java@v4.0.0
uses: actions/setup-java@v4.1.0
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'
Expand Down
9 changes: 6 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ plugins {
alias(libs.plugins.croissant.android.hilt)
alias(libs.plugins.croissant.android.application.firebase)
id("kotlin-parcelize")
id("com.google.android.gms.oss-licenses-plugin")
id(libs.plugins.gms.oss.licenses.plugin.get().pluginId)
alias(libs.plugins.androidx.baselineprofile)
id(libs.plugins.kotlinx.atomicfu.get().pluginId)
}

kotlin {
Expand All @@ -20,8 +21,8 @@ android {

defaultConfig {
applicationId = "com.joeloewi.croissant"
versionCode = 58
versionName = "1.2.8"
versionCode = 59
versionName = "1.3.0"
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -156,4 +157,6 @@ dependencies {
implementation(libs.gms.play.services.oss.licenses)

implementation(libs.fornewid.placeholder.material3)

implementation(libs.kotlinx.atomicfu)
}
28 changes: 16 additions & 12 deletions app/src/main/kotlin/com/joeloewi/croissant/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.os.bundleOf
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
Expand Down Expand Up @@ -105,10 +104,8 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

Expand All @@ -124,15 +121,22 @@ class MainActivity : AppCompatActivity() {
enableEdgeToEdge()

lifecycleScope.launch(CoroutineExceptionHandler { _, _ -> }) {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
_mainActivityViewModel.darkThemeEnabled.onEach { darkThemeEnabled ->
if (darkThemeEnabled) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
_mainActivityViewModel.darkThemeEnabled.flowWithLifecycle(lifecycle)
.flowOn(Dispatchers.IO).collect {
when (it) {
is LCE.Content -> {
if (it.content) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}

else -> {

}
}
}.collect()
}
}
}

lifecycleScope.launch(Dispatchers.IO + CoroutineExceptionHandler { _, _ -> }) {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/kotlin/com/joeloewi/croissant/di/EntryPoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.joeloewi.croissant.di

import android.content.Context
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.RunnableScheduler
import coil.ImageLoader
import com.joeloewi.croissant.data.di.DefaultDispatcherExecutor
import com.joeloewi.croissant.util.NotificationGenerator
Expand All @@ -37,7 +36,6 @@ interface InitializerEntryPoint {

@DefaultDispatcherExecutor
fun executor(): Executor
fun runnableScheduler(): RunnableScheduler
fun notificationGenerator(): NotificationGenerator
}

Expand Down
7 changes: 0 additions & 7 deletions app/src/main/kotlin/com/joeloewi/croissant/di/UtilModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.joeloewi.croissant.di
import android.content.Context
import android.os.Build
import android.text.format.DateFormat
import androidx.work.RunnableScheduler
import androidx.work.WorkManager
import coil.ImageLoader
import coil.decode.GifDecoder
Expand All @@ -18,7 +17,6 @@ import com.joeloewi.croissant.util.AlarmScheduler
import com.joeloewi.croissant.util.NotificationGenerator
import com.joeloewi.croissant.util.TextToSpeechFactory
import com.joeloewi.croissant.util.impl.AlarmSchedulerImpl
import com.joeloewi.croissant.util.impl.RunnableSchedulerImpl
import dagger.Binds
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -88,11 +86,6 @@ object UtilModule {
@Module
@InstallIn(SingletonComponent::class)
abstract class UtilModuleForBind {
@Singleton
@Binds
abstract fun bindRunnableScheduler(
runnableSchedulerImpl: RunnableSchedulerImpl
): RunnableScheduler

@Singleton
@Binds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ class WorkManagerInitializer : Initializer<WorkManager> {
val initializerEntryPoint: InitializerEntryPoint by context.entryPoints()
val hiltWorkerFactory = initializerEntryPoint.hiltWorkerFactory()
val executor = initializerEntryPoint.executor()
val runnableScheduler = initializerEntryPoint.runnableScheduler()

WorkManager.initialize(
context,
Configuration.Builder()
.setWorkerFactory(hiltWorkerFactory)
.setExecutor(executor)
.setTaskExecutor(executor)
.setRunnableScheduler(runnableScheduler)
.build()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ class AlarmReceiver : BroadcastReceiver() {
val attendanceId = p1.getLongExtra(ATTENDANCE_ID, Long.MIN_VALUE)
val attendanceWithGames = getOneAttendanceUseCase(attendanceId)
val attendance = attendanceWithGames.attendance
val oneTimeWork = AttendCheckInEventWorker.buildOneTimeWork(
attendanceId = attendance.id
)
val oneTimeWork =
AttendCheckInEventWorker.buildOneTimeWork(attendanceId = attendance.id)

workManager.beginUniqueWork(
attendance.oneTimeAttendCheckInEventWorkerName.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,8 @@ fun AttendanceWithGamesItem(
{ attendance ->
Firebase.analytics.logEvent("instant_attend_click", bundleOf())

val oneTimeWork = AttendCheckInEventWorker.buildOneTimeWork(
attendanceId = attendance.id
)
val oneTimeWork =
AttendCheckInEventWorker.buildOneTimeWork(attendanceId = attendance.id)

WorkManager.getInstance(context).beginUniqueWork(
attendance.oneTimeAttendCheckInEventWorkerName.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@ import android.os.Build
import android.os.Message
import android.view.View
import android.view.ViewGroup
import android.webkit.*
import androidx.compose.foundation.layout.*
import android.webkit.ConsoleMessage
import android.webkit.CookieManager
import android.webkit.SslErrorHandler
import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebSettings
import android.webkit.WebStorage
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.*
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -42,7 +69,12 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
import com.google.accompanist.web.*
import com.google.accompanist.web.AccompanistWebChromeClient
import com.google.accompanist.web.AccompanistWebViewClient
import com.google.accompanist.web.LoadingState
import com.google.accompanist.web.WebView
import com.google.accompanist.web.rememberWebViewNavigator
import com.google.accompanist.web.rememberWebViewState
import com.joeloewi.croissant.BuildConfig
import com.joeloewi.croissant.R
import com.joeloewi.croissant.state.ILCE
Expand Down Expand Up @@ -212,19 +244,25 @@ fun LoginHoYoLABContent(
}
},
title = {
Column {
Column(
modifier = Modifier
.fillMaxWidth()
.animateContentSize()
) {
Text(
text = webViewState.pageTitle ?: "Title",
style = MaterialTheme.typography.titleMedium,
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
Text(
text = webViewState.lastLoadedUrl ?: "",
style = MaterialTheme.typography.bodyMedium,
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
if (!webViewState.lastLoadedUrl.isNullOrEmpty()) {
Text(
text = webViewState.lastLoadedUrl ?: "",
style = MaterialTheme.typography.bodyMedium,
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
}
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -47,17 +43,21 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.contentColorFor
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -85,6 +85,9 @@ import io.github.fornewid.placeholder.foundation.PlaceholderHighlight
import io.github.fornewid.placeholder.foundation.fade
import io.github.fornewid.placeholder.foundation.placeholder
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOn

@Composable
fun RedemptionCodesScreen(
Expand All @@ -102,7 +105,7 @@ fun RedemptionCodesScreen(

@OptIn(
ExperimentalMaterial3Api::class,
ExperimentalMaterialApi::class, ExperimentalFoundationApi::class
ExperimentalFoundationApi::class
)
@Composable
private fun RedemptionCodesContent(
Expand All @@ -111,10 +114,33 @@ private fun RedemptionCodesContent(
onRefresh: () -> Unit
) {
val snackbarHostState = remember { SnackbarHostState() }
val pullRefreshState = rememberPullRefreshState(
refreshing = hoYoLABGameRedemptionCodesState().isLoading,
onRefresh = onRefresh
)
val pullToRefreshState = rememberPullToRefreshState()

LaunchedEffect(Unit) {
snapshotFlow { pullToRefreshState.isRefreshing }.flowOn(Dispatchers.IO).catch { }
.collect { isRefreshing ->
if (isRefreshing) {
onRefresh()
}
}
}

LaunchedEffect(pullToRefreshState) {
snapshotFlow { hoYoLABGameRedemptionCodesState() }.flowOn(Dispatchers.IO).catch { }
.collect {
when (it) {
LCE.Loading -> {

}

else -> {
if (pullToRefreshState.isRefreshing) {
pullToRefreshState.endRefresh()
}
}
}
}
}

Scaffold(
snackbarHost = {
Expand All @@ -133,7 +159,7 @@ private fun RedemptionCodesContent(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.pullRefresh(pullRefreshState)
.nestedScroll(pullToRefreshState.nestedScrollConnection)
) {
LazyColumn(
modifier = Modifier
Expand Down Expand Up @@ -212,12 +238,9 @@ private fun RedemptionCodesContent(
}
}

PullRefreshIndicator(
refreshing = hoYoLABGameRedemptionCodesState().isLoading,
state = pullRefreshState,
PullToRefreshContainer(
modifier = Modifier.align(Alignment.TopCenter),
backgroundColor = MaterialTheme.colorScheme.surface,
contentColor = contentColorFor(backgroundColor = MaterialTheme.colorScheme.surface)
state = pullToRefreshState
)
}
}
Expand Down
Loading

0 comments on commit 7a87121

Please sign in to comment.