From e40866d03008ec6dafa0016a31ee4c9e820032df Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Wed, 16 Jun 2021 01:57:50 +0530 Subject: Fix UI bugs and reformat code --- app/build.gradle | 4 + .../e/privacycentralapp/dummy/DummyDataSource.kt | 1 - .../privacycentralapp/dummy/TrackersDataSource.kt | 10 +- .../features/dashboard/DashboardFeature.kt | 2 +- .../features/trackers/TrackerAppsAdapter.kt | 6 +- .../features/trackers/TrackerAppsFragment.kt | 38 +++-- .../features/trackers/TrackersFeature.kt | 6 +- .../features/trackers/TrackersFragment.kt | 8 +- .../features/trackers/TrackersViewModel.kt | 2 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/fragment_dashboard.xml | 160 ++++++++++----------- app/src/main/res/layout/fragment_fake_location.xml | 6 +- .../layout/fragment_internet_activity_policy.xml | 46 +++--- .../main/res/layout/fragment_permission_apps.xml | 56 ++++---- app/src/main/res/layout/fragment_permissions.xml | 30 ++-- .../main/res/layout/fragment_quick_protection.xml | 91 ++++++------ app/src/main/res/layout/fragment_tracker_apps.xml | 56 ++++---- app/src/main/res/layout/fragment_trackers.xml | 30 ++-- app/src/main/res/layout/item_app_toggle.xml | 22 +-- app/src/main/res/layout/item_permission.xml | 30 ++-- app/src/main/res/layout/topbar.xml | 6 +- app/src/main/res/values/strings.xml | 2 +- scripts/sign_and_push.sh | 2 +- 23 files changed, 339 insertions(+), 277 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8c18e06..8d94e2b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,6 +80,10 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + + aaptOptions { + additionalParameters '-I', 'app/libs/e-ui-sdk-1.0.1-q.jar' + } } dependencies { diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt index dd6112d..fe61354 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt @@ -227,5 +227,4 @@ object DummyDataSource { _appsUsingLocationPerm.value = _populatedPermissions.value[permissionId].packagesAllowed } } - } diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt index 9485a26..07822bb 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt @@ -82,12 +82,14 @@ object TrackersDataSource { if (result) { _trackers.value = _trackers.value.map { if (it.name == tracker.name) { - it.copy(trackedApps = it.trackedApps.map { app -> - app.copy(isEnabled = enable) - }) + it.copy( + trackedApps = it.trackedApps.map { app -> + app.copy(isEnabled = enable) + } + ) } else it } } return result } -} \ No newline at end of file +} 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 index a273b88..c26fce1 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt @@ -164,7 +164,7 @@ class DashboardFeature( var activeTrackersCount: Int = 0 outer@ for (tracker in it) { for (app in tracker.trackedApps) { - if(!app.isEnabled) { + if (!app.isEnabled) { continue@outer } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsAdapter.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsAdapter.kt index 04e3f04..ae236b9 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsAdapter.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsAdapter.kt @@ -43,8 +43,10 @@ class TrackerAppsAdapter( val view = LayoutInflater.from(parent.context) .inflate(R.layout.item_app_toggle, parent, false) val holder = TrackerViewHolder(view) - holder.toggleBlocker.setOnCheckedChangeListener { _, isChecked -> - listener(tracker, isChecked) + holder.toggleBlocker.setOnClickListener { + if (it is Switch) { + listener(tracker, it.isChecked) + } } return holder } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsFragment.kt index 67ae0cc..53c26a9 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackerAppsFragment.kt @@ -18,8 +18,10 @@ package foundation.e.privacycentralapp.features.trackers import android.os.Bundle +import android.util.Log +import android.view.View import android.widget.Toast -import androidx.fragment.app.viewModels +import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -33,7 +35,9 @@ class TrackerAppsFragment : NavToolbarFragment(R.layout.fragment_tracker_apps), MVIView { - private val viewModel: TrackersViewModel by viewModels() + private val viewModel: TrackersViewModel by activityViewModels() + + private val TAG = "TrackerAppsFragment" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -44,6 +48,11 @@ class TrackerAppsFragment : viewModel.trackersFeature.singleEvents.collect { event -> when (event) { is TrackersFeature.SingleEvent.ErrorEvent -> displayToast(event.error) + is TrackersFeature.SingleEvent.BlockerErrorEvent -> { + displayToast("Couldn't toggle") + // Re-render the current state to reset the switches. + render(viewModel.trackersFeature.state.value) + } } } } @@ -56,19 +65,24 @@ class TrackerAppsFragment : override fun getTitle(): String = getString(R.string.tracker) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + view.findViewById(R.id.recylcer_view_tracker_apps)?.apply { + layoutManager = LinearLayoutManager(requireContext()) + setHasFixedSize(true) + } + } + override fun render(state: TrackersFeature.State) { + Log.d(TAG, "render() called with: state = $state") state.currentSelectedTracker?.let { tracker -> - view?.findViewById(R.id.recylcer_view_tracker_apps)?.apply { - layoutManager = LinearLayoutManager(requireContext()) - setHasFixedSize(true) - adapter = TrackerAppsAdapter(tracker) { tracker, grant -> - viewModel.submitAction( - TrackersFeature.Action.ToggleTrackerAction( - tracker, - grant - ) + view?.findViewById(R.id.recylcer_view_tracker_apps)?.adapter = TrackerAppsAdapter(tracker) { it, grant -> + viewModel.submitAction( + TrackersFeature.Action.ToggleTrackerAction( + it, + grant ) - } + ) } getToolbar()?.title = tracker.name } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt index f9fbf63..4a08328 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt @@ -40,7 +40,7 @@ class TrackersFeature( actor, reducer, coroutineScope, - { message -> Log.d("PermissionsFeature", message) }, + { message -> Log.d("TrackersFeature", message) }, singleEventProducer ) { data class State( @@ -112,7 +112,9 @@ class TrackersFeature( singleEventProducer = { _, _, effect -> when (effect) { is Effect.ErrorEffect -> SingleEvent.ErrorEvent(effect.message) - is Effect.TrackerToggleEffect -> SingleEvent.BlockerErrorEvent + is Effect.TrackerToggleEffect -> { + if (!effect.result) SingleEvent.BlockerErrorEvent else null + } else -> null } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt index d0242d3..00fefb6 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt @@ -19,9 +19,9 @@ package foundation.e.privacycentralapp.features.trackers import android.os.Bundle import android.view.View +import androidx.fragment.app.activityViewModels import androidx.fragment.app.add import androidx.fragment.app.commit -import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -34,7 +34,7 @@ class TrackersFragment : NavToolbarFragment(R.layout.fragment_trackers), MVIView { - private val viewModel: TrackersViewModel by viewModels() + private val viewModel: TrackersViewModel by activityViewModels() private lateinit var trackersAdapter: TrackersAdapter override fun onCreate(savedInstanceState: Bundle?) { @@ -59,9 +59,7 @@ class TrackersFragment : } } - override fun getTitle(): String { - return getString(R.string.trackers) - } + override fun getTitle() = getString(R.string.trackers) override fun render(state: TrackersFeature.State) { if (state.currentSelectedTracker != null) { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt index 79ae146..d75d6ec 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt @@ -37,4 +37,4 @@ class TrackersViewModel : ViewModel() { _actions.emit(action) } } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7013496..2627a32 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_dashboard.xml b/app/src/main/res/layout/fragment_dashboard.xml index dc79878..effd992 100644 --- a/app/src/main/res/layout/fragment_dashboard.xml +++ b/app/src/main/res/layout/fragment_dashboard.xml @@ -2,46 +2,46 @@ - + diff --git a/app/src/main/res/layout/fragment_fake_location.xml b/app/src/main/res/layout/fragment_fake_location.xml index 40324a1..d60513b 100644 --- a/app/src/main/res/layout/fragment_fake_location.xml +++ b/app/src/main/res/layout/fragment_fake_location.xml @@ -8,7 +8,7 @@ android:layout_width="match_parent" > - + @@ -29,9 +29,9 @@ android:layout_gravity="center_horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" - android:paddingTop="16dp" android:paddingLeft="32dp" android:paddingRight="32dp" + android:paddingTop="16dp" android:text="@string/fake_location_info" android:textColor="@color/black" android:textSize="14sp" diff --git a/app/src/main/res/layout/fragment_internet_activity_policy.xml b/app/src/main/res/layout/fragment_internet_activity_policy.xml index 7a5d8b5..c3021df 100644 --- a/app/src/main/res/layout/fragment_internet_activity_policy.xml +++ b/app/src/main/res/layout/fragment_internet_activity_policy.xml @@ -2,23 +2,23 @@ - + + + android:textSize="14sp" + /> + + android:textSize="14sp" + /> diff --git a/app/src/main/res/layout/fragment_permission_apps.xml b/app/src/main/res/layout/fragment_permission_apps.xml index 760c891..db61e93 100644 --- a/app/src/main/res/layout/fragment_permission_apps.xml +++ b/app/src/main/res/layout/fragment_permission_apps.xml @@ -2,37 +2,45 @@ - + - - + android:orientation="vertical" + tools:context=".main.MainActivity" + > - - + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_permissions.xml b/app/src/main/res/layout/fragment_permissions.xml index a452570..7ca4b43 100644 --- a/app/src/main/res/layout/fragment_permissions.xml +++ b/app/src/main/res/layout/fragment_permissions.xml @@ -2,16 +2,22 @@ - + + + + /> + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_quick_protection.xml b/app/src/main/res/layout/fragment_quick_protection.xml index d57a101..569f9b1 100644 --- a/app/src/main/res/layout/fragment_quick_protection.xml +++ b/app/src/main/res/layout/fragment_quick_protection.xml @@ -1,59 +1,70 @@ - + - - + android:orientation="vertical" + tools:context=".main.MainActivity" + > + + + + + + + - - + /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_tracker_apps.xml b/app/src/main/res/layout/fragment_tracker_apps.xml index bb31b5b..3341d95 100644 --- a/app/src/main/res/layout/fragment_tracker_apps.xml +++ b/app/src/main/res/layout/fragment_tracker_apps.xml @@ -2,37 +2,45 @@ - + - - + android:orientation="vertical" + tools:context=".main.MainActivity" + > - - + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_trackers.xml b/app/src/main/res/layout/fragment_trackers.xml index 13fcab3..591b2b6 100644 --- a/app/src/main/res/layout/fragment_trackers.xml +++ b/app/src/main/res/layout/fragment_trackers.xml @@ -2,23 +2,23 @@ - + + + /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_app_toggle.xml b/app/src/main/res/layout/item_app_toggle.xml index 7d02ec0..d0f565f 100644 --- a/app/src/main/res/layout/item_app_toggle.xml +++ b/app/src/main/res/layout/item_app_toggle.xml @@ -2,33 +2,33 @@ \ No newline at end of file diff --git a/app/src/main/res/layout/item_permission.xml b/app/src/main/res/layout/item_permission.xml index 8f54f64..66d4213 100644 --- a/app/src/main/res/layout/item_permission.xml +++ b/app/src/main/res/layout/item_permission.xml @@ -17,57 +17,57 @@ \ No newline at end of file diff --git a/app/src/main/res/layout/topbar.xml b/app/src/main/res/layout/topbar.xml index 9142d79..a493b3b 100644 --- a/app/src/main/res/layout/topbar.xml +++ b/app/src/main/res/layout/topbar.xml @@ -18,20 +18,20 @@ --> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb799d1..3105ddb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,7 +42,7 @@ Quick Protection Privacy Dashboard Click to learn more - \"Apps Permission\" + Apps Permission Trackers See trackers usage over time and manage trackers available in applications Following trackers are in use diff --git a/scripts/sign_and_push.sh b/scripts/sign_and_push.sh index dd37f2a..035a47b 100755 --- a/scripts/sign_and_push.sh +++ b/scripts/sign_and_push.sh @@ -10,7 +10,7 @@ adb root wait ${!} adb devices wait ${!} -adb install -r build/outputs/apk/e/debug/PrivacyCentral-e-debug-1.0.0-alpha.apk +adb install -r app/build/outputs/apk/e/debug/PrivacyCentral-e-debug-1.0.0-alpha.apk wait ${!} adb remount && adb push privapp-permissions-foundation.e.privacycentralapp.xml system/etc/permissions wait ${!} -- cgit v1.2.1