OmniControl: Add back QSSettingsFragment and update it to OmniLib

Change-Id: I232149fee243f37198fd937c05b2488bd183d567
diff --git a/app/src/main/java/org/omnirom/control/GridViewFragment.kt b/app/src/main/java/org/omnirom/control/GridViewFragment.kt
index aa05401..5d60695 100644
--- a/app/src/main/java/org/omnirom/control/GridViewFragment.kt
+++ b/app/src/main/java/org/omnirom/control/GridViewFragment.kt
@@ -157,14 +157,14 @@
                 OverlaysFragment()
             )
         )
-//        gridItems.add(
-//            FragmentGridItem(
-//                R.string.qs_settings_title,
-//                R.string.qs_settings_summary,
-//                R.drawable.ic_qs_tile,
-//                QSSettingsFragment()
-//            )
-//        )
+        gridItems.add(
+            FragmentGridItem(
+                R.string.qs_settings_title,
+                R.string.qs_settings_summary,
+                R.drawable.ic_qs_tile,
+                QSSettingsFragment()
+            )
+        )
         if (Utils.isAvailableApp(requireContext(), "org.omnirom.omniwallpaper")) {
             val intent = Intent()
             intent.component = ComponentName(
diff --git a/app/src/main/java/org/omnirom/control/QSSettingsFragment.kt b/app/src/main/java/org/omnirom/control/QSSettingsFragment.kt
index 5ae7afb..bdfe4ce 100644
--- a/app/src/main/java/org/omnirom/control/QSSettingsFragment.kt
+++ b/app/src/main/java/org/omnirom/control/QSSettingsFragment.kt
@@ -1,110 +1,110 @@
-///*
-// *  Copyright (C) 2021 The OmniROM Project
-// *
-// * 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 2 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 <http://www.gnu.org/licenses/>.
-// *
-// */
-//package org.omnirom.control
-//
-//import android.os.Bundle
-//import android.provider.Settings
-//import androidx.annotation.DrawableRes
-//import androidx.annotation.XmlRes
-//import androidx.preference.Preference
-//import org.omnirom.omnilib.preference.SeekBarPreference
-//import org.omnirom.omnilib.utils.OmniSettings
-//
-//class QSSettingsFragment : AbstractSettingsFragment() {
-//    companion object {
-//        @DrawableRes
-//        val ICON_RES = R.drawable.ic_qs_tile
-//        @XmlRes
-//        val XML_RES = R.xml.qs_settings_preferences
-//    }
-//    override fun getFragmentTitle(): String {
-//        return resources.getString(R.string.qs_settings_title)
-//    }
-//
-//    override fun getFragmentSummary(): String {
-//        return resources.getString(R.string.qs_settings_summary)
-//    }
-//
-//    override fun getFragmentIcon(): Int {
-//        return ICON_RES
-//    }
-//
-//    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
-//        setPreferencesFromResource(XML_RES, rootKey)
-//
-//        val pm = requireContext().packageManager
-//        val resources = pm.getResourcesForApplication("com.android.systemui")
-//
-//        var defPortraitColumns = 2
-//        val portraitColumns = findPreference<SeekBarPreference>("qs_layout_columns")
-//        if (portraitColumns != null) {
-//            var id =
-//                resources.getIdentifier(
-//                    "quick_settings_num_columns",
-//                    "integer",
-//                    "com.android.systemui"
-//                )
-//            if (id != 0) {
-//                defPortraitColumns = resources.getInteger(id)
-//            }
-//            val settingsPortraitColumns = Settings.System.getInt(
-//                requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS,
-//                defPortraitColumns
-//            )
-//            portraitColumns.setValue(settingsPortraitColumns)
-//            portraitColumns.onPreferenceChangeListener =
-//                Preference.OnPreferenceChangeListener { _, newValue ->
-//                    Settings.System.putInt(
-//                        requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS,
-//                        newValue as Int
-//                    )
-//                    true
-//                }
-//        }
-//        val landscapeColumns = findPreference<SeekBarPreference>("qs_layout_columns_landscape")
-//        if (landscapeColumns != null) {
-//            var defLandspaceColumns = defPortraitColumns
-//            var id =
-//                resources.getIdentifier(
-//                    "quick_settings_num_columns_landscape",
-//                    "integer",
-//                    "com.android.systemui"
-//                )
-//            if (id != 0) {
-//                defLandspaceColumns = resources.getInteger(id)
-//            }
-//            val settingsLandscapeColumns = Settings.System.getInt(
-//                requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS_LANDSCAPE,
-//                defLandspaceColumns
-//            )
-//            landscapeColumns.setValue(settingsLandscapeColumns)
-//            landscapeColumns.onPreferenceChangeListener =
-//                Preference.OnPreferenceChangeListener { _, newValue ->
-//                    Settings.System.putInt(
-//                        requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS_LANDSCAPE,
-//                        newValue as Int
-//                    )
-//                    true
-//                }
-//        }
-//    }
-//
-//    override fun onPreferenceTreeClick(preference: Preference): Boolean {
-//        return super.onPreferenceTreeClick(preference)
-//    }
-//}
+/*
+ *  Copyright (C) 2021 The OmniROM Project
+ *
+ * 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 2 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.control
+
+import android.os.Bundle
+import android.provider.Settings
+import androidx.annotation.DrawableRes
+import androidx.annotation.XmlRes
+import androidx.preference.Preference
+import omnirom.preference.SeekBarPreference
+import org.omnirom.omnilib.utils.OmniSettings
+
+class QSSettingsFragment : AbstractSettingsFragment() {
+    companion object {
+        @DrawableRes
+        val ICON_RES = R.drawable.ic_qs_tile
+        @XmlRes
+        val XML_RES = R.xml.qs_settings_preferences
+    }
+    override fun getFragmentTitle(): String {
+        return resources.getString(R.string.qs_settings_title)
+    }
+
+    override fun getFragmentSummary(): String {
+        return resources.getString(R.string.qs_settings_summary)
+    }
+
+    override fun getFragmentIcon(): Int {
+        return ICON_RES
+    }
+
+    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+        setPreferencesFromResource(XML_RES, rootKey)
+
+        val pm = requireContext().packageManager
+        val resources = pm.getResourcesForApplication("com.android.systemui")
+
+        var defPortraitColumns = 2
+        val portraitColumns = findPreference<SeekBarPreference>("qs_layout_columns")
+        if (portraitColumns != null) {
+            var id =
+                resources.getIdentifier(
+                    "quick_settings_num_columns",
+                    "integer",
+                    "com.android.systemui"
+                )
+            if (id != 0) {
+                defPortraitColumns = resources.getInteger(id)
+            }
+            val settingsPortraitColumns = Settings.System.getInt(
+                requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS,
+                defPortraitColumns
+            )
+            portraitColumns.setValue(settingsPortraitColumns)
+            portraitColumns.onPreferenceChangeListener =
+                Preference.OnPreferenceChangeListener { _, newValue ->
+                    Settings.System.putInt(
+                        requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS,
+                        newValue as Int
+                    )
+                    true
+                }
+        }
+        val landscapeColumns = findPreference<SeekBarPreference>("qs_layout_columns_landscape")
+        if (landscapeColumns != null) {
+            var defLandspaceColumns = defPortraitColumns
+            var id =
+                resources.getIdentifier(
+                    "quick_settings_num_columns_landscape",
+                    "integer",
+                    "com.android.systemui"
+                )
+            if (id != 0) {
+                defLandspaceColumns = resources.getInteger(id)
+            }
+            val settingsLandscapeColumns = Settings.System.getInt(
+                requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS_LANDSCAPE,
+                defLandspaceColumns
+            )
+            landscapeColumns.setValue(settingsLandscapeColumns)
+            landscapeColumns.onPreferenceChangeListener =
+                Preference.OnPreferenceChangeListener { _, newValue ->
+                    Settings.System.putInt(
+                        requireContext().contentResolver, OmniSettings.OMNI_QS_LAYOUT_COLUMNS_LANDSCAPE,
+                        newValue as Int
+                    )
+                    true
+                }
+        }
+    }
+
+    override fun onPreferenceTreeClick(preference: Preference): Boolean {
+        return super.onPreferenceTreeClick(preference)
+    }
+}
diff --git a/app/src/main/java/org/omnirom/control/search/SearchProvider.kt b/app/src/main/java/org/omnirom/control/search/SearchProvider.kt
index 76a8583..1ddf97a 100644
--- a/app/src/main/java/org/omnirom/control/search/SearchProvider.kt
+++ b/app/src/main/java/org/omnirom/control/search/SearchProvider.kt
@@ -29,7 +29,7 @@
 import org.omnirom.control.FingerprintSettingsFragment
 import org.omnirom.control.LockscreenSettingsFragment
 import org.omnirom.control.MoreSettingsFragment
-//import org.omnirom.control.QSSettingsFragment
+import org.omnirom.control.QSSettingsFragment
 import org.omnirom.control.search.PreferenceXmlParserUtils.METADATA_KEY
 import org.omnirom.control.search.PreferenceXmlParserUtils.METADATA_SUMMARY
 import org.omnirom.control.search.PreferenceXmlParserUtils.METADATA_TITLE
@@ -88,14 +88,14 @@
                 this::isEnabled
             )
         )
-//        searchItemList.add(
-//            SearchItem(
-//                QSSettingsFragment.XML_RES,
-//                QSSettingsFragment().javaClass.canonicalName,
-//                QSSettingsFragment.ICON_RES,
-//                this::isEnabled
-//            )
-//        )
+        searchItemList.add(
+            SearchItem(
+                QSSettingsFragment.XML_RES,
+                QSSettingsFragment().javaClass.canonicalName,
+                QSSettingsFragment.ICON_RES,
+                this::isEnabled
+            )
+        )
 
         searchItemList.add(
             SearchItem(