Skip to content

Commit

Permalink
Merge pull request #10 from Mygod/master
Browse files Browse the repository at this point in the history
sync upstream 1.1
  • Loading branch information
acocalypso authored Jan 29, 2024
2 parents e156deb + 5242600 commit 5f6e509
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/be/mygod/reactmap/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import be.mygod.reactmap.util.DeviceStorageApp
import be.mygod.reactmap.util.UpdateChecker
import be.mygod.reactmap.webkit.SiteController
import com.google.android.gms.location.LocationServices
import com.google.android.material.color.DynamicColors
import com.google.firebase.FirebaseApp
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.DEBUG_PROPERTY_NAME
Expand Down Expand Up @@ -105,6 +106,7 @@ class App : Application() {
})
work = WorkManager.getInstance(deviceStorage)
BackgroundLocationReceiver.setup()
DynamicColors.applyToActivitiesIfAvailable(this)
}

val customTabsIntent by lazy {
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/java/be/mygod/reactmap/ConfigDialogFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import android.content.DialogInterface
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Parcelable
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.edit
import androidx.core.net.toUri
import be.mygod.reactmap.App.Companion.app
Expand All @@ -18,7 +17,7 @@ import be.mygod.reactmap.util.AlertDialogFragment
import be.mygod.reactmap.util.Empty
import be.mygod.reactmap.util.readableMessage
import be.mygod.reactmap.webkit.ReactMapHttpEngine
import com.google.android.material.materialswitch.MaterialSwitch
import com.google.android.material.textfield.MaterialAutoCompleteTextView
import kotlinx.parcelize.Parcelize

class ConfigDialogFragment : AlertDialogFragment<ConfigDialogFragment.Arg, Empty>() {
Expand All @@ -30,8 +29,8 @@ class ConfigDialogFragment : AlertDialogFragment<ConfigDialogFragment.Arg, Empty
data class Arg(val welcome: Boolean) : Parcelable

private lateinit var historyUrl: Set<String?>
private lateinit var urlEdit: AutoCompleteTextView
private lateinit var followerSwitch: MaterialSwitch
private lateinit var urlEdit: MaterialAutoCompleteTextView
private lateinit var followerSwitch: SwitchCompat

private val requestLocation = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
if (it.any { (_, v) -> v }) {
Expand Down Expand Up @@ -59,7 +58,7 @@ class ConfigDialogFragment : AlertDialogFragment<ConfigDialogFragment.Arg, Empty
historyUrl = app.pref.getStringSet(KEY_HISTORY_URL, null) ?: setOf("https://${BuildConfig.DEFAULT_DOMAIN}")
val context = requireContext()
urlEdit = findViewById(android.R.id.edit)!!
urlEdit.setAdapter(ArrayAdapter(context, android.R.layout.select_dialog_item, historyUrl.toTypedArray()))
urlEdit.setSimpleItems(historyUrl.toTypedArray())
urlEdit.setText(app.activeUrl)
followerSwitch = findViewById(android.R.id.switch_widget)!!
followerSwitch.isChecked = BackgroundLocationReceiver.enabled && (context.checkSelfPermission(
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/be/mygod/reactmap/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import android.system.Os
import android.system.OsConstants
import android.view.WindowManager
import android.webkit.WebView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.core.content.res.use
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.commit
import androidx.lifecycle.Lifecycle
Expand All @@ -28,6 +28,7 @@ import be.mygod.reactmap.util.UpdateChecker
import be.mygod.reactmap.util.readableMessage
import be.mygod.reactmap.webkit.ReactMapFragment
import com.google.android.material.materialswitch.MaterialSwitch
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -174,7 +175,8 @@ class MainActivity : FragmentActivity() {
} catch (e: Exception) {
Timber.w(e)
withContext(Dispatchers.Main) {
Toast.makeText(this@MainActivity, e.readableMessage, Toast.LENGTH_LONG).show()
Snackbar.make(currentFragment?.web ?: findViewById(android.R.id.content), e.readableMessage,
Snackbar.LENGTH_LONG).show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.coordinatorlayout.widget.CoordinatorLayout
Expand Down Expand Up @@ -61,7 +60,7 @@ class ReactMapFragment @JvmOverloads constructor(private var overrideUri: Uri? =
private val supportedHosts = setOf("discordapp.com", "discord.com", "telegram.org", "oauth.telegram.org")
}

private lateinit var web: WebView
lateinit var web: WebView
private lateinit var glocation: Glocation
private lateinit var siteController: SiteController
private lateinit var hostname: String
Expand Down Expand Up @@ -165,7 +164,7 @@ class ReactMapFragment @JvmOverloads constructor(private var overrideUri: Uri? =
true
}
"http".equals(parsed.scheme, true) -> {
Toast.makeText(view.context, R.string.error_https_only, Toast.LENGTH_SHORT).show()
Snackbar.make(view, R.string.error_https_only, Snackbar.LENGTH_SHORT).show()
true
}
else -> false
Expand Down Expand Up @@ -205,8 +204,8 @@ class ReactMapFragment @JvmOverloads constructor(private var overrideUri: Uri? =
}
setDownloadListener { url, _, contentDisposition, mimetype, _ ->
if (!url.startsWith("data:", true)) {
Toast.makeText(context, context.getString(R.string.error_unsupported_download, url),
Toast.LENGTH_LONG).show()
Snackbar.make(web, context.getString(R.string.error_unsupported_download, url),
Snackbar.LENGTH_LONG).show()
return@setDownloadListener
}
pendingJson = URLDecoder.decode(url.substringAfter(','), "utf-8")
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/dialog_config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
Expand All @@ -10,7 +9,7 @@
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@android:id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
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=64
reactmap.versionName=1.0.0
reactmap.versionCode=65
reactmap.versionName=1.1.0

# Optional ReactMap settings
# If you need translations, you should edit the strings.xml instead of using this
Expand Down

0 comments on commit 5f6e509

Please sign in to comment.