summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml3
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt5
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt71
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt30
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt3
-rw-r--r--app/src/main/res/layout/activity_main.xml2
6 files changed, 105 insertions, 9 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a28e77e..b1db8d0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,13 +3,14 @@
package="foundation.e.privacycentralapp">
<application
+ android:name=".PrivacyCentralApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PrivacyCentralApp">
- <activity android:name=".MainActivity">
+ <activity android:name=".features.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt b/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt
index 4f5039a..87be346 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt
@@ -17,5 +17,6 @@
package foundation.e.privacycentralapp
-class PrivacyCentralApplication {
-} \ No newline at end of file
+import android.app.Application
+
+class PrivacyCentralApplication : Application()
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt
index 43f29d2..766d1fa 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt
@@ -1,4 +1,71 @@
+/*
+ * Copyright (C) 2021 E FOUNDATION
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package foundation.e.privacycentralapp.features
-class HomeFeature {
-} \ No newline at end of file
+import foundation.e.flowmvi.Actor
+import foundation.e.flowmvi.Reducer
+import foundation.e.flowmvi.feature.BaseFeature
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.flowOf
+
+// Define a state machine for HomeFeature
+object HomeFeature {
+ sealed class State {
+ object Loading : State()
+ object Loaded : State()
+ }
+
+ sealed class SingleEvent {
+ object NavigateToQuickProtection : SingleEvent()
+ object NavigateToTrackers : SingleEvent()
+ object NavigateToInternetActivityPolicy : SingleEvent()
+ object NavigateToLocation : SingleEvent()
+ object NavigateToPermissionManagement : SingleEvent()
+ }
+
+ sealed class Action {
+ object load : Action()
+ }
+
+ sealed class Effect {
+ object LoadingFinished : Effect()
+ }
+}
+
+private val reducer: Reducer<HomeFeature.State, HomeFeature.Effect> = { _, effect ->
+ when (effect) {
+ HomeFeature.Effect.LoadingFinished -> HomeFeature.State.Loaded
+ }
+}
+
+private val actor: Actor<HomeFeature.State, HomeFeature.Action, HomeFeature.Effect> =
+ { _, action ->
+ when (action) {
+ HomeFeature.Action.load -> flowOf(HomeFeature.Effect.LoadingFinished)
+ }
+ }
+
+fun homeFeature(
+ initialState: HomeFeature.State = HomeFeature.State.Loading,
+ coroutineScope: CoroutineScope
+) = BaseFeature<HomeFeature.State, HomeFeature.Action, HomeFeature.Effect, HomeFeature.SingleEvent>(
+ initialState,
+ actor,
+ reducer,
+ coroutineScope
+)
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt
index 6cb37c6..1a338f9 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt
@@ -1,4 +1,30 @@
+/*
+ * Copyright (C) 2021 E FOUNDATION
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package foundation.e.privacycentralapp.features
-class HomeViewModel {
-} \ No newline at end of file
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import foundation.e.flowmvi.feature.BaseFeature
+
+class HomeViewModel : ViewModel() {
+
+ val homeFeature: BaseFeature<HomeFeature.State, HomeFeature.Action,
+ HomeFeature.Effect, HomeFeature.SingleEvent> by lazy {
+ homeFeature(coroutineScope = viewModelScope)
+ }
+}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt b/app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt
index 3dd2145..eefb5e1 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt
@@ -15,10 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-package foundation.e.privacycentralapp
+package foundation.e.privacycentralapp.features
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
+import foundation.e.privacycentralapp.R
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4fc2444..bdbfeeb 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".MainActivity">
+ tools:context=".features.MainActivity">
<TextView
android:layout_width="wrap_content"