Skip to content

Commit

Permalink
Update night work :))
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeMeow1027 committed Sep 22, 2024
1 parent 9eeef73 commit 76830a5
Show file tree
Hide file tree
Showing 83 changed files with 718 additions and 422 deletions.
24 changes: 24 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.

68 changes: 43 additions & 25 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ android {
vectorDrawables {
useSupportLibrary true
}

// Support for Java 8 with kotlinx.datetime
// https://github.com/Kotlin/kotlinx-datetime/issues/48
// Required when setting minSdkVersion to 20 or lower
multiDexEnabled true
}

buildTypes {
Expand All @@ -31,11 +36,14 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 11
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = '11'
}
buildFeatures {
buildConfig true
Expand All @@ -55,39 +63,43 @@ android {

dependencies {
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.5'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.6'
implementation 'androidx.activity:activity-compose:1.9.2'
implementation platform('androidx.compose:compose-bom:2024.09.00')
implementation "androidx.compose.ui:ui:1.7.0"
implementation "androidx.compose.ui:ui-tooling-preview:1.7.0"
implementation platform('androidx.compose:compose-bom:2024.09.00')
implementation platform('androidx.compose:compose-bom:2024.09.02')
implementation "androidx.compose.ui:ui:1.7.2"
implementation "androidx.compose.ui:ui-tooling-preview:1.7.2"
implementation platform('androidx.compose:compose-bom:2024.09.02')
implementation 'androidx.compose.ui:ui-graphics'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation platform('androidx.compose:compose-bom:2024.09.00')
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.7.0"
androidTestImplementation platform('androidx.compose:compose-bom:2024.09.00')
debugImplementation "androidx.compose.ui:ui-tooling:1.7.0"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.7.0"
androidTestImplementation platform('androidx.compose:compose-bom:2024.09.02')
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.7.2"
androidTestImplementation platform('androidx.compose:compose-bom:2024.09.02')
debugImplementation "androidx.compose.ui:ui-tooling:1.7.2"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.7.2"
implementation "androidx.appcompat:appcompat:1.7.0"
implementation "androidx.appcompat:appcompat-resources:1.7.0"

// https://mvnrepository.com/artifact/androidx.core/core-splashscreen
implementation 'androidx.core:core-splashscreen:1.2.0-alpha02'

// https://mvnrepository.com/artifact/androidx.navigation/navigation-compose
implementation 'androidx.navigation:navigation-compose:2.8.0'
implementation 'androidx.navigation:navigation-compose:2.8.1'

// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-ktx
runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.5'
runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6'

// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-compose
runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5'
runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6'

// https://mvnrepository.com/artifact/androidx.fragment/fragment-ktx
runtimeOnly 'androidx.fragment:fragment-ktx:1.8.3'

// Material design
implementation 'com.google.android.material:material:1.12.0'

// Material 3 design
// https://mvnrepository.com/artifact/androidx.compose.material3/material3
implementation 'androidx.compose.material3:material3:1.3.0'

Expand All @@ -103,38 +115,44 @@ dependencies {
implementation 'com.google.dagger:hilt-android:2.51.1'
kapt 'com.google.dagger:hilt-compiler:2.51.1'

// Accompanist - Pull-to-refresh - https://mvnrepository.com/artifact/com.google.accompanist/accompanist-swiperefresh
// Accompanist - Pull-to-refresh
// https://mvnrepository.com/artifact/com.google.accompanist/accompanist-swiperefresh
implementation 'com.google.accompanist:accompanist-swiperefresh:0.33.2-alpha'

// Accompanist - Pager - https://mvnrepository.com/artifact/com.google.accompanist/accompanist-pager
// Accompanist - Pager
// https://mvnrepository.com/artifact/com.google.accompanist/accompanist-pager
// runtimeOnly 'com.google.accompanist:accompanist-pager:0.33.2-alpha'

// https://mvnrepository.com/artifact/com.google.accompanist/accompanist-pager-indicators
runtimeOnly 'com.google.accompanist:accompanist-pager-indicators:0.33.2-alpha'

// Jsoup HTML parser library - https://mvnrepository.com/artifact/org.jsoup/jsoup
// Jsoup HTML parser library
// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation 'org.jsoup:jsoup:1.18.1'

// Google Gson - https://mvnrepository.com/artifact/com.google.code.gson/gson
// Google Gson
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation 'com.google.code.gson:gson:2.11.0'

// Android Browser (use WebView in app) - https://mvnrepository.com/artifact/androidx.browser/browser
// Android Browser (use WebView in app)
// https://mvnrepository.com/artifact/androidx.browser/browser
implementation 'androidx.browser:browser:1.8.0'

// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.14'

implementation 'org.jetbrains.kotlinx:kotlinx-datetime:0.5.0'

implementation 'com.google.android.material:material:1.12.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2'

// Display time ago in news subject
implementation 'com.github.marlonlom:timeago:4.0.3'

// This implementation is from jitpack.io. We don't need this anymore.
// This implementation is from jitpack.io.
// implementation 'com.github.dutwrapper:dutwrapper-java:204328e7f2'
// Instead, use GitHub Packages with dutwrapper/dutwrapper-java package.
implementation 'io.dutwrapper:dutwrapper:1.11.1'
// An another option is use GitHub Packages with dutwrapper/dutwrapper-java package.
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'io.dutwrapper:dutwrapper:1.11.1-patch1'
}

// Allow references to generated code
Expand Down
Binary file added app/libs/dutwrapper-1.11.1-patch1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.zoemeow.dutschedule.activity

import android.content.Context
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand All @@ -22,6 +23,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.compose.viewModel
import io.zoemeow.dutschedule.di.LocaleService
import io.zoemeow.dutschedule.model.AppearanceState
import io.zoemeow.dutschedule.model.settings.BackgroundImageOption
import io.zoemeow.dutschedule.model.settings.ThemeMode
Expand All @@ -32,7 +34,6 @@ import io.zoemeow.dutschedule.viewmodel.MainViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch


abstract class BaseActivity: ComponentActivity() {
companion object {
private var mainViewModel: MainViewModel? = null
Expand Down Expand Up @@ -205,4 +206,14 @@ abstract class BaseActivity: ComponentActivity() {
snackBarHostState.currentSnackbarData?.dismiss()
}
}

override fun attachBaseContext(newBase: Context?) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
val lang = LocaleService.getCurrentLocaleTag(newBase!!)
val context1 = LocaleService.generateContextFromLocale(newBase, lang)
super.attachBaseContext(context1)
} else {
super.attachBaseContext(newBase)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import io.zoemeow.dutschedule.R
import io.zoemeow.dutschedule.model.AppearanceState
import io.zoemeow.dutschedule.ui.component.permissionrequest.PermissionInformation
import io.zoemeow.dutschedule.ui.view.permissionrequest.controls.PermissionInformation

class PermissionsActivity : BaseActivity() {
private val permissionStatusList = mutableStateListOf<PermissionCheckResult>()
Expand Down
105 changes: 105 additions & 0 deletions app/src/main/java/io/zoemeow/dutschedule/di/LocaleService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package io.zoemeow.dutschedule.di

import android.annotation.TargetApi
import android.app.LocaleManager
import android.content.Context
import android.content.res.Configuration
import android.os.Build
import android.os.Build.VERSION_CODES
import android.os.LocaleList
import android.util.Log
import io.zoemeow.dutschedule.R
import java.io.File
import java.util.Locale

object LocaleService {
fun generateContextFromLocale(context: Context, tag: String): Context {
val locale = Locale(tag)
Locale.setDefault(locale)
val configuration = Configuration(context.resources.configuration)
configuration.setLocale(locale)
configuration.setLayoutDirection(locale)
return context.createConfigurationContext(configuration)
}

fun getCurrentLocaleTag(context: Context, oldLangSelector: Boolean = false): String {
// Android 13 or later have built-in language selector.
val langTag = if (Build.VERSION.SDK_INT >= VERSION_CODES.TIRAMISU && !oldLangSelector) {
getLocaleSystem()
}
// Android 12 or lower, or, we force that.
else {
if (getLocaleFromPrefs(context).compareTo("auto") == 0) getLocaleSystem(true)
else getLocaleFromPrefs(context)
}
Log.d("Info", String.format("Selected language tag: %s", langTag))
return langTag
}

fun getCurrentLocaleDisplayName(context: Context): String {
// Android 13 or later have built-in language selector.
val langTag = if (Build.VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
Locale.getDefault().displayName
}
// Android 12 or lower
else {
if (getLocaleFromPrefs(context).compareTo("auto") == 0)
context.getString(R.string.settings_applanguage_yoursystemlang)
else Locale(getCurrentLocaleTag(context)).displayName
}
Log.d("Info", String.format("Selected language tag: %s", langTag))
return langTag
}


fun getSettingsLocaleTag(context: Context, oldLangSelector: Boolean = false): String {
// Android 13 or later have built-in language selector.
val langTag = if (Build.VERSION.SDK_INT >= VERSION_CODES.TIRAMISU && !oldLangSelector) {
getLocaleSystem()
}
// Android 12 or lower, or, we force that.
else {
getLocaleFromPrefs(context)
}
return langTag
}

private fun getLocaleFromPrefs(context: Context): String {
val langPath = "${context.filesDir.path}/language.settings"
val file = File(langPath)
try {
if (file.isFile) {
val lang = file.readText().trim()
return lang
} else throw Exception("File not found: language.settings.")
} catch (ex: Exception) {
ex.printStackTrace()
return "auto"
}
}

private fun getLocaleSystem(iso639Format: Boolean = false): String {
return when (iso639Format) {
false -> Locale.getDefault().toLanguageTag()
true -> Locale.getDefault().language
}
}

@TargetApi(VERSION_CODES.TIRAMISU)
fun setLocaleA13(context: Context, tag: String) {
context.getSystemService(LocaleManager::class.java)
.applicationLocales = LocaleList.forLanguageTags(tag)
}

fun saveLocale(context: Context, langTag: String) {
val langPath = "${context.filesDir.path}/language.settings"
val file = File(langPath)
try {
val locale = Locale(langTag)
Locale.setDefault(locale)
file.writeText(langTag)
} catch (ex: Exception) {
ex.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import io.zoemeow.dutschedule.model.settings.AppSettings
import java.io.File

@Suppress("PrivatePropertyName", "SpellCheckingInspection")
class FileModuleRepository(
context: Context
) {
class FileModuleRepository(context: Context) {
private val PATH_CACHE_NEWSGLOBAL = "${context.filesDir.path}/news.global.cache.json"
private val PATH_CACHE_NEWSSUBJECT = "${context.filesDir.path}/news.subject.cache.json"
private val PATH_APPSETTINGS = "${context.filesDir.path}/settings.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.material3.Checkbox
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
Expand Down Expand Up @@ -81,7 +81,7 @@ fun DialogBase(
) {
Text(
title,
style = TextStyle(fontSize = 24.sp),
style = TextStyle(fontSize = 22.sp),
modifier = Modifier.fillMaxWidth().padding(bottom = 15.dp),
textAlign = if (isTitleCentered) TextAlign.Center else TextAlign.Start
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.zoemeow.dutschedule.ui.component.base
package io.zoemeow.dutschedule.ui.component

import androidx.compose.material3.Checkbox
import androidx.compose.runtime.Composable
Expand Down
Loading

0 comments on commit 76830a5

Please sign in to comment.