Skip to content

Commit

Permalink
#17 in progress
Browse files Browse the repository at this point in the history
- treasure editor screen
  • Loading branch information
mjureczko committed Nov 13, 2024
1 parent b5310cb commit 17b68c7
Show file tree
Hide file tree
Showing 77 changed files with 1,330 additions and 648 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)


TODO:

- remove dead code
- prepare custom version artifact for the play shop

- accept only alphanumeric-_ characters in the route name input

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import pl.marianjureczko.poszukiwacz.activity.facebook.n.ROUTE_NAME
import pl.marianjureczko.poszukiwacz.model.Route
import pl.marianjureczko.poszukiwacz.model.TreasureDescription
import pl.marianjureczko.poszukiwacz.model.TreasuresProgress
import pl.marianjureczko.poszukiwacz.shared.StorageHelper
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper

abstract class ReportAbstractTest {
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.junit.runner.RunWith
import pl.marianjureczko.poszukiwacz.activity.facebook.n.ReportCommemorativePhotos
import pl.marianjureczko.poszukiwacz.activity.facebook.n.ReportCommons
import pl.marianjureczko.poszukiwacz.model.Route
import pl.marianjureczko.poszukiwacz.shared.StorageHelper
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper
import java.io.File
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import pl.marianjureczko.poszukiwacz.model.TreasureDescription
import pl.marianjureczko.poszukiwacz.model.TreasureType
import pl.marianjureczko.poszukiwacz.model.TreasuresProgress
import pl.marianjureczko.poszukiwacz.shared.Coordinates
import pl.marianjureczko.poszukiwacz.shared.StorageHelper
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper
import java.io.File
import java.util.Date

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Test
import pl.marianjureczko.poszukiwacz.activity.searching.n.STEPS_TO_TREASURE
import pl.marianjureczko.poszukiwacz.screen.main.CustomInitializerForRoute
import pl.marianjureczko.poszukiwacz.shared.StorageHelper
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper

@HiltAndroidTest
class SearchingScreenTest : UiTest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
//package pl.marianjureczko.poszukiwacz.activity.treasureseditor
//
//import android.app.AlertDialog
//import android.app.Dialog
//import android.content.DialogInterface
//import android.media.MediaRecorder
//import android.os.Bundle
//import android.util.Log
//import android.view.Gravity
//import android.widget.Chronometer
//import android.widget.Toast
//import androidx.fragment.app.DialogFragment
//import pl.marianjureczko.poszukiwacz.R
//
//private const val FILENAME = "filename"
//private const val CLOSED_AT = "closed_at"
//
//class RecordingDialog : DialogFragment() {
// private val TAG = javaClass.simpleName
// private var recorder: MediaRecorder? = null
// private var chronometer: Chronometer? = null
// private var dialog: AlertDialog? = null
//
// companion object {
// fun newInstance(fileName: String): RecordingDialog {
// val args = Bundle().apply {
// putSerializable(FILENAME, fileName)
// }
//
// return RecordingDialog().apply {
// arguments = args
// }
// }
// }
//
// override fun onStop() {
// super.onStop()
// stopRecording()
// if (chronometer != null) {
// arguments?.putString(CLOSED_AT, chronometer!!.text as String)
// }
// }
//
// override fun onResume() {
// super.onResume()
// val closedAt = arguments?.getSerializable(CLOSED_AT) as String?
// if (closedAt != null) {
// chronometer?.stop()
// dialog?.getButton(DialogInterface.BUTTON_NEUTRAL)?.setText(R.string.close)
// }
// }
//
// override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
// val fileName = arguments?.getSerializable(FILENAME) as String
// val closedAt = arguments?.getSerializable(CLOSED_AT) as String?
// val builder: AlertDialog.Builder = AlertDialog.Builder(activity)
// chronometer = createChronometer()
// if (closedAt != null) {
// builder.setNeutralButton(R.string.close) { _, _ -> dismiss() }
// chronometer?.text = closedAt
// } else {
// builder.setNeutralButton(R.string.stop_recording) { _, _ -> dismiss() }
// chronometer?.setOnChronometerTickListener {
// arguments?.putString(CLOSED_AT, it.text as String)
// }
// chronometer?.start()
// startRecording(fileName)
// }
// builder.setView(chronometer)
// dialog = builder.create()
// return dialog!!
// }
//
// private fun createChronometer(): Chronometer {
// val chronometer = Chronometer(activity)
// chronometer.textSize = 50.0f
// chronometer.gravity = Gravity.CENTER
// return chronometer
// }
//
// private fun startRecording(fileName: String) {
// recorder = MediaRecorder().apply {
// setAudioSource(MediaRecorder.AudioSource.MIC)
// setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
// setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
// setOutputFile(fileName)
// try {
// prepare()
// start()
// } catch (e: Exception) {
// Log.e(TAG, "Audio recording failed ${e.message}", e)
// Toast.makeText(activity, R.string.tip_recording_failed, Toast.LENGTH_SHORT).show()
// }
// }
// }
//
// private fun stopRecording() {
// recorder?.apply {
// stop()
// Toast.makeText(activity, R.string.tip_recorded, Toast.LENGTH_SHORT).show()
// release()
// }
// recorder = null
// }
//}
package pl.marianjureczko.poszukiwacz.activity.treasureseditor

import android.app.AlertDialog
import android.app.Dialog
import android.content.DialogInterface
import android.media.MediaRecorder
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.widget.Chronometer
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import pl.marianjureczko.poszukiwacz.R

private const val FILENAME = "filename"
private const val CLOSED_AT = "closed_at"

class RecordingDialog : DialogFragment() {
private val TAG = javaClass.simpleName
private var recorder: MediaRecorder? = null
private var chronometer: Chronometer? = null
private var dialog: AlertDialog? = null

companion object {
fun newInstance(fileName: String): RecordingDialog {
val args = Bundle().apply {
putSerializable(FILENAME, fileName)
}

return RecordingDialog().apply {
arguments = args
}
}
}

override fun onStop() {
super.onStop()
stopRecording()
if (chronometer != null) {
arguments?.putString(CLOSED_AT, chronometer!!.text as String)
}
}

override fun onResume() {
super.onResume()
val closedAt = arguments?.getSerializable(CLOSED_AT) as String?
if (closedAt != null) {
chronometer?.stop()
dialog?.getButton(DialogInterface.BUTTON_NEUTRAL)?.setText(R.string.close)
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val fileName = arguments?.getSerializable(FILENAME) as String
val closedAt = arguments?.getSerializable(CLOSED_AT) as String?
val builder: AlertDialog.Builder = AlertDialog.Builder(activity)
chronometer = createChronometer()
if (closedAt != null) {
builder.setNeutralButton(R.string.close) { _, _ -> dismiss() }
chronometer?.text = closedAt
} else {
builder.setNeutralButton(R.string.stop_recording) { _, _ -> dismiss() }
chronometer?.setOnChronometerTickListener {
arguments?.putString(CLOSED_AT, it.text as String)
}
chronometer?.start()
startRecording(fileName)
}
builder.setView(chronometer)
dialog = builder.create()
return dialog!!
}

private fun createChronometer(): Chronometer {
val chronometer = Chronometer(activity)
chronometer.textSize = 50.0f
chronometer.gravity = Gravity.CENTER
return chronometer
}

private fun startRecording(fileName: String) {
recorder = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
setOutputFile(fileName)
try {
prepare()
start()
} catch (e: Exception) {
Log.e(TAG, "Audio recording failed ${e.message}", e)
Toast.makeText(activity, R.string.tip_recording_failed, Toast.LENGTH_SHORT).show()
}
}
}

private fun stopRecording() {
recorder?.apply {
stop()
Toast.makeText(activity, R.string.tip_recorded, Toast.LENGTH_SHORT).show()
release()
}
recorder = null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pl.marianjureczko.poszukiwacz.activity.treasureseditor

import android.annotation.SuppressLint

@SuppressLint("DefaultLocale")
fun formatTime(ms:Long?): String {
if (ms == null) {
return "00:00" // Handle null input
}

val totalSeconds = ms / 1000
val minutes = totalSeconds / 60
val seconds = totalSeconds % 60

return String.format("%02d:%02d", minutes, seconds)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pl.marianjureczko.poszukiwacz.permissions

import android.Manifest
import pl.marianjureczko.poszukiwacz.R

object RequirementsForRecordingSound: Requirements {
override fun getPermission(): String = Manifest.permission.RECORD_AUDIO
override fun getMessage(): Int = R.string.missing_photo_and_audio_permission
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.marianjureczko.poszukiwacz.screen.main

import android.content.res.AssetManager
import pl.marianjureczko.poszukiwacz.shared.StorageHelper
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper

class CustomInitializerForRoute(
val storageHelper: StorageHelper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.model.Route
import pl.marianjureczko.poszukiwacz.shared.GoToTreasureEditor
import pl.marianjureczko.poszukiwacz.shared.StorageHelper
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper
import javax.inject.Inject

@HiltViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pl.marianjureczko.poszukiwacz.screen.treasureseditor
import java.text.NumberFormat
import java.util.Locale

//TODO t: to remove?
class CoordinatesFormatter {

fun format(cord: Double?): String {
Expand Down
Loading

0 comments on commit 17b68c7

Please sign in to comment.