Skip to content

Commit

Permalink
add: add string resources
Browse files Browse the repository at this point in the history
mod: sql query format
del: require guide from readme
mod: cmd in ci/cd
mod: ignore folding when content is small enough
mod: replace goAsync to processLifecycleScope
  • Loading branch information
joeloewi7178 committed Dec 21, 2023
1 parent 53fc9e0 commit 143960e
Show file tree
Hide file tree
Showing 20 changed files with 354 additions and 218 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ jobs:
target: google_apis
arch: x86_64
emulator-build: 9322596
script: ./gradlew :benchmark:connectedBenchmarkAndroidTest -P android.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile

- name: Move generated baseline profile to target folder
run: mv -f './benchmark/build/outputs/connected_android_test_additional_output/benchmark/connected/baselineProfGenerator(AVD) - 13/BaselineProfileGenerator_generate-baseline-prof.txt' ./app/src/main/baseline-prof.txt

- name: Check baseline-prof file status
run: stat ./app/src/main/baseline-prof.txt

- name: View some lines of baseline-prof file
run: head ./app/src/main/baseline-prof.txt
script: ./gradlew :app:generateBaselineProfile

- name: Build with Gradle
run: ./gradlew assemble
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@ An android app that can attend HoYoLAB check-in events automatically

- Clean Architecture
- MVVM

# Before Build & Run

This project uses firebase and not contains *google-services.json* file because it's a server key.
There will be errors if you only cloned and run it, so you have to get *google-services.json* from
your own firebase project and put in to cloned project directory.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.AlarmManagerCompat
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.work.Constraints
import androidx.work.ExistingWorkPolicy
import androidx.work.NetworkType
Expand All @@ -19,19 +21,28 @@ import com.google.firebase.crashlytics.crashlytics
import com.joeloewi.croissant.BuildConfig
import com.joeloewi.croissant.domain.usecase.AttendanceUseCase
import com.joeloewi.croissant.util.canScheduleExactAlarmsCompat
import com.joeloewi.croissant.util.goAsync
import com.joeloewi.croissant.util.pendingIntentFlagUpdateCurrent
import com.joeloewi.croissant.worker.AttendCheckInEventWorker
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import java.time.ZoneId
import java.time.ZonedDateTime
import javax.inject.Inject

@AndroidEntryPoint
class AlarmReceiver : BroadcastReceiver() {
private val _coroutineContext = Dispatchers.IO + CoroutineExceptionHandler { _, throwable ->
Firebase.crashlytics.apply {
log(this@AlarmReceiver.javaClass.simpleName)
recordException(throwable)
}
}
private val _processLifecycleScope by lazy { ProcessLifecycleOwner.get().lifecycleScope }

@Inject
lateinit var application: Application

Expand All @@ -47,15 +58,7 @@ class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(p0: Context, p1: Intent) {
when (p1.action) {
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED, AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED -> {
goAsync(
onError = { cause ->
Firebase.crashlytics.apply {
log(this@AlarmReceiver.javaClass.simpleName)
recordException(cause)
}
},
coroutineContext = Dispatchers.IO
) {
_processLifecycleScope.launch(_coroutineContext) {
getAllOneShotAttendanceUseCase().map { attendance ->
async(Dispatchers.IO) {
attendance.runCatching {
Expand Down Expand Up @@ -114,15 +117,7 @@ class AlarmReceiver : BroadcastReceiver() {
RECEIVE_ATTEND_CHECK_IN_ALARM -> {
val attendanceId = p1.getLongExtra(ATTENDANCE_ID, Long.MIN_VALUE)

goAsync(
onError = { cause ->
Firebase.crashlytics.apply {
log(this@AlarmReceiver.javaClass.simpleName)
recordException(cause)
}
},
coroutineContext = Dispatchers.IO
) {
_processLifecycleScope.launch(_coroutineContext) {
val attendanceWithGames = getOneAttendanceUseCase(attendanceId)
val attendance = attendanceWithGames.attendance
val oneTimeWork = OneTimeWorkRequestBuilder<AttendCheckInEventWorker>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ import android.app.Application
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.work.WorkManager
import com.google.firebase.Firebase
import com.google.firebase.crashlytics.crashlytics
import com.joeloewi.croissant.domain.usecase.AttendanceUseCase
import com.joeloewi.croissant.domain.usecase.ResinStatusWidgetUseCase
import com.joeloewi.croissant.util.goAsync
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class MigrationHelper : BroadcastReceiver() {
private val _coroutineContext = Dispatchers.IO + CoroutineExceptionHandler { _, throwable ->
Firebase.crashlytics.apply {
log(this@MigrationHelper.javaClass.simpleName)
recordException(throwable)
}
}
private val _processLifecycleScope by lazy { ProcessLifecycleOwner.get().lifecycleScope }

@Inject
lateinit var application: Application
Expand All @@ -34,15 +44,7 @@ class MigrationHelper : BroadcastReceiver() {
override fun onReceive(p0: Context, p1: Intent) {
when (p1.action) {
Intent.ACTION_MY_PACKAGE_REPLACED -> {
goAsync(
onError = { cause ->
Firebase.crashlytics.apply {
log(this@MigrationHelper.javaClass.simpleName)
recordException(cause)
}
},
coroutineContext = Dispatchers.IO
) {
_processLifecycleScope.launch(_coroutineContext) {
//because work manager's job can be deferred, cancel check in event worker
//instead of work manager, use alarm manager
getAllOneShotAttendanceUseCase().map { attendance ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.google.firebase.Firebase
import com.google.firebase.crashlytics.crashlytics
import com.joeloewi.croissant.R
import com.joeloewi.croissant.domain.usecase.ResinStatusWidgetUseCase
import com.joeloewi.croissant.util.isIgnoringBatteryOptimizationsCompat
Expand All @@ -35,6 +37,13 @@ import javax.inject.Inject

@AndroidEntryPoint
class ResinStatusWidgetProvider : AppWidgetProvider() {
private val _coroutineContext = Dispatchers.IO + CoroutineExceptionHandler { _, throwable ->
Firebase.crashlytics.apply {
log(this@ResinStatusWidgetProvider.javaClass.simpleName)
recordException(throwable)
}
}
private val _processLifecycleScope by lazy { ProcessLifecycleOwner.get().lifecycleScope }

@Inject
lateinit var powerManager: PowerManager
Expand All @@ -58,7 +67,7 @@ class ResinStatusWidgetProvider : AppWidgetProvider() {
super.onUpdate(context, appWidgetManager, appWidgetIds)
//this method also called when user put widget on home screen

_processLifecycleOwner.lifecycleScope.launch(Dispatchers.IO + CoroutineExceptionHandler { _, _ -> }) {
_processLifecycleOwner.lifecycleScope.launch(_coroutineContext) {
appWidgetIds.map { appWidgetId ->
async(Dispatchers.IO) {
if (powerManager.isPowerSaveMode && !powerManager.isIgnoringBatteryOptimizationsCompat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ private fun AttendanceDetailContent(
}
}

LaunchedEffect(Unit) {
snapshotFlow(updateAttendanceState).catch { }.collect {
when (it) {
is Lce.Content -> {
if (it.content != null) {
onNavigateUp()
}
}

else -> {

}
}
}
}

Scaffold(
topBar = {
TopAppBar(
Expand Down Expand Up @@ -410,8 +426,7 @@ private fun AttendanceDetailContent(
Text(text = stringResource(id = R.string.alert))
},
text = {
//TODO: add text resources
Text(text = stringResource(id = R.string.logs_deleted))
Text(text = stringResource(id = R.string.confirm_delete_attendance_job))
},
confirmButton = {
TextButton(onClick = onConfirmDelete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

const val COOKIE = "cookie"
Expand Down Expand Up @@ -297,12 +296,10 @@ fun LoginHoYoLABContent(
onCurrentCookieChange(cookie)
}

return runBlocking(Dispatchers.IO) {
super.shouldInterceptRequest(
view,
request
)
}
return super.shouldInterceptRequest(
view,
request
)
}

override fun shouldOverrideUrlLoading(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import com.joeloewi.croissant.R
import com.joeloewi.croissant.ui.theme.DefaultDp
import com.joeloewi.croissant.ui.theme.DoubleDp
import com.joeloewi.croissant.util.CroissantPermission
import com.joeloewi.croissant.util.SpecialPermission
import com.joeloewi.croissant.util.rememberSpecialPermissionState
import com.joeloewi.croissant.viewmodel.FirstLaunchViewModel
import kotlinx.coroutines.Dispatchers
Expand All @@ -93,15 +94,7 @@ private fun FirstLaunchContent(
) {
val context = LocalContext.current
val scheduleExactAlarmPermissionState =
rememberSpecialPermissionState(
permission = "android:schedule_exact_alarm",
intentForRequestPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)
} else {
//this intent won't be launched
Intent()
}
)
rememberSpecialPermissionState(specialPermission = SpecialPermission.ScheduleExactAlarms)
val multiplePermissionsState = rememberMultiplePermissionsState(
permissions = listOf(
CroissantPermission.AccessHoYoLABSession.permission,
Expand Down
Loading

0 comments on commit 143960e

Please sign in to comment.