From 75843f012b09f0f11da4aec10be2f378465a94c2 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Thu, 29 Apr 2021 14:49:04 +0530 Subject: Add dashboard feature UI --- .../e/privacycentralapp/features/HomeFeature.kt | 71 ---------------------- .../e/privacycentralapp/features/HomeViewModel.kt | 30 --------- .../e/privacycentralapp/features/MainActivity.kt | 29 --------- .../features/dashboard/DashboardActivity.kt | 49 +++++++++++++++ .../features/dashboard/DashboardFeature.kt | 71 ++++++++++++++++++++++ .../features/dashboard/DashboardViewModel.kt | 30 +++++++++ 6 files changed, 150 insertions(+), 130 deletions(-) delete mode 100644 app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt delete mode 100644 app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt delete mode 100644 app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt create mode 100644 app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardActivity.kt create mode 100644 app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt create mode 100644 app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt (limited to 'app/src/main/java/foundation') diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt deleted file mode 100644 index 766d1fa..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/features/HomeFeature.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 - -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 deleted file mode 100644 index 1a338f9..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/features/HomeViewModel.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 - -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 deleted file mode 100644 index eefb5e1..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/features/MainActivity.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import foundation.e.privacycentralapp.R - -class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - } -} diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardActivity.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardActivity.kt new file mode 100644 index 0000000..ef296ce --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardActivity.kt @@ -0,0 +1,49 @@ +/* + * 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.dashboard + +import android.graphics.Color +import android.os.Bundle +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ForegroundColorSpan +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import foundation.e.privacycentralapp.R + +class DashboardActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + title = "My Privacy Dashboard" + setSupportActionBar(findViewById(R.id.toolbar)) + + addClickToMore(findViewById(R.id.personal_leakag_info)) + } + + private fun addClickToMore(textView: TextView) { + val clickToMore = SpannableString("Click to learn more") + clickToMore.setSpan( + ForegroundColorSpan(Color.parseColor("#007fff")), + 0, + clickToMore.length, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + textView.append(clickToMore) + } +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt new file mode 100644 index 0000000..9b8e28f --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt @@ -0,0 +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.dashboard + +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/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt new file mode 100644 index 0000000..82c6c11 --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt @@ -0,0 +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.dashboard + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import foundation.e.flowmvi.feature.BaseFeature + +class DashboardViewModel : ViewModel() { + + val homeFeature: BaseFeature by lazy { + homeFeature(coroutineScope = viewModelScope) + } +} -- cgit v1.2.1