Skip to content

Commit

Permalink
Optimize repositioning the NFC action icon
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Sep 18, 2023
1 parent 949e03f commit 529a395
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
private fun loadAmiiboFiles(rootFolder: File?, recursiveFiles: Boolean) {
setSnackbarListener(object: SnackbarListener {
override fun onSnackbarHidden(fakeSnackbar: AnimatedLinearLayout) {
viewPager.postDelayed({
nfcFab.loadSavedPosition(prefs)
}, TagMo.uiDelay.toLong())
nfcFab.loadSavedPosition(prefs)
snackbarListener = null
}
})
Expand All @@ -1799,9 +1797,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
private fun loadAmiiboDocuments(rootFolder: DocumentFile?, recursiveFiles: Boolean) {
setSnackbarListener(object: SnackbarListener {
override fun onSnackbarHidden(fakeSnackbar: AnimatedLinearLayout) {
viewPager.postDelayed({
nfcFab.loadSavedPosition(prefs)
}, TagMo.uiDelay.toLong())
nfcFab.loadSavedPosition(prefs)
snackbarListener = null
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,6 @@ class GattService : Service() {

private val mBinder: IBinder = LocalBinder()

/**
* Initializes a reference to the local Bluetooth adapter.
*
* @return Return true if the initialization is successful.
*/
fun initialize(): Boolean {
// For API level 18 and above, get a reference to BluetoothAdapter through BluetoothManager.
mBluetoothAdapter = if (Version.isJellyBeanMR2) {
with (getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager) { adapter }
} else {
@Suppress("deprecation") BluetoothAdapter.getDefaultAdapter()
}
return mBluetoothAdapter != null
}

/**
* Connects to the GATT server hosted on the Bluetooth LE device.
*
Expand All @@ -577,10 +562,16 @@ class GattService : Service() {
* callback.
*/
fun connect(address: String?): Boolean {
mBluetoothAdapter = if (Version.isJellyBeanMR2) {
with (getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager) { adapter }
} else {
@Suppress("deprecation") BluetoothAdapter.getDefaultAdapter()
}
if (emptyAdapater || address == null) return false

// Previously connected device. Try to reconnect.
if (address == mBluetoothDeviceAddress) mBluetoothGatt?.let { return it.connect() }
if (Version.isJellyBeanMR2 && address == mBluetoothDeviceAddress)
mBluetoothGatt?.let { return it.connect() }
val device = mBluetoothAdapter?.getRemoteDevice(address) ?: return false
// We want to directly connect to the device, so we are setting the autoConnect
// parameter to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.view.View.OnTouchListener
import android.view.ViewGroup.MarginLayoutParams
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.hiddenramblings.tagmo.Preferences
import com.hiddenramblings.tagmo.TagMo
import kotlin.math.abs

class FABulous : FloatingActionButton, OnTouchListener {
Expand Down Expand Up @@ -130,12 +131,19 @@ class FABulous : FloatingActionButton, OnTouchListener {

override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
val bounds = getViewCoordinates(this, x, y)
animate().x(bounds[0]).y(bounds[1]).setDuration(0).start()
postDelayed({
val bounds = getViewCoordinates(this, x, y)
animate().x(bounds[0]).y(bounds[1]).setDuration(0).start()
}, TagMo.uiDelay.toLong())
}

fun loadSavedPosition(prefs: Preferences) {
animate().x(prefs.fabulousX(this)).y(prefs.fabulousY(this)).setDuration(0).start()
postDelayed({
val bounds = getViewCoordinates(
this, prefs.fabulousX(this), prefs.fabulousY(this)
)
animate().x(bounds[0]).y(bounds[1]).setDuration(0).start()
}, TagMo.uiDelay.toLong())
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ open class GattSlotFragment : Fragment(), GattSlotAdapter.OnAmiiboClickListener,
deviceDialog.dismiss()
deviceProfile = device.name
deviceAddress = device.address
dismissGattDiscovery()
showConnectionNotice()
startGattService()
dismissGattDiscovery()
}
return item
}
Expand Down Expand Up @@ -1276,7 +1276,7 @@ open class GattSlotFragment : Fragment(), GattSlotAdapter.OnAmiiboClickListener,
override fun onServiceConnected(component: ComponentName, binder: IBinder) {
val localBinder = binder as GattService.LocalBinder
serviceGatt = localBinder.service.apply {
if (initialize() && connect(deviceAddress)) {
if (connect(deviceAddress)) {
serviceType = deviceType
maxSlotCount = when (serviceType) {
Nordic.DEVICE.FLASK -> 85
Expand Down Expand Up @@ -1548,7 +1548,7 @@ open class GattSlotFragment : Fragment(), GattSlotAdapter.OnAmiiboClickListener,
})
} else {
stopGattService()
Toasty(requireContext()).Short(R.string.device_invalid)
Toasty(requireContext()).Short(R.string.gatt_connect_fail)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@

<string name="custom_tab_back">Zurück zu TagMo</string>
<string name="gatt_missing">Keine GATT-Geräte in der Nähe gefunden!</string>
<string name="device_invalid">Kein gültiges GATT-Gerät!</string>
<string name="gatt_connect_fail">Kein gültiges GATT-Gerät!</string>
<string name="gatt_scanning">Scannen nach Bluetooth GATT&#8230;</string>
<string name="gatt_located">Verbinde mit Bluetooth GATT&#8230;</string>
<string name="gatt_disconnect">GATT-Geräteverbindung verloren!</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@

<string name="custom_tab_back">Powrót do TagMo</string>
<string name="gatt_missing">Brak urządzeń GATT w pobliżu!</string>
<string name="device_invalid">Nieprawidłowe urządzenie GATT!</string>
<string name="gatt_connect_fail">Nieprawidłowe urządzenie GATT!</string>
<string name="gatt_scanning">Skanowanie w poszukiwaniu Bluetooth GATT&#8230;</string>
<string name="gatt_located">Łączenie z Bluetooth GATT&#8230;</string>
<string name="gatt_disconnect">Utracono połączenie z urządzeniem GATT!</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rTW/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@

<string name="custom_tab_back">返回 TagMo</string>
<string name="gatt_missing">附近沒有可用的GATT設備!</string>
<string name="device_invalid">無效的GATT設備!</string>
<string name="gatt_connect_fail">無效的GATT設備!</string>
<string name="gatt_scanning">正在掃描Bluetooth GATT&#8230;</string>
<string name="gatt_located">正在連接Bluetooth GATT&#8230;</string>
<string name="gatt_disconnect">GATT連線無法使用!</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
<string name="custom_tab_back">Back to TagMo</string>
<string name="shop_hardware">Shop amiibo hardware</string>
<string name="gatt_missing">No nearby GATT devices found!</string>
<string name="device_invalid">Not a valid GATT device!</string>
<string name="gatt_connect_fail">Failed to connect GATT service!</string>
<string name="gatt_services_null">%1$s services not found!</string>
<string name="characteristic_null">Characteristic not found!</string>
<string name="xor_invalid">Empty collection can\'t be reduced</string>
Expand Down

0 comments on commit 529a395

Please sign in to comment.