Skip to content

Commit

Permalink
indicate in create note dialog that a GPX is attached (#3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed May 23, 2022
1 parent c6290e0 commit 88ed465
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import android.view.animation.Animation
import android.view.animation.AnimationSet
import android.view.animation.BounceInterpolator
import android.view.animation.TranslateAnimation
import androidx.core.os.bundleOf
import androidx.core.view.isGone
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.databinding.FormLeaveNoteBinding
import de.westnordost.streetcomplete.databinding.FragmentCreateNoteBinding
import de.westnordost.streetcomplete.quests.note_discussion.AttachPhotoFragment
import de.westnordost.streetcomplete.util.ktx.childFragmentManagerOrNull
import de.westnordost.streetcomplete.util.ktx.getLocationInWindow
import de.westnordost.streetcomplete.util.ktx.hideKeyboard
import de.westnordost.streetcomplete.util.viewBinding
Expand Down Expand Up @@ -47,6 +50,15 @@ class CreateNoteFragment : AbstractCreateNoteFragment() {
}
private val listener: Listener? get() = parentFragment as? Listener ?: activity as? Listener

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManagerOrNull?.addFragmentOnAttachListener { fragmentManager, fragment ->
if (fragment is AttachPhotoFragment) {
fragment.hasGpxAttached = arguments?.getBoolean(ARG_HAS_GPX_ATTACHED) ?: false
}
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentCreateNoteBinding.inflate(inflater, container, false)
inflater.inflate(R.layout.form_leave_note, bottomSheetBinding.content)
Expand Down Expand Up @@ -118,4 +130,12 @@ class CreateNoteFragment : AbstractCreateNoteFragment() {

listener?.onCreatedNote(text, imagePaths, screenPos)
}

companion object {
private const val ARG_HAS_GPX_ATTACHED = "hasGpxAttached"

fun create(hasGpxAttached: Boolean) = CreateNoteFragment().also {
it.arguments = bundleOf(ARG_HAS_GPX_ATTACHED to hasGpxAttached)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AttachPhotoFragment : Fragment(R.layout.fragment_attach_photo) {
private lateinit var noteImageAdapter: NoteImageAdapter

val imagePaths: List<String> get() = noteImageAdapter.list
var hasGpxAttached = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -46,6 +47,8 @@ class AttachPhotoFragment : Fragment(R.layout.fragment_attach_photo) {
binding.photosList.adapter = noteImageAdapter
noteImageAdapter.registerAdapterDataObserver(AdapterDataChangedWatcher { updateHintVisibility() })

binding.attachedGpxView.isGone = !hasGpxAttached

updateHintVisibility()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class MainFragment :
mapFragment.updateCameraPosition { position = offsetPos }

freezeMap()
showInBottomSheet(CreateNoteFragment())
showInBottomSheet(CreateNoteFragment.create(mapFragment.recordedTracks.isNotEmpty()))
}

private fun onClickCreateTrack() {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_attach_gpx_24dp.xml
Original file line number Diff line number Diff line change
@@ -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="m5.002,0.996 l-0.002,9.004h-3v11h3l0.002,2.002h17v-16.195l-5.277,-5.811zM5.998,2h10.002v5.5h4.998v2.5h-14.998zM6,11c2,0 2.5,1 2.5,3h-1.5c0,-0.688 -0,-1.5 -1,-1.5 -1,0 -1,1.5 -1,3s0,3 1,3c1,0 1,-0.75 1,-1.75h-1v-1.25h2.5c0.016,3.116 -0.5,4.5 -2.5,4.5 -2,0 -2.5,-2.494 -2.5,-4.5 0,-2.006 0.5,-4.5 2.5,-4.5zM10,11h2c4,0 4,6 0,6h-0.5v3h-1.5zM15.5,11h1.5l1,3 1,-3h1.5l-1.5,4.5 1.5,4.5h-1.5l-1,-3 -1,3h-1.5l1.5,-4.5zM11.5,12.5v3c1,0 2,-0.5 2,-1.5 0,-1 -1,-1.5 -2,-1.5zM6,21h14.998v0.998h-15z"/>
</vector>
21 changes: 17 additions & 4 deletions app/src/main/res/layout/fragment_attach_photo.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginEnd="72dp">

<com.google.android.material.button.MaterialButton
Expand All @@ -21,9 +21,22 @@
android:contentDescription="@string/quest_leave_new_note_photo"
android:layout_centerVertical="true"/>

<ImageView
android:id="@+id/attachedGpxView"
android:layout_toEndOf="@id/takePhotoButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@drawable/ic_attach_gpx_24dp"
app:tint="@color/disabled_text"
android:visibility="gone"
tools:visibility="visible"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_centerVertical="true" />

<TextView
android:id="@+id/photosAreUsefulExplanation"
android:layout_toEndOf="@id/takePhotoButton"
android:layout_toEndOf="@id/attachedGpxView"
android:layout_marginStart="8dp"
android:text="@string/quest_leave_new_note_photos_are_useful"
android:layout_width="match_parent"
Expand All @@ -32,7 +45,7 @@

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/photosList"
android:layout_toEndOf="@id/takePhotoButton"
android:layout_toEndOf="@id/attachedGpxView"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/raw/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ v44.0-beta1: |
<h3>Enhancements and Fixes</h3>
<ul>
<li>Clarify a lot of wordings in American English (#4030) by @ZeLonewolf</li>
<li>Various minor enhancements and fixes (#4015, ...), thanks @Helium314</li>
<li>Various minor enhancements, wording improvements and fixes (#4015, #4042, #4001, #4039, #4032...), thanks @Helium314, @peternewman, @riQQ</li>
</ul>
v43.2: |
Expand Down
4 changes: 4 additions & 0 deletions res/graphics/note/attach_gpx_24dp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 88ed465

Please sign in to comment.