diff --git a/app/build.gradle b/app/build.gradle index c743a7d..00252cc 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 91749d7..10d060c 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/MainActivity.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/MainActivity.kt @@ -54,13 +54,6 @@ 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 9e607fe..9c084af 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/PopupSettingsFragment.kt @@ -1,7 +1,5 @@ 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 @@ -10,7 +8,6 @@ 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() { @@ -33,61 +30,85 @@ class PopupSettingsFragment : Fragment() { 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") - ), - ) + prefs = Preferences(requireContext()) + window = PopupWindow(requireContext(), null) - val adapter = ServiceAdapter( - context = requireContext(), - services = services.toMutableList(), - onReordered = { updatedList -> - updatedList.forEachIndexed { index, entry -> - requireContext().setServicePriority(entry.mimetype, index) - } + 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() } - ) - binding.serviceRecycler.adapter = adapter - binding.serviceRecycler.layoutManager = LinearLayoutManager(requireContext()) + popupEnabledCheckbox.isChecked = prefs.popupEnabled + popupEnabledCheckbox.setOnCheckedChangeListener { _, isChecked -> + prefs.popupEnabled = isChecked + } - val touchHelper = ItemTouchHelper(adapter.dragHelper) - touchHelper.attachToRecyclerView(binding.serviceRecycler) + popupPreview.setOnClickListener { + window.preview() + } - adapter.setDragStartListener { viewHolder -> - touchHelper.startDrag(viewHolder) + 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) + } + } + ) + + serviceRecycler.adapter = adapter + serviceRecycler.layoutManager = LinearLayoutManager(requireContext()) + + val touchHelper = ItemTouchHelper(adapter.dragHelper) + touchHelper.attachToRecyclerView(serviceRecycler) + + adapter.setDragStartListener { viewHolder -> + touchHelper.startDrag(viewHolder) + } } } private fun getScreenHeightPx(): Int { - 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 - } + val metrics = DisplayMetrics() + requireActivity().windowManager.defaultDisplay.getMetrics(metrics) + return 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 59edda9..6565c3b 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.bindingAdapterPosition - val to = target.bindingAdapterPosition + val from = viewHolder.adapterPosition + val to = target.adapterPosition 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 deleted file mode 100644 index 104ceeb..0000000 --- a/app/src/main/java/partisan/weforge/xyz/pulse/ServicesFragment.kt +++ /dev/null @@ -1,77 +0,0 @@ -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 deleted file mode 100644 index 3edfe1d..0000000 --- a/app/src/main/res/drawable/heart_24.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/services_24.xml b/app/src/main/res/drawable/services_24.xml deleted file mode 100644 index 5bbe6bf..0000000 --- a/app/src/main/res/drawable/services_24.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - diff --git a/app/src/main/res/drawable/settings_24.xml b/app/src/main/res/drawable/settings_24.xml deleted file mode 100644 index 41a82ed..0000000 --- a/app/src/main/res/drawable/settings_24.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/layout/fragment_popup_settings.xml b/app/src/main/res/layout/fragment_popup_settings.xml index 2afe2ae..c9cec7c 100644 --- a/app/src/main/res/layout/fragment_popup_settings.xml +++ b/app/src/main/res/layout/fragment_popup_settings.xml @@ -20,70 +20,88 @@ + app:layout_constraintEnd_toStartOf="@id/popupPreview" />