Added Services into its own menu

This commit is contained in:
partisan 2025-05-16 12:50:35 +02:00
parent 72d4a797ea
commit 2939fb55d1
10 changed files with 243 additions and 139 deletions

View file

@ -54,6 +54,13 @@ class MainActivity : AppCompatActivity() {
.commit() .commit()
true true
} }
R.id.action_services -> {
supportFragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, ServiceSettingsFragment())
.addToBackStack(null)
.commit()
true
}
R.id.action_contacts -> { R.id.action_contacts -> {
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, ContactsFragment()) .replace(R.id.fragmentContainer, ContactsFragment())

View file

@ -30,36 +30,6 @@ class PopupSettingsFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
prefs = Preferences(requireContext())
window = PopupWindow(requireContext(), null)
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( val services = listOf(
ServiceEntry( ServiceEntry(
"vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call", "vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call",
@ -93,17 +63,16 @@ class PopupSettingsFragment : Fragment() {
} }
) )
serviceRecycler.adapter = adapter binding.serviceRecycler.adapter = adapter
serviceRecycler.layoutManager = LinearLayoutManager(requireContext()) binding.serviceRecycler.layoutManager = LinearLayoutManager(requireContext())
val touchHelper = ItemTouchHelper(adapter.dragHelper) val touchHelper = ItemTouchHelper(adapter.dragHelper)
touchHelper.attachToRecyclerView(serviceRecycler) touchHelper.attachToRecyclerView(binding.serviceRecycler)
adapter.setDragStartListener { viewHolder -> adapter.setDragStartListener { viewHolder ->
touchHelper.startDrag(viewHolder) touchHelper.startDrag(viewHolder)
} }
} }
}
private fun getScreenHeightPx(): Int { private fun getScreenHeightPx(): Int {
val metrics = DisplayMetrics() val metrics = DisplayMetrics()

View file

@ -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
}
}

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M16.5,3c-1.74,0 -3.41,0.81 -4.5,2.09C10.91,3.81 9.24,3 7.5,3 4.42,3 2,5.42 2,8.5c0,3.78 3.4,6.86 8.55,11.54L12,21.35l1.45,-1.32C18.6,15.36 22,12.28 22,8.5 22,5.42 19.58,3 16.5,3zM12.1,18.55l-0.1,0.1 -0.1,-0.1C7.14,14.24 4,11.39 4,8.5 4,6.5 5.5,5 7.5,5c1.54,0 3.04,0.99 3.57,2.36h1.87C13.46,5.99 14.96,5 16.5,5c2,0 3.5,1.5 3.5,3.5 0,2.89 -3.14,5.74 -7.9,10.05z"/>
</vector>

View file

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.17,13.71l1.4,-2.42c0.09,-0.15 0.05,-0.34 -0.08,-0.45l-1.48,-1.16c0.03,-0.22 0.05,-0.45 0.05,-0.68s-0.02,-0.46 -0.05,-0.69l1.48,-1.16c0.13,-0.11 0.17,-0.3 0.08,-0.45l-1.4,-2.42c-0.09,-0.15 -0.27,-0.21 -0.43,-0.15L12,4.83c-0.36,-0.28 -0.75,-0.51 -1.18,-0.69l-0.26,-1.85C10.53,2.13 10.38,2 10.21,2h-2.8C7.24,2 7.09,2.13 7.06,2.3L6.8,4.15C6.38,4.33 5.98,4.56 5.62,4.84l-1.74,-0.7c-0.16,-0.06 -0.34,0 -0.43,0.15l-1.4,2.42C1.96,6.86 2,7.05 2.13,7.16l1.48,1.16C3.58,8.54 3.56,8.77 3.56,9s0.02,0.46 0.05,0.69l-1.48,1.16C2,10.96 1.96,11.15 2.05,11.3l1.4,2.42c0.09,0.15 0.27,0.21 0.43,0.15l1.74,-0.7c0.36,0.28 0.75,0.51 1.18,0.69l0.26,1.85C7.09,15.87 7.24,16 7.41,16h2.8c0.17,0 0.32,-0.13 0.35,-0.3l0.26,-1.85c0.42,-0.18 0.82,-0.41 1.18,-0.69l1.74,0.7C13.9,13.92 14.08,13.86 14.17,13.71zM8.81,11c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2C10.81,10.1 9.91,11 8.81,11z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M21.92,18.67l-0.96,-0.74c0.02,-0.14 0.04,-0.29 0.04,-0.44c0,-0.15 -0.01,-0.3 -0.04,-0.44l0.95,-0.74c0.08,-0.07 0.11,-0.19 0.05,-0.29l-0.9,-1.55c-0.05,-0.1 -0.17,-0.13 -0.28,-0.1l-1.11,0.45c-0.23,-0.18 -0.48,-0.33 -0.76,-0.44l-0.17,-1.18C18.73,13.08 18.63,13 18.53,13h-1.79c-0.11,0 -0.21,0.08 -0.22,0.19l-0.17,1.18c-0.27,0.12 -0.53,0.26 -0.76,0.44l-1.11,-0.45c-0.1,-0.04 -0.22,0 -0.28,0.1l-0.9,1.55c-0.05,0.1 -0.04,0.22 0.05,0.29l0.95,0.74c-0.02,0.14 -0.03,0.29 -0.03,0.44c0,0.15 0.01,0.3 0.03,0.44l-0.95,0.74c-0.08,0.07 -0.11,0.19 -0.05,0.29l0.9,1.55c0.05,0.1 0.17,0.13 0.28,0.1l1.11,-0.45c0.23,0.18 0.48,0.33 0.76,0.44l0.17,1.18c0.02,0.11 0.11,0.19 0.22,0.19h1.79c0.11,0 0.21,-0.08 0.22,-0.19l0.17,-1.18c0.27,-0.12 0.53,-0.26 0.75,-0.44l1.12,0.45c0.1,0.04 0.22,0 0.28,-0.1l0.9,-1.55C22.03,18.86 22,18.74 21.92,18.67zM17.63,18.83c-0.74,0 -1.35,-0.6 -1.35,-1.35s0.6,-1.35 1.35,-1.35s1.35,0.6 1.35,1.35S18.37,18.83 17.63,18.83z"/>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>

View file

@ -20,39 +20,23 @@
<CheckBox <CheckBox
android:id="@+id/popupEnabledCheckbox" android:id="@+id/popupEnabledCheckbox"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/popup_enabled" android:text="@string/popup_enabled"
android:textSize="14sp" android:textSize="14sp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/description" app:layout_constraintTop_toBottomOf="@id/description"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/popupPreview" /> app:layout_constraintEnd_toEndOf="parent" />
<Button <Button
android:id="@+id/popupPreview" android:id="@+id/popupPreview"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/test" android:text="@string/test"
app:layout_constraintTop_toTopOf="@id/popupEnabledCheckbox" android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@id/popupEnabledCheckbox"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/popupEnabledCheckbox" app:layout_constraintTop_toBottomOf="@id/popupEnabledCheckbox"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.slider.Slider <com.google.android.material.slider.Slider
android:id="@+id/redirectionDelay" android:id="@+id/redirectionDelay"
@ -102,6 +86,4 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:scrollbars="vertical" android:scrollbars="vertical"
android:layout_marginTop="8dp" /> android:layout_marginTop="8dp" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/serviceHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/service_settings_title"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="8dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/serviceRecycler"
android:layout_width="0dp"
android:layout_height="0dp"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="@id/serviceHeader"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -6,16 +6,21 @@
android:id="@+id/section_settings" android:id="@+id/section_settings"
android:title="Settings" android:title="Settings"
android:enabled="false" /> android:enabled="false" />
<item
android:id="@+id/action_popup_settings"
android:title="Popup Settings"
android:icon="@drawable/tooltip_24px"
app:showAsAction="never" />
<item <item
android:id="@+id/action_contacts" android:id="@+id/action_contacts"
android:title="Contacts" android:title="Contacts"
android:icon="@drawable/group_24px" android:icon="@drawable/group_24px"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_popup_settings"
android:title="Popup"
android:icon="@drawable/tooltip_24px"
app:showAsAction="never" />
<item
android:id="@+id/action_services"
android:title="Services"
android:icon="@drawable/services_24"
app:showAsAction="never" />
<!-- About section --> <!-- About section -->
<item <item

View file

@ -11,6 +11,7 @@
<string name="popup_position">Popup position</string> <string name="popup_position">Popup position</string>
<string name="fallback">Fallback</string> <string name="fallback">Fallback</string>
<string name="activate_description">To start, grant the required permissions by tapping the Activate button.</string> <string name="activate_description">To start, grant the required permissions by tapping the Activate button.</string>
<string name="service_settings_title">Service Preferences</string>
<string name="activate">Activate</string> <string name="activate">Activate</string>
<string name="navigation_drawer_open">Open menu</string> <string name="navigation_drawer_open">Open menu</string>
<string name="navigation_drawer_close">Close menu</string> <string name="navigation_drawer_close">Close menu</string>