Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.

Commit 3a2e2d4

Browse files
committed
feat: improve write to device activity feedback
1 parent f0c26a0 commit 3a2e2d4

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

app/src/main/java/com/eps/todoturtle/nfc/WriteToDeviceActivity.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.eps.todoturtle.nfc
22

3+
import android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION
34
import android.os.Bundle
5+
import android.widget.Toast
46
import androidx.activity.ComponentActivity
57
import androidx.activity.compose.setContent
68
import androidx.compose.foundation.layout.fillMaxSize
79
import androidx.compose.material3.MaterialTheme
810
import androidx.compose.material3.Surface
911
import androidx.compose.ui.Modifier
1012
import androidx.compose.ui.platform.LocalContext
13+
import com.eps.todoturtle.R
1114
import com.eps.todoturtle.nfc.logic.NfcWriteViewModel.INIT.getNfcWriteModel
1215
import com.eps.todoturtle.nfc.ui.WriteDevice
1316
import com.eps.todoturtle.shared.logic.extensions.dataStore
@@ -23,9 +26,29 @@ class WriteToDeviceActivity : ComponentActivity() {
2326
modifier = Modifier.fillMaxSize(),
2427
color = MaterialTheme.colorScheme.background,
2528
) {
26-
WriteDevice(viewModel = viewModel)
29+
WriteDevice(viewModel = viewModel,
30+
onTagNotWriteable = ::restartActivity,
31+
onTagLost = ::restartActivity,
32+
unknownError = ::restartActivity,
33+
onNfcNotSupported = {
34+
Toast.makeText(this, getString(R.string.nfc_not_supported_solution), Toast.LENGTH_SHORT).show()
35+
finish()
36+
},
37+
onWriteSuccessful = {
38+
Toast.makeText(this, getString(R.string.nfc_write_success), Toast.LENGTH_SHORT)
39+
.show()
40+
finish()
41+
})
2742
}
2843
}
2944
}
3045
}
46+
47+
private fun restartActivity() {
48+
finish()
49+
startActivity(intent.apply {
50+
addFlags(FLAG_ACTIVITY_NO_ANIMATION)
51+
})
52+
}
3153
}
54+

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<string name="go_history_icon_desc">Go history</string>
1010
<string name="go_back_to_notes_icon_desc">Go back to undone notes</string>
1111
<string name="welcome_message_part1">"Welcome to "</string>
12-
<string name="title_activity_write_to_device">WriteToDeviceActivity</string>
12+
<string name="title_activity_write_to_device">Write Tag</string>
1313
<string name="title_activity_read_nfc">ReadNfcActivity</string>
1414
<string name="welcome_message_part2">ToDo Turtle</string>
1515
<string name="add_note_button_description">Button that prompts the form to create a new note.</string>

0 commit comments

Comments
 (0)