Skip to content

Commit

Permalink
allow viewing photos when creating a note
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Oct 13, 2022
1 parent dab6964 commit 5a37dec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package de.westnordost.streetcomplete.quests.note_discussion

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import androidx.core.view.doOnLayout
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.databinding.CellImageThumbnailBinding
import de.westnordost.streetcomplete.util.decodeScaledBitmapAndNormalize
import de.westnordost.streetcomplete.util.getRotationMatrix
import de.westnordost.streetcomplete.view.ListAdapter
import java.io.File

Expand All @@ -23,7 +27,7 @@ class NoteImageAdapter(list: List<String>, private val context: Context) : ListA
init {
binding.imageView.setOnClickListener {
val index = adapterPosition
if (index > -1) onClickDelete(index)
if (index > -1) onClickImage(index)
}
}

Expand All @@ -35,11 +39,24 @@ class NoteImageAdapter(list: List<String>, private val context: Context) : ListA
}
}

private fun onClickDelete(index: Int) {
private fun onClickImage(index: Int) {
val imagePath = list[index]
val image = File(imagePath)
if (!image.exists()) return // delete from list?
val v = ImageView(context).apply {
scaleType = ImageView.ScaleType.FIT_CENTER
val bitmap = BitmapFactory.decodeFile(imagePath)
val matrix = getRotationMatrix(imagePath)
val result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
if (result != bitmap) {
bitmap.recycle()
}
setImageBitmap(result)
}
AlertDialog.Builder(context)
.setMessage(R.string.quest_leave_new_note_photo_delete_title)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok) { _, _ -> delete(index) }
.setView(v)
.setNegativeButton(R.string.attach_photo_delete) { _, _ -> delete(index) }
.setPositiveButton(android.R.string.ok, null)
.show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private fun getImageSize(imagePath: String): Size? {
return Size(width, height)
}

private fun getRotationMatrix(imagePath: String): Matrix =
fun getRotationMatrix(imagePath: String): Matrix =
try {
ExifInterface(imagePath).rotationMatrix
} catch (ignore: IOException) {
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/layout/cell_image_thumbnail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,4 @@
android:layout_width="56dp"
android:layout_height="56dp"/>

<ImageView
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:src="@drawable/ic_close_24dp"
app:tint="#fff"
android:background="#9333"
android:layout_alignEnd="@id/imageView"/>

</RelativeLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/raw/changelog_ee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ v48.0_ee: |
<li>Restart in no longer necessary for applying changed quest settings</li>
<li>Option to dynamically create quests (will immediately apply changed quest settings)</li>
<li>Full element selection for all filter type quests (via quest settings). Quest settings for phone, website and wheelchair quests have been reset to work with the new style</li>
<li>Some improvements when showing nearby quests</li>
<li>Allow viewing photos when creating a note</li>
<li>Some performance improvements</li>
</ul>
Expand Down
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 @@ -292,5 +292,6 @@ This version lets you access your user statistics, but any quests solved using t
<string name="create_poi">Add POI</string>
<string name="custom_overlay_title">Custom overlay</string>
<string name="custom_overlay_hint">Element selection goes here</string>
<string name="attach_photo_delete">Delete</string>

</resources>

0 comments on commit 5a37dec

Please sign in to comment.