diff options
author | RaindropsSys <contact@minteck.org> | 2023-05-13 19:26:02 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-05-13 19:26:02 +0200 |
commit | a249ac5c1de45cb188aec32010b6097c606e6aed (patch) | |
tree | 434cc865014b06a8ff58dd5752f95164b99ea2a0 /app/src/main/java/dev/equestria/delta | |
parent | d1d855bed901003a4dd3bb5f3da49f477786f83a (diff) | |
download | delta-android-a249ac5c1de45cb188aec32010b6097c606e6aed.tar.gz delta-android-a249ac5c1de45cb188aec32010b6097c606e6aed.tar.bz2 delta-android-a249ac5c1de45cb188aec32010b6097c606e6aed.zip |
Updated 6 files (automated)
Diffstat (limited to 'app/src/main/java/dev/equestria/delta')
-rw-r--r-- | app/src/main/java/dev/equestria/delta/MainActivity.kt | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/app/src/main/java/dev/equestria/delta/MainActivity.kt b/app/src/main/java/dev/equestria/delta/MainActivity.kt index 341e1f4..8ac7e99 100644 --- a/app/src/main/java/dev/equestria/delta/MainActivity.kt +++ b/app/src/main/java/dev/equestria/delta/MainActivity.kt @@ -46,6 +46,7 @@ class MainActivity : AppCompatActivity() { private var changedNavItem: Boolean = false private var deltaInformation: JSONObject? = null private var lastRequestLoggedIn: Boolean = false + private var deltaRoot: String = "" override fun onCreateOptionsMenu(menu: Menu?): Boolean { val inflater = menuInflater @@ -59,7 +60,7 @@ class MainActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.user -> { - binding.webView.loadUrl("${getString(R.string.delta_root)}/profile") + binding.webView.loadUrl("${deltaRoot}/profile") return true } @@ -74,7 +75,21 @@ class MainActivity : AppCompatActivity() { } R.id.btn_user_logout -> { - binding.webView.loadUrl("${getString(R.string.delta_root)}/logout") + binding.webView.loadUrl("${deltaRoot}/logout") + return true + } + + R.id.btn_switch -> { + if (deltaRoot === getString(R.string.delta_root_production)) { + deltaRoot = getString(R.string.delta_root_staging) + appMenu.getItem(5).title = getString(R.string.navigation_user_switch_production) + handoffApi31() + } else { + deltaRoot = getString(R.string.delta_root_production) + appMenu.getItem(5).title = getString(R.string.navigation_user_switch_staging) + handoffApi31() + } + return true } @@ -129,6 +144,8 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) DynamicColors.applyToActivitiesIfAvailable(application) + deltaRoot = getString(R.string.delta_root_production) + val name = getString(R.string.channel_name) val descriptionText = getString(R.string.channel_description) val importance = NotificationManager.IMPORTANCE_DEFAULT @@ -154,8 +171,8 @@ class MainActivity : AppCompatActivity() { Log.d("Firebase", token) HTTPRequest.request( - "${getString(R.string.delta_root)}/handoff/fcm/", - getCookie(getString(R.string.delta_root), "DeltaSession") + "||||" + token, + "${deltaRoot}/handoff/fcm/", + getCookie(deltaRoot, "DeltaSession") + "||||" + token, binding.root.context, resources, this, @@ -183,8 +200,8 @@ class MainActivity : AppCompatActivity() { } fun initialCheck() { - HTTPRequest.request("${getString(R.string.delta_root)}/handoff/version/", - getCookie(getString(R.string.delta_root), "DeltaSession"), + HTTPRequest.request("${deltaRoot}/handoff/version/", + getCookie(deltaRoot, "DeltaSession"), binding.root.context, resources, this, @@ -193,6 +210,13 @@ class MainActivity : AppCompatActivity() { { deltaInformation = it appMenu.getItem(3).isEnabled = deltaInformation!!.get("loggedIn") as Boolean + + if (deltaInformation!!.has("admin")) { + appMenu.getItem(5).isVisible = deltaInformation!!.get("admin") as Boolean + } else { + appMenu.getItem(5).isVisible = false + } + initialise() }) { val openURL = Intent(Intent.ACTION_VIEW) @@ -202,8 +226,8 @@ class MainActivity : AppCompatActivity() { } fun routineCheck() { - HTTPRequest.request("${getString(R.string.delta_root)}/handoff/version/", - getCookie(getString(R.string.delta_root), "DeltaSession"), + HTTPRequest.request("${deltaRoot}/handoff/version/", + getCookie(deltaRoot, "DeltaSession"), binding.root.context, resources, this, @@ -250,7 +274,7 @@ class MainActivity : AppCompatActivity() { } Picasso.get().load( - "${getString(R.string.delta_root)}/handoff/avatar/?token=" + deltaInformation.get("session") + "${deltaRoot}/handoff/avatar/?token=" + deltaInformation.get("session") ).into(target) } @@ -331,7 +355,9 @@ class MainActivity : AppCompatActivity() { "/studio/" ) || URL(url).path === "/studio" || URL(url).path.startsWith( "/logout/" - ) || URL(url).path === "/logout" + ) || URL(url).path === "/logout" || URL(url).path.startsWith( + "/pass/" + ) || URL(url).path === "/pass" ) { changedNavItem = true binding.navigationBar.selectedItemId = R.id.navigation_profile @@ -350,7 +376,7 @@ class MainActivity : AppCompatActivity() { ): WebResourceResponse? { request.url.host?.let { Log.i("MainActivity", '"' + it + '"') } - if (request.url.host != getString(R.string.delta_root).split("/")[2]) { + if (request.url.host != deltaRoot.split("/")[2]) { val openURL = Intent(Intent.ACTION_VIEW) openURL.data = request.url startActivity(openURL) @@ -369,7 +395,7 @@ class MainActivity : AppCompatActivity() { if (!changedNavItem) { changedNavItem = true - binding.webView.loadUrl("${getString(R.string.delta_root)}/") + binding.webView.loadUrl("${deltaRoot}/") } true @@ -380,7 +406,7 @@ class MainActivity : AppCompatActivity() { if (!changedNavItem) { changedNavItem = true - binding.webView.loadUrl("${getString(R.string.delta_root)}/search") + binding.webView.loadUrl("${deltaRoot}/search") } true @@ -391,7 +417,7 @@ class MainActivity : AppCompatActivity() { if (!changedNavItem) { changedNavItem = true - binding.webView.loadUrl("${getString(R.string.delta_root)}/content") + binding.webView.loadUrl("${deltaRoot}/content") } true @@ -402,7 +428,7 @@ class MainActivity : AppCompatActivity() { if (!changedNavItem) { changedNavItem = true - binding.webView.loadUrl("${getString(R.string.delta_root)}/profile") + binding.webView.loadUrl("${deltaRoot}/profile") } true @@ -473,20 +499,20 @@ class MainActivity : AppCompatActivity() { if (Intent.ACTION_VIEW == appLinkAction) { if (appLinkData != null) { binding.webView.loadUrl( - "${getString(R.string.delta_root)}/handoff/?version=" + BuildConfig.VERSION_CODE + "&colors=" + colors.joinToString( + "${deltaRoot}/handoff/?version=" + BuildConfig.VERSION_CODE + "&colors=" + colors.joinToString( "," ) + "&return=" + java.net.URLEncoder.encode(appLinkData.path, "utf-8") ) } else { binding.webView.loadUrl( - "${getString(R.string.delta_root)}/handoff/?version=" + BuildConfig.VERSION_CODE + "&colors=" + colors.joinToString( + "${deltaRoot}/handoff/?version=" + BuildConfig.VERSION_CODE + "&colors=" + colors.joinToString( "," ) + "&return=/" ) } } else { binding.webView.loadUrl( - "${getString(R.string.delta_root)}/handoff/?version=" + BuildConfig.VERSION_CODE + "&colors=" + colors.joinToString( + "${deltaRoot}/handoff/?version=" + BuildConfig.VERSION_CODE + "&colors=" + colors.joinToString( "," ) + "&return=/" ) |