Skip to content

Commit

Permalink
Enable editing and checking serial number
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Nov 15, 2024
1 parent 881345c commit 09b4a29
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ open class AmiiboData : Parcelable {
if (value < WRITE_COUNT_MIN_VALUE || value > WRITE_COUNT_MAX_VALUE) throw NumberFormatException()
}

@Throws(StringIndexOutOfBoundsException::class)
fun checkSerialNumber(value: String) {
if (value.length < 18) throw StringIndexOutOfBoundsException()
}

@set:Throws(NumberFormatException::class)
var writeCount: Int
get() = tagData.getShort(WRITE_COUNT_OFFSET).toInt() and 0xFFFF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,20 @@ class TagDataEditor : AppCompatActivity() {
onAppDataSwitchClicked(checked)
}
}
txtSerialNumber = findViewById(R.id.txtSerialNumber)
txtSerialNumber = findViewById<EditText>(R.id.txtSerialNumber).apply {
addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
override fun afterTextChanged(editable: Editable) {
try {
amiiboData.checkSerialNumber(editable.toString())
txtSerialNumber.error = null
} catch (e: Exception) {
txtSerialNumber.error = getString(R.string.error_serial)
}
}
})
}
generateSerial = findViewById<AppCompatButton>(R.id.random_serial).apply {
setOnClickListener {
txtSerialNumber.setText(Foomiibo.generateRandomUID().toHex())
Expand Down Expand Up @@ -954,7 +967,7 @@ class TagDataEditor : AppCompatActivity() {

private fun loadSerialNumber() {
txtSerialNumber.tag = txtSerialNumber.keyListener
txtSerialNumber.keyListener = null
// txtSerialNumber.keyListener = null
val value = amiiboData.uID
txtSerialNumber.setText(value.toHex())
}
Expand Down Expand Up @@ -1839,4 +1852,4 @@ class TagDataEditor : AppCompatActivity() {
.show()
setResult(RESULT_OK, Intent(NFCIntent.ACTION_FIX_BANK_DATA))
}
}
}
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_tag_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@
android:id="@+id/txtSerialNumber"
android:importantForAutofill="no"
style="@style/TagEditor.EditSerial"
android:maxLength="10"
android:maxLines="1"
android:paddingLeft="6dp"
android:paddingRight="6dp"
tools:ignore="LabelFor,TextFields" />
Expand Down Expand Up @@ -438,4 +440,4 @@
android:padding="2dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
<string name="error_tag_unavailable">NTAG215 connection cannot be established!</string>
<string name="error_state">State error. Invalid action: %1$s</string>
<string name="error_length">Must be 8 characters</string>
<string name="error_serial">Must be 18 characters</string>
<string name="error_input">Invalid input</string>
<string name="error_min_max">Must be between %1$d and %2$d</string>
<string name="error_data_write">Error while writing main data (stage 1)</string>
Expand Down

0 comments on commit 09b4a29

Please sign in to comment.