Implement ThemeChooserActivity.kt
Implement layout, ViewModel interactions and connection with BaseSettingsActivity.kt MAILAND-2635
This commit is contained in:
parent
768927b1ff
commit
3411d97e3d
|
@ -350,6 +350,9 @@
|
|||
<activity
|
||||
android:name=".labels.presentation.ui.ParentFolderPickerActivity"
|
||||
android:exported="true"/>
|
||||
<activity
|
||||
android:name=".settings.presentation.ui.ThemeChooserActivity"
|
||||
android:exported="false"/>
|
||||
|
||||
<service
|
||||
android:name=".api.services.MessagesService"
|
||||
|
|
|
@ -75,6 +75,7 @@ import ch.protonmail.android.settings.presentation.EXTRA_SETTINGS_ATTACHMENT_STO
|
|||
import ch.protonmail.android.settings.presentation.SettingsDividerItemDecoration
|
||||
import ch.protonmail.android.settings.presentation.SnoozeNotificationsActivity
|
||||
import ch.protonmail.android.settings.presentation.SwipeSettingFragment
|
||||
import ch.protonmail.android.settings.presentation.ui.ThemeChooserActivity
|
||||
import ch.protonmail.android.uiModel.SettingsItemUiModel
|
||||
import ch.protonmail.android.usecase.fetch.LaunchInitialDataFetch
|
||||
import ch.protonmail.android.utils.AppUtil
|
||||
|
@ -132,6 +133,8 @@ abstract class BaseSettingsActivity : BaseConnectivityActivity() {
|
|||
|
||||
var settingsUiList: List<SettingsItemUiModel> = ArrayList()
|
||||
|
||||
private val themeChooserLauncher = registerForActivityResult(ThemeChooserActivity.Launcher()) {}
|
||||
|
||||
var contactDao: ContactDao? = null
|
||||
var messageDao: MessageDao? = null
|
||||
var conversationDao: ConversationDao? = null
|
||||
|
@ -398,6 +401,7 @@ abstract class BaseSettingsActivity : BaseConnectivityActivity() {
|
|||
)
|
||||
startActivity(AppUtil.decorInAppIntent(attachmentStorageIntent))
|
||||
}
|
||||
APP_THEME -> themeChooserLauncher.launch(Unit)
|
||||
PUSH_NOTIFICATION -> {
|
||||
val privateNotificationsIntent =
|
||||
AppUtil.decorInAppIntent(Intent(this, EditSettingsItemActivity::class.java))
|
||||
|
@ -462,8 +466,6 @@ abstract class BaseSettingsActivity : BaseConnectivityActivity() {
|
|||
)
|
||||
}
|
||||
}
|
||||
else -> { /* ignored */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,13 @@ import ch.protonmail.android.labels.data.LabelRepositoryImpl
|
|||
import ch.protonmail.android.labels.domain.LabelRepository
|
||||
import ch.protonmail.android.mailbox.data.ConversationsRepositoryImpl
|
||||
import ch.protonmail.android.mailbox.domain.ConversationsRepository
|
||||
import ch.protonmail.android.settings.domain.DeviceSettingsRepository
|
||||
import ch.protonmail.android.settings.domain.model.AppThemeSettings
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Inject
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
|
@ -44,6 +47,9 @@ internal interface ApplicationBindsModule {
|
|||
@Binds
|
||||
fun DefaultImageDecoder.imageDecoder(): ImageDecoder
|
||||
|
||||
@Binds
|
||||
fun DeviceSettingsRepositoryImpl.deviceSettingsRepository(): DeviceSettingsRepository
|
||||
|
||||
@Binds
|
||||
fun provideLabelRepository(repo: LabelRepositoryImpl): LabelRepository
|
||||
|
||||
|
@ -54,3 +60,15 @@ internal interface ApplicationBindsModule {
|
|||
fun provideCounterRepository(repo: CounterRepositoryImpl): CounterRepository
|
||||
|
||||
}
|
||||
|
||||
class DeviceSettingsRepositoryImpl @Inject constructor() : DeviceSettingsRepository {
|
||||
|
||||
override suspend fun getAppThemeSettings(): AppThemeSettings {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun saveAppThemeSettings(settings: AppThemeSettings) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,20 +21,74 @@ package ch.protonmail.android.settings.presentation.ui
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import ch.protonmail.android.R
|
||||
import ch.protonmail.android.databinding.ActivityThemeChooserBinding
|
||||
import ch.protonmail.android.settings.domain.model.AppThemeSettings
|
||||
import ch.protonmail.android.settings.presentation.viewmodel.ThemeChooserViewModel
|
||||
import ch.protonmail.android.settings.presentation.viewmodel.ThemeChooserViewModel.Action
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import me.proton.core.util.kotlin.unsupported
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ThemeChooserActivity : AppCompatActivity() {
|
||||
|
||||
private val viewModel: ThemeChooserViewModel by viewModels()
|
||||
private lateinit var binding: ActivityThemeChooserBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityThemeChooserBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.appThemeToolbar)
|
||||
|
||||
viewModel.state
|
||||
.onEach(::updateThemeSelection)
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
binding.appThemeRadioGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||
val action = when (checkedId) {
|
||||
R.id.app_theme_light_radio_button -> Action.SetLightTheme
|
||||
R.id.app_theme_dark_radio_button -> Action.SetDarkTheme
|
||||
R.id.app_theme_system_radio_button -> Action.SetSystemTheme
|
||||
else -> unsupported
|
||||
}
|
||||
viewModel.process(action)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_app_theme, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == R.id.app_theme_done) onBackPressed()
|
||||
else return super.onOptionsItemSelected(item)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun updateThemeSelection(theme: AppThemeSettings) {
|
||||
val radioButton = when (theme) {
|
||||
AppThemeSettings.LIGHT -> binding.appThemeLightRadioButton
|
||||
AppThemeSettings.DARK -> binding.appThemeDarkRadioButton
|
||||
AppThemeSettings.FOLLOW_SYSTEM -> binding.appThemeSystemRadioButton
|
||||
}
|
||||
binding.appThemeRadioGroup.check(radioButton.id)
|
||||
}
|
||||
|
||||
class Launcher : ActivityResultContract<Unit, Unit>() {
|
||||
|
||||
override fun createIntent(context: Context, input: Unit?): Intent {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun parseResult(resultCode: Int, intent: Intent?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun createIntent(context: Context, input: Unit) = Intent(context, ThemeChooserActivity::class.java)
|
||||
override fun parseResult(resultCode: Int, intent: Intent?) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class ThemeChooserViewModel @Inject constructor(
|
|||
private val getAppThemeSettings: GetAppThemeSettings,
|
||||
private val saveAppThemeSettings: SaveAppThemeSettings,
|
||||
private val applyAppThemeFromSettings: ApplyAppThemeFromSettings
|
||||
): ViewModel() {
|
||||
) : ViewModel() {
|
||||
|
||||
val state: StateFlow<AppThemeSettings> get() = mutableState.asStateFlow()
|
||||
private val mutableState = MutableStateFlow(AppThemeSettings.FOLLOW_SYSTEM)
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (c) 2020 Proton Technologies AG
|
||||
~
|
||||
~ This file is part of ProtonMail.
|
||||
~
|
||||
~ ProtonMail is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ ProtonMail is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
||||
-->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/app_theme_toolbar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:title="@string/app_theme_title"
|
||||
app:menu="@menu/menu_app_theme"/>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/app_theme_radio_group"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/app_theme_toolbar">
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonRadioButton
|
||||
android:id="@+id/app_theme_light_radio_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="@dimen/padding_l"
|
||||
android:text="@string/app_theme_light"
|
||||
tools:checked="true"/>
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonRadioButton
|
||||
android:id="@+id/app_theme_dark_radio_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="@dimen/padding_l"
|
||||
android:text="@string/app_theme_dark"/>
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonRadioButton
|
||||
android:id="@+id/app_theme_system_radio_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="@dimen/padding_l"
|
||||
android:text="@string/app_theme_system"/>
|
||||
</RadioGroup>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (c) 2020 Proton Technologies AG
|
||||
~
|
||||
~ This file is part of ProtonMail.
|
||||
~
|
||||
~ ProtonMail is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ ProtonMail is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:id="@+id/app_theme_done"
|
||||
android:title="@string/x_done"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
|
@ -91,6 +91,13 @@
|
|||
<string name="settings_swipe_right_to_left">Right to left</string>
|
||||
<!-- endregion -->
|
||||
|
||||
<!-- region App Theme -->
|
||||
<string name="app_theme_title">App theme</string>
|
||||
<string name="app_theme_light">Light</string>
|
||||
<string name="app_theme_dark">Dark</string>
|
||||
<string name="app_theme_system">System default</string>
|
||||
<!-- endregion -->
|
||||
|
||||
<!-- region Labels Manger -->
|
||||
<string name="labels_manager_select_parent_folder">Select parent folder</string>
|
||||
<string name="labels_manager_parent_folder_selected"><b>Parent folder selected.</b> Tap to change</string>
|
||||
|
|
Loading…
Reference in New Issue