| author | Da Risk <da_risk@geekorum.com> |
| Sun, 20 Apr 2025 12:11:25 -0400 | |
| changeset 1317 | 0f73b76f38e4 |
| parent 1303 | 4ad7fcac5018 |
| child 1370 | 13e39ef920a8 |
| permissions | -rw-r--r-- |
|
59
58ca8a2d60c6
Make all activities inheriting from AppCompatActivity directly inherit BaseActivity
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
| 1174 | 4 |
* Copyright (C) 2017-2024 by Frederic-Charles Barthelery. |
| 0 | 5 |
* |
6 |
* This file is part of Geekttrss. |
|
7 |
* |
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* Geekttrss is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
21 |
package com.geekorum.ttrss |
|
22 |
||
23 |
import android.content.Intent |
|
24 |
import android.os.Bundle |
|
|
385
f8dd2c300fe6
CoreComponents: InjectableBaseActivity now sets the default ViewModelProvider.Factory
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
25 |
import androidx.activity.viewModels |
|
1303
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
26 |
import androidx.lifecycle.Lifecycle |
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
27 |
import androidx.lifecycle.lifecycleScope |
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
28 |
import androidx.lifecycle.repeatOnLifecycle |
| 0 | 29 |
import com.geekorum.geekdroid.app.lifecycle.EventObserver |
30 |
import com.geekorum.ttrss.articles_list.ArticleListActivity |
|
31 |
import com.geekorum.ttrss.articles_list.TtrssAccountViewModel |
|
|
518
7749ede46361
Move CoreComponents into a core package
Da Risk <da_risk@geekorum.com>
parents:
385
diff
changeset
|
32 |
import com.geekorum.ttrss.core.BaseActivity |
|
728
c7885cda3244
MainActivity convert to hilt
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
33 |
import dagger.hilt.android.AndroidEntryPoint |
|
1303
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
34 |
import kotlinx.coroutines.launch |
| 0 | 35 |
|
|
1317
0f73b76f38e4
app: Start a new SingleActivity
Da Risk <da_risk@geekorum.com>
parents:
1303
diff
changeset
|
36 |
private val UseSingleActivity = false |
|
0f73b76f38e4
app: Start a new SingleActivity
Da Risk <da_risk@geekorum.com>
parents:
1303
diff
changeset
|
37 |
|
|
728
c7885cda3244
MainActivity convert to hilt
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
38 |
@AndroidEntryPoint |
|
59
58ca8a2d60c6
Make all activities inheriting from AppCompatActivity directly inherit BaseActivity
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
39 |
class MainActivity : BaseActivity() {
|
| 0 | 40 |
|
|
59
58ca8a2d60c6
Make all activities inheriting from AppCompatActivity directly inherit BaseActivity
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
41 |
private val accountViewModel: TtrssAccountViewModel by viewModels() |
| 0 | 42 |
|
43 |
override fun onCreate(savedInstanceState: Bundle?) {
|
|
44 |
super.onCreate(savedInstanceState) |
|
|
1303
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
45 |
lifecycleScope.launch {
|
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
46 |
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
47 |
accountViewModel.selectedAccount.collect { account ->
|
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
48 |
if (account != null) {
|
|
1317
0f73b76f38e4
app: Start a new SingleActivity
Da Risk <da_risk@geekorum.com>
parents:
1303
diff
changeset
|
49 |
val intent = if (UseSingleActivity) |
|
0f73b76f38e4
app: Start a new SingleActivity
Da Risk <da_risk@geekorum.com>
parents:
1303
diff
changeset
|
50 |
Intent(this@MainActivity, SingleActivity::class.java) |
|
0f73b76f38e4
app: Start a new SingleActivity
Da Risk <da_risk@geekorum.com>
parents:
1303
diff
changeset
|
51 |
else |
|
0f73b76f38e4
app: Start a new SingleActivity
Da Risk <da_risk@geekorum.com>
parents:
1303
diff
changeset
|
52 |
Intent(this@MainActivity, ArticleListActivity::class.java) |
|
1303
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
53 |
startActivity(intent) |
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
54 |
finish() |
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
55 |
} else {
|
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
56 |
accountViewModel.startSelectAccountActivity(this@MainActivity) |
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
57 |
} |
|
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
58 |
} |
| 0 | 59 |
} |
|
1303
4ad7fcac5018
app: use account stateflow instead of livedatas
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
60 |
} |
| 0 | 61 |
accountViewModel.noAccountSelectedEvent.observe(this, EventObserver { finish() })
|
62 |
} |
|
63 |
} |