forked from Shingyx/BoomSwitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve text and restructure project
- Use string resources for all text visible in UI - Use proper exception messages - Create ui and data subpackages - Move some inner classes to their own files - Delete unit tests
- Loading branch information
Showing
12 changed files
with
202 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...shingyx/boomswitch/BluetoothDeviceInfo.kt → ...yx/boomswitch/data/BluetoothDeviceInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
boomswitch/src/main/java/com/github/shingyx/boomswitch/data/GattCallbackWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.shingyx.boomswitch.data | ||
|
||
import android.bluetooth.BluetoothGatt | ||
import android.bluetooth.BluetoothGattCallback | ||
import android.bluetooth.BluetoothGattCharacteristic | ||
import android.util.Log | ||
|
||
private val TAG = GattCallbackWrapper::class.java.simpleName | ||
|
||
abstract class GattCallbackWrapper { | ||
protected val gattCallback = object : BluetoothGattCallback() { | ||
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { | ||
Log.v(TAG, "onConnectionStateChange: $status, $newState") | ||
onConnectionStateChange(status, newState) | ||
} | ||
|
||
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { | ||
Log.v(TAG, "onServicesDiscovered: $status") | ||
onServicesDiscovered(status) | ||
} | ||
|
||
override fun onCharacteristicRead(gatt: BluetoothGatt, char: BluetoothGattCharacteristic, status: Int) { | ||
Log.v(TAG, "onCharacteristicRead: $status, ${char.uuid} = [${char.value?.joinToString()}]") | ||
onCharacteristicRead(char, status) | ||
} | ||
|
||
override fun onCharacteristicWrite(gatt: BluetoothGatt, char: BluetoothGattCharacteristic, status: Int) { | ||
Log.v(TAG, "onCharacteristicWrite: $status, ${char.uuid} = [${char.value?.joinToString()}]") | ||
onCharacteristicWrite(char, status) | ||
} | ||
} | ||
|
||
protected abstract fun onConnectionStateChange(status: Int, newState: Int) | ||
protected abstract fun onServicesDiscovered(status: Int) | ||
protected abstract fun onCharacteristicRead(characteristic: BluetoothGattCharacteristic, status: Int) | ||
protected abstract fun onCharacteristicWrite(characteristic: BluetoothGattCharacteristic, status: Int) | ||
} |
2 changes: 1 addition & 1 deletion
2
.../github/shingyx/boomswitch/Preferences.kt → ...ub/shingyx/boomswitch/data/Preferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
boomswitch/src/main/java/com/github/shingyx/boomswitch/ui/BluetoothDeviceAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.github.shingyx.boomswitch.ui | ||
|
||
import android.app.Activity | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.BaseAdapter | ||
import android.widget.Filter | ||
import android.widget.Filterable | ||
import android.widget.TextView | ||
import com.github.shingyx.boomswitch.data.BluetoothDeviceInfo | ||
import com.github.shingyx.boomswitch.R | ||
|
||
class BluetoothDeviceAdapter( | ||
private val activity: Activity | ||
) : BaseAdapter(), Filterable { | ||
private var devices = emptyList<BluetoothDeviceInfo>() | ||
private val filter = NoFilter() | ||
|
||
fun updateItems(items: List<BluetoothDeviceInfo>) { | ||
devices = items | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { | ||
val view = convertView | ||
?: activity.layoutInflater.inflate(R.layout.dropdown_menu_popup_item, parent, false) | ||
(view as TextView).text = devices[position].toString() | ||
return view | ||
} | ||
|
||
override fun getItem(position: Int): BluetoothDeviceInfo { | ||
return devices[position] | ||
} | ||
|
||
override fun getItemId(position: Int): Long { | ||
return position.toLong() | ||
} | ||
|
||
override fun getCount(): Int { | ||
return devices.size | ||
} | ||
|
||
override fun getFilter(): Filter { | ||
return filter | ||
} | ||
|
||
private inner class NoFilter : Filter() { | ||
override fun performFiltering(constraint: CharSequence?): FilterResults { | ||
return FilterResults().apply { | ||
values = devices | ||
count = devices.size | ||
} | ||
} | ||
|
||
override fun publishResults(constraint: CharSequence?, results: FilterResults?) { | ||
notifyDataSetChanged() | ||
} | ||
} | ||
} |
Oops, something went wrong.