diff --git a/app/build.gradle b/app/build.gradle index c958fce0e..acfd3fa21 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' def appVersionCode = (System.env.GITHUB_RUN_NUMBER ? Integer.valueOf(System.env.GITHUB_RUN_NUMBER) : 2) + 6050 def appVersionName = (System.env.GITHUB_RUN_NUMBER ? Integer.valueOf(System.env.GITHUB_RUN_NUMBER) + 6050: "1.0.0") + "" diff --git a/app/src/main/kotlin/io/treehouses/remote/fragments/DiscoverFragment.kt b/app/src/main/kotlin/io/treehouses/remote/fragments/DiscoverFragment.kt index d0b366a63..7961e5067 100644 --- a/app/src/main/kotlin/io/treehouses/remote/fragments/DiscoverFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/fragments/DiscoverFragment.kt @@ -15,14 +15,13 @@ import android.widget.ImageView import android.widget.LinearLayout import com.parse.Parse.getApplicationContext import io.treehouses.remote.Constants -import io.treehouses.remote.fragments.dialogfragments.RPIDialogFragment -import io.treehouses.remote.interfaces.FragmentDialogInterface import io.treehouses.remote.R import io.treehouses.remote.bases.BaseFragment import io.treehouses.remote.databinding.ActivityDiscoverFragmentBinding +import io.treehouses.remote.fragments.dialogfragments.RPIDialogFragment +import io.treehouses.remote.interfaces.FragmentDialogInterface import io.treehouses.remote.utils.logD import io.treehouses.remote.utils.logE -import kotlinx.android.synthetic.main.activity_discover_fragment.view.* import kotlin.math.PI import kotlin.math.cos import kotlin.math.sin @@ -124,7 +123,7 @@ class DiscoverFragment : BaseFragment(), FragmentDialogInterface { } private fun updateGatewayIcon() { - val gatewayIcon = bind.gatewayContainer.gateway_icon + val gatewayIcon = bind.gatewayIcon bind.gatewayContainer.removeView(gatewayIcon) diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/network/NetworkFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/network/NetworkFragment.kt index f0e49b5ff..3c0c8effe 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/network/NetworkFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/network/NetworkFragment.kt @@ -20,6 +20,7 @@ import io.treehouses.remote.R import io.treehouses.remote.Tutorials import io.treehouses.remote.bases.BaseFragment import io.treehouses.remote.databinding.ActivityNetworkFragmentBinding +import io.treehouses.remote.databinding.DialogSpeedtestBinding import io.treehouses.remote.fragments.DiscoverFragment import io.treehouses.remote.fragments.dialogfragments.WifiDialogFragment import io.treehouses.remote.interfaces.FragmentDialogInterface @@ -29,7 +30,6 @@ import io.treehouses.remote.ui.network.bottomsheetdialogs.EthernetBottomSheet import io.treehouses.remote.ui.network.bottomsheetdialogs.HotspotBottomSheet import io.treehouses.remote.ui.network.bottomsheetdialogs.WifiBottomSheet import io.treehouses.remote.utils.Utils -import kotlinx.android.synthetic.main.dialog_speedtest.* open class NetworkFragment : BaseFragment(), View.OnClickListener, FragmentDialogInterface { private lateinit var binding: ActivityNetworkFragmentBinding private lateinit var speedDialog: Dialog @@ -37,6 +37,7 @@ open class NetworkFragment : BaseFragment(), View.OnClickListener, FragmentDialo private lateinit var speedDialogTest: Button private var speedDialogCheck: Boolean = false protected val viewModel: NetworkViewModel by viewModels(ownerProducer = { this }) + lateinit var dialogSpeedtestBinding: DialogSpeedtestBinding override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = ActivityNetworkFragmentBinding.inflate(inflater, container, false) loadObservers() @@ -94,8 +95,8 @@ open class NetworkFragment : BaseFragment(), View.OnClickListener, FragmentDialo binding.speedTest == v -> speedTest() binding.reverseLookup == v -> reverseLookup() binding.discoverBtn == v -> listener.openCallFragment(DiscoverFragment()) - speedDialog.speedBtnTest == v -> viewModel.treehousesInternet() - speedDialog.speedBtnDismiss == v -> speedDialog.dismiss() + dialogSpeedtestBinding.speedBtnTest == v -> viewModel.treehousesInternet() + dialogSpeedtestBinding.speedBtnDismiss == v -> speedDialog.dismiss() } } @@ -130,11 +131,12 @@ open class NetworkFragment : BaseFragment(), View.OnClickListener, FragmentDialo private fun initializeSpeedDialog() { speedDialog = Dialog(requireContext()) - speedDialog.setContentView(R.layout.dialog_speedtest) + dialogSpeedtestBinding = DialogSpeedtestBinding.inflate(layoutInflater) + speedDialog.setContentView(dialogSpeedtestBinding.root) speedDialogDismiss = speedDialog.findViewById(R.id.speedBtnDismiss); speedDialogTest = speedDialog.findViewById(R.id.speedBtnTest) speedDialogDismiss.setOnClickListener(this); speedDialogTest.setOnClickListener(this) viewModel.downloadUpload.observe(viewLifecycleOwner, Observer { - speedDialog.speed_text.text = it + dialogSpeedtestBinding.speedText.text = it }) viewModel.dialogCheck.observe(viewLifecycleOwner, Observer { speedDialogCheck = it diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt index ea394d72a..5e0df68f9 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt @@ -15,14 +15,16 @@ import io.treehouses.remote.Constants import io.treehouses.remote.R import io.treehouses.remote.Tutorials import io.treehouses.remote.databinding.ActivityTunnelSshFragmentBinding +import io.treehouses.remote.databinding.DialogSshtunnelHostsBinding +import io.treehouses.remote.databinding.DialogSshtunnelKeyBinding +import io.treehouses.remote.databinding.DialogSshtunnelPortsBinding import io.treehouses.remote.pojo.enum.Status import io.treehouses.remote.utils.* -import kotlinx.android.synthetic.main.dialog_sshtunnel_hosts.* -import kotlinx.android.synthetic.main.dialog_sshtunnel_key.* -import kotlinx.android.synthetic.main.dialog_sshtunnel_ports.* class SSHTunnelFragment : BaseSSHTunnelFragment() { - + lateinit var dialogSshTunnelPortsBinding: DialogSshtunnelPortsBinding + lateinit var dialogSshTunnelKeyBinding: DialogSshtunnelKeyBinding + lateinit var dialogSshTunnelHostsBinding: DialogSshtunnelHostsBinding @RequiresApi(Build.VERSION_CODES.N) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -45,7 +47,7 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { handlePhoneKeySave(it.data) if (it.data!!.showHandlePiKeySaveDialog) handlePiKeySave(it.data.profile, it.data.storedPublicKey, it.data.storedPrivateKey) - } + } else -> {} } }) } @@ -76,32 +78,32 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { val dialog = builder.create(); dialog.window!!.setBackgroundDrawableResource(android.R.color.transparent); dialog.show(); } - dialogPort.btn_adding_port.setOnClickListener { handleAddPort() } - dialogHosts.btn_adding_host.setOnClickListener { - val m1 = dialogHosts.PortNumberInput.text.toString() - val m2 = dialogHosts.UserNameInput.text.toString() + "@" + dialogHosts.DomainIPInput.text.toString() + dialogSshTunnelPortsBinding.btnAddingPort.setOnClickListener { handleAddPort() } + dialogSshTunnelHostsBinding.btnAddingHost.setOnClickListener { + val m1 = dialogSshTunnelHostsBinding.PortNumberInput.text.toString() + val m2 = dialogSshTunnelHostsBinding.UserNameInput.text.toString() + "@" + dialogSshTunnelHostsBinding.DomainIPInput.text.toString() viewModel.addingHostButton(m1, m2) dialogHosts.dismiss() } } private fun handleAddPort() { - if (dialogPort.ExternalTextInput.text!!.isNotEmpty() && dialogPort.InternalTextInput.text!!.isNotEmpty()) { - val parts = dialogPort.hosts?.selectedItem.toString().split(":")[0] - viewModel.addingPortButton(dialogPort.InternalTextInput.text.toString(), dialogPort.ExternalTextInput.text.toString(), parts) + if (dialogSshTunnelPortsBinding.ExternalTextInput.text!!.isNotEmpty() && dialogSshTunnelPortsBinding.InternalTextInput.text!!.isNotEmpty()) { + val parts = dialogSshTunnelPortsBinding.hosts?.selectedItem.toString().split(":")[0] + viewModel.addingPortButton(dialogSshTunnelPortsBinding.InternalTextInput.text.toString(), dialogSshTunnelPortsBinding.ExternalTextInput.text.toString(), parts) dialogPort.dismiss() } } private fun addListeners2() { - var profile = dialogKeys.findViewById(R.id.sshtunnel_profile).text.toString() - dialogKeys.btn_save_keys.setOnClickListener { viewModel.keyClickListener(profile); } - dialogKeys.btn_show_keys.setOnClickListener { + val profile = dialogKeys.findViewById(R.id.sshtunnel_profile).text.toString() + dialogSshTunnelKeyBinding.btnSaveKeys.setOnClickListener { viewModel.keyClickListener(profile); } + dialogSshTunnelKeyBinding.btnShowKeys.setOnClickListener { viewModel.keyClickListener(profile); viewModel.handleShowKeys(profile) } - dialogPort.addPortCloseButton.setOnClickListener { dialogPort.dismiss() } - dialogHosts.addHostCloseButton.setOnClickListener { dialogHosts.dismiss() } - dialogKeys.addKeyCloseButton.setOnClickListener { dialogKeys.dismiss() } + dialogSshTunnelPortsBinding.addPortCloseButton.setOnClickListener { dialogPort.dismiss() } + dialogSshTunnelHostsBinding.addHostCloseButton.setOnClickListener { dialogHosts.dismiss() } + dialogSshTunnelKeyBinding.addKeyCloseButton.setOnClickListener { dialogKeys.dismiss() } bind.sshPorts.onItemClickListener = AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, position: Int, _: Long -> handleDeletePort(position) } @@ -133,32 +135,41 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { bind.switchNotification.isEnabled = it.data.enableSwitchNotification; bind.btnAddHosts.text = it.data.addHostText bind.btnAddPort.text = it.data.addPortText; bind.btnAddPort.isEnabled = it.data.enableAddPort bind.btnAddHosts.isEnabled = it.data.enableAddHost; bind.sshPorts.isEnabled = it.data.enableSSHPort - dialogKeys.public_key.text = it.data.publicKey; dialogKeys.private_key.text = it.data.privateKey - dialogKeys.progress_bar.visibility = View.GONE + dialogSshTunnelKeyBinding.publicKey.text = it.data.publicKey; dialogSshTunnelKeyBinding.privateKey.text = it.data.privateKey + dialogSshTunnelKeyBinding.progressBar.visibility = View.GONE portsName = it.data.portNames; hostsName = it.data.hostNames adapter = TunnelUtils.getPortAdapter(requireContext(), portsName) bind.sshPorts.adapter = adapter adapter2 = ArrayAdapter(requireContext(), R.layout.support_simple_spinner_dropdown_item, hostsName!!) - dialogPort.hosts.adapter = adapter2 + dialogSshTunnelPortsBinding.hosts.adapter = adapter2 } Status.LOADING -> { if (it == null) return@Observer - dialogKeys.progress_bar.visibility = View.VISIBLE - } + dialogSshTunnelKeyBinding.progressBar.visibility = View.VISIBLE + } else -> {} } }) } @RequiresApi(Build.VERSION_CODES.N) private fun initializeDialog() { - dialogPort = Dialog(requireContext()); dialogHosts = Dialog(requireContext()); dialogKeys = Dialog(requireContext()) - dialogPort.setContentView(R.layout.dialog_sshtunnel_ports); dialogHosts.setContentView(R.layout.dialog_sshtunnel_hosts) - dialogKeys.setContentView(R.layout.dialog_sshtunnel_key) - addHostSyntaxCheck(dialogHosts.UserNameInput, dialogHosts.TLusername, Constants.userRegex, Constants.hostError) - addHostSyntaxCheck(dialogHosts.DomainIPInput, dialogHosts.TLdomain, Constants.domainRegex + "|" + Constants.ipRegex, Constants.domainIPError) - addHostSyntaxCheck(dialogHosts.PortNumberInput, dialogHosts.TLportname, Constants.portRegex, Constants.portError) - addPortSyntaxCheck(dialogPort.ExternalTextInput, dialogPort.TLexternal) - addPortSyntaxCheck(dialogPort.InternalTextInput, dialogPort.TLinternal) + dialogPort = Dialog(requireContext()) + dialogSshTunnelPortsBinding = DialogSshtunnelPortsBinding.inflate(layoutInflater) + dialogPort.setContentView(dialogSshTunnelPortsBinding.root) + + dialogHosts = Dialog(requireContext()) + dialogSshTunnelHostsBinding = DialogSshtunnelHostsBinding.inflate(layoutInflater) + dialogHosts.setContentView(dialogSshTunnelHostsBinding.root) + + dialogKeys = Dialog(requireContext()) + dialogSshTunnelKeyBinding = DialogSshtunnelKeyBinding.inflate(layoutInflater) + dialogKeys.setContentView(dialogSshTunnelKeyBinding.root) + + addHostSyntaxCheck(dialogSshTunnelHostsBinding.UserNameInput, dialogSshTunnelHostsBinding.TLusername, Constants.userRegex, Constants.hostError) + addHostSyntaxCheck(dialogSshTunnelHostsBinding.DomainIPInput, dialogSshTunnelHostsBinding.TLdomain, Constants.domainRegex + "|" + Constants.ipRegex, Constants.domainIPError) + addHostSyntaxCheck(dialogSshTunnelHostsBinding.PortNumberInput, dialogSshTunnelHostsBinding.TLportname, Constants.portRegex, Constants.portError) + addPortSyntaxCheck(dialogSshTunnelPortsBinding.ExternalTextInput, dialogSshTunnelPortsBinding.TLexternal) + addPortSyntaxCheck(dialogSshTunnelPortsBinding.InternalTextInput, dialogSshTunnelPortsBinding.TLinternal) viewModel.initializeArrays() val window = dialogPort.window; val windowHost = dialogHosts.window @@ -176,17 +187,17 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { // } fun checkAddingHostButtonEnable() { - if (dialogHosts.UserNameInput.editableText.isNotEmpty() && dialogHosts.DomainIPInput.editableText.isNotEmpty() - && dialogHosts.PortNumberInput.editableText.isNotEmpty()) - if (!dialogHosts.TLusername.isErrorEnabled && !dialogHosts.TLdomain.isErrorEnabled && !dialogHosts.TLportname.isErrorEnabled) - dialogHosts.btn_adding_host.isEnabled = true + if (dialogSshTunnelHostsBinding.UserNameInput.editableText.isNotEmpty() && dialogSshTunnelHostsBinding.DomainIPInput.editableText.isNotEmpty() + && dialogSshTunnelHostsBinding.PortNumberInput.editableText.isNotEmpty()) + if (!dialogSshTunnelHostsBinding.TLusername.isErrorEnabled && !dialogSshTunnelHostsBinding.TLdomain.isErrorEnabled && !dialogSshTunnelHostsBinding.TLportname.isErrorEnabled) + dialogSshTunnelHostsBinding.btnAddingHost.isEnabled = true } fun checkAddingPortButtonEnable() { - if (dialogPort.ExternalTextInput.editableText.isNotEmpty() && dialogPort.InternalTextInput.editableText.isNotEmpty()) - if (!dialogPort.TLexternal.isErrorEnabled && !dialogPort.TLinternal.isErrorEnabled) - dialogPort.btn_adding_port.isEnabled = true + if (dialogSshTunnelPortsBinding.ExternalTextInput.editableText.isNotEmpty() && dialogSshTunnelPortsBinding.InternalTextInput.editableText.isNotEmpty()) + if (!dialogSshTunnelPortsBinding.TLexternal.isErrorEnabled && !dialogSshTunnelPortsBinding.TLinternal.isErrorEnabled) + dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = true } /* @@ -198,10 +209,10 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { override fun afterTextChanged(s: Editable?) { textInputLayout.isErrorEnabled = true if (s!!.isEmpty()) { - dialogHosts.btn_adding_host.isEnabled = false + dialogSshTunnelHostsBinding.btnAddingHost.isEnabled = false } else { if (!s!!.toString().matches(regex.toRegex())) { - dialogHosts.btn_adding_host.isEnabled = false + dialogSshTunnelHostsBinding.btnAddingHost.isEnabled = false textInputLayout.error = error } else { textInputLayout.isErrorEnabled = false @@ -220,14 +231,14 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { override fun afterTextChanged(s: Editable?) { textInputLayout.isErrorEnabled = true if (s!!.isEmpty()) { - dialogPort.btn_adding_port.isEnabled = false + dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = false } else { if (!s!!.toString().matches(Constants.portRegex.toRegex())) { - dialogPort.btn_adding_port.isEnabled = false + dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = false textInputLayout.error = Constants.portError - } else if (textInputEditText == dialogPort.ExternalTextInput && viewModel.searchArray(portsName, s!!.toString())) { - dialogPort.btn_adding_port.isEnabled = false - dialogPort.TLexternal.error = "Port number already exists" + } else if (textInputEditText == dialogSshTunnelPortsBinding.ExternalTextInput && viewModel.searchArray(portsName, s!!.toString())) { + dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = false + dialogSshTunnelPortsBinding.TLexternal.error = "Port number already exists" } else { textInputLayout.isErrorEnabled = false checkAddingPortButtonEnable() diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/status/StatusFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/status/StatusFragment.kt index 5e1daae35..62bb4786a 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/status/StatusFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/status/StatusFragment.kt @@ -3,7 +3,6 @@ package io.treehouses.remote.ui.status import android.animation.ObjectAnimator import android.app.Dialog import android.content.Context -import android.content.DialogInterface import android.os.Bundle import android.text.TextUtils import android.view.LayoutInflater @@ -20,10 +19,10 @@ import io.treehouses.remote.bases.BaseFragment import io.treehouses.remote.callback.NotificationCallback import io.treehouses.remote.databinding.ActivityStatusFragmentBinding import io.treehouses.remote.databinding.DialogRenameStatusBinding +import io.treehouses.remote.databinding.DialogWificountryBinding +import io.treehouses.remote.interfaces.FragmentDialogInterface import io.treehouses.remote.utils.DialogUtils import io.treehouses.remote.utils.Utils -import io.treehouses.remote.interfaces.FragmentDialogInterface -import kotlinx.android.synthetic.main.dialog_wificountry.* class StatusFragment : BaseFragment(), FragmentDialogInterface { @@ -46,9 +45,10 @@ class StatusFragment : BaseFragment(), FragmentDialogInterface { private fun wifiCountry(adapter: ArrayAdapter) { val dialog = Dialog(requireContext()) - dialog.setContentView(R.layout.dialog_wificountry) - dialog.countries - countryList = dialog.countries + val dialogWifiCountryBinding = DialogWificountryBinding.inflate(layoutInflater) + dialog.setContentView(dialogWifiCountryBinding.root) + dialogWifiCountryBinding.countries + countryList = dialogWifiCountryBinding.countries adapter.filter.filter("") countryList?.adapter = adapter countryList?.isTextFilterEnabled = true @@ -57,10 +57,9 @@ class StatusFragment : BaseFragment(), FragmentDialogInterface { dialog.dismiss() } - searchView(dialog) + searchView(dialogWifiCountryBinding) dialog.show() } - private fun showBar(mutableData: MutableLiveData, barView: ProgressBar) { mutableData.observe(viewLifecycleOwner, Observer { ObjectAnimator.ofInt(barView, "progress", it).setDuration(600).start() @@ -157,8 +156,8 @@ class StatusFragment : BaseFragment(), FragmentDialogInterface { } - private fun searchView(dialog: Dialog) { - val searchView = dialog.search_bar + private fun searchView(dialogWifiCountryBinding: DialogWificountryBinding) { + val searchView = dialogWifiCountryBinding.searchBar searchView.isIconifiedByDefault = false searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { diff --git a/build.gradle b/build.gradle index ba2b7f846..79526f9c0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.21' + ext.kotlin_version = '1.9.22' repositories { jcenter() google()