From 44673dfa32ccc08d2341d3b1c8421c26958e3499 Mon Sep 17 00:00:00 2001 From: yourok <8yourok8@mail.ru> Date: Tue, 14 Nov 2023 17:32:04 +0300 Subject: [PATCH] Add speed test --- app/build.gradle | 2 + .../main/settings/SettingsFragment.kt | 8 + .../ui/fragments/speedtest/SpeedTest.kt | 224 ++++++++++++++++++ .../main/res/layout/speedtest_fragment.xml | 38 +++ app/src/main/res/values-bg/strings.xml | 2 + app/src/main/res/values-ru/strings.xml | 2 + app/src/main/res/values-uk/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/preferences.xml | 5 + 10 files changed, 288 insertions(+) create mode 100644 app/src/main/java/ru/yourok/torrserve/ui/fragments/speedtest/SpeedTest.kt create mode 100644 app/src/main/res/layout/speedtest_fragment.xml diff --git a/app/build.gradle b/app/build.gradle index 4f4ff882..65d368c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,6 +75,8 @@ dependencies { implementation 'com.google.firebase:firebase-analytics:19.0.2' //noinspection GradleDependency firebase-crashlytics:18.2.5 is last api17 compatible implementation 'com.google.firebase:firebase-crashlytics:18.2.5' + // speed test + implementation 'com.github.anastr:speedviewlib:1.6.0' } repositories { diff --git a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt index 6d33ecea..038028f0 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt @@ -32,6 +32,7 @@ import ru.yourok.torrserve.ui.fragments.main.servfinder.ServerFinderFragment import ru.yourok.torrserve.ui.fragments.main.servsets.ServerSettingsFragment import ru.yourok.torrserve.ui.fragments.main.update.apk.ApkUpdateFragment import ru.yourok.torrserve.ui.fragments.main.update.apk.UpdaterApk +import ru.yourok.torrserve.ui.fragments.speedtest.SpeedTest import ru.yourok.torrserve.utils.Accessibility @@ -90,6 +91,13 @@ class SettingsFragment : PreferenceFragmentCompat() { } } + findPreference("speedtest")?.apply { + setOnPreferenceClickListener { + SpeedTest().show(requireActivity(), R.id.container, true) + true + } + } + findPreference("server_settings")?.setOnPreferenceClickListener { ServerSettingsFragment().show(requireActivity(), R.id.container, true) true diff --git a/app/src/main/java/ru/yourok/torrserve/ui/fragments/speedtest/SpeedTest.kt b/app/src/main/java/ru/yourok/torrserve/ui/fragments/speedtest/SpeedTest.kt new file mode 100644 index 00000000..255ead19 --- /dev/null +++ b/app/src/main/java/ru/yourok/torrserve/ui/fragments/speedtest/SpeedTest.kt @@ -0,0 +1,224 @@ +package ru.yourok.torrserve.ui.fragments.speedtest + +import android.graphics.Color +import android.net.Uri +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.TextView +import androidx.lifecycle.lifecycleScope +import com.github.anastr.speedviewlib.TubeSpeedometer +import com.github.anastr.speedviewlib.components.Section +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import ru.yourok.torrserve.R +import ru.yourok.torrserve.ui.fragments.TSFragment +import ru.yourok.torrserve.utils.Http +import ru.yourok.torrserve.utils.Net + + +class SpeedTest : TSFragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val vi = inflater.inflate(R.layout.speedtest_fragment, container, false) + + val speedometer = vi.findViewById(R.id.tubeSpeedometer) + + speedometer.unit = "MBit/Sec" + speedometer.minSpeed = 0f + speedometer.maxSpeed = 500f + speedometer.withTremble = false + speedometer.clearSections() + speedometer.addSections( + Section(0f, getPrcSpeed(50f, speedometer.maxSpeed), Color.RED), + Section(getPrcSpeed(50f, speedometer.maxSpeed), getPrcSpeed(70f, speedometer.maxSpeed), Color.YELLOW), + Section(getPrcSpeed(70f, speedometer.maxSpeed), getPrcSpeed(100f, speedometer.maxSpeed), Color.GREEN), + Section(getPrcSpeed(100f, speedometer.maxSpeed), 1f, Color.BLUE) + ) +// lifecycleScope.launch(Dispatchers.IO) { +// setSpeedometer(501f) +// } + + vi.findViewById