Add internet helper preferences to search

This commit is contained in:
Arjan Schrijver
2025-12-25 14:45:08 +01:00
committed by Arjan Schrijver
parent 038f2eb36e
commit d51820019d
2 changed files with 28 additions and 27 deletions
@@ -20,40 +20,38 @@ import android.content.Intent
import android.os.Bundle
import androidx.core.net.toUri
import androidx.preference.Preference
import nodomain.freeyourgadget.gadgetbridge.BuildConfig
import androidx.preference.PreferenceFragmentCompat
import nodomain.freeyourgadget.gadgetbridge.GBApplication
import nodomain.freeyourgadget.gadgetbridge.R
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils
import nodomain.freeyourgadget.gadgetbridge.util.PermissionsUtils.PACKAGE_INTERNET_HELPER
class InternetHelperPreferencesActivity : AbstractGBActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
supportFragmentManager
.beginTransaction()
.replace(R.id.settings_container, InternetHelperPreferencesFragment())
.commit()
class InternetHelperPreferencesActivity : AbstractSettingsActivityV2() {
override fun newFragment(): PreferenceFragmentCompat? {
return InternetHelperPreferencesFragment()
}
class InternetHelperPreferencesFragment : AbstractPreferenceFragment() {
override fun onCreatePreferences(
savedInstanceState: Bundle?,
rootKey: String?
) {
setPreferencesFromResource(R.xml.internethelper_preferences, rootKey)
val unusedWarning = findPreference<Preference>("pref_key_internethelper_unused")
unusedWarning?.isVisible = GBApplication.hasDirectInternetAccess();
val installWarning = findPreference<Preference>("pref_key_internethelper_not_installed")
if (AndroidUtils.isPackageInstalled(PACKAGE_INTERNET_HELPER)) {
installWarning?.isVisible = false
} else {
installWarning?.setOnPreferenceClickListener {
val startIntent = Intent(Intent.ACTION_VIEW)
startIntent.data = "https://codeberg.org/Freeyourgadget/Internethelper/releases".toUri()
startActivity(startIntent)
true
companion object {
class InternetHelperPreferencesFragment : AbstractPreferenceFragment() {
override fun onCreatePreferences(
savedInstanceState: Bundle?,
rootKey: String?
) {
setPreferencesFromResource(R.xml.internethelper_preferences, rootKey)
val unusedWarning = findPreference<Preference>("pref_key_internethelper_unused")
unusedWarning?.isVisible = GBApplication.hasDirectInternetAccess();
val installWarning =
findPreference<Preference>("pref_key_internethelper_not_installed")
if (AndroidUtils.isPackageInstalled(PACKAGE_INTERNET_HELPER)) {
installWarning?.isVisible = false
} else {
installWarning?.setOnPreferenceClickListener {
val startIntent = Intent(Intent.ACTION_VIEW)
startIntent.data =
"https://codeberg.org/Freeyourgadget/Internethelper/releases".toUri()
startActivity(startIntent)
true
}
}
}
}
@@ -98,6 +98,8 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
open(MapsSettingsActivity.class, result);
} else if (result.getResourceFile() == R.xml.automations_settings) {
open(AutomationsSettingsActivity.class, result);
} else if (result.getResourceFile() == R.xml.internethelper_preferences) {
open(InternetHelperPreferencesActivity.class, result);
} else {
super.onSearchResultClicked(result);
}
@@ -121,6 +123,7 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
index(R.xml.notifications_preferences, R.string.pref_header_notifications);
index(R.xml.map_settings, R.string.maps_settings);
index(R.xml.automations_settings, R.string.pref_header_automations);
index(R.xml.internethelper_preferences, R.string.prefs_internet_helper_title);
setInputTypeFor("rtl_max_line_length", InputType.TYPE_CLASS_NUMBER);
setInputTypeFor("location_latitude", InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL);