From bb9c75de6d90a4803d989d3d385411431869e15b Mon Sep 17 00:00:00 2001 From: LagradOst Date: Mon, 30 Aug 2021 23:42:58 +0200 Subject: [PATCH] benene --- app/build.gradle | 1 + .../com/lagradost/cloudstream3/MainAPI.kt | 5 +- .../lagradost/cloudstream3/MainActivity.kt | 19 +++-- .../cloudstream3/ui/settings/ScoreManager.kt | 43 ++++++++++ .../ui/settings/SettingsFragment.kt | 84 +++++++++++++++++++ app/src/main/res/drawable/benene.xml | 58 +++++++++++++ app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/settings.xml | 6 ++ 8 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/ui/settings/ScoreManager.kt create mode 100644 app/src/main/res/drawable/benene.xml diff --git a/app/build.gradle b/app/build.gradle index 67c7b7f0..c922111a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,6 +37,7 @@ android { resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}" buildConfigField("String", "BUILDDATE", "new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm\").format(new java.util.Date(" + System.currentTimeMillis() + "L));") + buildConfigField("String", "PRIVATE_BENENE_KEY", "\"${(System.getenv("PRIVATE_BENENE_KEY") ?: "")}\"") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index ecd35e7c..06f54bfa 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -42,7 +42,10 @@ object APIHolder { WatchCartoonOnlineProvider(), AllMoviesForYouProvider(), AsiaFlixProvider(), - //NyaaProvider(), + ) + + val restrictedApis = arrayListOf( + NyaaProvider(), ) fun getApiFromName(apiName: String?): MainAPI { diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 1ec405cd..7a0aab62 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -8,7 +8,6 @@ import android.content.pm.PackageManager import android.content.res.ColorStateList import android.os.Build import android.os.Bundle -import android.os.Environment import android.view.* import android.widget.TextView import android.widget.Toast @@ -17,14 +16,11 @@ import androidx.appcompat.app.AppCompatActivity import androidx.navigation.NavOptions import androidx.navigation.findNavController import androidx.navigation.fragment.NavHostFragment -import com.github.se_bastiaan.torrentstream.StreamStatus -import com.github.se_bastiaan.torrentstream.Torrent -import com.github.se_bastiaan.torrentstream.TorrentOptions -import com.github.se_bastiaan.torrentstream.TorrentStream -import com.github.se_bastiaan.torrentstream.listeners.TorrentListener +import androidx.preference.PreferenceManager import com.google.android.gms.cast.framework.CastButtonFactory import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import com.lagradost.cloudstream3.APIHolder.apis +import com.lagradost.cloudstream3.APIHolder.restrictedApis import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.download.DownloadChildFragment @@ -356,5 +352,16 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { thread { runAutoUpdate() } + + // must give benenes to get beta providers + try { + val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) + val count = settingsManager.getInt(getString(R.string.benene_count), 0) + if (count > 30) + apis.addAll(restrictedApis) + } catch (e : Exception) { + e.printStackTrace() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/ScoreManager.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/ScoreManager.kt new file mode 100644 index 00000000..628964a7 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/ScoreManager.kt @@ -0,0 +1,43 @@ +package com.lagradost.cloudstream3.ui.settings + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.module.kotlin.readValue +import com.lagradost.cloudstream3.BuildConfig +import com.lagradost.cloudstream3.mapper + +object ScoreManager { + private const val mainUrl = "http://dreamlo.com" + private const val publicCode = "612d3dcf8f40bb6e98bece15" + var privateCode: String? = BuildConfig.PRIVATE_BENENE_KEY // plz keep it a bit fair + + data class DreamloMain( + @JsonProperty("dreamlo") var dreamlo: Dreamlo + ) + + data class Dreamlo( + @JsonProperty("leaderboard") var leaderboard: Leaderboard + ) + + data class Leaderboard( + @JsonProperty("entry") var entry: List + ) + + data class DreamloEntry( + @JsonProperty("name") var name: String, + @JsonProperty("score") var score: String, + //@JsonProperty("seconds") var seconds: String, + //@JsonProperty("text") var text: String, + // @JsonProperty("date") var date: String + ) + + fun getScore(): List { + val response = khttp.get("$mainUrl/lb/$publicCode/json") + + return mapper.readValue(response.text).dreamlo.leaderboard.entry + } + + fun addScore(name: String, score: Int) { // plz dont cheat + if(score < 0 || score > 100000 || privateCode.isNullOrBlank()) return + khttp.get("$mainUrl/lb/$privateCode/add/$name/$score") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index f293b3a7..f2ccee64 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -4,18 +4,102 @@ import android.os.Bundle import android.widget.Toast import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceManager import com.lagradost.cloudstream3.MainActivity.Companion.showToast import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.mvvm.normalSafeApiCall import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment +import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay +import java.lang.Exception +import java.util.* import kotlin.concurrent.thread class SettingsFragment : PreferenceFragmentCompat() { + var count = 0 + private var scoreboard: List? = null + + private var usernameUUID: String? = null + + var ongoingJob: Job? = null + + private fun saveAfterTime() { + ongoingJob?.cancel() + ongoingJob = main { + delay(10000) // dont ddos the scoreboard + saveAndUpload() + } + } + + private fun saveAndUpload() { + val settingsManager = PreferenceManager.getDefaultSharedPreferences(context) + val uuid = usernameUUID + if (uuid != null) { + settingsManager.edit() + .putString(getString(R.string.benene_count_uuid), uuid) + .putInt(getString(R.string.benene_count), count) + .apply() + thread { + normalSafeApiCall { + ScoreManager.addScore(uuid, count) + } + } + } + } + + override fun onPause() { + saveAndUpload() + super.onPause() + } + + override fun onDestroy() { + saveAndUpload() + super.onDestroy() + } + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + val settingsManager = PreferenceManager.getDefaultSharedPreferences(context) + + count = settingsManager.getInt(getString(R.string.benene_count), 0) + usernameUUID = settingsManager.getString(getString(R.string.benene_count_uuid), UUID.randomUUID().toString()) + hideKeyboard() setPreferencesFromResource(R.xml.settings, rootKey) val updatePrefrence = findPreference(getString(R.string.manual_check_update_key))!! + + val benenePref = findPreference(getString(R.string.benene_count))!! + if (count > 20) { + thread { + scoreboard = normalSafeApiCall { ScoreManager.getScore() } + } + } + benenePref.summary = if(count <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format(count) + benenePref.setOnPreferenceClickListener { + try { + count++ + settingsManager.edit().putInt(getString(R.string.benene_count), count).apply() + var add = "" + val localScoreBoard = scoreboard + if (localScoreBoard != null) { + for ((index, score) in localScoreBoard.withIndex()) { + if (count > (score.score.toIntOrNull() ?: 0)) { + add = " (${index + 1}/${localScoreBoard.size})" + break + } + } + } + it.summary = getString(R.string.benene_count_text).format(count) + add + saveAfterTime() + } catch (e: Exception) { + e.printStackTrace() + } + + return@setOnPreferenceClickListener true + } + updatePrefrence.setOnPreferenceClickListener { thread { if (!requireActivity().runAutoUpdate(false)) { diff --git a/app/src/main/res/drawable/benene.xml b/app/src/main/res/drawable/benene.xml new file mode 100644 index 00000000..61a861fa --- /dev/null +++ b/app/src/main/res/drawable/benene.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 969d4b9d..111cafe2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,6 +88,10 @@ auto_update prerelease_update manual_check_update + benene_count + benene_count_uuid + %d Benenes given to devs + No Benenes given unknown_prerelease Auto Select Language diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 028d9f47..eac34b61 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -133,5 +133,11 @@ + + \ No newline at end of file