forked from recloudstream/cloudstream
benene
This commit is contained in:
parent
3b6b3dedc0
commit
bb9c75de6d
8 changed files with 213 additions and 7 deletions
|
@ -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"
|
||||
|
||||
|
|
|
@ -42,7 +42,10 @@ object APIHolder {
|
|||
WatchCartoonOnlineProvider(),
|
||||
AllMoviesForYouProvider(),
|
||||
AsiaFlixProvider(),
|
||||
//NyaaProvider(),
|
||||
)
|
||||
|
||||
val restrictedApis = arrayListOf(
|
||||
NyaaProvider(),
|
||||
)
|
||||
|
||||
fun getApiFromName(apiName: String?): MainAPI {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<DreamloEntry>
|
||||
)
|
||||
|
||||
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<DreamloEntry> {
|
||||
val response = khttp.get("$mainUrl/lb/$publicCode/json")
|
||||
|
||||
return mapper.readValue<DreamloMain>(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")
|
||||
}
|
||||
}
|
|
@ -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<ScoreManager.DreamloEntry>? = 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<Preference>(getString(R.string.manual_check_update_key))!!
|
||||
|
||||
val benenePref = findPreference<Preference>(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)) {
|
||||
|
|
58
app/src/main/res/drawable/benene.xml
Normal file
58
app/src/main/res/drawable/benene.xml
Normal file
|
@ -0,0 +1,58 @@
|
|||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="vector"
|
||||
android:width="36dp"
|
||||
android:height="36dp"
|
||||
android:viewportWidth="36"
|
||||
android:viewportHeight="36">
|
||||
<path
|
||||
android:name="path"
|
||||
android:pathData="M 28 2 C 30.684 0.658 33 6 31 15 C 29.894 19.977 26 24 22 27 C 18 30 11 26 15 22 C 19 18 23 15 25 9 C 26.304 5.088 26 3 28 2 Z"
|
||||
android:fillColor="#ffe8b6"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_1"
|
||||
android:pathData="M 31 8 C 31 11 30 17 27 21 C 24 25 20 26 23 22 C 26 18 28 15 29 11 C 30 7 31 4 31 8 Z"
|
||||
android:fillColor="#ffd983"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_2"
|
||||
android:pathData="M 22 20 C 21.704 20.592 23.167 16.167 19 14 C 17.016 12.968 9 15 15 15 C 18 15 19 17 17 19 C 16.709 19.292 16.511 19.603 16.378 19.912 C 15.961 20.258 15.505 20.621 15 21 C 12.737 22.697 9.16 25.227 5 28 C 2 30 1 31 1 32 C 1 35 10 35 15 33 C 20 31 25 26 25 26 L 29 22 C 26 18 22 20 22 20 Z"
|
||||
android:fillColor="#ffcc4d"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_3"
|
||||
android:pathData="M 22 20 C 22 20 23.792 15.271 19 13 C 14.958 11.084 11 12 8 14 C 5 16 6 18 5 19 C 4 20 6 21 8 19 C 10 17 16.316 14.105 19 15 C 22 16 21 17.999 22 20 Z"
|
||||
android:fillColor="#ffe8b6"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_4"
|
||||
android:pathData="M 26 35 L 22 35 C 20 35 19 36 18 36 C 17 36 16 34 18 34 C 20 34 22 34 23 33 C 24 32 28 35 26 35 Z"
|
||||
android:fillColor="#a6d388"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_5"
|
||||
android:pathData="M 18 34 C 17.735 34 17.48 34.105 17.293 34.293 C 17.105 34.48 17 34.735 17 35 C 17 35.265 17.105 35.52 17.293 35.707 C 17.48 35.895 17.735 36 18 36 C 18.265 36 18.52 35.895 18.707 35.707 C 18.895 35.52 19 35.265 19 35 C 19 34.735 18.895 34.48 18.707 34.293 C 18.52 34.105 18.265 34 18 34 Z"
|
||||
android:fillColor="#3e721d"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_6"
|
||||
android:pathData="M 32.208 28 C 32.208 28 28 35 26 35 L 22 35 C 20 35 22 34 23 33 C 24 32 28 33 28 27 C 28 24 32.208 28 32.208 28 Z"
|
||||
android:fillColor="#ffcc4d"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_7"
|
||||
android:pathData="M 26 19 C 29 19 34 22 33 28 C 32 34 28 35 26 35 L 24 35 C 22 35 23 34 24 33 C 25 32 28 33 28 27 C 28 24 24 20 22 20 C 22 20 24 19 26 19 Z"
|
||||
android:fillColor="#ffe8b6"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_8"
|
||||
android:pathData="M 17 21 C 20 21 22 22 20 24 C 18.419 25.581 14 29 10 30 C 6 31 2 31 5 29 C 8 27 14.764 21 17 21 Z"
|
||||
android:fillColor="#ffd983"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_9"
|
||||
android:pathData="M 2 31 C 3 31 3 31 3 31.667 C 3 32.333 3 33 2 33 C 1 33 1 31.667 1 31.667 C 1 31.667 1 31 2 31 Z"
|
||||
android:fillColor="#c1694f"
|
||||
android:strokeWidth="1"/>
|
||||
</vector>
|
|
@ -88,6 +88,10 @@
|
|||
<string name="auto_update_key">auto_update</string>
|
||||
<string name="prerelease_update_key">prerelease_update</string>
|
||||
<string name="manual_check_update_key">manual_check_update</string>
|
||||
<string name="benene_count">benene_count</string>
|
||||
<string name="benene_count_uuid">benene_count_uuid</string>
|
||||
<string name="benene_count_text">%d Benenes given to devs</string>
|
||||
<string name="benene_count_text_none">No Benenes given</string>
|
||||
|
||||
<string name="prerelease_commit_hash">unknown_prerelease</string>
|
||||
<string name="subs_auto_select_language">Auto Select Language</string>
|
||||
|
|
|
@ -133,5 +133,11 @@
|
|||
<intent android:action="android.intent.action.VIEW"
|
||||
android:data="https://discord.gg/5Hus6fM"/>
|
||||
</Preference>
|
||||
<Preference
|
||||
android:key="@string/benene_count"
|
||||
android:title="Give a benene to the devs"
|
||||
android:icon="@drawable/benene"
|
||||
app:summary="Given benenes">
|
||||
</Preference>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue