Skip to content

Commit

Permalink
Add upload option for connected BT device
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Sep 23, 2023
1 parent 7c5795f commit 9e36d80
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 52 deletions.
16 changes: 11 additions & 5 deletions app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2430,26 +2430,32 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
pagerAdapter.browser.setFoomiiboVisibility(false)
}

fun showGattPage(extras: Bundle) {
private fun showGattPage(extras: Bundle) {
val index = if (prefs.eliteEnabled()) 3 else 2
if (viewPager.currentItem != index) viewPager.setCurrentItem(index, false)
pagerAdapter.gattSlots.arguments = extras
if (viewPager.currentItem != index) {
viewPager.setCurrentItem(index, false)
} else {
pagerAdapter.gattSlots.processArguments()
}
}

fun showElitePage(extras: Bundle) {
pagerAdapter.eliteBanks.arguments = extras
if (viewPager.currentItem == 2) {
pagerAdapter.eliteBanks.onHardwareLoaded(extras)
pagerAdapter.eliteBanks.processArguments()
return
}
if (TagMo.isUserInputEnabled) {
setScrollListener(object : ScrollListener {
override fun onScrollComplete() {
pagerAdapter.eliteBanks.onHardwareLoaded(extras)
pagerAdapter.eliteBanks.processArguments()
scrollListener = null
}
})
} else {
viewPager.postDelayed({
pagerAdapter.eliteBanks.onHardwareLoaded(extras)
pagerAdapter.eliteBanks.processArguments()
}, TagMo.uiDelay.toLong())
}
viewPager.setCurrentItem(2, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,38 +907,40 @@ class EliteBankFragment : Fragment(), EliteBankAdapter.OnAmiiboClickListener {
.show()
}

fun onHardwareLoaded(extras: Bundle) {
try {
val bankCount = extras.getInt(
NFCIntent.EXTRA_BANK_COUNT, prefs.eliteBankCount()
)
val activeBank = extras.getInt(
NFCIntent.EXTRA_ACTIVE_BANK, prefs.eliteActiveBank()
)
requireView().findViewById<TextView>(R.id.hardware_info).text = getString(
R.string.elite_signature, extras.getString(NFCIntent.EXTRA_SIGNATURE)
)
eliteBankCount.value = bankCount
setRefreshListener(object : RefreshListener {
override fun onListRefreshed(amiibos: ArrayList<EliteTag?>) {
refreshListener = null
amiibos[activeBank]?.id?.let {
onBottomSheetChanged(SHEET.AMIIBO)
updateAmiiboView(amiiboTile, null, it, activeBank)
updateAmiiboView(amiiboCard, null, it, activeBank)
Handler(Looper.getMainLooper()).postDelayed({
bottomSheet?.state = BottomSheetBehavior.STATE_EXPANDED
}, 125)
} ?: onBottomSheetChanged(SHEET.MENU)
}
})
updateEliteAdapter(extras.getStringArrayList(NFCIntent.EXTRA_AMIIBO_LIST))
bankStats?.text = getString(
R.string.bank_stats, eliteBankCount.getValueByPosition(activeBank), bankCount
)
updateNumberedText(bankCount)
} catch (ignored: Exception) {
if (amiibos.isEmpty()) onBottomSheetChanged(SHEET.LOCKED)
fun processArguments() {
arguments?.let { extras ->
try {
val bankCount = extras.getInt(
NFCIntent.EXTRA_BANK_COUNT, prefs.eliteBankCount()
)
val activeBank = extras.getInt(
NFCIntent.EXTRA_ACTIVE_BANK, prefs.eliteActiveBank()
)
requireView().findViewById<TextView>(R.id.hardware_info).text =
getString(R.string.elite_signature, extras.getString(NFCIntent.EXTRA_SIGNATURE))
eliteBankCount.value = bankCount
setRefreshListener(object : RefreshListener {
override fun onListRefreshed(amiibos: ArrayList<EliteTag?>) {
refreshListener = null
amiibos[activeBank]?.id?.let {
onBottomSheetChanged(SHEET.AMIIBO)
updateAmiiboView(amiiboTile, null, it, activeBank)
updateAmiiboView(amiiboCard, null, it, activeBank)
Handler(Looper.getMainLooper()).postDelayed({
bottomSheet?.state = BottomSheetBehavior.STATE_EXPANDED
}, 125)
} ?: onBottomSheetChanged(SHEET.MENU)
}
})
updateEliteAdapter(extras.getStringArrayList(NFCIntent.EXTRA_AMIIBO_LIST))
bankStats?.text = getString(
R.string.bank_stats, eliteBankCount.getValueByPosition(activeBank), bankCount
)
updateNumberedText(bankCount)
} catch (ignored: Exception) {
if (amiibos.isEmpty()) onBottomSheetChanged(SHEET.LOCKED)
}
arguments = null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,6 @@ open class GattSlotFragment : Fragment(), GattSlotAdapter.OnAmiiboClickListener,
gattButtonState
}

fun getWritableArguments() {
arguments?.let { extras ->
if (extras.containsKey(NFCIntent.EXTRA_TAG_DATA)) {
try {
extras.getByteArray(NFCIntent.EXTRA_TAG_DATA)?.let {
uploadAmiiboData(AmiiboData(it))
}
} catch (ignored: Exception) {

}
}
}
}

private fun onBottomSheetChanged(sheet: SHEET) {
bottomSheet?.state = BottomSheetBehavior.STATE_COLLAPSED
bottomSheet?.isFitToContents = true
Expand Down Expand Up @@ -1116,6 +1102,23 @@ open class GattSlotFragment : Fragment(), GattSlotAdapter.OnAmiiboClickListener,
super.onDestroy()
}

fun processArguments() {
arguments?.let { extras ->
if (extras.containsKey(NFCIntent.EXTRA_TAG_DATA)) {
if (isServiceDiscovered) {
try {
extras.getByteArray(NFCIntent.EXTRA_TAG_DATA)?.let {
uploadAmiiboData(AmiiboData(it))
}
} catch (ignored: Exception) { }
} else {
Toasty(requireActivity()).Long(R.string.fail_no_device)
}
}
}
arguments = null
}

private fun onFragmentLoaded() {
if (statusBar?.isShown != true) {
fragmentHandler.postDelayed({
Expand Down Expand Up @@ -1287,8 +1290,8 @@ open class GattSlotFragment : Fragment(), GattSlotAdapter.OnAmiiboClickListener,
selectBluetoothDevice()
}

private var isServiceDiscovered = false
private var gattServerConn: ServiceConnection = object : ServiceConnection {
var isServiceDiscovered = false
override fun onServiceConnected(component: ComponentName, binder: IBinder) {
val localBinder = binder as GattService.LocalBinder
serviceGatt = localBinder.service.apply {
Expand Down
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 @@ -348,6 +348,7 @@
<string name="gatt_create">Creating blank tag&#8230;</string>
<string name="gatt_format">Formatting device&#8230;</string>
<string name="fail_bluetooth_adapter">Bluetooth adapter unavailable!</string>
<string name="fail_no_device">No GATT device connected!</string>
<string name="tiramisu_bluetooth">Android 13 requires manually enabling Bluetooth. Open Settings to enable Bluetooth?</string>
<string name="fail_permissions">Required permission denied by user!</string>
<string name="location_disclosure">Location is required for Bluetooth LE scan. In accordance with Google Play policy, TagMo is required to notify you that location data may be collected in the background. TagMo does not read, store, or share location data. As such, this notice is strictly a formality.</string>
Expand Down

0 comments on commit 9e36d80

Please sign in to comment.