LeoColman / Petals

🌻 The Open Source app Petals aims to help its users to either quit weed, reduce usage or simply know how much they're using.
GNU Affero General Public License v3.0
85 stars 33 forks source link

✨ Add app language selection setting #725

Closed rubenquadros closed 1 month ago

rubenquadros commented 1 month ago

A language selection setting is added to the settings page. The MainActivity now extends AppCompatActivity to handle changing the app language. More info on this here: https://developer.android.com/guide/topics/resources/app-languages#androidx-impl

Closes #678

rubenquadros commented 1 month ago

Getting close. There are a few changes to make and fix the linter complaints then I think we are good to go!

What do we do about Enum entry names should match the pattern for AppLanguage? 😬

LeoColman commented 1 month ago

I think we can go with having the English name as the enum name and a variable inside the enum having a string with the localized name.

I agree with detekt that it's a bit weird to have enums with cyrilic 😂

rubenquadros commented 1 month ago

@rubenquadros Couldn't get it to work here :/

Screencast.from.2024-10-09.17-43-43.mp4

Can you share the device details? Could have missed some version specific changes

LeoColman commented 1 month ago

It's an emulator:

Properties
avd.ini.displayname              Pixel 2 API 33
avd.ini.encoding                 UTF-8
AvdId                            Pixel_2_API_33
disk.dataPartition.size          6442450944
fastboot.chosenSnapshotFile      
fastboot.forceChosenSnapshotBoot no
fastboot.forceColdBoot           no
fastboot.forceFastBoot           yes
hw.accelerometer                 yes
hw.arc                           false
hw.audioInput                    yes
hw.battery                       yes
hw.camera.back                   virtualscene
hw.camera.front                  emulated
hw.cpu.ncore                     4
hw.device.hash2                  MD5:55acbc835978f326788ed66a5cd4c9a7
hw.device.manufacturer           Google
hw.device.name                   pixel_2
hw.dPad                          no
hw.gps                           yes
hw.gpu.enabled                   yes
hw.gpu.mode                      auto
hw.initialOrientation            Portrait
hw.keyboard                      yes
hw.lcd.density                   420
hw.lcd.height                    1920
hw.lcd.width                     1080
hw.mainKeys                      no
hw.ramSize                       1536
hw.sdCard                        yes
hw.sensors.orientation           yes
hw.sensors.proximity             yes
hw.trackBall                     no
image.androidVersion.api         33
image.sysdir.1                   system-images/android-33/google_apis/x86_64/
PlayStore.enabled                false
runtime.network.latency          none
runtime.network.speed            full
showDeviceFrame                  yes
skin.dynamic                     yes
tag.display                      Google APIs
tag.id                           google_apis
vm.heapSize                      228
rubenquadros commented 1 month ago

Yes it does not seem to be working with a fresh install😭 When I was making the changes and testing it was working. I will have to check what is happening. It would be great if you also take a look. More eyes the better!

https://github.com/user-attachments/assets/51b6c2f7-cdfe-45db-a4c8-d7397089f5d0

rubenquadros commented 1 month ago

Nvm I got the issue. It was caused by yesterday's refactoring:

 fun getAppLanguageCode(languageName: String): String {
      return entries.firstOrNull { it.name == languageName }?.languageCode ?: English.languageCode
    }

Notice it? It should be it.languageName and not it.name 😝

LeoColman commented 1 month ago

Thanks @rubenquadros ! Good Job :D