Browse Source

Add sound id

pull/1/head
Nils Dittberner 7 years ago
parent
commit
b175c6f423
3 changed files with 12 additions and 5 deletions
  1. +0
    -3
      app/src/main/java/de/mlte/soundboard/EditActivity.kt
  2. +11
    -2
      app/src/main/java/de/mlte/soundboard/MainActivity.kt
  3. +1
    -0
      app/src/main/java/de/mlte/soundboard/SoundButton.kt

+ 0
- 3
app/src/main/java/de/mlte/soundboard/EditActivity.kt View File

@@ -24,9 +24,6 @@ class EditActivity : AppCompatActivity() {
val captionEditText = findViewById<EditText>(R.id.captionEditText) val captionEditText = findViewById<EditText>(R.id.captionEditText)
captionEditText.setText(intent.getStringExtra("caption")) captionEditText.setText(intent.getStringExtra("caption"))


currentUri = intent.getParcelableExtra<Uri>("uri")
displayFile();

val okButton = findViewById<Button>(R.id.okButton) val okButton = findViewById<Button>(R.id.okButton)
okButton.setOnClickListener { okButton.setOnClickListener {
val data = Intent() val data = Intent()


+ 11
- 2
app/src/main/java/de/mlte/soundboard/MainActivity.kt View File

@@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
} }
playing = false playing = false
} else { } else {
val file = getFileStreamPath("audio" + index)
val file = getFileStreamPath("audio" + soundButton.soundId)
if (file.exists()) { if (file.exists()) {
val mp = MediaPlayer.create(this, Uri.fromFile(file)) val mp = MediaPlayer.create(this, Uri.fromFile(file))
mp.setOnCompletionListener { mp.setOnCompletionListener {
@@ -132,6 +132,8 @@ class MainActivity : AppCompatActivity() {
addButton(soundButton) addButton(soundButton)
val caption = preferences.getString("caption" + index, "") val caption = preferences.getString("caption" + index, "")
soundButton.btn.text = caption soundButton.btn.text = caption
val soundId = preferences.getLong("soundId" + index, 0)
soundButton.soundId = soundId
} }
} }


@@ -143,6 +145,7 @@ class MainActivity : AppCompatActivity() {
if (index > -1 && index < buttons.size) { if (index > -1 && index < buttons.size) {
val btn = buttons[index].btn val btn = buttons[index].btn
if (data.getBooleanExtra("delete", false)) { if (data.getBooleanExtra("delete", false)) {
deleteFile("audio" + buttons[index].soundId)
buttons.removeAt(index) buttons.removeAt(index)
val parent = findViewById<GridLayout>(R.id.grid_layout) val parent = findViewById<GridLayout>(R.id.grid_layout)
parent.removeView(btn) parent.removeView(btn)
@@ -162,13 +165,19 @@ class MainActivity : AppCompatActivity() {
private fun savePreferences(caption: String, uri: Uri?, index: Int) { private fun savePreferences(caption: String, uri: Uri?, index: Int) {
if (index > -1 && index < buttons.size) { if (index > -1 && index < buttons.size) {
val btn = buttons[index].btn val btn = buttons[index].btn
val soundId = buttons[index].soundId
val editor = getPreferences(Context.MODE_PRIVATE).edit() val editor = getPreferences(Context.MODE_PRIVATE).edit()
editor.putString("caption" + index, btn.text.toString()) editor.putString("caption" + index, btn.text.toString())
editor.commit() editor.commit()


uri?.let { uri -> uri?.let { uri ->
deleteFile("audio" + soundId)
val newSoundId = System.currentTimeMillis()
buttons[index].soundId = newSoundId
editor.putLong("soundId" + index, newSoundId)
editor.commit()
grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
val output = BufferedOutputStream(openFileOutput("audio" + index, Context.MODE_PRIVATE))
val output = BufferedOutputStream(openFileOutput("audio" + newSoundId, Context.MODE_PRIVATE))
val input = BufferedInputStream(getContentResolver().openInputStream(uri)) val input = BufferedInputStream(getContentResolver().openInputStream(uri))
try { try {
val buf = ByteArray(1024) val buf = ByteArray(1024)


+ 1
- 0
app/src/main/java/de/mlte/soundboard/SoundButton.kt View File

@@ -13,6 +13,7 @@ class SoundButton : FrameLayout {
val progressBar: ProgressBar val progressBar: ProgressBar
val btn: TextView val btn: TextView
val objectAnimator: ObjectAnimator val objectAnimator: ObjectAnimator
var soundId: Long = 0


constructor(context: Context) : super(context) { constructor(context: Context) : super(context) {
View.inflate(context, R.layout.layout_button, this) View.inflate(context, R.layout.layout_button, this)


Loading…
Cancel
Save