MainActivity.kt 1.35 KB
Newer Older
Anon's avatar
Anon committed
1 2
package com.github.antweb.donkey

Anon's avatar
Anon committed
3
import android.content.Intent
Anon's avatar
Anon committed
4 5 6
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
Anon's avatar
Anon committed
7
import androidx.appcompat.app.AppCompatActivity
Anon's avatar
Anon committed
8

Anon's avatar
Anon committed
9
private const val TAG = "MainActivity"
Anon's avatar
Anon committed
10

Anon's avatar
Anon committed
11
class MainActivity : AppCompatActivity() {
Anon's avatar
Anon committed
12 13 14 15

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
        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)
Anon's avatar
Anon committed
39

40
        val buttonConnect = findViewById<Button>(R.id.button_connect)
Anon's avatar
Anon committed
41
        buttonConnect.setOnClickListener {
Anon's avatar
Anon committed
42 43 44
            val intent = Intent(this, ScanActivity::class.java)
            startActivity(intent)
        }
Anon's avatar
Anon committed
45 46
    }
}