From 2939fb55d14f0e0dc9f0ddf77ba177248c7965f1 Mon Sep 17 00:00:00 2001 From: partisan Date: Fri, 16 May 2025 12:50:35 +0200 Subject: [PATCH 1/2] Added Services into its own menu --- .../weforge/xyz/pulse/MainActivity.kt | 7 ++ .../xyz/pulse/PopupSettingsFragment.kt | 107 ++++++----------- .../weforge/xyz/pulse/ServicesFragment.kt | 77 ++++++++++++ app/src/main/res/drawable/heart_24.xml | 10 ++ app/src/main/res/drawable/services_24.xml | 13 ++ app/src/main/res/drawable/settings_24.xml | 10 ++ .../res/layout/fragment_popup_settings.xml | 112 ++++++++---------- .../res/layout/fragment_service_settings.xml | 30 +++++ app/src/main/res/menu/main_menu.xml | 15 ++- app/src/main/res/values/strings.xml | 1 + 10 files changed, 243 insertions(+), 139 deletions(-) create mode 100644 app/src/main/java/partisan/weforge/xyz/pulse/ServicesFragment.kt create mode 100644 app/src/main/res/drawable/heart_24.xml create mode 100644 app/src/main/res/drawable/services_24.xml create mode 100644 app/src/main/res/drawable/settings_24.xml create mode 100644 app/src/main/res/layout/fragment_service_settings.xml diff --git a/app/src/main/java/partisan/weforge/xyz/pulse/MainActivity.kt b/app/src/main/java/partisan/weforge/xyz/pulse/MainActivity.kt index 10d060c..91749d7 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/MainActivity.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/MainActivity.kt @@ -54,6 +54,13 @@ class MainActivity : AppCompatActivity() { .commit() true } + R.id.action_services -> { + supportFragmentManager.beginTransaction() + .replace(R.id.fragmentContainer, ServiceSettingsFragment()) + .addToBackStack(null) + .commit() + true + } R.id.action_contacts -> { supportFragmentManager.beginTransaction() .replace(R.id.fragmentContainer, ContactsFragment()) diff --git a/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt b/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt index 9c084af..ac4b0f4 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt @@ -30,78 +30,47 @@ class PopupSettingsFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - prefs = Preferences(requireContext()) - window = PopupWindow(requireContext(), null) + val services = listOf( + ServiceEntry( + "vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call", + R.string.destination_signal, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call") + ), + ServiceEntry( + "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call", + R.string.destination_telegram, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.org.telegram.messenger.android.call") + ), + ServiceEntry( + "vnd.android.cursor.item/vnd.ch.threema.app.call", + R.string.destination_threema, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.ch.threema.app.call") + ), + ServiceEntry( + "vnd.android.cursor.item/vnd.com.whatsapp.voip.call", + R.string.destination_whatsapp, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.com.whatsapp.voip.call") + ), + ) - val screenHeight = getScreenHeightPx() - - binding.apply { - redirectionDelay.value = (prefs.redirectionDelay / 1000).toFloat() - redirectionDelay.setLabelFormatter { - String.format("%.1f", it) - } - redirectionDelay.addOnChangeListener { _, value, _ -> - prefs.redirectionDelay = (value * 1000).toLong() - } - - popupEnabledCheckbox.isChecked = prefs.popupEnabled - popupEnabledCheckbox.setOnCheckedChangeListener { _, isChecked -> - prefs.popupEnabled = isChecked - } - - popupPreview.setOnClickListener { - window.preview() - } - - popupHeightSlider.valueFrom = 0f - popupHeightSlider.valueTo = screenHeight.toFloat() - popupHeightSlider.value = prefs.popupPosition.toFloat() - popupHeightSlider.addOnChangeListener { _, value, _ -> - prefs.popupPosition = value.toInt().coerceIn(0, screenHeight) - } - - val services = listOf( - ServiceEntry( - "vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call", - R.string.destination_signal, - requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call") - ), - ServiceEntry( - "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call", - R.string.destination_telegram, - requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.org.telegram.messenger.android.call") - ), - ServiceEntry( - "vnd.android.cursor.item/vnd.ch.threema.app.call", - R.string.destination_threema, - requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.ch.threema.app.call") - ), - ServiceEntry( - "vnd.android.cursor.item/vnd.com.whatsapp.voip.call", - R.string.destination_whatsapp, - requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.com.whatsapp.voip.call") - ), - ) - - val adapter = ServiceAdapter( - context = requireContext(), - services = services.toMutableList(), - onReordered = { updatedList -> - updatedList.forEachIndexed { index, entry -> - requireContext().setServicePriority(entry.mimetype, index) - } + val adapter = ServiceAdapter( + context = requireContext(), + services = services.toMutableList(), + onReordered = { updatedList -> + updatedList.forEachIndexed { index, entry -> + requireContext().setServicePriority(entry.mimetype, index) } - ) - - serviceRecycler.adapter = adapter - serviceRecycler.layoutManager = LinearLayoutManager(requireContext()) - - val touchHelper = ItemTouchHelper(adapter.dragHelper) - touchHelper.attachToRecyclerView(serviceRecycler) - - adapter.setDragStartListener { viewHolder -> - touchHelper.startDrag(viewHolder) } + ) + + binding.serviceRecycler.adapter = adapter + binding.serviceRecycler.layoutManager = LinearLayoutManager(requireContext()) + + val touchHelper = ItemTouchHelper(adapter.dragHelper) + touchHelper.attachToRecyclerView(binding.serviceRecycler) + + adapter.setDragStartListener { viewHolder -> + touchHelper.startDrag(viewHolder) } } diff --git a/app/src/main/java/partisan/weforge/xyz/pulse/ServicesFragment.kt b/app/src/main/java/partisan/weforge/xyz/pulse/ServicesFragment.kt new file mode 100644 index 0000000..104ceeb --- /dev/null +++ b/app/src/main/java/partisan/weforge/xyz/pulse/ServicesFragment.kt @@ -0,0 +1,77 @@ +package partisan.weforge.xyz.pulse + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.ItemTouchHelper +import androidx.recyclerview.widget.LinearLayoutManager +import partisan.weforge.xyz.pulse.databinding.FragmentServiceSettingsBinding + +class ServiceSettingsFragment : Fragment() { + + private var _binding: FragmentServiceSettingsBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentServiceSettingsBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val services = listOf( + ServiceEntry( + "vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call", + R.string.destination_signal, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call") + ), + ServiceEntry( + "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call", + R.string.destination_telegram, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.org.telegram.messenger.android.call") + ), + ServiceEntry( + "vnd.android.cursor.item/vnd.ch.threema.app.call", + R.string.destination_threema, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.ch.threema.app.call") + ), + ServiceEntry( + "vnd.android.cursor.item/vnd.com.whatsapp.voip.call", + R.string.destination_whatsapp, + requireContext().isServiceEnabled("vnd.android.cursor.item/vnd.com.whatsapp.voip.call") + ), + ) + + val adapter = ServiceAdapter( + context = requireContext(), + services = services.toMutableList(), + onReordered = { updatedList -> + updatedList.forEachIndexed { index, entry -> + requireContext().setServicePriority(entry.mimetype, index) + } + } + ) + + binding.serviceRecycler.adapter = adapter + binding.serviceRecycler.layoutManager = LinearLayoutManager(requireContext()) + + val touchHelper = ItemTouchHelper(adapter.dragHelper) + touchHelper.attachToRecyclerView(binding.serviceRecycler) + + adapter.setDragStartListener { viewHolder -> + touchHelper.startDrag(viewHolder) + } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} diff --git a/app/src/main/res/drawable/heart_24.xml b/app/src/main/res/drawable/heart_24.xml new file mode 100644 index 0000000..3edfe1d --- /dev/null +++ b/app/src/main/res/drawable/heart_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/services_24.xml b/app/src/main/res/drawable/services_24.xml new file mode 100644 index 0000000..5bbe6bf --- /dev/null +++ b/app/src/main/res/drawable/services_24.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/settings_24.xml b/app/src/main/res/drawable/settings_24.xml new file mode 100644 index 0000000..41a82ed --- /dev/null +++ b/app/src/main/res/drawable/settings_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_popup_settings.xml b/app/src/main/res/layout/fragment_popup_settings.xml index c9cec7c..2afe2ae 100644 --- a/app/src/main/res/layout/fragment_popup_settings.xml +++ b/app/src/main/res/layout/fragment_popup_settings.xml @@ -20,88 +20,70 @@ + app:layout_constraintEnd_toEndOf="parent" />