Commit 3624ec85 authored by Anon's avatar Anon

Merge branch 'release-changes' into 'master'

Fix jumpy scanner UI and manual set time button

See merge request !17
parents aec0ac31 828a5152
......@@ -104,16 +104,16 @@ class MainActivity : AppCompatActivity() {
.replace(R.id.fragment_container, fragment)
.commit()
val workManager = WorkManager.getInstance(this)
if (!bluetoothAdapter.bondedDevices.isEmpty()
) {
val updateClockRequest =
PeriodicWorkRequestBuilder<UpdateClockJob>(UPDATE_CLOCK_FREQUENCY_MINS.toLong(), TimeUnit.MINUTES)
.build()
workManager
.enqueueUniquePeriodicWork(WORK_NAME, ExistingPeriodicWorkPolicy.REPLACE, updateClockRequest)
} else {
workManager.cancelUniqueWork(WORK_NAME)
}
// val workManager = WorkManager.getInstance(this)
// if (!bluetoothAdapter.bondedDevices.isEmpty()
// ) {
// val updateClockRequest =
// PeriodicWorkRequestBuilder<UpdateClockJob>(UPDATE_CLOCK_FREQUENCY_MINS.toLong(), TimeUnit.MINUTES)
// .build()
// workManager
// .enqueueUniquePeriodicWork(WORK_NAME, ExistingPeriodicWorkPolicy.REPLACE, updateClockRequest)
// } else {
// workManager.cancelUniqueWork(WORK_NAME)
// }
}
}
......@@ -26,8 +26,10 @@ import android.bluetooth.*
import android.content.Context
import android.util.Log
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.CARD10_SERVICE_UUID
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.filetransfer.LowEffortService
import de.ccc.events.badge.card10.time.Card10Service
import java.lang.IllegalStateException
import java.lang.NullPointerException
import java.util.*
......@@ -37,6 +39,7 @@ private const val TAG = "ConnectionService"
object ConnectionService {
var device: BluetoothDevice? = null
var leService: LowEffortService? = null
var card10Service: Card10Service? = null
var mtu = 100
private var connection: BluetoothGatt? = null
......@@ -98,6 +101,8 @@ object ConnectionService {
if (service.uuid == fileServiceUuid) {
leService = LowEffortService(service)
} else if (service.uuid == CARD10_SERVICE_UUID) {
card10Service = Card10Service(service)
}
}
......@@ -160,7 +165,13 @@ object ConnectionService {
}
fun writeCharacteristic(characteristic: BluetoothGattCharacteristic): Boolean {
return connection?.writeCharacteristic(characteristic) ?: false
val status = connection?.writeCharacteristic(characteristic) ?: false
if (!status) {
Log.d(TAG, "Write status: $status")
}
return status
}
}
\ No newline at end of file
......@@ -80,13 +80,7 @@ class LowEffortService(
val bytes = packet.getBytes()
centralTx.value = bytes
val status = ConnectionService.writeCharacteristic(centralTx)
if (!status) {
Log.d(TAG, "Write status: $status")
}
return status
return ConnectionService.writeCharacteristic(centralTx)
}
fun setOnPacketReceivedListener(packetListener: OnPacketReceivedListener) {
......
......@@ -29,6 +29,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.R
......@@ -38,6 +39,7 @@ import de.ccc.events.badge.card10.hatchery.AppListFragment
import de.ccc.events.badge.card10.mood.MoodFragment
import de.ccc.events.badge.card10.scanner.ScannerFragment
import de.ccc.events.badge.card10.sparkle.BeautifulFragment
import de.ccc.events.badge.card10.time.TimeUpdateDialog
import kotlinx.android.synthetic.main.main_fragment.*
class MainFragment : Fragment() {
......@@ -53,6 +55,13 @@ class MainFragment : Fragment() {
button_hatchery.setOnClickListener { startFragment(AppListFragment()) }
button_send.setOnClickListener { startFragment(FileTransferFragment()) }
button_set_time.setOnClickListener {
val dialogFragment = TimeUpdateDialog()
dialogFragment.show(fragmentManager, "time")
dialogFragment.setTime()
dialogFragment.dismiss()
}
val bondedCard10s =
bluetoothAdapter.bondedDevices.filter { it.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true) }
......@@ -76,6 +85,7 @@ class MainFragment : Fragment() {
private fun showConnectedView(view: View) {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.VISIBLE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.GONE
view.findViewById<Button>(R.id.button_pair).text = getString(R.string.main_button_manage_pairings)
}
private fun showDisconnectedView(view: View) {
......
......@@ -26,10 +26,12 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import java.util.*
import kotlin.collections.HashSet
class ScannerListAdapter(val clickListener: (Device) -> Unit) : RecyclerView.Adapter<DeviceViewHolder>() {
private val list = LinkedList<Device>()
private val foundDevices = mutableSetOf<String>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DeviceViewHolder {
val inflater = LayoutInflater.from(parent.context)
......@@ -44,6 +46,12 @@ class ScannerListAdapter(val clickListener: (Device) -> Unit) : RecyclerView.Ada
override fun getItemCount(): Int = list.size
fun put(device: Device) {
if (foundDevices.contains(device.btMac)) {
return
} else {
foundDevices.add(device.btMac)
}
list.remove(device)
list.add(device)
notifyDataSetChanged()
......
/*
* Copyright by the original author or authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.ccc.events.badge.card10.time
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattService
import de.ccc.events.badge.card10.TIME_CHARACTERISTIC_UUID
import de.ccc.events.badge.card10.common.ConnectionService
import java.nio.ByteBuffer
class Card10Service(
service: BluetoothGattService
) {
private val timeCharacteristic: BluetoothGattCharacteristic
init {
timeCharacteristic = service.getCharacteristic(TIME_CHARACTERISTIC_UUID)
timeCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
}
fun setTime() {
val buffer = ByteBuffer.allocate(8)
buffer.putLong(System.currentTimeMillis())
timeCharacteristic.value = buffer.array()
ConnectionService.writeCharacteristic(timeCharacteristic)
}
}
\ No newline at end of file
/*
* Copyright by the original author or authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.ccc.events.badge.card10.time
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.common.ConnectionService
private const val TAG = "TimeUpdateDialog"
class TimeUpdateDialog : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.time_update_dialog, container, false)
fun setTime() {
ConnectionService.card10Service?.setTime() ?: Log.e(TAG, "card10 service not initialized")
}
}
\ No newline at end of file
......@@ -3,17 +3,17 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/loading_dialog_padding">
android:padding="@dimen/dialog_padding">
<ProgressBar android:layout_width="@dimen/loading_dialog_progress"
android:layout_height="@dimen/loading_dialog_progress"
<ProgressBar android:layout_width="@dimen/progress_dialog_progress_size"
android:layout_height="@dimen/progress_dialog_progress_size"
android:layout_gravity="center"
android:indeterminate="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/loading_dialog_text_margin"
android:layout_marginTop="@dimen/progress_dialog_text_margin"
android:text="@string/loading_dialog_loading"/>
</LinearLayout>
\ No newline at end of file
......@@ -62,8 +62,7 @@
android:text="@string/main_button_send_file"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_hatchery"
android:enabled="false"/>
app:layout_constraintTop_toBottomOf="@+id/button_hatchery"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -85,6 +84,16 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_button_margin"
style="@style/MainButton"
android:id="@+id/button_set_time"
android:text="@string/main_button_set_time"
app:layout_constraintTop_toBottomOf="@+id/button_beautiful"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/dialog_padding">
<ProgressBar android:layout_width="@dimen/progress_dialog_progress_size"
android:layout_height="@dimen/progress_dialog_progress_size"
android:layout_gravity="center"
android:indeterminate="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/progress_dialog_text_margin"
android:text="@string/time_update_dialog_setting"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="activity_padding">24dp</dimen>
<dimen name="dialog_padding">24dp</dimen>
<dimen name="logo_margin_bottom">24dp</dimen>
<dimen name="main_label_margin">32dp</dimen>
......@@ -13,9 +14,8 @@
<dimen name="app_list_item_padding">16dp</dimen>
<dimen name="app_detail_description_margin">16dp</dimen>
<dimen name="loading_dialog_padding">24dp</dimen>
<dimen name="loading_dialog_progress">48dp</dimen>
<dimen name="loading_dialog_text_margin">16dp</dimen>
<dimen name="progress_dialog_progress_size">48dp</dimen>
<dimen name="progress_dialog_text_margin">16dp</dimen>
<dimen name="default_list_item_margin_side">16dp</dimen>
<dimen name="default_list_item_height">56dp</dimen>
......
......@@ -10,6 +10,7 @@
<string name="main_button_send_file">Send File</string>
<string name="main_button_mood">Change Mood</string>
<string name="main_button_beautiful">Beautiful</string>
<string name="main_button_set_time">Set Time</string>
<string name="file_transfer_button_pick_file">Select file</string>
<string name="file_transfer_button_start_transfer">Start</string>
......@@ -32,6 +33,8 @@
<string name="dialog_action_ok">OK</string>
<string name="dialog_action_cancel">Cancel</string>
<string name="time_update_dialog_setting">Setting time</string>
<string name="hatchery_error_generic">Something went wrong</string>
<string name="app_detail_downloads">Downloads: %1$d</string>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment