Files
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/InternetHelperPreferencesActivity.kt
T

61 lines
2.6 KiB
Kotlin

/* Copyright (C) 2025 Arjan Schrijver
This file is part of Gadgetbridge.
Gadgetbridge 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.
Gadgetbridge 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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.activities
import android.content.Intent
import android.os.Bundle
import androidx.core.net.toUri
import androidx.preference.Preference
import nodomain.freeyourgadget.gadgetbridge.BuildConfig
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 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
}
}
}
}
}