diff --git a/android/SmartIRHub/.idea/misc.xml b/android/SmartIRHub/.idea/misc.xml index 7bfef59..37a7509 100644 --- a/android/SmartIRHub/.idea/misc.xml +++ b/android/SmartIRHub/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/android/SmartIRHub/app/build.gradle b/android/SmartIRHub/app/build.gradle index fd6d9c0..1eaec1c 100644 --- a/android/SmartIRHub/app/build.gradle +++ b/android/SmartIRHub/app/build.gradle @@ -77,7 +77,7 @@ dependencies { implementation 'com.google.android.material:material:1.1.0-alpha09' //Bottom Sheet Dialog - implementation 'com.github.andrefrsousa:SuperBottomSheet:1.3.0' +// implementation 'com.github.andrefrsousa:SuperBottomSheet:1.3.0' //Potential Remote Buttons implementation 'com.github.armcha:ElasticView:0.2.0' diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/CBWalkthroughActivity.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/CBWalkthroughActivity.kt index c37ea6a..d22aa05 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/CBWalkthroughActivity.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/CBWalkthroughActivity.kt @@ -15,7 +15,7 @@ import com.ms8.smartirhub.android.R import com.ms8.smartirhub.android.create_button._old.CBStyleActivity import com.ms8.smartirhub.android.create_command.ActionSequenceAdapter import com.ms8.smartirhub.android.create_command.CC_ChooseIrSignalActivity -import com.ms8.smartirhub.android.custom_views.bottom_sheets.BackWarningSheet +import com.ms8.smartirhub.android.custom_views.bottom_sheets.BottomSheet import com.ms8.smartirhub.android.custom_views.bottom_sheets.SimpleListDescSheet import com.ms8.smartirhub.android.custom_views.bottom_sheets.SimpleListDescSheet.Companion.REQ_EDIT_ACTION import com.ms8.smartirhub.android.custom_views.bottom_sheets.SimpleListDescSheet.Companion.REQ_NEW_ACTION @@ -33,8 +33,8 @@ import com.ms8.smartirhub.android.utils.MyValidators.ButtonNameValidator class CBWalkThroughActivity : AppCompatActivity() { lateinit var binding: ACreateButtonWalkthroughBinding - private val warningSheet: BackWarningSheet = BackWarningSheet() - private val pickNameSheet = PickNameSheet() + private lateinit var warningSheet : BottomSheet + private val pickNameSheet = PickNameSheet(this) /* ---------------------------------------------- @@ -57,7 +57,8 @@ class CBWalkThroughActivity : AppCompatActivity() { ) } }) - private val pickActionsSheet = SimpleListDescSheet() + + private val pickActionsSheet = SimpleListDescSheet(this) private val commandListener = object : ObservableList.OnListChangedCallback>() { override fun onChanged(sender: ObservableArrayList) { @@ -104,7 +105,7 @@ class CBWalkThroughActivity : AppCompatActivity() { override fun onBackPressed() { when { - pickNameSheet.isVisible -> { + pickNameSheet.isShowing -> { pickNameSheet.dismiss() } binding.prog3.bOnThisStep -> { @@ -120,7 +121,7 @@ class CBWalkThroughActivity : AppCompatActivity() { super.onBackPressed() } !warningSheet.bIsShowing -> { - warningSheet.show(supportFragmentManager, "WarningBottomSheet") + warningSheet.show() } } } @@ -164,8 +165,18 @@ class CBWalkThroughActivity : AppCompatActivity() { if (AppState.tempData.tempButton == null) AppState.tempData.tempButton = RemoteProfile.Button() + // set up warning sheet + warningSheet = BottomSheet(this, + getString(R.string.exit_app_title), + getString(R.string.exit_app_desc), + getString(R.string.leave), + getString(android.R.string.cancel), + { finishAndRemoveTask() }) + warningSheet.setup() + //Set up PickNameSheet pickNameSheet.nameDesc = getString(R.string.remember_button_name_desc) + pickNameSheet.setup() //Set up pickActionsSheet pickActionsSheet.sheetTitle = this@CBWalkThroughActivity.getString(R.string.command_title) @@ -289,7 +300,7 @@ class CBWalkThroughActivity : AppCompatActivity() { binding.prog3.bOnThisStep = true binding.btnNextStep.text = getString(R.string.select_style) binding.btnNextStep.setOnClickListener { getButtonStyle() } - binding.prog1.setOnClickListener { getButtonStyle() } + binding.prog1. setOnClickListener { getButtonStyle() } } } } @@ -301,14 +312,14 @@ class CBWalkThroughActivity : AppCompatActivity() { */ private fun showPickNameSheet() { - if (!pickNameSheet.isVisible) { - pickNameSheet.show(supportFragmentManager, "PickButtonNameSheet") + if (!pickNameSheet.isShowing) { + pickNameSheet.show() } } private fun getSignalOrAction() { - if (!pickActionsSheet.isVisible) { - pickActionsSheet.show(supportFragmentManager, "PickActionsSheet") + if (!pickActionsSheet.isShowing) { + pickActionsSheet.show() } } diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/_old/CBNameActivity.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/_old/CBNameActivity.kt index 60fe0fc..e95006f 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/_old/CBNameActivity.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/create_button/_old/CBNameActivity.kt @@ -4,22 +4,31 @@ import android.app.Activity import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.databinding.DataBindingUtil +import com.google.android.material.bottomsheet.BottomSheetDialog import com.ms8.smartirhub.android.R -import com.ms8.smartirhub.android.custom_views.bottom_sheets.BottomErrorSheet import com.ms8.smartirhub.android.database.AppState import com.ms8.smartirhub.android.databinding.ACreateButtonNameBinding +import com.ms8.smartirhub.android.databinding.VBottomSheetBinding import com.ms8.smartirhub.android.utils.MyValidators.ButtonNameValidator class CBNameActivity : AppCompatActivity() { lateinit var binding: ACreateButtonNameBinding - val errorNameSheet = BottomErrorSheet() + private lateinit var errorNameSheet : BottomSheetDialog + private var errorNameSheetBinding: VBottomSheetBinding? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.a_create_button_name) - errorNameSheet.sheetTitle = getString(R.string.err_invalid_button_name_title) - errorNameSheet.description = getString(R.string.err_invalid_button_name_desc) + // set up error BottomSheet + errorNameSheet = BottomSheetDialog(this) + val errorNameSheetView = layoutInflater.inflate(R.layout.v_bottom_sheet, null) + errorNameSheet.setContentView(errorNameSheetView) + errorNameSheetBinding = DataBindingUtil.bind(errorNameSheetView) + errorNameSheetBinding?.let { b -> + b.tvTitle.text = getString(R.string.err_invalid_button_name_title) + b.tvDescription.text = getString(R.string.err_invalid_button_name_desc) + } binding.btnPickName.setOnClickListener { checkName() } @@ -36,7 +45,7 @@ class CBNameActivity : AppCompatActivity() { */ private fun checkName() { val isValidName = binding.txtButtonName.editText!!.text.toString().ButtonNameValidator() - .addErrorCallback { errorNameSheet.show(supportFragmentManager, "bottom_sheet_error_invalid_name") } + .addErrorCallback { errorNameSheet.show() } .check() if (isValidName) { AppState.tempData.tempButton?.name = binding.txtButtonName.editText!!.text.toString() diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BackWarningSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BackWarningSheet.kt deleted file mode 100644 index 6471799..0000000 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BackWarningSheet.kt +++ /dev/null @@ -1,109 +0,0 @@ -package com.ms8.smartirhub.android.custom_views.bottom_sheets - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.core.content.ContextCompat -import androidx.databinding.DataBindingUtil -import com.andrefrsousa.superbottomsheet.SuperBottomSheetFragment -import com.ms8.smartirhub.android.R -import com.ms8.smartirhub.android.databinding.VBottomSheetBinding - -class BackWarningSheet : SuperBottomSheetFragment() { - private var binding: VBottomSheetBinding? = null - var bWantsToLeave = false - var bIsShowing = false - - var titleStr = "" - set(value) { - field = value - binding?.tvTitle?.text = titleStr - } - var descStr = "" - set(value) { - field = value - binding?.tvDescription?.text = descStr - } - var btnNegStr = "" - set(value) { - field = value - binding?.btnNeg?.text = value - } - var btnPosStr = "" - set(value) { - field = value - binding?.btnPos?.text = value - } - - var callback : BackWaringSheetCallback? = null - - var performDefaultPosAction = true - var performDefaultNegAction = true - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState.putStringArrayList(KEY_STR_STATE, arrayListOf(titleStr, descStr, btnNegStr, btnPosStr)) - outState.putBooleanArray(KEY_DEF_ACTION_STATE, BooleanArray(2).apply { - set(0, performDefaultPosAction) - set(1, performDefaultNegAction) - }) - } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - super.onCreateView(inflater, container, savedInstanceState) - binding = DataBindingUtil.inflate(inflater, R.layout.v_bottom_sheet, container, false) - - val strArray = savedInstanceState?.getStringArray(KEY_STR_STATE) - binding?.tvTitle?.text = strArray?.get(0) ?: if (titleStr == "") context!!.getString(R.string.are_you_sure) else titleStr - binding?.tvDescription?.text = strArray?.get(1) ?: if (descStr == "") context!!.getString(R.string.wrn_create_button_desc) else descStr - binding?.btnNeg?.text = strArray?.get(2) ?: if (btnNegStr == "") context!!.getString(R.string.stay) else btnNegStr - binding?.btnPos?.text = strArray?.get(3) ?: if (btnPosStr == "") context!!.getString(R.string.go_back) else btnPosStr - - val boolArray = savedInstanceState?.getBooleanArray(KEY_DEF_ACTION_STATE) - performDefaultNegAction = boolArray?.get(1) ?: performDefaultNegAction - performDefaultPosAction = boolArray?.get(0) ?: performDefaultPosAction - - binding?.btnNeg?.setOnClickListener { dismissWarning() } - binding?.btnPos?.setOnClickListener { leave() } - - return binding?.root - } - - -// override fun getPeekHeight() = 250 - - override fun animateCornerRadius() = true - - override fun getBackgroundColor(): Int { - return ContextCompat.getColor(context!!, R.color.colorCardDark) - } - - private fun dismissWarning() { - callback?.btnNegAction() - - if (performDefaultNegAction) { - bIsShowing = false - dismiss() - } - } - - private fun leave() { - callback?.btnPosAction() - - if (performDefaultPosAction) { - bWantsToLeave = true - activity?.onBackPressed() - } - } - - interface BackWaringSheetCallback { - fun btnNegAction() - fun btnPosAction() - } - - companion object { - const val KEY_STR_STATE = "KEY_STR_STATE" - const val KEY_DEF_ACTION_STATE = "KEY_DEF_ACT_STATE" - } -} \ No newline at end of file diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BottomErrorSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BottomErrorSheet.kt deleted file mode 100644 index e55d6b6..0000000 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BottomErrorSheet.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.ms8.smartirhub.android.custom_views.bottom_sheets - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.core.content.ContextCompat -import androidx.databinding.DataBindingUtil -import com.andrefrsousa.superbottomsheet.SuperBottomSheetFragment -import com.ms8.smartirhub.android.R -import com.ms8.smartirhub.android.databinding.VBottomSheetBinding - -class BottomErrorSheet : SuperBottomSheetFragment() { - lateinit var binding: VBottomSheetBinding - var bWantsToLeave = false - var bIsShowing = false - var description = "" - var sheetTitle = "" - - var posText = "" - var posListener : () -> Any? = {} - - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - super.onCreateView(inflater, container, savedInstanceState) - binding = DataBindingUtil.inflate(inflater, R.layout.v_bottom_sheet, container, false) - binding.tvTitle.text = sheetTitle - binding.tvTitle.setTextColor(ContextCompat.getColor(context!!, android.R.color.holo_red_dark)) - binding.tvDescription.text = description - binding.btnNeg.text = context!!.getString(R.string.dismiss) - binding.btnNeg.setOnClickListener { dismissWarning() } - - if (posText == "") { - binding.btnPos.visibility = View.GONE - } else { - binding.btnPos.visibility = View.VISIBLE - binding.btnPos.text = posText - binding.btnPos.setOnClickListener { - dismiss() - posListener() - } - } - - return binding.root - } - - override fun getBackgroundColor(): Int { - return ContextCompat.getColor(context!!, R.color.colorPrimaryDark) - } - - private fun dismissWarning() { - bIsShowing = false - dismiss() - } - - fun setPositiveButton(buttonTitle: String, action: () -> Any?) { - posText = buttonTitle - posListener = action - - } - -} \ No newline at end of file diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BottomSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BottomSheet.kt new file mode 100644 index 0000000..837d712 --- /dev/null +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/BottomSheet.kt @@ -0,0 +1,120 @@ +package com.ms8.smartirhub.android.custom_views.bottom_sheets + +import android.content.Context +import android.view.View +import androidx.core.content.ContextCompat +import androidx.databinding.DataBindingUtil +import com.google.android.material.bottomsheet.BottomSheetDialog +import com.ms8.smartirhub.android.R +import com.ms8.smartirhub.android.databinding.VBottomSheetBinding + +@Suppress("JoinDeclarationAndAssignment") +open class BottomSheet(context: Context) : BottomSheetDialog(context) { + private val sheetView : View + protected var binding : VBottomSheetBinding? + + var bWantsToLeave = false + var bIsShowing = false + var dismissOnButtonClick = true + + var description = "" + set(value) { + field = value + binding?.tvDescription?.text = field + } + var sheetTitle = "" + set(value) { + field = value + binding?.tvTitle?.text = field + } + + var posText = "" + set(value) { + field = value + binding?.let { b -> + b.btnPos.text = field + if (posText == "") { + b.btnPos.visibility = View.GONE + } else { + b.btnPos.visibility = View.VISIBLE + b.btnPos.text = posText + } + } + + } + + var negText = context.getString(R.string.dismiss) + set(value) { + field = value + binding?.btnNeg?.text = field + } + + var posListener : () -> Any? = {} + var negListener : () -> Any? = {} + + constructor(context: Context, + sheetTitle : String = "", + description : String = "", + posText : String = "", + negText : String = "", + posListener : () -> Any? = {}, + negListener : () -> Any? = {}) : this(context) { + this.sheetTitle = sheetTitle + this.description = description + this.posText = posText + this.negText = negText + this.posListener = posListener + this.negListener = negListener + } + + init { + sheetView = layoutInflater.inflate(R.layout.v_bottom_sheet, null) + binding = DataBindingUtil.bind(sheetView) + + binding?.let { b -> + b.tvTitle.text = sheetTitle + b.tvDescription.text = description + b.btnPos.text = posText + b.btnNeg.text = negText + + b.btnPos.setOnClickListener { + if (dismissOnButtonClick) + dismiss() + posListener() + } + b.btnNeg.setOnClickListener { + if (dismissOnButtonClick) + dismiss() + negListener + } + } + } + + fun setup() { + setContentView(sheetView) + } +} + +class BottomErrorSheet(context: Context) : BottomSheet(context) { + + constructor(context: Context, + sheetTitle : String = "", + description : String = "", + posText : String = "", + negText : String = "", + posListener : () -> Any? = {}, + negListener : () -> Any? = {}) : this(context) { + this.sheetTitle = sheetTitle + this.description = description + this.posText = posText + this.negText = negText + this.posListener = posListener + this.negListener = negListener + } + + init { + binding?.tvTitle?.setTextColor(ContextCompat.getColor(context, android.R.color.holo_red_dark)) + } + + +} \ No newline at end of file diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/HubSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/HubSheet.kt index 166a99d..d298216 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/HubSheet.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/HubSheet.kt @@ -1,23 +1,23 @@ package com.ms8.smartirhub.android.custom_views.bottom_sheets +import android.content.Context import com.ms8.smartirhub.android.R import com.ms8.smartirhub.android.learn_signal.HubCardListAdapter -class HubSheet : SimpleListDescSheet() { +class HubSheet(context: Context) : SimpleListDescSheet(context) { - override fun onPause() { + fun onPause() { binding?.sheetList?.adapter?.let { (it as HubCardListAdapter).listen(false) } - super.onPause() } - override fun onResume() { - binding?.btnSaveCommand?.text = getString(R.string.select) + fun onResume() { + binding?.btnSaveCommand?.text = context.getString(R.string.select) binding?.sheetList?.adapter?.let { (it as HubCardListAdapter).listen(true) } - super.onResume() + } } \ No newline at end of file diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/LearnSignalSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/LearnSignalSheet.kt index f501839..117aeab 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/LearnSignalSheet.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/LearnSignalSheet.kt @@ -2,32 +2,29 @@ package com.ms8.smartirhub.android.custom_views.bottom_sheets import android.animation.Animator import android.annotation.SuppressLint +import android.content.Context import android.content.Intent -import android.os.Bundle import android.os.Handler import android.util.Log -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.view.animation.AccelerateDecelerateInterpolator import androidx.databinding.DataBindingUtil -import com.andrefrsousa.superbottomsheet.SuperBottomSheetFragment -import com.andrognito.flashbar.Flashbar +import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.DataSnapshot import com.google.firebase.database.DatabaseError import com.google.firebase.database.ValueEventListener import com.ms8.smartirhub.android.R import com.ms8.smartirhub.android.database.AppState -import com.ms8.smartirhub.android.models.realtimedatabase.HubResult -import com.ms8.smartirhub.android.models.firestore.IrSignal import com.ms8.smartirhub.android.databinding.VLearnSigSheetBinding import com.ms8.smartirhub.android.firebase.FirebaseConstants import com.ms8.smartirhub.android.firebase.RealtimeDatabaseFunctions -import com.ms8.smartirhub.android.learn_signal.* -import java.lang.Exception +import com.ms8.smartirhub.android.learn_signal.AdvancedSignalInfoActivity +import com.ms8.smartirhub.android.learn_signal.LSListenActivity +import com.ms8.smartirhub.android.models.firestore.IrSignal +import com.ms8.smartirhub.android.models.realtimedatabase.HubResult -class LearnSignalSheet : SuperBottomSheetFragment() { +class LearnSignalSheet(context: Context) : BottomSheetDialog(context) { var binding : VLearnSigSheetBinding? = null var callback: Callback? = null @@ -144,37 +141,16 @@ class LearnSignalSheet : SuperBottomSheetFragment() { } } -/* - ---------------------------------------------- - Overridden Functions - ---------------------------------------------- -*/ - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState.putBooleanArray(KEY_LSS_BOOLS, BooleanArray(4).apply { - set(0, isListeningForResult) - set(1, isListeningForRawData) - set(2, isListeningForTestSignal) - }) - outState.putString(KEY_HUB_UID, hubUID) - } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - super.onCreateView(inflater, container, savedInstanceState) - - binding = DataBindingUtil.inflate(inflater, R.layout.v_learn_sig_sheet, container, false) - - /* -- Restore State --*/ - savedInstanceState?.getString(KEY_HUB_UID)?.let { hubUID = it } - - binding!!.let { b -> + init { + binding = DataBindingUtil.inflate(layoutInflater, R.layout.v_learn_sig_sheet, null, false) + binding?.let { b -> b.btnTestSignal.setOnClickListener { testSignal() } b.btnRetry.setOnClickListener { retry() } b.btnShowAdvancedInfo.setOnClickListener { showAdvancedLayout() } } + } - + fun setup() { val len = AppState.tempData.tempSignal?.rawData?.size ?: -1 if (len > 0) { Log.d("TEST", "Showing learned layout") @@ -184,13 +160,26 @@ class LearnSignalSheet : SuperBottomSheetFragment() { Log.d("TEST", "Hiding learned layout") hideLearnedLayout(false) } - - return binding!!.root } - override fun onPause() { - super.onPause() +/* + ---------------------------------------------- + Overridden Functions + ---------------------------------------------- +*/ + +// override fun onSaveInstanceState(outState: Bundle) { +// super.onSaveInstanceState(outState) +// outState.putBooleanArray(KEY_LSS_BOOLS, BooleanArray(4).apply { +// set(0, isListeningForResult) +// set(1, isListeningForRawData) +// set(2, isListeningForTestSignal) +// }) +// outState.putString(KEY_HUB_UID, hubUID) +// } + + fun onPause() { if (isListeningForResult) { RealtimeDatabaseFunctions.getHubResults(hubUID).removeEventListener(resultListener) binding?.btnStartListening?.revertAnimation() @@ -209,7 +198,7 @@ class LearnSignalSheet : SuperBottomSheetFragment() { ---------------------------------------------- */ - fun onBackPressed() : Boolean { + fun performBack() : Boolean { Log.d("TEST", "onBackPressed") return when { isListeningForResult or isListeningForRawData -> { @@ -228,7 +217,7 @@ class LearnSignalSheet : SuperBottomSheetFragment() { } private fun showAdvancedLayout() { - startActivity(Intent(activity, AdvancedSignalInfoActivity::class.java)) + context.startActivity(Intent(context, AdvancedSignalInfoActivity::class.java)) } private fun showLearnedLayout(animate: Boolean) { @@ -239,7 +228,7 @@ class LearnSignalSheet : SuperBottomSheetFragment() { it.tvSigCode.text = irSignal.code } // Set Listening Button to Save - it.btnStartListening.text = getString(R.string.save) + it.btnStartListening.text = context.getString(R.string.save) it.btnStartListening.setOnClickListener { saveRecordedSignal() } // Enable Advanced Info button it.btnShowAdvancedInfo.isEnabled = true @@ -286,7 +275,7 @@ class LearnSignalSheet : SuperBottomSheetFragment() { //Enable Test Signal button it.btnTestSignal.isEnabled = false // Set Listening Button to Start Listening - it.btnStartListening.text = (getString(R.string.start_listening)) + it.btnStartListening.text = (context.getString(R.string.start_listening)) it.btnStartListening.setOnClickListener { beginListeningProcess() } // Hide Learned Info Layout, Advanced Info button, and Test Signal button @@ -370,31 +359,31 @@ class LearnSignalSheet : SuperBottomSheetFragment() { @SuppressLint("LogNotTimber") private fun showUnknownError(e: Exception?) { - context?.let { - showErrorLayout(getString(R.string.err_unknown_sig_title), getString(R.string.err_unknown_sig_desc)) + context.let { + showErrorLayout(context.getString(R.string.err_unknown_sig_title), context.getString(R.string.err_unknown_sig_desc)) } e?.let { Log.e("LSListenActivity", "Unknown Error: $it") } } private fun showNoResponseError() { - context?.let { - showErrorLayout(getString(R.string.err_no_response_title), getString(R.string.err_no_response_desc)) + context.let { + showErrorLayout(context.getString(R.string.err_no_response_title), context.getString(R.string.err_no_response_desc)) } } private fun showHubBusyError() { - context?.let { - showErrorLayout(getString(R.string.err_hub_busy_title), getString(R.string.err_hub_busy_desc)) + context.let { + showErrorLayout(context.getString(R.string.err_hub_busy_title), context.getString(R.string.err_hub_busy_desc)) } } private fun showOverflowError() { - context?.let { - showErrorLayout(getString(R.string.err_overflow_title), getString(R.string.err_overflow_desc)) + context.let { + showErrorLayout(context.getString(R.string.err_overflow_title), context.getString(R.string.err_overflow_desc)) } } private fun showTimeoutError() { - context?.let { - showErrorLayout(getString(R.string.err_timeout_title), getString(R.string.err_timeout_desc)) + context.let { + showErrorLayout(context.getString(R.string.err_timeout_title), context.getString(R.string.err_timeout_desc)) } } @@ -455,9 +444,9 @@ class LearnSignalSheet : SuperBottomSheetFragment() { .addOnSuccessListener { isListeningForTestSignal = false binding?.btnTestSignal?.revertAnimation() - this@LearnSignalSheet.activity?.let { a -> - Flashbar.Builder(a).message(R.string.signal_sent).show() - } +// this@LearnSignalSheet.activity?.let { a -> +// Flashbar.Builder(a).message(R.string.signal_sent).show() +// } } .addOnFailureListener {e -> showUnknownError(e) } } diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/PickNameSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/PickNameSheet.kt index 2c3e732..e608739 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/PickNameSheet.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/PickNameSheet.kt @@ -1,24 +1,22 @@ package com.ms8.smartirhub.android.custom_views.bottom_sheets -import android.content.DialogInterface +import android.content.Context import android.content.res.ColorStateList -import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup -import android.widget.FrameLayout import androidx.core.content.ContextCompat import androidx.databinding.DataBindingUtil -import com.andrefrsousa.superbottomsheet.SuperBottomSheetFragment +import com.google.android.material.bottomsheet.BottomSheetDialog import com.ms8.smartirhub.android.R import com.ms8.smartirhub.android.database.AppState -import com.ms8.smartirhub.android.utils.MyValidators.ButtonNameValidator import com.ms8.smartirhub.android.databinding.VChooseNameSheetBinding +import com.ms8.smartirhub.android.utils.MyValidators.ButtonNameValidator import org.jetbrains.anko.sdk27.coroutines.onFocusChange -class PickNameSheet : SuperBottomSheetFragment() { +class PickNameSheet(context: Context) : BottomSheetDialog(context) { var binding: VChooseNameSheetBinding? = null + private var nameView: View = layoutInflater.inflate(R.layout.v_bottom_sheet, null) + var callback: Callback? = null var btnName = "" @@ -62,30 +60,19 @@ class PickNameSheet : SuperBottomSheetFragment() { binding?.txtInput?.hint = value } + var strList : ArrayList? = null - /* - ---------------------------------------------- - Overridden Functions - ---------------------------------------------- -*/ - - override fun getTheme() = R.style.AppTheme - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState.putStringArrayList(KEY_STR_LIST, arrayListOf(btnName, nameTitle, nameDesc, tipsTitle, tipsDesc1, tipsDesc2, tipsExampleTitle, nameInputHint)) + init { + binding = DataBindingUtil.bind(nameView) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - super.onCreateView(inflater, container, savedInstanceState) - binding = DataBindingUtil.inflate(inflater, R.layout.v_choose_name_sheet, container, false) - - val strList = savedInstanceState?.getStringArrayList(KEY_STR_LIST) + fun setup() { + setContentView(nameView) - binding!!.let { b -> - b.btnPickName.text = strList?.get(0) ?: if (btnName != "") btnName else getString(R.string.pick_name) - b.tvTitle.text = strList?.get(1) ?: if (nameTitle != "") nameTitle else getString(R.string.need_help_with_a_name) - b.tvHelpNameDesc.text = strList?.get(2) ?: if (nameDesc != "") nameDesc else getString(R.string.need_help_name_desc) + binding?.let { b -> + b.btnPickName.text = strList?.get(0) ?: if (btnName != "") btnName else context.getString(R.string.pick_name) + b.tvTitle.text = strList?.get(1) ?: if (nameTitle != "") nameTitle else context.getString(R.string.need_help_with_a_name) + b.tvHelpNameDesc.text = strList?.get(2) ?: if (nameDesc != "") nameDesc else context.getString(R.string.need_help_name_desc) b.tvTipsTitle.text = strList?.get(3) ?: tipsTitle b.tvTipsTitle.visibility = if (b.tvTipsTitle.text == "") View.GONE else View.VISIBLE b.tvTipsDesc1.text = strList?.get(4) ?: tipsDesc1 @@ -97,24 +84,24 @@ class PickNameSheet : SuperBottomSheetFragment() { b.txtInput.hint = strList?.get(6) ?: nameInputHint b.btnPickName.setOnClickListener { if (callback != null) callback?.onSavePressed(binding) else dismiss() } + + b.txtInput.editText!!.setUnderlineColor() + b.txtInput.editText!!.onFocusChange {v, _ -> v.setUnderlineColor() } } - return binding!!.root + setOnDismissListener { callback?.onDismiss() } } - override fun onStart() { - super.onStart() - val layoutParams = dialog!!.findViewById(R.id.super_bottom_sheet).layoutParams - layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT - dialog!!.findViewById(R.id.super_bottom_sheet).layoutParams = layoutParams - binding?.txtInput?.editText!!.setUnderlineColor() - binding?.txtInput?.editText!!.onFocusChange {v, _ -> - v.setUnderlineColor() - } - - //binding.txtInput.editText!!.inputType = (InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or InputType.TYPE_TEXT_VARIATION_PASSWORD ) + fun revertAnimation() { + binding?.btnPickName?.revertAnimation() } +/* + ---------------------------------------------- + Overridden Functions + ---------------------------------------------- +*/ + private fun View.setUnderlineColor() { val color = ContextCompat.getColor(context!!, R.color.colorControlNormalWhite) this.backgroundTintList = ColorStateList( @@ -129,35 +116,6 @@ class PickNameSheet : SuperBottomSheetFragment() { ) } - override fun onDismiss(dialog: DialogInterface) { - super.onDismiss(dialog) - callback?.onDismiss() - } - - override fun getBackgroundColor() = ContextCompat.getColor(context!!, R.color.colorCardDark) - - override fun animateCornerRadius() = true - - override fun animateStatusBar() = true - - override fun isSheetAlwaysExpanded() = true - -// override fun getPeekHeight(): Int { -// val displayMetrics = DisplayMetrics() -// displayMetrics.heightPixels = 0 -// context?.windowManager?.defaultDisplay?.getMetrics(displayMetrics) -// var height = displayMetrics.heightPixels -// height = if (height <= 0){ -// 500 -// } -// else { -// height - (height * .05).toInt() -// } -// -// @Suppress("UNNECESSARY_SAFE_CALL") -// return -// } - /* ---------------------------------------------- OnClick Functions @@ -166,7 +124,7 @@ class PickNameSheet : SuperBottomSheetFragment() { private fun checkName() { binding?.txtInput?.error = "" val isValidName = binding?.txtInput?.editText!!.text.toString().ButtonNameValidator() - .addErrorCallback { binding?.txtInput?.error = getString(R.string.err_invalid_button_name) } + .addErrorCallback { binding?.txtInput?.error = context.getString(R.string.err_invalid_button_name) } .check() if (isValidName) { AppState.tempData.tempButton?.name = binding?.txtInput?.editText!!.text.toString() diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/SimpleListDescSheet.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/SimpleListDescSheet.kt index 99c1383..3d0c658 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/SimpleListDescSheet.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/custom_views/bottom_sheets/SimpleListDescSheet.kt @@ -1,16 +1,12 @@ package com.ms8.smartirhub.android.custom_views.bottom_sheets -import android.os.Bundle -import android.view.LayoutInflater +import android.content.Context import android.view.View -import android.view.ViewGroup -import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.RecyclerView -import com.andrefrsousa.superbottomsheet.SuperBottomSheetFragment -import com.ms8.smartirhub.android.R +import com.google.android.material.bottomsheet.BottomSheetDialog import com.ms8.smartirhub.android.databinding.VSimpleListDescSheetBinding -open class SimpleListDescSheet : SuperBottomSheetFragment() { +open class SimpleListDescSheet(context: Context) : BottomSheetDialog(context) { var binding: VSimpleListDescSheetBinding? = null var hasSecondaryAction: Boolean = true @@ -47,35 +43,8 @@ open class SimpleListDescSheet : SuperBottomSheetFragment() { var callback: SimpleListDescSheetCallback? = null - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState.putStringArrayList(KEY_SHEET_STRS, arrayListOf(sheetTitle, helpTitle, helpDesc)) - outState.putBooleanArray(KEY_SHEET_BOOLS, BooleanArray(2).apply { - set(0, isSaveEnabled) - set(1, hasSecondaryAction) - }) - } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - super.onCreateView(inflater, container, savedInstanceState) - binding = DataBindingUtil.inflate(inflater, R.layout.v_simple_list_desc_sheet, container, false) - - // Restore state - savedInstanceState?.let { s -> - s.getBooleanArray(KEY_SHEET_BOOLS)?.let { - isSaveEnabled = it[0] - hasSecondaryAction = it[1] - } - s.getStringArrayList(KEY_SHEET_STRS)?.let { - sheetTitle = it[0] - helpTitle = it[1] - helpDesc = it[2] - } - } - - // Set up layout - binding!!.let { b -> + fun setup() { + binding?.let { b -> b.sheetList.adapter = callback?.getAdapter() b.sheetList.layoutManager = callback?.getLayoutManager() b.tvTitle.text = sheetTitle @@ -90,10 +59,9 @@ open class SimpleListDescSheet : SuperBottomSheetFragment() { b.btnSaveCommand.isEnabled = isSaveEnabled b.btnClearActions.isEnabled = hasSecondaryAction b.btnClearActions.visibility = if (hasSecondaryAction) View.VISIBLE else View.GONE - } - callback?.onCreateView(binding!!) - return binding!!.root + callback?.onCreateView(b) + } } interface SimpleListDescSheetCallback { diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSListenActivity.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSListenActivity.kt index b74ca36..c620df8 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSListenActivity.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSListenActivity.kt @@ -19,18 +19,18 @@ import com.google.firebase.database.ValueEventListener import com.ms8.smartirhub.android.R import com.ms8.smartirhub.android.custom_views.bottom_sheets.BottomErrorSheet import com.ms8.smartirhub.android.database.AppState -import com.ms8.smartirhub.android.models.realtimedatabase.HubResult -import com.ms8.smartirhub.android.models.firestore.IrSignal import com.ms8.smartirhub.android.databinding.ALearnSigListenBinding import com.ms8.smartirhub.android.firebase.FirebaseConstants import com.ms8.smartirhub.android.firebase.RealtimeDatabaseFunctions import com.ms8.smartirhub.android.learn_signal.LSWalkThroughActivity.Companion.LISTENING_HUB -import java.lang.Exception +import com.ms8.smartirhub.android.models.firestore.IrSignal +import com.ms8.smartirhub.android.models.realtimedatabase.HubResult class LSListenActivity : AppCompatActivity() { lateinit var binding: ALearnSigListenBinding lateinit var hubUID: String - val bottomErrorSheet = BottomErrorSheet() + lateinit var bottomErrorSheet : BottomErrorSheet + var isListeningForResult = false var isListeningForRawData = false @@ -219,18 +219,21 @@ class LSListenActivity : AppCompatActivity() { hubUID = intent.getStringExtra(LISTENING_HUB) ?: "" - bottomErrorSheet.sheetTitle = getString(R.string.err_hub_busy_title) - bottomErrorSheet.description = getString(R.string.err_hub_busy_desc) - binding = DataBindingUtil.setContentView(this, R.layout.a_learn_sig_listen) binding.btnShowAdvancedInfo.setOnClickListener { showAdvancedInfo() } binding.btnRetry.setOnClickListener { retry() } binding.btnTestSignal.setOnClickListener { testSignal() } + // set up toolbar setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) + // set up error BottomSheet + bottomErrorSheet = BottomErrorSheet(this, getString(R.string.err_hub_busy_title), getString(R.string.err_hub_busy_desc)) + bottomErrorSheet.setup() + + // find learning state val len = AppState.tempData.tempSignal?.rawLength ?: 0 Log.d("LEN", "$len") when { @@ -291,7 +294,7 @@ class LSListenActivity : AppCompatActivity() { val uid = FirebaseAuth.getInstance().currentUser?.uid if (sender != "_none_" && sender != uid) { binding.btnStartListening.revertAnimation() - if (!bottomErrorSheet.bIsShowing) { showHubBusyError() } + if (!bottomErrorSheet.isShowing) { showHubBusyError() } } else { sendListenAction() } @@ -385,36 +388,51 @@ class LSListenActivity : AppCompatActivity() { --------------------------------------------- */ private fun LSListenActivity.showUnknownError(e: Exception?) { + if (bottomErrorSheet.isShowing) + bottomErrorSheet.dismiss() + binding.btnTestSignal.revertAnimation() bottomErrorSheet.sheetTitle = getString(R.string.err_unknown_sig_title) bottomErrorSheet.description = getString(R.string.err_unknown_sig_desc) - bottomErrorSheet.show(supportFragmentManager, "Bottom_sheet_error_timeout") + bottomErrorSheet.show() e?.let { Log.e("LSListenActivity", "Unknown Error: $it") } - } private fun LSListenActivity.showNoResponseError() { + if (bottomErrorSheet.isShowing) + bottomErrorSheet.dismiss() + binding.btnStartListening.revertAnimation() + bottomErrorSheet.sheetTitle = getString(R.string.err_no_response_title) bottomErrorSheet.description = getString(R.string.err_no_response_desc) - bottomErrorSheet.show(supportFragmentManager, "Bottom_sheet_error_timeout") + bottomErrorSheet.show() } private fun LSListenActivity.showHubBusyError() { + if (bottomErrorSheet.isShowing) + bottomErrorSheet.dismiss() + binding.btnStartListening.revertAnimation() bottomErrorSheet.sheetTitle = getString(R.string.err_hub_busy_title) bottomErrorSheet.description = getString(R.string.err_hub_busy_desc) - bottomErrorSheet.show(supportFragmentManager, "Bottom_error_frag") + bottomErrorSheet.show() } private fun LSListenActivity.showOverflowError() { + if (bottomErrorSheet.isShowing) + bottomErrorSheet.dismiss() + binding.btnStartListening.revertAnimation() bottomErrorSheet.sheetTitle = getString(R.string.err_overflow_title) bottomErrorSheet.description = getString(R.string.err_overflow_desc) - bottomErrorSheet.show(supportFragmentManager, "Bottom_sheet_error_overflow") + bottomErrorSheet.show() } private fun LSListenActivity.showTimeoutError() { + if (bottomErrorSheet.isShowing) + bottomErrorSheet.dismiss() + binding.btnStartListening.revertAnimation() bottomErrorSheet.sheetTitle = getString(R.string.err_timeout_title) bottomErrorSheet.description = getString(R.string.err_timeout_desc) - bottomErrorSheet.show(supportFragmentManager, "Bottom_sheet_error_timeout") + bottomErrorSheet.show() } diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSNameSignalActivity.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSNameSignalActivity.kt index 7b5a146..2067f66 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSNameSignalActivity.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSNameSignalActivity.kt @@ -9,6 +9,7 @@ import android.util.Log import androidx.databinding.DataBindingUtil import com.ms8.smartirhub.android.R import com.ms8.smartirhub.android.custom_views.bottom_sheets.BottomErrorSheet +import com.ms8.smartirhub.android.custom_views.bottom_sheets.BottomSheet import com.ms8.smartirhub.android.database.AppState import com.ms8.smartirhub.android.databinding.ALearnSigNameBinding import com.ms8.smartirhub.android.firebase.FirestoreActions @@ -17,16 +18,25 @@ import com.ms8.smartirhub.android.utils.MyValidators.SignalNameValidator class LSNameSignalActivity : AppCompatActivity() { lateinit var binding : ALearnSigNameBinding - val errorSaveSheet = BottomErrorSheet() - val errorNameSheet = BottomErrorSheet() + lateinit var errorSaveSheet : BottomErrorSheet + lateinit var errorNameSheet : BottomErrorSheet override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - errorSaveSheet.sheetTitle = getString(R.string.err_uploading_signal_title) - errorSaveSheet.description = getString(R.string.err_uploading_signal_desc) - errorSaveSheet.setPositiveButton(getString(R.string.retry)) { uploadIrSignal() } - errorNameSheet.sheetTitle = getString(R.string.err_invalid_sig_name_title) - errorNameSheet.description = getString(R.string.err_invalid_sig_name_desc) + + // set up saving error BottomErrorSheet + errorSaveSheet = BottomErrorSheet(this, + getString(R.string.err_uploading_signal_title), + getString(R.string.err_uploading_signal_desc), + getString(R.string.retry)) + .apply { posListener = { uploadIrSignal() } } + errorSaveSheet.setup() + + // set up naming error BottomErrorSheet + errorNameSheet = BottomErrorSheet(this, + getString(R.string.err_invalid_sig_name_title), + getString(R.string.err_invalid_sig_name_desc)) + errorNameSheet.setup() binding = DataBindingUtil.setContentView(this, R.layout.a_learn_sig_name) binding.btnPickName.setOnClickListener { checkName() } @@ -36,6 +46,13 @@ class LSNameSignalActivity : AppCompatActivity() { supportActionBar?.setDisplayShowHomeEnabled(true) } + private fun hideErrorSheets() { + if (errorSaveSheet.isShowing) + errorSaveSheet.dismiss() + if (errorNameSheet.isShowing) + errorNameSheet.dismiss() + } + /* ---------------------------------------------- OnClick Functions @@ -43,7 +60,10 @@ class LSNameSignalActivity : AppCompatActivity() { */ private fun checkName() { val isValidName = binding.txtSignalName.editText!!.text.toString().SignalNameValidator() - .addErrorCallback { errorNameSheet.show(supportFragmentManager, "bottom_sheet_error_invalid_name") } + .addErrorCallback { + hideErrorSheets() + errorNameSheet.show() + } .check() if (isValidName) { AppState.tempData.tempSignal!!.name = binding.txtSignalName.editText!!.text.toString() @@ -66,7 +86,8 @@ class LSNameSignalActivity : AppCompatActivity() { } .addOnFailureListener { Log.e("LSNameSignalActivity", "AddIrSignal listener error: $it") - errorSaveSheet.show(supportFragmentManager, "bottom_error_sheet_ir_upload") + hideErrorSheets() + errorSaveSheet.show() } .addOnSuccessListener { setResult(Activity.RESULT_OK, Intent().putExtra(NEW_IR_SIGNAL_UID, AppState.tempData.tempSignal?.uid)) diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSWalkthroughActivity.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSWalkthroughActivity.kt index 3854e82..f18db3d 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSWalkthroughActivity.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/learn_signal/LSWalkthroughActivity.kt @@ -26,10 +26,10 @@ import com.ms8.smartirhub.android.utils.MyValidators.SignalNameValidator class LSWalkThroughActivity : AppCompatActivity() { lateinit var binding : ACreateButtonWalkthroughBinding - private val warningSheet: BackWarningSheet = BackWarningSheet() + private lateinit var warningSheet : BottomSheet /* Pick Name Bottom Sheet */ - private val nameSheet: PickNameSheet = PickNameSheet() + private val nameSheet: PickNameSheet = PickNameSheet(this) private val nameSheetCallback = object: PickNameSheet.Callback { override fun onSavePressed(sheetBinding: VChooseNameSheetBinding?) { sheetBinding?.txtInput?.error = "" @@ -49,10 +49,10 @@ class LSWalkThroughActivity : AppCompatActivity() { } /* Pick Listening Hub Bottom Sheet */ - private val pickHubSheet = HubSheet() + private val pickHubSheet = HubSheet(this) /* Listen for Signal Bottom Sheet */ - private val listenSignalSheet = LearnSignalSheet() + private val listenSignalSheet = LearnSignalSheet(this) private val listenSignalSheetCallback = object : LearnSignalSheet.Callback { override fun onSaveSignal() { determineWalkThroughState() } } @@ -69,17 +69,17 @@ class LSWalkThroughActivity : AppCompatActivity() { override fun onBackPressed() { when { - nameSheet.isVisible -> { + nameSheet.isShowing -> { nameSheet.dismiss() } - pickHubSheet.isVisible -> { + pickHubSheet.isShowing -> { pickHubSheet.dismiss() } - listenSignalSheet.onBackPressed() -> {} + listenSignalSheet.performBack() -> {} binding.prog1.bOnThisStep -> { when { warningSheet.bWantsToLeave -> super.onBackPressed() - !warningSheet.bIsShowing -> warningSheet.show(supportFragmentManager, "WarningBottomSheet") + !warningSheet.bIsShowing -> warningSheet.show() } } binding.prog2.bOnThisStep -> { @@ -111,6 +111,18 @@ class LSWalkThroughActivity : AppCompatActivity() { //Restore state savedInstanceState?.getString(LISTENING_HUB)?.let { listeningHub = it } + // set up warning sheet + warningSheet = BottomSheet(this, + getString(R.string.exit_app_title), + getString(R.string.exit_app_desc), + getString(R.string.leave), + getString(android.R.string.cancel), + { finishAndRemoveTask() }) + warningSheet.setup() + + // setup nameSheet + nameSheet.setup() + //Set up pickHubSheet pickHubSheet.sheetTitle = this@LSWalkThroughActivity.getString(R.string.hubs) pickHubSheet.helpTitle = this@LSWalkThroughActivity.getString(R.string.dont_see_hub_title) @@ -169,6 +181,8 @@ class LSWalkThroughActivity : AppCompatActivity() { //Set up listenSignalSheet + listenSignalSheet.setup() + listenSignalSheet.hubUID = listeningHub listenSignalSheet.callback = listenSignalSheetCallback //Set up toolbar @@ -186,6 +200,7 @@ class LSWalkThroughActivity : AppCompatActivity() { super.onResume() clicked = false determineWalkThroughState() + pickHubSheet.onResume() } // override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -259,25 +274,25 @@ class LSWalkThroughActivity : AppCompatActivity() { */ private fun showLearnSignalSheet() { - if (!listenSignalSheet.isVisible) - listenSignalSheet.show(supportFragmentManager, "ListeningSignalSheet") + if (!listenSignalSheet.isShowing) + listenSignalSheet.show() } private fun showPickHubSheet() { - if (!pickHubSheet.isVisible) - pickHubSheet.show(supportFragmentManager, "ListeningHubSheet") + if (!pickHubSheet.isShowing) + pickHubSheet.show() } private fun showNameSheet() { - if (!nameSheet.isVisible) - nameSheet.show(supportFragmentManager, "SignalNameSheet") + if (!nameSheet.isShowing) + nameSheet.show() } @SuppressLint("LogNotTimber") private fun uploadIrSignal() { FirestoreActions.addIrSignal() .addOnCompleteListener { - nameSheet.binding?.btnPickName?.revertAnimation() + nameSheet.revertAnimation() } .addOnFailureListener { Log.e("LSNameSignalActivity", "AddIrSignal listener error: $it") diff --git a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/main_view/MainViewActivity.kt b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/main_view/MainViewActivity.kt index 08a7d23..e86c5ee 100644 --- a/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/main_view/MainViewActivity.kt +++ b/android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/main_view/MainViewActivity.kt @@ -3,48 +3,46 @@ package com.ms8.smartirhub.android.main_view import android.annotation.SuppressLint import android.content.Context import android.content.Intent -import android.graphics.Color -import android.inputmethodservice.InputMethodService import android.os.Bundle import android.os.Parcel import android.os.Parcelable -import android.text.Spannable -import android.text.SpannableString -import android.text.style.ForegroundColorSpan import android.util.Log -import android.view.* +import android.util.TypedValue +import android.view.Gravity +import android.view.Surface +import android.view.View +import android.view.WindowManager +import android.view.animation.AccelerateInterpolator +import android.view.animation.DecelerateInterpolator +import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.content.ContextCompat import androidx.databinding.DataBindingUtil import androidx.databinding.ObservableMap import androidx.fragment.app.FragmentPagerAdapter import androidx.viewpager.widget.ViewPager +import com.andrognito.flashbar.Flashbar +import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.firebase.auth.FirebaseAuth import com.mikepenz.materialdrawer.AccountHeaderBuilder import com.mikepenz.materialdrawer.Drawer import com.mikepenz.materialdrawer.DrawerBuilder import com.mikepenz.materialdrawer.model.ProfileDrawerItem import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem -import com.ms8.smartirhub.android.custom_views.bottom_sheets.BackWarningSheet -import com.ms8.smartirhub.android.custom_views.bottom_sheets.RemoteTemplatesSheet -import com.ms8.smartirhub.android.remote_control.models.RemoteProfile +import com.ms8.smartirhub.android.R +import com.ms8.smartirhub.android.custom_views.bottom_sheets.BottomSheet +import com.ms8.smartirhub.android.database.AppState import com.ms8.smartirhub.android.databinding.ActivityMainViewBinding -import com.ms8.smartirhub.android.utils.extensions.getNavBarHeight +import com.ms8.smartirhub.android.databinding.VCreateRemoteFromBinding import com.ms8.smartirhub.android.firebase.FirestoreActions import com.ms8.smartirhub.android.learn_signal.LSWalkThroughActivity import com.ms8.smartirhub.android.main_view.fragments.* import com.ms8.smartirhub.android.remote_control.RemoteFragment -import com.ms8.smartirhub.android.utils.extensions.findNavBarHeight -import android.util.TypedValue -import android.view.animation.AccelerateInterpolator -import android.view.animation.DecelerateInterpolator -import android.view.inputmethod.InputMethodManager -import androidx.core.content.ContextCompat -import com.google.android.material.bottomsheet.BottomSheetDialog -import com.ms8.smartirhub.android.R -import com.ms8.smartirhub.android.database.AppState -import com.ms8.smartirhub.android.databinding.VCreateRemoteFromBinding +import com.ms8.smartirhub.android.remote_control.models.RemoteProfile import com.ms8.smartirhub.android.remote_control.views.asymmetric_gridview.Utils +import com.ms8.smartirhub.android.utils.extensions.findNavBarHeight +import com.ms8.smartirhub.android.utils.extensions.getNavBarHeight class MainViewActivity : AppCompatActivity() { @@ -54,7 +52,7 @@ class MainViewActivity : AppCompatActivity() { private lateinit var pagerAdapter: MainViewAdapter private val remoteFragment = RemoteFragment() - private val exitWarningSheet = BackWarningSheet() + private lateinit var exitWarningSheet : BottomSheet private var createRemoteFromBinding : VCreateRemoteFromBinding? = null private var createRemoteDialog : BottomSheetDialog? = null @@ -83,7 +81,7 @@ class MainViewActivity : AppCompatActivity() { // check remoteTemplateSheet state //remoteTemplatesSheet.onBackPressed() -> {} // show exit warning before leaving - !exitWarningSheet.isVisible -> { exitWarningSheet.show(supportFragmentManager, "ExitWarningSheet") } + !exitWarningSheet.isShowing -> { exitWarningSheet.show() } // proceed with normal onBackPressed else -> { super.onBackPressed() } } @@ -99,18 +97,13 @@ class MainViewActivity : AppCompatActivity() { binding = DataBindingUtil.setContentView(this, R.layout.activity_main_view) // setup exit warning sheet - exitWarningSheet - .apply { - titleStr = this@MainViewActivity.getString(R.string.exit_app_title) - descStr = this@MainViewActivity.getString(R.string.exit_app_desc) - btnNegStr = this@MainViewActivity.getString(android.R.string.cancel) - btnPosStr = this@MainViewActivity.getString(R.string.leave) - callback = object : BackWarningSheet.BackWaringSheetCallback { - override fun btnNegAction() {} - - override fun btnPosAction() { finishAndRemoveTask() } - } - } + exitWarningSheet = BottomSheet(this, + this@MainViewActivity.getString(R.string.exit_app_title), + this@MainViewActivity.getString(R.string.exit_app_desc), + this@MainViewActivity.getString(R.string.leave), + this@MainViewActivity.getString(android.R.string.cancel), + { finishAndRemoveTask() }) + exitWarningSheet.setup() // build drawer header layout val header = AccountHeaderBuilder() @@ -508,14 +501,22 @@ class MainViewActivity : AppCompatActivity() { private fun createRemote(forceShow : Boolean = false) { FirestoreActions.getRemoteTemplates() if (!state.isShowingCreateRemoteFromView || forceShow) { + + // set up bottom sheet dialog val createRemoteView = layoutInflater.inflate(R.layout.v_create_remote_from, null) createRemoteDialog = BottomSheetDialog(this) createRemoteFromBinding = DataBindingUtil.bind(createRemoteView) createRemoteDialog?.setContentView(createRemoteView) - createRemoteDialog?.setOnDismissListener { - state.isShowingCreateRemoteFromView = false } + createRemoteDialog?.setOnDismissListener { state.isShowingCreateRemoteFromView = false } + // set up onClick listeners (device template, existing remote, blank layout) createRemoteFromBinding?.tvFromScratch?.setOnClickListener { createBlankRemote() } + createRemoteFromBinding?.tvFromDeviceTemplate?.setOnClickListener { createFromDeviceTemplate() } + createRemoteFromBinding?.tvFromExistingRemote?.setOnClickListener { createFromExistingRemote() } + + // Hide "From Existing Remote" if user doesn't have any + if (AppState.userData.remotes.size == 0) + createRemoteFromBinding?.tvFromExistingRemote?.visibility = View.GONE createRemoteDialog?.show() state.isShowingCreateRemoteFromView = true @@ -524,6 +525,22 @@ class MainViewActivity : AppCompatActivity() { //remoteTemplatesSheet.show(supportFragmentManager, "RemoteTemplateSheet") } + /* -------- Create Remote Functions -------- */ + + private fun createFromExistingRemote() { + createRemoteDialog?.dismiss() + + createRemoteDialog = BottomSheetDialog(this) + + + debug_showComingSoonFlashbar() + } + + private fun createFromDeviceTemplate() { + createRemoteDialog?.dismiss() + debug_showComingSoonFlashbar() + } + private fun createBlankRemote() { // dismiss "create from" dialog createRemoteDialog?.dismiss() @@ -544,6 +561,8 @@ class MainViewActivity : AppCompatActivity() { binding.toolbar.selectTitleText() } + + private fun createCommand() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } @@ -560,6 +579,21 @@ class MainViewActivity : AppCompatActivity() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } + /* -------- DEBUG FUNCTIONS -------- */ + + fun debug_showComingSoonFlashbar() { + Flashbar.Builder(this) + .gravity(Flashbar.Gravity.BOTTOM) + .message("Feature coming soon!") + .showOverlay() + .enableSwipeToDismiss() + .dismissOnTapOutside() + .duration(Flashbar.DURATION_SHORT) + .build() + .show() + } + + companion object { const val REQ_NEW_IR_SIG = 2 const val STATE = "MAIN_STATE" diff --git a/android/SmartIRHub/app/src/main/res/layout/v_remote_templates_sheet.xml b/android/SmartIRHub/app/src/main/res/layout/v_remote_templates_sheet.xml deleted file mode 100644 index 5e49850..0000000 --- a/android/SmartIRHub/app/src/main/res/layout/v_remote_templates_sheet.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - -