From da842396556248654acacfdebbc01f5e20132eb6 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Fri, 14 May 2021 21:20:57 +0530 Subject: Extract toolbar implementation and add back navigation support --- .../privacycentralapp/common/NavToolbarFragment.kt | 34 ++++++++++++++++++ .../e/privacycentralapp/common/ToolbarFragment.kt | 42 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt create mode 100644 app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt (limited to 'app/src/main/java/foundation/e/privacycentralapp/common') diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt new file mode 100644 index 0000000..0a9d102 --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt @@ -0,0 +1,34 @@ +/* + * 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.common + +import android.widget.Toolbar +import androidx.annotation.LayoutRes + +abstract class NavToolbarFragment(@LayoutRes contentLayoutId: Int) : ToolbarFragment(contentLayoutId) { + + override fun setupToolbar(toolbar: Toolbar) { + super.setupToolbar(toolbar) + toolbar.apply { + setNavigationIcon(lineageos.platform.R.drawable.ic_back) + setNavigationOnClickListener { + requireActivity().onBackPressed() + } + } + } +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt new file mode 100644 index 0000000..c316340 --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt @@ -0,0 +1,42 @@ +/* + * 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.common + +import android.os.Bundle +import android.view.View +import android.widget.Toolbar +import androidx.annotation.LayoutRes +import androidx.fragment.app.Fragment +import foundation.e.privacycentralapp.R + +abstract class ToolbarFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLayoutId) { + + /** + * @return title to be used in toolbar + */ + abstract fun getTitle(): String + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupToolbar(view.findViewById(R.id.toolbar)) + } + + open fun setupToolbar(toolbar: Toolbar) { + toolbar.title = getTitle() + } +} -- cgit v1.2.3 From 47194484d7c2ca6ce8103312b9dbfb1244e8c4e6 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Sat, 15 May 2021 01:18:21 +0530 Subject: Use MaterialToolbar from MDC instead of android Toolbar --- .../privacycentralapp/common/NavToolbarFragment.kt | 4 +-- .../e/privacycentralapp/common/ToolbarFragment.kt | 5 +-- app/src/main/res/layout/fragment_dashboard.xml | 8 ++--- app/src/main/res/layout/fragment_fake_location.xml | 10 +++--- .../layout/fragment_internet_activity_policy.xml | 8 ++--- .../main/res/layout/fragment_permission_apps.xml | 7 ++-- app/src/main/res/layout/fragment_permissions.xml | 7 ++-- .../main/res/layout/fragment_quick_protection.xml | 7 ++-- app/src/main/res/layout/toolbar.xml | 28 ---------------- app/src/main/res/layout/topbar.xml | 37 ++++++++++++++++++++++ 10 files changed, 64 insertions(+), 57 deletions(-) delete mode 100644 app/src/main/res/layout/toolbar.xml create mode 100644 app/src/main/res/layout/topbar.xml (limited to 'app/src/main/java/foundation/e/privacycentralapp/common') diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt index 0a9d102..52197cd 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/NavToolbarFragment.kt @@ -17,12 +17,12 @@ package foundation.e.privacycentralapp.common -import android.widget.Toolbar import androidx.annotation.LayoutRes +import com.google.android.material.appbar.MaterialToolbar abstract class NavToolbarFragment(@LayoutRes contentLayoutId: Int) : ToolbarFragment(contentLayoutId) { - override fun setupToolbar(toolbar: Toolbar) { + override fun setupToolbar(toolbar: MaterialToolbar) { super.setupToolbar(toolbar) toolbar.apply { setNavigationIcon(lineageos.platform.R.drawable.ic_back) diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt index c316340..f156e09 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/ToolbarFragment.kt @@ -19,9 +19,9 @@ package foundation.e.privacycentralapp.common import android.os.Bundle import android.view.View -import android.widget.Toolbar import androidx.annotation.LayoutRes import androidx.fragment.app.Fragment +import com.google.android.material.appbar.MaterialToolbar import foundation.e.privacycentralapp.R abstract class ToolbarFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLayoutId) { @@ -33,10 +33,11 @@ abstract class ToolbarFragment(@LayoutRes contentLayoutId: Int) : Fragment(conte override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + setupToolbar(view.findViewById(R.id.toolbar)) } - open fun setupToolbar(toolbar: Toolbar) { + open fun setupToolbar(toolbar: MaterialToolbar) { toolbar.title = getTitle() } } diff --git a/app/src/main/res/layout/fragment_dashboard.xml b/app/src/main/res/layout/fragment_dashboard.xml index 027945d..dc79878 100644 --- a/app/src/main/res/layout/fragment_dashboard.xml +++ b/app/src/main/res/layout/fragment_dashboard.xml @@ -1,12 +1,12 @@ - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_fake_location.xml b/app/src/main/res/layout/fragment_fake_location.xml index de62537..40324a1 100644 --- a/app/src/main/res/layout/fragment_fake_location.xml +++ b/app/src/main/res/layout/fragment_fake_location.xml @@ -1,5 +1,5 @@ - - + @@ -131,4 +131,4 @@ - \ No newline at end of file + \ No newline at end of file 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 66ff2b4..7a5d8b5 100644 --- a/app/src/main/res/layout/fragment_internet_activity_policy.xml +++ b/app/src/main/res/layout/fragment_internet_activity_policy.xml @@ -1,5 +1,5 @@ - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_permission_apps.xml b/app/src/main/res/layout/fragment_permission_apps.xml index 605b6ff..65f4169 100644 --- a/app/src/main/res/layout/fragment_permission_apps.xml +++ b/app/src/main/res/layout/fragment_permission_apps.xml @@ -1,5 +1,5 @@ - - + @@ -36,4 +35,4 @@ tools:listitem="@layout/item_permission_apps" android:id="@+id/recylcer_view_permission_apps"/> - \ No newline at end of file + \ 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 72748b4..a452570 100644 --- a/app/src/main/res/layout/fragment_permissions.xml +++ b/app/src/main/res/layout/fragment_permissions.xml @@ -1,5 +1,5 @@ - - + @@ -47,4 +46,4 @@ tools:listitem="@layout/item_permission" android:id="@+id/recylcer_view_permissions"/> - \ No newline at end of file + \ 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 55d6f71..d57a101 100644 --- a/app/src/main/res/layout/fragment_quick_protection.xml +++ b/app/src/main/res/layout/fragment_quick_protection.xml @@ -1,18 +1,17 @@ - - + @@ -57,4 +56,4 @@ android:textSize="14sp" android:fontFamily="sans-serif-medium" android:layout_gravity="bottom|right"/> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/toolbar.xml b/app/src/main/res/layout/toolbar.xml deleted file mode 100644 index 29c1fa1..0000000 --- a/app/src/main/res/layout/toolbar.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/topbar.xml b/app/src/main/res/layout/topbar.xml new file mode 100644 index 0000000..9142d79 --- /dev/null +++ b/app/src/main/res/layout/topbar.xml @@ -0,0 +1,37 @@ + + + + + + + + -- cgit v1.2.3