Skip to content

Commit

Permalink
Merge pull request #2843 from FloEdelmann/drag-handle
Browse files Browse the repository at this point in the history
Clarify that quest selection screen allows reordering
  • Loading branch information
westnordost committed May 4, 2021
2 parents 8847b16 + 208fa9f commit 76b2b7d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.ItemTouchHelper
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
Expand Down Expand Up @@ -47,6 +48,8 @@ class QuestSelectionAdapter @Inject constructor(
) : ListAdapter<QuestVisibility>() {
private val currentCountryCodes: List<String>

private val itemTouchHelper by lazy { ItemTouchHelper(TouchHelperCallback()) }

interface Listener {
fun onReorderedQuests(before: QuestType<*>, after: QuestType<*>)
fun onChangedQuestVisibility(questType: QuestType<*>, visible: Boolean)
Expand All @@ -61,8 +64,7 @@ class QuestSelectionAdapter @Inject constructor(

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
val ith = ItemTouchHelper(TouchHelperCallback())
ith.attachToRecyclerView(recyclerView)
itemTouchHelper.attachToRecyclerView(recyclerView)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<QuestVisibility> {
Expand Down Expand Up @@ -123,6 +125,7 @@ class QuestSelectionAdapter @Inject constructor(
private inner class QuestVisibilityViewHolder(itemView: View) :
ListAdapter.ViewHolder<QuestVisibility>(itemView), CompoundButton.OnCheckedChangeListener {

private val dragHandle: ImageView = itemView.dragHandle
private val questIcon: ImageView = itemView.questIcon
private val questTitle: TextView = itemView.questTitle
private val visibilityCheckBox: CheckBox = itemView.visibilityCheckBox
Expand Down Expand Up @@ -152,6 +155,14 @@ class QuestSelectionAdapter @Inject constructor(
visibilityCheckBox.isEnabled = item.isInteractionEnabled
visibilityCheckBox.setOnCheckedChangeListener(this)

dragHandle.setOnTouchListener { v, event ->
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> itemTouchHelper.startDrag(this)
MotionEvent.ACTION_UP -> v.performClick()
}
true
}

countryDisabledText.isGone = isEnabledInCurrentCountry
if (!isEnabledInCurrentCountry) {
val cc = if (currentCountryCodes.isEmpty()) "Atlantis" else currentCountryCodes[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class QuestSelectionFragment
@Inject internal lateinit var visibleQuestTypeController: VisibleQuestTypeController
@Inject internal lateinit var questTypeOrderList: QuestTypeOrderList

override val title: String get() = getString(R.string.pref_title_quests)
override val title: String get() = getString(R.string.pref_title_quests2)

init {
Injector.applicationComponent.inject(this)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_drag_vertical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#888"
android:pathData="M9,3H11V5H9V3M13,3H15V5H13V3M9,7H11V9H9V7M13,7H15V9H13V7M9,11H11V13H9V11M13,11H15V13H13V11M9,15H11V17H9V15M13,15H15V17H13V15M9,19H11V21H9V19M13,19H15V21H13V19Z" />
</vector>
68 changes: 41 additions & 27 deletions app/src/main/res/layout/row_quest_selection.xml
Original file line number Diff line number Diff line change
@@ -1,67 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
xmlns:tools="http://schemas.android.com/tools"
android:background="?android:attr/colorBackground"
tools:ignore="RtlSymmetry">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:paddingTop="8dp"
android:paddingBottom="8dp"
tools:ignore="RtlSymmetry">

<ImageView
android:id="@+id/questIcon"
android:layout_width="@dimen/table_icon_size"
android:layout_height="@dimen/table_icon_size"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
tools:src="@drawable/ic_quest_street"/>
android:layout_marginStart="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/dragHandle"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_quest_street" />

<LinearLayout
<ImageView
android:id="@+id/dragHandle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:paddingEnd="24dp"
android:src="@drawable/ic_drag_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toEndOf="@+id/questIcon"
android:layout_toStartOf="@+id/visibilityCheckBoxContainer"
android:layout_centerVertical="true"
android:paddingStart="16dp"
android:paddingEnd="16dp">
android:paddingEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/visibilityCheckBoxContainer"
app:layout_constraintStart_toEndOf="@+id/questIcon"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/questTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/quest_lanes_title"
android:textAppearance="@android:style/TextAppearance.Theme.Dialog"
android:id="@+id/questTitle"/>
tools:text="@string/quest_lanes_title" />

<TextView
android:id="@+id/countryDisabledText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:textStyle="italic"
tools:text="@string/questList_disabled_in_country"
android:background="@drawable/background_quest_disabled_notice"
android:id="@+id/countryDisabledText"/>
android:textStyle="italic"
tools:text="@string/questList_disabled_in_country" />

</LinearLayout>

<FrameLayout
android:id="@+id/visibilityCheckBoxContainer"
android:layout_width="@dimen/table_icon_size"
android:layout_height="@dimen/table_icon_size"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">

<CheckBox
android:id="@+id/visibilityCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
android:layout_gravity="center" />

</FrameLayout>



</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards
<string name="resurvey_intervals_less_often">Ask less often</string>
<string name="resurvey_intervals_default">Default</string>
<string name="resurvey_intervals_more_often">Ask more often</string>
<string name="pref_title_quests">Quest selection</string>
<string name="pref_title_quests2">Quest selection and priority</string>
<string name="quest_enabled">Enabled</string>
<string name="quest_type">Quest type</string>
<string name="action_reset">Reset</string>
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

<Preference
android:key="quests"
android:title="@string/pref_title_quests"
android:widgetLayout="@layout/widget_image_next"
/>
android:title="@string/pref_title_quests2"
android:widgetLayout="@layout/widget_image_next" />

<ListPreference
android:key="quests.resurveyIntervals"
Expand Down

0 comments on commit 76b2b7d

Please sign in to comment.