From 1f74d52c1a9ba81ad3a268a08cabb1b62911e2cf Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Thu, 29 Apr 2021 02:26:12 +0530 Subject: Add Home feature --- .../privacycentralapp/PrivacyCentralApplication.kt | 5 +- .../e/privacycentralapp/features/HomeFeature.kt | 71 +++++++++++++++++++++- .../e/privacycentralapp/features/HomeViewModel.kt | 30 ++++++++- .../e/privacycentralapp/features/MainActivity.kt | 3 +- 4 files changed, 102 insertions(+), 7 deletions(-) (limited to 'app/src/main/java/foundation') 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 . + */ + 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 = { _, effect -> + when (effect) { + HomeFeature.Effect.LoadingFinished -> HomeFeature.State.Loaded + } +} + +private val actor: Actor = + { _, action -> + when (action) { + HomeFeature.Action.load -> flowOf(HomeFeature.Effect.LoadingFinished) + } + } + +fun homeFeature( + initialState: HomeFeature.State = HomeFeature.State.Loading, + coroutineScope: CoroutineScope +) = BaseFeature( + 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 . + */ + 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 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 . */ -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?) { -- cgit v1.2.1