Skip to content

Commit

Permalink
Merge pull request #6 from Mygod/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
acocalypso authored Dec 5, 2023
2 parents ae4026b + da41b17 commit 5490642
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/be/mygod/reactmap/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class MainActivity : FragmentActivity() {
}

private fun handleIntent(intent: Intent?) {
when (intent?.action) {
if (intent == null || intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY ==
Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) return
when (intent.action) {
ACTION_CONFIGURE -> startConfigure(false)
ACTION_RESTART_GAME -> AlertDialog.Builder(this).apply {
setTitle(R.string.restart_game_dialog_title)
Expand Down
39 changes: 19 additions & 20 deletions app/src/main/java/be/mygod/reactmap/webkit/ReactMapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import be.mygod.reactmap.App.Companion.app
import be.mygod.reactmap.R
Expand All @@ -48,7 +47,7 @@ import java.net.URLDecoder
import java.nio.charset.Charset
import java.util.Locale

class ReactMapFragment @JvmOverloads constructor(private val overrideUri: Uri? = null) : Fragment() {
class ReactMapFragment @JvmOverloads constructor(private var overrideUri: Uri? = null) : Fragment() {
companion object {
private val filenameExtractor = "filename=(\"([^\"]+)\"|[^;]+)".toRegex(RegexOption.IGNORE_CASE)
private val vendorJsMatcher = "/vendor-[0-9a-f]{8}\\.js".toRegex()
Expand Down Expand Up @@ -81,7 +80,7 @@ class ReactMapFragment @JvmOverloads constructor(private val overrideUri: Uri? =
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Timber.d("Creating ReactMapFragment")
val activeUrl = overrideUri?.toString() ?: app.activeUrl
hostname = if (overrideUri == null) Uri.parse(activeUrl).host!! else overrideUri.host!!
hostname = (overrideUri ?: Uri.parse(activeUrl)).host!!
val activity = requireActivity()
web = WebView(activity).apply {
settings.apply {
Expand Down Expand Up @@ -229,6 +228,9 @@ class ReactMapFragment @JvmOverloads constructor(private val overrideUri: Uri? =
} catch (e: IOException) {
Timber.d(e)
null
} catch (e: IllegalArgumentException) {
Timber.d(e)
null
}
private fun handleSettings(request: WebResourceRequest) = buildResponse(request) { reader ->
val response = reader.readText()
Expand Down Expand Up @@ -272,24 +274,21 @@ class ReactMapFragment @JvmOverloads constructor(private val overrideUri: Uri? =
}

fun handleUri(uri: Uri?) = uri?.host?.let { host ->
viewLifecycleOwnerLiveData.observe(this, object : Observer<LifecycleOwner> {
override fun onChanged(value: LifecycleOwner) {
viewLifecycleOwnerLiveData.removeObserver(this)
Timber.d("Handling URI $uri")
if (host != hostname) {
hostname = host
return web.loadUrl(uri.toString())
}
val path = uri.path
if (path.isNullOrEmpty() || path == "/") return
val match = flyToMatcher.matchEntire(path) ?: return web.loadUrl(uri.toString())
val script = StringBuilder(
"window._hijackedMap.flyTo([${match.groupValues[1]}, ${match.groupValues[2]}]")
match.groups[3]?.let { script.append(", ${it.value}") }
script.append(')')
web.evaluateJavascript(script.toString(), null)
Timber.d("Handling URI $uri")
if (view == null) overrideUri = uri else {
if (host != hostname) {
hostname = host
return web.loadUrl(uri.toString())
}
})
val path = uri.path
if (path.isNullOrEmpty() || path == "/") return@let
val match = flyToMatcher.matchEntire(path) ?: return web.loadUrl(uri.toString())
val script = StringBuilder(
"window._hijackedMap.flyTo([${match.groupValues[1]}, ${match.groupValues[2]}]")
match.groups[3]?.let { script.append(", ${it.value}") }
script.append(')')
web.evaluateJavascript(script.toString(), null)
}
}
fun terminate() = web.destroy()
}
4 changes: 0 additions & 4 deletions app/src/main/res/raw/keep.xml

This file was deleted.

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android.enableResourceOptimizations=false
# If you want to support more domains, edit `app/src/main/AndroidManifest.xml`: find the line `<data android:host="${defaultDomain}" />` and add more domains by adding lines like `<data android:host="www.reactmap.dev" />`.
reactmap.defaultDomain=vip.pogofuerth.de
reactmap.packageName=be.mygod.reactmap
reactmap.versionCode=63
reactmap.versionName=0.6.2
reactmap.versionCode=64
reactmap.versionName=1.0.0

# Optional ReactMap settings
# If you need translations, you should edit the strings.xml instead of using this
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
activity = "1.8.1"
agp = "8.3.0-alpha14"
agp = "8.3.0-alpha16"
androidx-test-ext-junit = "1.1.5"
browser = "1.7.0"
browser = "1.8.0-beta01"
core = "1.12.0"
crashlytics = "2.9.9"
desugar = "2.0.4"
Expand All @@ -16,7 +16,7 @@ lifecycle = "2.7.0-rc01"
google-services = "4.4.0"
play-services-location = "21.0.1"
timber = "5.0.1"
work = "2.9.0-rc01"
work = "2.9.0"
gradle-versions = "0.50.0"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 5490642

Please sign in to comment.