diff --git a/app/build.gradle b/app/build.gradle index 00252cc..c743a7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,7 +29,7 @@ android { buildTypes { release { minifyEnabled = false - signingConfig signingConfigs.release + signingConfig = signingConfigs.release proguardFiles(getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro') } } 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..9e607fe 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt @@ -1,5 +1,7 @@ package partisan.weforge.xyz.pulse +import android.graphics.Rect +import android.os.Build import android.os.Bundle import android.util.DisplayMetrics import android.view.LayoutInflater @@ -8,6 +10,7 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import androidx.core.content.getSystemService import partisan.weforge.xyz.pulse.databinding.FragmentPopupSettingsBinding class PopupSettingsFragment : Fragment() { @@ -30,85 +33,61 @@ 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) } } private fun getScreenHeightPx(): Int { - val metrics = DisplayMetrics() - requireActivity().windowManager.defaultDisplay.getMetrics(metrics) - return metrics.heightPixels + val wm = requireContext().getSystemService()!! + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val bounds: Rect = wm.currentWindowMetrics.bounds + bounds.height() + } else { + val metrics = DisplayMetrics() + @Suppress("DEPRECATION") + requireActivity().windowManager.defaultDisplay.getMetrics(metrics) + metrics.heightPixels + } } override fun onDestroyView() { diff --git a/app/src/main/java/partisan/weforge/xyz/pulse/ServiceAdapter.kt b/app/src/main/java/partisan/weforge/xyz/pulse/ServiceAdapter.kt index 6565c3b..59edda9 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/ServiceAdapter.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/ServiceAdapter.kt @@ -66,8 +66,8 @@ class ServiceAdapter( viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder ): Boolean { - val from = viewHolder.adapterPosition - val to = target.adapterPosition + val from = viewHolder.bindingAdapterPosition + val to = target.bindingAdapterPosition services.add(to, services.removeAt(from)) notifyItemMoved(from, to) return true 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" />