diff --git a/app/src/main/java/com/nin0dev/vendroid/MainActivity.kt b/app/src/main/java/com/nin0dev/vendroid/MainActivity.kt index aa30dea..6ed47d3 100644 --- a/app/src/main/java/com/nin0dev/vendroid/MainActivity.kt +++ b/app/src/main/java/com/nin0dev/vendroid/MainActivity.kt @@ -11,7 +11,10 @@ import android.os.Bundle import android.os.StrictMode import android.os.StrictMode.ThreadPolicy import android.view.KeyEvent +import android.view.View.VISIBLE import android.view.WindowManager +import android.webkit.CookieManager +import android.webkit.CookieSyncManager import android.webkit.ValueCallback import android.webkit.WebView import android.widget.Toast @@ -21,8 +24,10 @@ import com.android.volley.toolbox.Volley import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.nin0dev.vendroid.HttpClient.fetchVencord import com.nin0dev.vendroid.Logger.e +import pl.droidsonroids.gif.GifImageView import java.io.IOException + class MainActivity : Activity() { private var wvInitialized = false private var wv: WebView? = null @@ -36,25 +41,31 @@ class MainActivity : Activity() { val queue = Volley.newRequestQueue(this) val url = "https://raw.githubusercontent.com/VendroidEnhanced/UpdateTracker/main/vendroid" val stringRequest = StringRequest( - Request.Method.GET, url, - { response -> - if(Integer.parseInt(response.trim()) != BuildConfig.VERSION_CODE) - { - val madb = MaterialAlertDialogBuilder(this) - madb.setTitle(getString(R.string.vendroid_update_available)) - madb.setMessage("To make sure that no unexpected bugs happen, it is recommended to update.") - madb.setPositiveButton(getString(R.string.update), DialogInterface.OnClickListener { dialogInterface, i -> - val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk")) - startActivity(browserIntent) - }) - madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> }) - madb.show() - } - if(ignoreSetting && Integer.parseInt(response.trim()) == BuildConfig.VERSION_CODE) { - showDiscordToast("No updates available", "MESSAGE") - } - }, - { }) + Request.Method.GET, url, + { response -> + if(Integer.parseInt(response.trim()) != BuildConfig.VERSION_CODE) + { + val madb = MaterialAlertDialogBuilder(this) + madb.setTitle(getString(R.string.vendroid_update_available)) + madb.setMessage("To make sure that no unexpected bugs happen, it is recommended to update.") + madb.setPositiveButton(getString(R.string.update), DialogInterface.OnClickListener { dialogInterface, i -> + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk")) + startActivity(browserIntent) + }) + madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> }) + madb.show() + } + if(ignoreSetting && Integer.parseInt(response.trim()) == BuildConfig.VERSION_CODE) { + showDiscordToast("No updates available", "MESSAGE") + } + }, + { error -> + if (BuildConfig.DEBUG) { + e("Network error during update check", error) + } + Toast.makeText(this, "Failed to check for updates", Toast.LENGTH_SHORT).show() + } + ) stringRequest.setShouldCache(false); queue.add(stringRequest) } @@ -69,9 +80,13 @@ class MainActivity : Activity() { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) window.navigationBarColor = Color.TRANSPARENT val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE) + val editor = sPrefs.edit() // https://developer.chrome.com/docs/devtools/remote-debugging/webviews/ WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG) setContentView(R.layout.activity_main) + if (sPrefs.getString("splash", "viggy") == "viggy") findViewById(R.id.viggy_gif).visibility = VISIBLE + else if (sPrefs.getString("splash", "viggy") == "shiggy") findViewById(R.id.shiggy_gif).visibility = VISIBLE + else if (sPrefs.getString("splash", "viggy") == "oneko") findViewById(R.id.oneko_gif).visibility = VISIBLE wv = findViewById(R.id.webview)!! explodeAndroid() wv!!.setWebViewClient(VWebviewClient()) @@ -80,11 +95,18 @@ class MainActivity : Activity() { s.javaScriptEnabled = true s.domStorageEnabled = true s.allowFileAccess = true - wv?.addJavascriptInterface(VencordNative(this, wv!!), "VencordMobileNative") - try { - fetchVencord(this) - } catch (ex: IOException) { + if(!sPrefs.getBoolean("safeMode", false)) { + wv?.addJavascriptInterface(VencordNative(this, wv!!), "VencordMobileNative") + try { + fetchVencord(this) + } catch (ex: IOException) { + } + } + else { + Toast.makeText(this, "Safe mode enabled, Vencord won't be loaded", Toast.LENGTH_SHORT).show() + editor.putBoolean("safeMode", false) + editor.apply() } val intent = intent if (intent.action == Intent.ACTION_VIEW) { @@ -138,9 +160,9 @@ class MainActivity : Activity() { private fun explodeAndroid() { StrictMode.setThreadPolicy( - ThreadPolicy.Builder() // trolley - .permitNetwork() - .build() + ThreadPolicy.Builder() // trolley + .permitNetwork() + .build() ) } diff --git a/app/src/main/java/com/nin0dev/vendroid/RecoveryActivity.kt b/app/src/main/java/com/nin0dev/vendroid/RecoveryActivity.kt index 8e7b2cd..45bc602 100644 --- a/app/src/main/java/com/nin0dev/vendroid/RecoveryActivity.kt +++ b/app/src/main/java/com/nin0dev/vendroid/RecoveryActivity.kt @@ -5,11 +5,15 @@ import android.content.Intent import android.graphics.Color import android.os.Bundle import android.view.WindowManager +import android.webkit.CookieManager +import android.webkit.CookieSyncManager +import android.webkit.WebView import android.widget.Button import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import com.google.android.material.card.MaterialCardView import com.google.android.material.snackbar.Snackbar class RecoveryActivity : AppCompatActivity() { @@ -23,14 +27,23 @@ class RecoveryActivity : AppCompatActivity() { setContentView(R.layout.activity_recovery) - findViewById