Too much changes
This commit is contained in:
parent
4148fed9df
commit
ff8d3d731d
11 changed files with 265 additions and 12 deletions
|
@ -34,5 +34,8 @@ dependencies {
|
|||
implementation 'androidx.annotation:annotation:1.7.1'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.28'
|
||||
implementation 'com.google.android.material:material:1.11.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.activity:activity:1.8.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:targetApi="34">
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".WelcomeActivity"
|
||||
android:exported="false"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.nin0dev.vendroid
|
||||
|
||||
object Constants {
|
||||
const val JS_BUNDLE_URL = "https://github.com/VendroidEnhanced/Vencord/releases/latest/download/mobile.js"
|
||||
const val JS_BUNDLE_URL = "https://github.com/VendroidEnhanced/Vencord/releases/download/devbuild/browser.js"
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.HttpURLConnection
|
||||
|
@ -19,15 +20,25 @@ object HttpClient {
|
|||
@Throws(IOException::class)
|
||||
fun fetchVencord(activity: Activity) {
|
||||
val sPrefs = activity.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
if (VencordRuntime != null) return
|
||||
var vendroidFile = File(activity.filesDir, "vencord.js")
|
||||
val res = activity.resources
|
||||
res.openRawResource(R.raw.vencord_mobile).use { `is` -> VencordMobileRuntime = readAsText(`is`) }
|
||||
val conn = fetch(sPrefs.getString("vencordLocation", Constants.JS_BUNDLE_URL)!!)
|
||||
conn.inputStream.use { `is` -> VencordRuntime = readAsText(`is`) }
|
||||
if (VencordRuntime != null) return
|
||||
if (sPrefs.getString("vencordLocation", Constants.JS_BUNDLE_URL) == Constants.JS_BUNDLE_URL || BuildConfig.DEBUG) { // user is debugging vencord or app, always redownload
|
||||
vendroidFile.delete()
|
||||
}
|
||||
if (vendroidFile.exists()) {
|
||||
VencordRuntime = vendroidFile.readText()
|
||||
}
|
||||
else {
|
||||
val conn = fetch(sPrefs.getString("vencordLocation", Constants.JS_BUNDLE_URL)!!)
|
||||
vendroidFile.writeText(readAsText(conn.inputStream))
|
||||
VencordRuntime = vendroidFile.readText()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun fetch(url: String): HttpURLConnection {
|
||||
fun fetch(url: String): HttpURLConnection {
|
||||
val conn = URL(url).openConnection() as HttpURLConnection
|
||||
if (conn.getResponseCode() >= 300) {
|
||||
throw HttpException(conn)
|
||||
|
@ -36,7 +47,7 @@ object HttpClient {
|
|||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun readAsText(`is`: InputStream): String {
|
||||
fun readAsText(`is`: InputStream): String {
|
||||
ByteArrayOutputStream().use { baos ->
|
||||
var n: Int
|
||||
val buf = ByteArray(16384) // 16 KB
|
||||
|
|
|
@ -122,6 +122,12 @@ class MainActivity : Activity() {
|
|||
data?.let { handleUrl(it) }
|
||||
}
|
||||
|
||||
fun showDiscordToast(message: String, type: String) {
|
||||
wv?.post(Runnable {
|
||||
wv?.evaluateJavascript("toasts=Vencord.Webpack.Common.Toasts; toasts.show({id: toasts.genId(), message: \"$message\", type: toasts.Type.$type, options: {position: toasts.Position.BOTTOM,}})", null) // NOBODY LIKES TOASTS AT THE TOP
|
||||
})
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val FILECHOOSER_RESULTCODE = 8485
|
||||
}
|
||||
|
|
62
app/src/main/java/com/nin0dev/vendroid/SettingsActivity.kt
Normal file
62
app/src/main/java/com/nin0dev/vendroid/SettingsActivity.kt
Normal file
|
@ -0,0 +1,62 @@
|
|||
package com.nin0dev.vendroid
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.RadioButton
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
import com.google.android.material.materialswitch.MaterialSwitch
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
window.statusBarColor = Color.TRANSPARENT
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
|
||||
window.navigationBarColor = Color.TRANSPARENT
|
||||
|
||||
setContentView(R.layout.activity_settings)
|
||||
|
||||
val devbuildCheckbox = findViewById<CheckBox>(R.id.allow_custom_location)
|
||||
devbuildCheckbox.setOnClickListener {
|
||||
if (devbuildCheckbox.isChecked) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle("Warning")
|
||||
.setMessage("If you set a custom location, you will be loading and injecting Vencord from a different location. This feature is meant for developers ONLY. Never edit this setting if someone else asked you to, or if you don't know what you're doing! If you do set a custom location, you will not be able to ask for support in the Vencord support channel or in this project's issues. Are you sure you want to continue?")
|
||||
.setNegativeButton(resources.getString(R.string.no)) { _, _ ->
|
||||
devbuildCheckbox.isChecked = false
|
||||
}
|
||||
.setPositiveButton(resources.getString(R.string.yes)) { _, _ ->
|
||||
findViewById<EditText>(R.id.custom_location).visibility = View.VISIBLE
|
||||
}
|
||||
.show()
|
||||
}
|
||||
else {
|
||||
findViewById<EditText>(R.id.custom_location).visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
findViewById<ExtendedFloatingActionButton>(R.id.save_settings).setOnClickListener {
|
||||
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
val editor = sPrefs.edit()
|
||||
|
||||
editor.putBoolean("checkVendroidUpdates", findViewById<MaterialSwitch>(R.id.check_vendroid_updates).isChecked)
|
||||
if (findViewById<RadioButton>(R.id.stable).isChecked) editor.putString("discordBranch", "stable")
|
||||
if (findViewById<RadioButton>(R.id.ptb).isChecked) editor.putString("discordBranch", "ptb")
|
||||
if (findViewById<RadioButton>(R.id.canary).isChecked) editor.putString("discordBranch", "canary")
|
||||
if (findViewById<CheckBox>(R.id.allow_custom_location).isChecked && findViewById<EditText>(R.id.custom_location).text.isNotBlank()) editor.putString("vencordLocation", findViewById<EditText>(R.id.custom_location).text.toString())
|
||||
|
||||
editor.apply()
|
||||
Toast.makeText(this, "Settings saved, restart Vendroid to apply them.", Toast.LENGTH_LONG).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,14 @@
|
|||
package com.nin0dev.vendroid
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebView
|
||||
import android.widget.Toast
|
||||
import java.io.File
|
||||
|
||||
class VencordNative(private val activity: Activity, private val wv: WebView) {
|
||||
class VencordNative(private val activity: MainActivity, private val wv: WebView) {
|
||||
@JavascriptInterface
|
||||
fun goBack() {
|
||||
activity.runOnUiThread {
|
||||
|
@ -12,4 +16,18 @@ class VencordNative(private val activity: Activity, private val wv: WebView) {
|
|||
activity.getActionBar()
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun openSettings() {
|
||||
activity.startActivity(Intent(activity, SettingsActivity::class.java))
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun updateVencord() {
|
||||
val sPrefs = activity.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
var vendroidFile = File(activity.filesDir, "vencord.js")
|
||||
val conn = HttpClient.fetch(sPrefs.getString("vencordLocation", Constants.JS_BUNDLE_URL)!!)
|
||||
vendroidFile.writeText(HttpClient.readAsText(conn.inputStream))
|
||||
activity.showDiscordToast("Updated Vencord, restart to apply changes!", "SUCCESS")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.nin0dev.vendroid
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
|
@ -14,7 +13,6 @@ import android.widget.RadioButton
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.materialswitch.MaterialSwitch
|
||||
|
||||
|
||||
|
@ -48,7 +46,7 @@ class WelcomeActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
findViewById<ExtendedFloatingActionButton>(R.id.start_vendroid).setOnClickListener {
|
||||
findViewById<ExtendedFloatingActionButton>(R.id.save_settings).setOnClickListener {
|
||||
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
val editor = sPrefs.edit()
|
||||
|
||||
|
@ -60,7 +58,7 @@ class WelcomeActivity : AppCompatActivity() {
|
|||
|
||||
editor.apply()
|
||||
startActivity(Intent(this@WelcomeActivity, MainActivity::class.java))
|
||||
finishActivity(0)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
9
app/src/main/res/drawable/save_black_24dp.xml
Normal file
9
app/src/main/res/drawable/save_black_24dp.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM19,19L5,19L5,5h11.17L19,7.83L19,19zM12,12c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3zM6,6h9v4L6,10z"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
143
app/src/main/res/layout/activity_settings.xml
Normal file
143
app/src/main/res/layout/activity_settings.xml
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="20dp"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/updates_title"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/check_vendroid_updates"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:checked="true"
|
||||
android:text="@string/autocheck_vendroid" />
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/autoupdate_vencord"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:enabled="false"
|
||||
android:text="@string/autocheck_vencord" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/discord_branch"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/stable"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/stable" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/ptb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/ptb" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/canary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/canary" />
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/vencord_location"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/allow_custom_location"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/set_custom_location" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true"
|
||||
android:hint="@string/custom_location_url">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/custom_location"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
|
||||
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
style="?attr/collapsingToolbarLayoutLargeStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/collapsingToolbarLayoutLargeSize"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
|
||||
app:contentScrim="?attr/colorSurfaceContainer">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:elevation="0dp"
|
||||
app:layout_collapseMode="pin"
|
||||
app:title="Vendroid Settings"
|
||||
app:titleTextColor="@color/text" />
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/save_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:contentDescription="Start Vendroid"
|
||||
android:text="Save settings"
|
||||
app:icon="@drawable/save_black_24dp" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -130,7 +130,7 @@
|
|||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/start_vendroid"
|
||||
android:id="@+id/save_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
|
|
Loading…
Add table
Reference in a new issue