| author | Da Risk <da_risk@geekorum.com> | 
| Sun, 27 Apr 2025 16:32:52 -0400 | |
| changeset 60 | b6ea11765022 | 
| parent 43 | b144901856dc | 
| child 61 | 95e68d22bef2 | 
| permissions | -rw-r--r-- | 
| 14 | 1  | 
/*  | 
2  | 
* AboutOss is an utility library to retrieve and display  | 
|
3  | 
* opensource licenses in Android applications.  | 
|
4  | 
*  | 
|
| 
34
 
ce299aacc068
build: update license headers
 
Da Risk <da_risk@geekorum.com> 
parents: 
17 
diff
changeset
 | 
5  | 
* Copyright (C) 2023-2025 by Frederic-Charles Barthelery.  | 
| 14 | 6  | 
*  | 
7  | 
* This file is part of AboutOss.  | 
|
8  | 
*  | 
|
9  | 
* AboutOss is free software: you can redistribute it and/or modify  | 
|
10  | 
* it under the terms of the GNU General Public License as published by  | 
|
11  | 
* the Free Software Foundation, either version 3 of the License, or  | 
|
12  | 
* (at your option) any later version.  | 
|
13  | 
*  | 
|
14  | 
* AboutOss is distributed in the hope that it will be useful,  | 
|
15  | 
* but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
|
16  | 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  | 
|
17  | 
* GNU General Public License for more details.  | 
|
18  | 
*  | 
|
19  | 
* You should have received a copy of the GNU General Public License  | 
|
20  | 
* along with AboutOss. If not, see <http://www.gnu.org/licenses/>.  | 
|
21  | 
*/  | 
|
22  | 
package com.geekorum.aboutoss.ui.material3  | 
|
23  | 
||
24  | 
import android.os.Bundle  | 
|
25  | 
import androidx.activity.compose.setContent  | 
|
| 
60
 
b6ea11765022
ui:material3: remove some deprecated methods. Add support for dark theme by default
 
Da Risk <da_risk@geekorum.com> 
parents: 
43 
diff
changeset
 | 
26  | 
import androidx.activity.enableEdgeToEdge  | 
| 
42
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
27  | 
import androidx.activity.viewModels  | 
| 14 | 28  | 
import androidx.compose.foundation.isSystemInDarkTheme  | 
29  | 
import androidx.compose.material3.MaterialTheme  | 
|
| 
60
 
b6ea11765022
ui:material3: remove some deprecated methods. Add support for dark theme by default
 
Da Risk <da_risk@geekorum.com> 
parents: 
43 
diff
changeset
 | 
30  | 
import androidx.compose.material3.darkColorScheme  | 
| 
 
b6ea11765022
ui:material3: remove some deprecated methods. Add support for dark theme by default
 
Da Risk <da_risk@geekorum.com> 
parents: 
43 
diff
changeset
 | 
31  | 
import androidx.compose.material3.lightColorScheme  | 
| 14 | 32  | 
import androidx.compose.runtime.Composable  | 
| 
42
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
33  | 
import com.geekorum.aboutoss.core.gms.GmsLicenseInfoRepository  | 
| 14 | 34  | 
import com.geekorum.aboutoss.ui.common.BaseOpensourceLicenseActivity  | 
| 
42
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
35  | 
import com.geekorum.aboutoss.ui.common.Factory  | 
| 14 | 36  | 
import com.geekorum.aboutoss.ui.common.OpenSourceLicensesViewModel  | 
| 
42
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
37  | 
import com.geekorum.aboutoss.ui.material3.OpenSourceLicensesActivity.Companion.themeProvider  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
38  | 
import kotlinx.coroutines.Dispatchers  | 
| 14 | 39  | 
|
40  | 
/**  | 
|
41  | 
* Activity to display opensource license information  | 
|
42  | 
*  | 
|
43  | 
* This activity use Material compose to create the UI.  | 
|
44  | 
* You can specify the Material theme to use by setting [themeProvider]  | 
|
45  | 
* before launching the activity  | 
|
46  | 
*/  | 
|
| 
17
 
6ff6774c8121
ui: Make OpenSourceLicensesActivity open so users can override viewModel
 
Da Risk <da_risk@geekorum.com> 
parents: 
14 
diff
changeset
 | 
47  | 
open class OpenSourceLicensesActivity : BaseOpensourceLicenseActivity() {
 | 
| 
42
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
48  | 
override val viewModel: OpenSourceLicensesViewModel by viewModels(  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
49  | 
        factoryProducer = {
 | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
50  | 
val gmsLicenseInfoRepository = GmsLicenseInfoRepository(  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
51  | 
appContext = applicationContext,  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
52  | 
mainCoroutineDispatcher = Dispatchers.Main,  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
53  | 
ioCoroutineDispatcher = Dispatchers.IO,  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
54  | 
)  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
55  | 
OpenSourceLicensesViewModel.Factory(gmsLicenseInfoRepository)  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
56  | 
}  | 
| 
 
d59fc19f19fa
ui:material3: convert to kotlin-multiplatform
 
Da Risk <da_risk@geekorum.com> 
parents: 
34 
diff
changeset
 | 
57  | 
)  | 
| 14 | 58  | 
|
59  | 
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
|
60  | 
super.onCreate(savedInstanceState)  | 
|
| 
60
 
b6ea11765022
ui:material3: remove some deprecated methods. Add support for dark theme by default
 
Da Risk <da_risk@geekorum.com> 
parents: 
43 
diff
changeset
 | 
61  | 
enableEdgeToEdge()  | 
| 14 | 62  | 
        setContent {
 | 
63  | 
            themeProvider {
 | 
|
| 
43
 
b144901856dc
ui:material3: extract OpenSourceDependenciesNavHost to common
 
Da Risk <da_risk@geekorum.com> 
parents: 
42 
diff
changeset
 | 
64  | 
OpenSourceDependenciesNavHost(  | 
| 14 | 65  | 
openSourceLicensesViewModel = viewModel,  | 
66  | 
                    navigateUp = {
 | 
|
67  | 
                        if (!onNavigateUp()) {
 | 
|
68  | 
finish()  | 
|
69  | 
}  | 
|
70  | 
}  | 
|
71  | 
)  | 
|
72  | 
}  | 
|
73  | 
}  | 
|
74  | 
}  | 
|
75  | 
||
76  | 
    companion object {
 | 
|
77  | 
/**  | 
|
78  | 
* The composable Theme function to set the theme of the UI in [OpenSourceLicensesActivity]  | 
|
79  | 
* Default to base material theme [MaterialTheme]  | 
|
80  | 
*/  | 
|
81  | 
        var themeProvider: @Composable (@Composable () -> Unit) -> Unit = { content ->
 | 
|
82  | 
val darkTheme: Boolean = isSystemInDarkTheme()  | 
|
| 
60
 
b6ea11765022
ui:material3: remove some deprecated methods. Add support for dark theme by default
 
Da Risk <da_risk@geekorum.com> 
parents: 
43 
diff
changeset
 | 
83  | 
val colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme()  | 
| 
 
b6ea11765022
ui:material3: remove some deprecated methods. Add support for dark theme by default
 
Da Risk <da_risk@geekorum.com> 
parents: 
43 
diff
changeset
 | 
84  | 
MaterialTheme(colorScheme, content = content)  | 
| 14 | 85  | 
}  | 
86  | 
}  | 
|
87  | 
}  | 
|
88  |