Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement direct view #61

Merged
merged 11 commits into from
Dec 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.domi04151309.home.activities
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
Expand All @@ -15,7 +14,6 @@ import io.github.domi04151309.home.adapters.DeviceListAdapter
import io.github.domi04151309.home.data.DeviceItem
import io.github.domi04151309.home.helpers.Devices
import io.github.domi04151309.home.data.SimpleListItem
import io.github.domi04151309.home.helpers.Global
import io.github.domi04151309.home.helpers.Theme
import io.github.domi04151309.home.interfaces.RecyclerViewHelperInterfaceAdvanced

Expand Down Expand Up @@ -77,14 +75,17 @@ class DevicesActivity : AppCompatActivity(), RecyclerViewHelperInterfaceAdvanced
}

private fun loadDevices(){
val listItems: ArrayList<SimpleListItem> = ArrayList(devices.length())
val listItems: ArrayList<SimpleListItem> = arrayListOf()
try {
listItems.ensureCapacity(devices.length())
var currentDevice: DeviceItem
for (i in 0 until devices.length()) {
currentDevice = devices.getDeviceByIndex(i)
listItems += SimpleListItem(
title = currentDevice.name,
summary = currentDevice.address,
summary =
if (currentDevice.hide) resources.getString(R.string.device_config_hidden) + " · " + currentDevice.address
else currentDevice.address,
hidden = "edit#${currentDevice.id}",
icon = currentDevice.iconId
)
Expand All @@ -102,7 +103,6 @@ class DevicesActivity : AppCompatActivity(), RecyclerViewHelperInterfaceAdvanced
hidden = "none",
icon = R.drawable.ic_warning
)
Log.e(Global.LOG_TAG, e.toString())
}

recyclerView.adapter = DeviceListAdapter(listItems, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ import io.github.domi04151309.home.helpers.Theme

class EditDeviceActivity : AppCompatActivity() {

companion object {
private val SUPPORTS_DIRECT_VIEW = arrayOf(
"ESP Easy", "Hue API", "Shelly Gen 1", "Shelly Gen 2", "SimpleHome API"
)
private val HAS_CONFIG = arrayOf(
"Hue API", "ESP Easy", "Node-RED", "Shelly Gen 1", "Shelly Gen 2"
)
}

override fun onCreate(savedInstanceState: Bundle?) {
Theme.set(this)
super.onCreate(savedInstanceState)
Expand All @@ -52,6 +61,8 @@ class EditDeviceActivity : AppCompatActivity() {
val specialSection = findViewById<LinearLayout>(R.id.specialSection)
val usernameBox = findViewById<TextInputLayout>(R.id.usernameBox)
val passwordBox = findViewById<TextInputLayout>(R.id.passwordBox)
val configHide = findViewById<CheckBox>(R.id.configHide)
val configDirectView = findViewById<CheckBox>(R.id.configDirectView)
val configBtn = findViewById<Button>(R.id.configBtn)

findViewById<TextView>(R.id.idTxt).text = (resources.getString(R.string.pref_add_id, deviceId))
Expand All @@ -74,11 +85,16 @@ class EditDeviceActivity : AppCompatActivity() {
specialSection.visibility = specialVisibility
usernameBox.visibility = usernameVisibility

if (SUPPORTS_DIRECT_VIEW.contains(string)) {
configDirectView.isEnabled = true
} else {
configDirectView.isEnabled = false
configDirectView.isChecked = false
}

if (editing) {
configBtn.visibility =
if (
arrayOf("Hue API", "ESP Easy", "Node-RED", "Shelly Gen 1", "Shelly Gen 2").contains(string)
) View.VISIBLE
if (HAS_CONFIG.contains(string)) View.VISIBLE
else View.GONE
}
}
Expand All @@ -102,6 +118,8 @@ class EditDeviceActivity : AppCompatActivity() {
modeSpinner.setText(deviceObj.mode)
usernameBox.editText?.setText(deviceSecrets.username)
passwordBox.editText?.setText(deviceSecrets.password)
configHide.isChecked = deviceObj.hide
configDirectView.isChecked = deviceObj.directView

configBtn.setOnClickListener {
when (modeSpinner.text.toString()) {
Expand Down Expand Up @@ -218,6 +236,8 @@ class EditDeviceActivity : AppCompatActivity() {
newItem.address = tempAddress
newItem.mode = modeSpinner.text.toString()
newItem.iconName = iconSpinner.text.toString()
newItem.hide = configHide.isChecked
newItem.directView = configDirectView.isChecked
devices.addDevice(newItem)
deviceSecrets.username = usernameBox.editText?.text.toString()
deviceSecrets.password = passwordBox.editText?.text.toString()
Expand Down
Loading