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 --- app/build.gradle | 22 +++---- app/src/main/AndroidManifest.xml | 3 +- .../privacycentralapp/PrivacyCentralApplication.kt | 5 +- .../e/privacycentralapp/features/HomeFeature.kt | 71 +++++++++++++++++++++- .../e/privacycentralapp/features/HomeViewModel.kt | 30 ++++++++- .../e/privacycentralapp/features/MainActivity.kt | 3 +- app/src/main/res/layout/activity_main.xml | 2 +- 7 files changed, 115 insertions(+), 21 deletions(-) (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index 35e1c73..3e1624b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,14 +4,14 @@ plugins { } android { - compileSdkVersion 29 + compileSdkVersion buildConfig.compileSdk defaultConfig { applicationId "foundation.e.privacycentralapp" - minSdkVersion 24 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" + minSdkVersion buildConfig.minSdk + targetSdkVersion buildConfig.targetSdk + versionCode buildConfig.version.code + versionName buildConfig.version.fullName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -26,17 +26,15 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = '1.8' - } } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.32" - implementation 'androidx.core:core-ktx:1.3.2' + implementation project(":flow-mvi") + implementation Libs.Kotlin.stdlib + implementation Libs.AndroidX.coreKtx implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation Libs.AndroidX.Lifecycle.runtime + implementation Libs.AndroidX.Lifecycle.viewmodel testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 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"> - + 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?) { 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">