Skip to content

Commit

Permalink
Fix : add navigation icon + title (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenfeld authored Oct 2, 2024
1 parent 09b7105 commit 53c564d
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import de.westnordost.streetcomplete.quests.tree.FILENAME_TREES
import de.westnordost.streetcomplete.screens.HasTitle
import de.westnordost.streetcomplete.util.dialogs.setViewWithDefaultPadding
import de.westnordost.streetcomplete.util.getFakeCustomOverlays
import de.westnordost.streetcomplete.util.ktx.setUpToolbarTitleAndIcon
import de.westnordost.streetcomplete.util.ktx.toast
import de.westnordost.streetcomplete.util.logs.Log
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -78,7 +79,7 @@ class DataManagementSettingsFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.rootView.findViewById<Toolbar>(R.id.toolbar)?.apply {
// setUpToolbarTitleAndIcon(this)
setUpToolbarTitleAndIcon(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.LatLon
import de.westnordost.streetcomplete.data.visiblequests.VisibleQuestTypeController
import de.westnordost.streetcomplete.screens.HasTitle
import de.westnordost.streetcomplete.util.dialogs.setViewWithDefaultPadding
import de.westnordost.streetcomplete.util.ktx.setUpToolbarTitleAndIcon
import de.westnordost.streetcomplete.util.ktx.toast
import io.ticofab.androidgpxparser.parser.GPXParser
import kotlinx.coroutines.GlobalScope
Expand All @@ -49,7 +50,7 @@ class DisplaySettingsFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.rootView.findViewById<Toolbar>(R.id.toolbar)?.apply {
// setUpToolbarTitleAndIcon(this)
setUpToolbarTitleAndIcon(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import de.westnordost.streetcomplete.data.osmnotes.notequests.getRawBlockList
import de.westnordost.streetcomplete.data.preferences.Preferences
import de.westnordost.streetcomplete.screens.HasTitle
import de.westnordost.streetcomplete.util.dialogs.setDefaultDialogPadding
import de.westnordost.streetcomplete.util.ktx.setUpToolbarTitleAndIcon
import de.westnordost.streetcomplete.util.ktx.toast
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
Expand All @@ -40,7 +41,7 @@ class NoteSettingsFragment : PreferenceFragmentCompat(), HasTitle {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.rootView.findViewById<Toolbar>(R.id.toolbar)?.apply {
// setUpToolbarTitleAndIcon(this)
setUpToolbarTitleAndIcon(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import de.westnordost.streetcomplete.screens.HasTitle
import de.westnordost.streetcomplete.util.dialogs.setViewWithDefaultPadding
import de.westnordost.streetcomplete.util.ktx.dpToPx
import de.westnordost.streetcomplete.util.ktx.hasPermission
import de.westnordost.streetcomplete.util.ktx.setUpToolbarTitleAndIcon
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
Expand All @@ -53,7 +54,7 @@ class QuestsSettingsFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.rootView.findViewById<Toolbar>(R.id.toolbar)?.apply {
// setUpToolbarTitleAndIcon(this)
setUpToolbarTitleAndIcon(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.preference.DialogPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
Expand All @@ -22,6 +23,7 @@ import de.westnordost.streetcomplete.Prefs
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.screens.HasTitle
import de.westnordost.streetcomplete.util.dialogs.setViewWithDefaultPadding
import de.westnordost.streetcomplete.util.ktx.setUpToolbarTitleAndIcon
import org.koin.android.ext.android.inject

class UiSettingsFragment : PreferenceFragmentCompat(), HasTitle {
Expand All @@ -33,7 +35,7 @@ class UiSettingsFragment : PreferenceFragmentCompat(), HasTitle {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.rootView.findViewById<Toolbar>(R.id.toolbar)?.apply {
// setUpToolbarTitleAndIcon(this)
setUpToolbarTitleAndIcon(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.westnordost.streetcomplete.util.ktx

import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import de.westnordost.streetcomplete.screens.HasTitle
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
Expand All @@ -25,3 +27,22 @@ fun <T> Fragment.observe(flow: SharedFlow<T>, collector: FlowCollector<T>) {
}
}
}

fun Fragment.setUpToolbarTitleAndIcon(toolbar: Toolbar) {
if (this is HasTitle) {
toolbar.title = title
toolbar.subtitle = subtitle
}

val typedArray =
toolbar.context.obtainStyledAttributes(intArrayOf(androidx.appcompat.R.attr.homeAsUpIndicator))
val attributeResourceId = typedArray.getResourceId(0, 0)
val backIcon = toolbar.context.getDrawable(attributeResourceId)
typedArray.recycle()

toolbar.setNavigationOnClickListener {
requireActivity().onBackPressedDispatcher.onBackPressed()
}

toolbar.navigationIcon = backIcon
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</style>

<style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
<item name="tint">?attr/colorControlNormal</item>
<item name="tint">@android:color/white</item>
</style>

</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/xml/preferences_ee_data_management.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<SwitchPreference
app:iconSpaceReserved="false"
android:key="auto_download"
android:title="@string/pref_auto_download_title"
android:summary="@string/pref_auto_download_summary"
android:defaultValue="true"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="manual_download_override_cache"
android:title="@string/pref_manual_download_cache_title"
android:summary="@string/pref_manual_download_cache_summary"
android:defaultValue="true"
android:persistent="true" />

<Preference
app:iconSpaceReserved="false"
android:key="raster_tile_url"
android:title="@string/pref_tile_source_title" />

<de.westnordost.streetcomplete.screens.settings.NumberPickerPreference
app:iconSpaceReserved="false"
android:key="data_retain_time"
android:title="@string/pref_delete_old_data_after"
android:summary="@string/pref_delete_old_data_after_summary"
Expand All @@ -35,13 +39,15 @@
android:negativeButtonText="@android:string/cancel" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="update_local_statistics"
android:title="@string/pref_update_local_statistics"
android:summary="@string/pref_update_local_statistics_summary"
android:defaultValue="true"
android:persistent="true" />

<de.westnordost.streetcomplete.screens.settings.NumberPickerPreference
app:iconSpaceReserved="false"
android:key="gps_interval"
android:title="@string/pref_gps_interval_title"
android:summary="@string/pref_interval_summary"
Expand All @@ -56,6 +62,7 @@
android:negativeButtonText="@android:string/cancel" />

<de.westnordost.streetcomplete.screens.settings.NumberPickerPreference
app:iconSpaceReserved="false"
android:key="network_interval"
android:title="@string/pref_network_interval_title"
android:summary="@string/pref_interval_summary"
Expand All @@ -70,20 +77,24 @@
android:negativeButtonText="@android:string/cancel" />

<Preference
app:iconSpaceReserved="false"
android:key="trees"
android:title="@string/pref_trees_title"
android:summary="@string/pref_tree_custom_quest_summary" />

<Preference
app:iconSpaceReserved="false"
android:key="custom_quest"
android:title="@string/pref_custom_title"
android:summary="@string/pref_tree_custom_quest_summary" />

<Preference
app:iconSpaceReserved="false"
android:key="export"
android:title="@string/pref_export" />

<Preference
app:iconSpaceReserved="false"
android:key="import"
android:title="@string/pref_import" />

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/xml/preferences_ee_display.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- not possible with mapLibre
<SwitchPreference
android:key="3d_buildings"
Expand All @@ -8,34 +9,39 @@
android:persistent="true" />
-->
<SwitchPreference
app:iconSpaceReserved="false"
android:key="show_way_direction"
android:title="@string/pref_way_direction"
android:summary="@string/pref_way_direction_summary"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="quest_geometries"
android:title="@string/pref_quest_geometries_title"
android:summary="@string/pref_quest_geometries_summary"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="offset_fix"
android:title="@string/pref_offset_fix_title2"
android:summary="@string/pref_offset_fix_summary"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="show_solved_animation"
android:title="@string/pref_show_solved_animation"
android:summary="@string/pref_show_solved_animation_summary"
android:defaultValue="true"
android:persistent="true" />

<Preference
app:iconSpaceReserved="false"
android:key="display_gpx_track"
android:title="@string/pref_gpx_track_title" />

Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/xml/preferences_ee_notes.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<SwitchPreference
app:iconSpaceReserved="false"
android:key="gpx_button"
android:title="@string/pref_show_gpx_button_title"
android:summary="@string/pref_show_gpx_button_summary"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="swap_gpx_note_buttons"
android:title="@string/pref_swap_gpx_note_button"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="hide_keyboard_for_note"
android:title="@string/pref_hide_keyboard_title"
android:summary="@string/pref_hide_keyboard_summary"
android:defaultValue="true"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="create_external_quests"
android:title="@string/pref_create_custom_quest_title"
android:summary="@string/pref_create_custom_quest_summary"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="save_photos"
android:title="@string/pref_save_photos_title"
android:summary="@string/pref_save_photos_summary"
android:defaultValue="false"
android:persistent="true" />

<Preference
app:iconSpaceReserved="false"
android:key="hide_notes_by2"
android:title="@string/pref_hide_notes_title" />

<Preference
app:iconSpaceReserved="false"
android:key="get_gpx_notes"
android:title="@string/pref_save_gpx" />

<Preference
app:iconSpaceReserved="false"
android:key="get_photos"
android:title="@string/pref_get_photos_title" />

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences_ee_quests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<ListPreference
app:iconSpaceReserved="false"
android:key="day_night_behavior"
android:title="@string/pref_day_night_title"
app:useSimpleSummaryProvider="true"
Expand All @@ -12,30 +13,35 @@
android:persistent="true" />

<Preference
app:iconSpaceReserved="false"
android:key="advanced_resurvey"
android:title="@string/pref_advanced_resurvey_title"
android:summary="@string/pref_advanced_resurvey_summary" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="quest_settings_per_preset"
android:title="@string/pref_quest_settings_preset_title"
android:summary="@string/pref_quest_settings_preset_summary"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="dynamic_quest_creation"
android:title="@string/pref_dynamic_quest_creation_title"
android:summary="@string/pref_dynamic_quest_creation_summary"
android:defaultValue="false"
android:persistent="true" />

<Preference
app:iconSpaceReserved="false"
android:key="quest_monitor"
android:title="@string/pref_quest_monitor_title"
android:summary="@string/pref_quest_monitor_summary" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="hide_overlay_quests"
android:title="@string/pref_hide_overlay_quests"
android:defaultValue="true"
Expand Down
Loading

0 comments on commit 53c564d

Please sign in to comment.