-
Notifications
You must be signed in to change notification settings - Fork 818
Add MQTT dependencies, settings UI, and test coverage (CATROID-1670, CATROID-1672) #5220
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
Open
Paras-ydv
wants to merge
10
commits into
Catrobat:develop
Choose a base branch
from
Paras-ydv:mqtt-settings-entry-task-tdd
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+538
−3
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f49480
test: add MQTT settings tests (defaults, persistence, validation)
Paras-ydv 3ce2096
feat: add MQTT settings constants and accessor methods
Paras-ydv 638bd54
feat: add MQTT settings fragment with port validation logic
Paras-ydv 4995ba8
feat: add MQTT settings UI resources and preferences
Paras-ydv 222dd13
feat: integrate MQTT settings screen into SettingsFragment navigation
Paras-ydv cc34243
test: add UI test for MQTT settings entry
Paras-ydv ad8a53e
CATROID-1670 Add Eclipse Paho MQTT dependencies and Android config
Paras-ydv ddc7440
CATROID-1672 Fix: address static analysis warnings
Paras-ydv 3eb0c8d
CATROID-1670, CATROID-1672 Fix: remove unused MQTT android service an…
Paras-ydv a066366
CATROID-1670 fix checkstyle blank lines and move default MQTT host to…
Paras-ydv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
catroid/src/main/java/org/catrobat/catroid/ui/settingsfragments/MqttSettingsFragment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Catroid: An on-device visual programming system for Android devices | ||
| * Copyright (C) 2010-2026 The Catrobat Team | ||
| * (<http://developer.catrobat.org/credits>) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * An additional term exception under section 7 of the GNU Affero | ||
| * General Public License, version 3, is available at | ||
| * http://developer.catrobat.org/license_additional_term | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.catrobat.catroid.ui.settingsfragments | ||
|
|
||
| import android.os.Bundle | ||
| import android.preference.CheckBoxPreference | ||
| import android.preference.EditTextPreference | ||
| import android.preference.Preference | ||
| import android.preference.PreferenceCategory | ||
| import android.preference.PreferenceFragment | ||
| import android.widget.Toast | ||
| import androidx.annotation.VisibleForTesting | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import org.catrobat.catroid.R | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.MQTT_CONNECTION_SETTINGS_CATEGORY | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.MQTT_CLIENT_ID | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.MQTT_HOST | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.MQTT_PASSWORD | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.MQTT_PORT | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.MQTT_USERNAME | ||
| import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.SETTINGS_SHOW_MQTT_BRICKS | ||
|
|
||
| class MqttSettingsFragment : PreferenceFragment() { | ||
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| (activity as AppCompatActivity).supportActionBar?.title = preferenceScreen.title | ||
| } | ||
|
|
||
| override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
| super.onActivityCreated(savedInstanceState) | ||
| SettingsFragment.setToChosenLanguage(activity) | ||
| addPreferencesFromResource(R.xml.mqtt_preferences) | ||
|
|
||
| val mqttCheckBoxPreference = findPreference(SETTINGS_SHOW_MQTT_BRICKS) as CheckBoxPreference | ||
| val mqttConnectionSettings = findPreference(MQTT_CONNECTION_SETTINGS_CATEGORY) as PreferenceCategory | ||
| mqttConnectionSettings.isEnabled = mqttCheckBoxPreference.isChecked | ||
|
|
||
| mqttCheckBoxPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, isChecked -> | ||
| mqttConnectionSettings.isEnabled = isChecked as Boolean | ||
| true | ||
| } | ||
|
|
||
| bindSummaryToValue(findPreference(MQTT_HOST) as EditTextPreference) | ||
| bindSummaryToValue(findPreference(MQTT_USERNAME) as EditTextPreference) | ||
| bindSummaryToValue(findPreference(MQTT_CLIENT_ID) as EditTextPreference) | ||
|
|
||
| val portPreference = findPreference(MQTT_PORT) as EditTextPreference | ||
| portPreference.summary = portPreference.text | ||
| portPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> | ||
| if (!isValidPort(newValue.toString())) { | ||
| Toast.makeText(activity, R.string.preference_mqtt_port_invalid, Toast.LENGTH_SHORT).show() | ||
| return@OnPreferenceChangeListener false | ||
| } | ||
| portPreference.summary = newValue.toString() | ||
| true | ||
| } | ||
|
|
||
| val passwordPreference = findPreference(MQTT_PASSWORD) as EditTextPreference | ||
| passwordPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ -> true } | ||
| } | ||
|
|
||
| private fun bindSummaryToValue(preference: EditTextPreference) { | ||
| preference.summary = preference.text | ||
| preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { pref, newValue -> | ||
| (pref as EditTextPreference).summary = newValue.toString() | ||
| true | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val MIN_PORT = 1 | ||
| private const val MAX_PORT = 65_535 | ||
|
|
||
| @JvmField val TAG: String = MqttSettingsFragment::class.java.simpleName | ||
|
|
||
| @VisibleForTesting | ||
| @JvmStatic | ||
| fun isValidPort(value: String): Boolean { | ||
| val port = value.toIntOrNull() ?: return false | ||
| return port in MIN_PORT..MAX_PORT | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| ~ Catroid: An on-device visual programming system for Android devices | ||
| ~ Copyright (C) 2010-2025 The Catrobat Team | ||
| ~ (<http://developer.catrobat.org/credits>) | ||
| ~ | ||
| ~ This program is free software: you can redistribute it and/or modify | ||
| ~ it under the terms of the GNU Affero General Public License as | ||
| ~ published by the Free Software Foundation, either version 3 of the | ||
| ~ License, or (at your option) any later version. | ||
| ~ | ||
| ~ An additional term exception under section 7 of the GNU Affero | ||
| ~ General Public License, version 3, is available at | ||
| ~ http://developer.catrobat.org/license_additional_term | ||
| ~ | ||
| ~ This program is distributed in the hope that it will be useful, | ||
| ~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ~ GNU Affero General Public License for more details. | ||
| ~ | ||
| ~ You should have received a copy of the GNU Affero General Public License | ||
| ~ along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| --> | ||
| <PreferenceScreen | ||
| android:key="settings_mqtt_screen" | ||
| android:summary="@string/preference_description_mqtt_bricks" | ||
| android:title="@string/preference_title_enable_mqtt_bricks" | ||
| xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <CheckBoxPreference | ||
| android:defaultValue="false" | ||
| android:key="setting_mqtt_bricks" | ||
| android:summary="@string/preference_description_mqtt_enabled" | ||
| android:title="@string/preference_title_mqtt_enabled" /> | ||
|
|
||
| <PreferenceCategory | ||
| android:key="setting_mqtt_category" | ||
| android:title="@string/preference_title_mqtt_category"> | ||
|
|
||
| <EditTextPreference | ||
| android:defaultValue="192.168.0.1" | ||
| android:key="setting_mqtt_host" | ||
| android:summary="@string/preference_description_mqtt_broker_host" | ||
| android:title="@string/preference_title_mqtt_broker_host" /> | ||
|
|
||
| <EditTextPreference | ||
| android:defaultValue="1883" | ||
| android:inputType="number" | ||
| android:key="setting_mqtt_port" | ||
| android:summary="@string/preference_description_mqtt_broker_port" | ||
| android:title="@string/preference_title_mqtt_broker_port" /> | ||
|
|
||
| <CheckBoxPreference | ||
| android:defaultValue="false" | ||
| android:key="setting_mqtt_tls" | ||
| android:title="@string/preference_title_mqtt_use_tls" /> | ||
|
|
||
| <EditTextPreference | ||
| android:defaultValue="" | ||
| android:key="setting_mqtt_username" | ||
| android:title="@string/preference_title_mqtt_username" /> | ||
|
|
||
| <EditTextPreference | ||
| android:defaultValue="" | ||
| android:inputType="textPassword" | ||
| android:key="setting_mqtt_password" | ||
| android:title="@string/preference_title_mqtt_password" /> | ||
|
|
||
| <EditTextPreference | ||
| android:defaultValue="" | ||
| android:key="setting_mqtt_client_id" | ||
| android:title="@string/preference_title_mqtt_client_id" /> | ||
|
|
||
| </PreferenceCategory> | ||
|
|
||
| </PreferenceScreen> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.