Commit bcf06692 authored by Anon's avatar Anon

Turn MainActivity into a menu with status

parent a9a9d954
package com.github.antweb.donkey
import android.bluetooth.BluetoothDevice
object ConnectionService {
var device: BluetoothDevice? = null
val deviceName: String?
get() = device?.name
val deviceAddress: String?
get() = device?.address
fun hasDevice(): Boolean {
return device != null
}
}
\ No newline at end of file
......@@ -10,19 +10,34 @@ private const val TAG = "MainActivity"
class MainActivity : AppCompatActivity() {
private lateinit var tvConnection: TextView
private lateinit var tvValue: TextView
private lateinit var buttonConnect: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tvValue = findViewById(R.id.text_value)
tvConnection = findViewById(R.id.text_connection_status)
tvConnection.text = "STATE_DISCONNECTED"
if (ConnectionService.hasDevice()) {
showConnectedView()
} else {
showNotConnectedView()
}
}
private fun showConnectedView() {
setContentView(R.layout.activity_main_connected)
val buttonSend = findViewById<Button>(R.id.button_send)
buttonSend.setOnClickListener {
val intent = Intent(this, SendActivity::class.java)
startActivity(intent)
}
val tvStatus = findViewById<TextView>(R.id.label_status)
tvStatus.text =
getString(R.string.main_label_status, ConnectionService.deviceName, ConnectionService.deviceAddress)
}
private fun showNotConnectedView() {
setContentView(R.layout.activity_main_not_connected)
buttonConnect = findViewById(R.id.button_connect)
val buttonConnect = findViewById<Button>(R.id.button_connect)
buttonConnect.setOnClickListener {
val intent = Intent(this, ScanActivity::class.java)
startActivity(intent)
......
......@@ -41,8 +41,8 @@ class ScanActivity : AppCompatActivity() {
val item = adapterView.adapter.getItem(i) as? BluetoothDevice
if (item != null) {
selectedDevice = item
val intent = Intent(this, SendActivity::class.java)
ConnectionService.device = item
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
......
<?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">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/label_status"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button_send"
android:text="@string/main_button_send"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_connection_status"
/>
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_value"
/>
android:text="@string/main_label_not_connected"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_button_connect"
android:id="@+id/button_connect"
/>
android:id="@+id/button_connect"/>
</LinearLayout>
\ No newline at end of file
<resources>
<string name="app_name">BLE File Transfer</string>
<string name="main_activity_title">BLE File Transfer</string>
<string name="main_button_connect">Reconnect</string>
<string name="app_name">card10</string>
<string name="scan_activity_title">Scan Devices</string>
<string name="send_activity_title">Send File</string>
<string name="main_activity_title">@string/app_name</string>
<string name="main_label_not_connected">You are currently not connected to your card10.</string>
<string name="main_label_status">You are connected to %1$s (%2$s)</string>
<string name="main_button_connect">Connect</string>
<string name="main_button_send">Send File</string>
</resources>
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