Skip to content

Commit

Permalink
add full grid main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Sep 28, 2022
1 parent 28c02c6 commit f6cffff
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/de/westnordost/streetcomplete/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ object Prefs {
const val SHOW_SOLVED_ANIMATION = "show_solved_animation"
const val PREFER_EXTERNAL_SD = "prefer_external_sd"
const val SHOW_NEXT_QUEST_IMMEDIATELY = "show_next_quest_immediately"
const val MAIN_MENU_FULL_GRID = "main_menu_full_grid"

enum class Autosync {
ON, WIFI, OFF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package de.westnordost.streetcomplete.screens.main.controls

import android.content.Intent
import android.content.SharedPreferences
import android.net.ConnectivityManager
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.content.getSystemService
import androidx.fragment.app.Fragment
import de.westnordost.streetcomplete.Prefs
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.download.DownloadController
import de.westnordost.streetcomplete.data.osm.mapdata.BoundingBox
Expand All @@ -28,6 +30,7 @@ class MainMenuButtonFragment : Fragment(R.layout.fragment_main_menu_button) {

private val teamModeQuestFilter: TeamModeQuestFilter by inject()
private val downloadController: DownloadController by inject()
private val prefs: SharedPreferences by inject()

interface Listener {
fun getDownloadArea(): BoundingBox?
Expand Down Expand Up @@ -69,14 +72,24 @@ class MainMenuButtonFragment : Fragment(R.layout.fragment_main_menu_button) {
/* ------------------------------------------------------------------------------------------ */

internal fun onClickMainMenu() {
val d = MainMenuDialog(
requireContext(),
if (teamModeQuestFilter.isEnabled) teamModeQuestFilter.indexInTeam else null,
this::onClickDownload,
teamModeQuestFilter::enableTeamMode,
teamModeQuestFilter::disableTeamMode,
this::onClickOverlays,
)
val d = if (prefs.getBoolean(Prefs.MAIN_MENU_FULL_GRID, false))
MainMenuGridDialog(
requireContext(),
if (teamModeQuestFilter.isEnabled) teamModeQuestFilter.indexInTeam else null,
this::onClickDownload,
teamModeQuestFilter::enableTeamMode,
teamModeQuestFilter::disableTeamMode,
this::onClickOverlays,
)
else
MainMenuDialog(
requireContext(),
if (teamModeQuestFilter.isEnabled) teamModeQuestFilter.indexInTeam else null,
this::onClickDownload,
teamModeQuestFilter::enableTeamMode,
teamModeQuestFilter::disableTeamMode,
this::onClickOverlays,
)
d.setOnKeyListener { _, _, keyEvent ->
if (keyEvent.keyCode == KeyEvent.KEYCODE_MENU && keyEvent.action == KeyEvent.ACTION_UP) {
val intent = Intent(requireContext(), SettingsActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package de.westnordost.streetcomplete.screens.main.controls

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import androidx.core.view.doOnPreDraw
import de.westnordost.streetcomplete.databinding.DialogMainMenuGridBinding
import de.westnordost.streetcomplete.screens.about.AboutActivity
import de.westnordost.streetcomplete.screens.main.teammode.TeamModeDialog
import de.westnordost.streetcomplete.screens.settings.SettingsActivity
import de.westnordost.streetcomplete.screens.user.UserActivity

/** Shows a dialog containing the main menu items.
* This is an almost exact copy of MainMenuDialog, because the compiler doesn't like being able to select
* the binding on init. */
class MainMenuGridDialog(
context: Context,
indexInTeam: Int?,
onClickDownload: () -> Unit,
onEnableTeamMode: (Int, Int) -> Unit,
onDisableTeamMode: () -> Unit,
onClickOverlays: () -> Unit,
) : AlertDialog(context) {
init {
val binding = DialogMainMenuGridBinding.inflate(LayoutInflater.from(context))

binding.profileButton.setOnClickListener {
val intent = Intent(context, UserActivity::class.java)
context.startActivity(intent)
dismiss()
}
binding.enableTeamModeButton.setOnClickListener {
TeamModeDialog(context, onEnableTeamMode).show()
dismiss()
}
binding.disableTeamModeButton.setOnClickListener {
onDisableTeamMode()
dismiss()
}
binding.settingsButton.setOnClickListener {
val intent = Intent(context, SettingsActivity::class.java)
context.startActivity(intent)
dismiss()
}
binding.aboutButton.setOnClickListener {
val intent = Intent(context, AboutActivity::class.java)
context.startActivity(intent)
dismiss()
}
binding.downloadButton.setOnClickListener {
onClickDownload()
dismiss()
}

binding.overlaysButton.setOnClickListener {
onClickOverlays()
dismiss()
}

if (indexInTeam != null) {
binding.teamModeColorCircle.setIndexInTeam(indexInTeam)
binding.bigMenuItemsContainer.removeView(binding.enableTeamModeButton)
} else {
binding.bigMenuItemsContainer.removeView(binding.disableTeamModeButton)
}

binding.root.doOnPreDraw {
binding.bigMenuItemsContainer.columnCount = binding.root.width / binding.profileButton.width
}

setView(binding.root)
}
}
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_team_mode_48dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,5.5A3.5,3.5 0 0,1 15.5,9A3.5,3.5 0 0,1 12,12.5A3.5,3.5 0 0,1 8.5,9A3.5,3.5 0 0,1 12,5.5M5,8C5.56,8 6.08,8.15 6.53,8.42C6.38,9.85 6.8,11.27 7.66,12.38C7.16,13.34 6.16,14 5,14A3,3 0 0,1 2,11A3,3 0 0,1 5,8M19,8A3,3 0 0,1 22,11A3,3 0 0,1 19,14C17.84,14 16.84,13.34 16.34,12.38C17.2,11.27 17.62,9.85 17.47,8.42C17.92,8.15 18.44,8 19,8M5.5,18.25C5.5,16.18 8.41,14.5 12,14.5C15.59,14.5 18.5,16.18 18.5,18.25V20H5.5V18.25M0,20V18.5C0,17.11 1.89,15.94 4.45,15.6C3.86,16.28 3.5,17.22 3.5,18.25V20H0M24,20H20.5V18.25C20.5,17.22 20.14,16.28 19.55,15.6C22.11,15.94 24,17.11 24,18.5V20Z"
/>
</vector>
115 changes: 115 additions & 0 deletions app/src/main/res/layout/dialog_main_menu_grid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content">

<GridLayout
android:id="@+id/bigMenuItemsContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:columnCount="2"
android:orientation="horizontal">

<TextView
android:id="@+id/profileButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp"
android:text="@string/user_profile"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:drawableTopCompat="@drawable/ic_profile_48dp" />

<TextView
android:id="@+id/enableTeamModeButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp"
android:text="@string/team_mode"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:drawableTopCompat="@drawable/ic_team_mode_48dp" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/disableTeamModeButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp">

<de.westnordost.streetcomplete.screens.main.teammode.TeamModeColorCircleView
android:id="@+id/teamModeColorCircle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="4dp"
app:layout_constraintBottom_toTopOf="@+id/disableTeamModeText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/disableTeamModeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/team_mode_exit"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/aboutButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp"
android:text="@string/action_about2"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:drawableTopCompat="@drawable/ic_info_outline_48dp" />

<TextView
android:id="@+id/overlaysButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp"
android:text="@string/action_overlays"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:drawableTopCompat="@drawable/ic_overlay_48dp" />

<TextView
android:id="@+id/settingsButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp"
android:text="@string/action_settings"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:drawableTopCompat="@drawable/ic_settings_48dp" />

<TextView
android:id="@+id/downloadButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:padding="16dp"
android:text="@string/action_download"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
app:drawableTopCompat="@drawable/ic_search_48dp" />

</GridLayout>

</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings_ee.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,6 @@ This version lets you access your user statistics, but any quests solved using t
<string name="moving">Moving tiles…</string>
<string name="pref_show_next_quest_title">Show next quest immediately</string>
<string name="pref_show_next_quest_summary">Display further quest for same element right after solving</string>
<string name="pref_main_menu_grid">Show all main menu items as grid</string>

</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@
android:positiveButtonText="@android:string/ok"
android:negativeButtonText="@android:string/cancel" />

<SwitchPreference
android:key="main_menu_full_grid"
android:title="@string/pref_main_menu_grid"
android:defaultValue="false"
android:persistent="true" />

<SwitchPreference
android:key="show_hide_button"
android:title="@string/pref_hide_button_title"
Expand Down

0 comments on commit f6cffff

Please sign in to comment.