|
| 1 | +package com.ms8.smartirhub.android._tests.dev_playground |
| 2 | + |
| 3 | +import android.os.Bundle |
| 4 | +import android.os.Handler |
| 5 | +import android.view.Gravity |
| 6 | +import androidx.appcompat.app.AppCompatActivity |
| 7 | +import androidx.databinding.DataBindingUtil |
| 8 | +import com.ms8.smartirhub.android.R |
| 9 | +import com.ms8.smartirhub.android.database.AppState |
| 10 | +import com.ms8.smartirhub.android.databinding.TestBinding |
| 11 | +import com.ms8.smartirhub.android.firebase.RealtimeDatabaseFunctions |
| 12 | +import com.ms8.smartirhub.android.remote_control.command.creation.CommandCreator |
| 13 | +import com.ms8.smartirhub.android.remote_control.button.creation.ButtonCreator |
| 14 | +import com.ms8.smartirhub.android.remote_control.button.models.Button |
| 15 | +import com.ms8.smartirhub.android.remote_control.views.RemoteLayout |
| 16 | + |
| 17 | +class TestEnvActivity : AppCompatActivity() { |
| 18 | + enum class TestType {COMMAND_CREATOR, BUTTON_CREATOR, REMOTE_LAYOUT} |
| 19 | + |
| 20 | + private val testType = TestType.REMOTE_LAYOUT |
| 21 | + |
| 22 | + private val commandCreator = CommandCreator() |
| 23 | + private val buttonCreator = ButtonCreator() |
| 24 | + private lateinit var binding: TestBinding |
| 25 | + private var remoteLayout : RemoteLayout? = null |
| 26 | + |
| 27 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 28 | + super.onCreate(savedInstanceState) |
| 29 | + binding = DataBindingUtil.setContentView(this, R.layout._test) |
| 30 | + |
| 31 | + when (testType) { |
| 32 | + TestType.COMMAND_CREATOR -> setupCommandCreator() |
| 33 | + TestType.BUTTON_CREATOR -> setupButtonCreator() |
| 34 | + TestType.REMOTE_LAYOUT -> setupRemoteLayout() |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + private fun setupRemoteLayout() { |
| 39 | + AppState.tempData.tempRemoteProfile.apply { |
| 40 | + name = "Test Remote" |
| 41 | + inEditMode.set(false) |
| 42 | + |
| 43 | + buttons.addAll(arrayListOf( |
| 44 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 45 | + properties[0].text = "1" |
| 46 | + }, |
| 47 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 48 | + properties[0].text = "2" |
| 49 | + }, |
| 50 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 51 | + properties[0].text = "3" |
| 52 | + }, |
| 53 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 54 | + properties[0].text = "4" |
| 55 | + }, |
| 56 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_INCREMENTER_VERTICAL).apply { |
| 57 | + properties[1].text = "VOL" |
| 58 | + }, |
| 59 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_RADIAL_W_CENTER).apply { |
| 60 | + properties[4].text = "OK" |
| 61 | + }, |
| 62 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_INCREMENTER_VERTICAL).apply { |
| 63 | + properties[1].text = "CH" |
| 64 | + }, |
| 65 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 66 | + properties[0].text = "5" |
| 67 | + }, |
| 68 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 69 | + properties[0].text = "6" |
| 70 | + }, |
| 71 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 72 | + properties[0].text = "7" |
| 73 | + }, |
| 74 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 75 | + properties[0].text = "8" |
| 76 | + }, |
| 77 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 78 | + properties[0].text = "9" |
| 79 | + }, |
| 80 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 81 | + properties[0].text = "10" |
| 82 | + }, |
| 83 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 84 | + properties[0].text = "11" |
| 85 | + }, |
| 86 | + Button(Button.Companion.ButtonStyle.STYLE_BTN_SINGLE_ACTION_ROUND).apply { |
| 87 | + properties[0].text = "12" |
| 88 | + properties[0].bgTint = "#EF5350" |
| 89 | + } |
| 90 | + )) |
| 91 | + } |
| 92 | + remoteLayout = RemoteLayout(this) |
| 93 | + remoteLayout?.setupAdapter() |
| 94 | + |
| 95 | + binding.testRoot.addView(remoteLayout?.getRemoteView()) |
| 96 | + |
| 97 | + Handler().postDelayed({AppState.tempData.tempRemoteProfile.buttons.clear()}, 5000) |
| 98 | + } |
| 99 | + |
| 100 | + private fun setupButtonCreator() { |
| 101 | + binding.testRoot.addView(android.widget.Button(this).apply { |
| 102 | + gravity = Gravity.CENTER |
| 103 | + setBackgroundResource(R.drawable.bg_outline_white_ripple) |
| 104 | + setText(R.string.test_button_creator) |
| 105 | + setOnClickListener { buttonCreator.showBottomDialog() } |
| 106 | + }) |
| 107 | + } |
| 108 | + |
| 109 | + private fun setupCommandCreator() { |
| 110 | + binding.apply { |
| 111 | + testRoot.addView(android.widget.Button(this@TestEnvActivity).apply { |
| 112 | + gravity = Gravity.CENTER |
| 113 | + setBackgroundResource(R.drawable.bg_outline_white_ripple) |
| 114 | + setText(R.string.test_command_creator) |
| 115 | + setOnClickListener { commandCreator.showBottomDialog(0) } |
| 116 | + }) |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + override fun onResume() { |
| 121 | + super.onResume() |
| 122 | + commandCreator.context = this |
| 123 | + buttonCreator.context = this |
| 124 | + RealtimeDatabaseFunctions.debugMode = true |
| 125 | + |
| 126 | + when (testType) { |
| 127 | + TestType.REMOTE_LAYOUT -> |
| 128 | + { |
| 129 | + remoteLayout?.startListening() |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + override fun onPause() { |
| 135 | + super.onPause() |
| 136 | + commandCreator.context = null |
| 137 | + buttonCreator.context = null |
| 138 | + |
| 139 | + when (testType) { |
| 140 | + TestType.REMOTE_LAYOUT -> |
| 141 | + { |
| 142 | + remoteLayout?.stopListening() |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | +} |
0 commit comments