mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-22 11:06:05 -06:00
Add full panic mode (#2569)
This commit is contained in:
parent
c7afa262d9
commit
e971eb7821
@ -191,7 +191,7 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.wulkanowy:sdk:2.6.10'
|
||||
implementation 'io.github.wulkanowy:sdk:2.6.11-SNAPSHOT'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
|
||||
|
||||
|
@ -30,6 +30,7 @@ import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.message.MessageFragment
|
||||
import io.github.wulkanowy.ui.modules.notificationscenter.NotificationsCenterFragment
|
||||
import io.github.wulkanowy.ui.modules.panicmode.PanicModeFragment
|
||||
import io.github.wulkanowy.ui.modules.schoolannouncement.SchoolAnnouncementFragment
|
||||
import io.github.wulkanowy.ui.modules.timetable.TimetableFragment
|
||||
import io.github.wulkanowy.utils.capitalise
|
||||
@ -241,6 +242,10 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
|
||||
requireContext().openInternetBrowser(url)
|
||||
}
|
||||
|
||||
override fun openPanicWebView(url: String) {
|
||||
(requireActivity() as MainActivity).pushView(PanicModeFragment.newInstance(url))
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
dashboardAdapter.clearTimers()
|
||||
presenter.onDetachView()
|
||||
|
@ -296,7 +296,7 @@ class DashboardPresenter @Inject constructor(
|
||||
.build()
|
||||
.toString()
|
||||
|
||||
view?.openInternetBrowser(urlToOpen)
|
||||
view?.openPanicWebView(urlToOpen)
|
||||
}
|
||||
.launch("panic_button")
|
||||
}
|
||||
|
@ -31,4 +31,6 @@ interface DashboardView : BaseView {
|
||||
fun openNotificationsCenterView()
|
||||
|
||||
fun openInternetBrowser(url: String)
|
||||
|
||||
fun openPanicWebView(url: String)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.message.MessageFragment
|
||||
import io.github.wulkanowy.ui.modules.message.mailboxchooser.MailboxChooserDialog
|
||||
import io.github.wulkanowy.ui.modules.message.preview.MessagePreviewFragment
|
||||
import io.github.wulkanowy.ui.modules.panicmode.PanicModeFragment
|
||||
import io.github.wulkanowy.ui.widgets.DividerItemDecoration
|
||||
import io.github.wulkanowy.utils.dpToPx
|
||||
import io.github.wulkanowy.utils.getThemeAttrColor
|
||||
@ -132,6 +133,7 @@ class MessageTabFragment : BaseFragment<FragmentMessageTabBinding>(R.layout.frag
|
||||
)
|
||||
messageTabErrorRetry.setOnClickListener { presenter.onRetry() }
|
||||
messageTabErrorDetails.setOnClickListener { presenter.onDetailsClick() }
|
||||
messageTabPanicSection.dashboardPanicButton.setOnClickListener { presenter.onPanicButtonClicked() }
|
||||
}
|
||||
|
||||
setFragmentResultListener(requireArguments().getString(MESSAGE_TAB_FOLDER_ID)!!) { _, bundle ->
|
||||
@ -283,6 +285,10 @@ class MessageTabFragment : BaseFragment<FragmentMessageTabBinding>(R.layout.frag
|
||||
)
|
||||
}
|
||||
|
||||
override fun openPanicWebView(url: String) {
|
||||
(requireActivity() as MainActivity).pushView(PanicModeFragment.newInstance(url))
|
||||
}
|
||||
|
||||
override fun hideKeyboard() {
|
||||
activity?.hideSoftInput()
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import me.xdrop.fuzzywuzzy.FuzzySearch
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.pow
|
||||
@ -429,4 +430,20 @@ class MessageTabPresenter @Inject constructor(
|
||||
+ dateRatio.toDouble().pow(2) * 2
|
||||
).toInt()
|
||||
}
|
||||
|
||||
fun onPanicButtonClicked() {
|
||||
resourceFlow { studentRepository.getCurrentStudent() }
|
||||
.onResourceError { errorHandler.dispatch(it) }
|
||||
.onResourceSuccess {
|
||||
val baseUrl = it.scrapperBaseUrl.toHttpUrl()
|
||||
val urlToOpen = baseUrl.newBuilder()
|
||||
.host("uonetplus${it.scrapperDomainSuffix}-wiadomosciplus.${baseUrl.host}")
|
||||
.addPathSegment(it.symbol)
|
||||
.build()
|
||||
.toString()
|
||||
|
||||
view?.openPanicWebView(urlToOpen)
|
||||
}
|
||||
.launch("panic_button")
|
||||
}
|
||||
}
|
||||
|
@ -50,4 +50,6 @@ interface MessageTabView : BaseView {
|
||||
fun showRecyclerBottomPadding(show: Boolean)
|
||||
|
||||
fun showMailboxChooser(mailboxes: List<Mailbox>)
|
||||
|
||||
fun openPanicWebView(url: String)
|
||||
}
|
||||
|
@ -0,0 +1,99 @@
|
||||
package io.github.wulkanowy.ui.modules.panicmode
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.activity.addCallback
|
||||
import androidx.core.os.bundleOf
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||
import io.github.wulkanowy.databinding.FragmentPanicModeBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class PanicModeFragment : BaseFragment<FragmentPanicModeBinding>(R.layout.fragment_panic_mode),
|
||||
MainView.TitledView {
|
||||
|
||||
@Inject
|
||||
lateinit var wulkanowySdkFactory: WulkanowySdkFactory
|
||||
|
||||
@Inject
|
||||
lateinit var webkitCookieManagerProxy: WebkitCookieManagerProxy
|
||||
|
||||
private var webView: WebView? = null
|
||||
|
||||
override val titleStringId: Int get() = R.string.panic_mode_title
|
||||
|
||||
companion object {
|
||||
|
||||
private const val PANIC_URL = "panic_mode_url"
|
||||
fun newInstance(url: String?): PanicModeFragment {
|
||||
return PanicModeFragment().apply {
|
||||
arguments = bundleOf(PANIC_URL to url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding = FragmentPanicModeBinding.bind(view)
|
||||
|
||||
binding.panicModeRefresh.setOnClickListener {
|
||||
binding.panicModeWebview.loadUrl(
|
||||
binding.panicModeWebview.url ?: arguments?.getString(PANIC_URL).orEmpty()
|
||||
)
|
||||
}
|
||||
binding.panicModeBack.setOnClickListener { binding.panicModeWebview.goBack() }
|
||||
binding.panicModeHome.setOnClickListener {
|
||||
binding.panicModeWebview.loadUrl(
|
||||
arguments?.getString(PANIC_URL).orEmpty()
|
||||
)
|
||||
}
|
||||
binding.panicModeForward.setOnClickListener { binding.panicModeWebview.goForward() }
|
||||
binding.panicModeShare.setOnClickListener {
|
||||
requireContext().openInternetBrowser(
|
||||
binding.panicModeWebview.url.toString(),
|
||||
)
|
||||
}
|
||||
|
||||
val onBackPressedCallback = requireActivity().onBackPressedDispatcher
|
||||
.addCallback(viewLifecycleOwner) {
|
||||
binding.panicModeWebview.goBack()
|
||||
}
|
||||
|
||||
with(binding.panicModeWebview) {
|
||||
webView = this
|
||||
with(settings) {
|
||||
javaScriptEnabled = true
|
||||
userAgentString = wulkanowySdkFactory.createBase().userAgent
|
||||
}
|
||||
|
||||
webViewClient = object : WebViewClient() {
|
||||
override fun doUpdateVisitedHistory(
|
||||
view: WebView?,
|
||||
url: String?,
|
||||
isReload: Boolean
|
||||
) {
|
||||
binding.panicModeBack.isEnabled = binding.panicModeWebview.canGoBack()
|
||||
binding.panicModeForward.isEnabled = binding.panicModeWebview.canGoForward()
|
||||
onBackPressedCallback.isEnabled = binding.panicModeWebview.canGoBack()
|
||||
}
|
||||
}
|
||||
loadUrl(arguments?.getString(PANIC_URL).orEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
webkitCookieManagerProxy.webkitCookieManager?.flush()
|
||||
webView?.destroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
@ -60,6 +60,16 @@
|
||||
tools:ignore="UseCompoundDrawables"
|
||||
tools:visibility="invisible">
|
||||
|
||||
<include
|
||||
android:id="@+id/message_tab_panic_section"
|
||||
layout="@layout/item_dashboard_panic_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="16dp"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintTop_toBottomOf="@id/dashboard_error_admin_message" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
|
69
app/src/main/res/layout/fragment_panic_mode.xml
Normal file
69
app/src/main/res/layout/fragment_panic_mode.xml
Normal file
@ -0,0 +1,69 @@
|
||||
<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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.modules.panicmode.PanicModeFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?colorControlHighlight">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/panic_mode_share"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
app:icon="@drawable/ic_share"
|
||||
app:iconTint="?colorOnSurface" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/panic_mode_home"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
app:icon="@drawable/ic_all_home"
|
||||
app:iconTint="?colorOnSurface" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/panic_mode_refresh"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:contentDescription="@string/logviewer_refresh"
|
||||
app:icon="@drawable/ic_refresh"
|
||||
app:iconTint="?colorOnSurface" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/panic_mode_back"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
app:icon="@drawable/ic_chevron_left"
|
||||
app:iconTint="?colorOnSurface" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/panic_mode_forward"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
app:icon="@drawable/ic_chevron_right"
|
||||
app:iconTint="?colorOnSurface" />
|
||||
</LinearLayout>
|
||||
|
||||
<WebView
|
||||
android:id="@+id/panic_mode_webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</LinearLayout>
|
@ -872,6 +872,8 @@
|
||||
<string name="captcha_dialog_title">Strona dziennika VULCAN wymaga weryfikacji</string>
|
||||
<string name="captcha_dialog_description"><b>Dlaczego to widzę?</b>\nStrona internetowa dziennika, z której Wulkanowy pobiera dane, wyświetla ten sam ekran jak powyżej, więc Wulkanowy musi również ją pokazać, aby móc pobrać dane z tej witryny. Nie da się tego obejść</string>
|
||||
<string name="captcha_verified_message">Pomyślnie zweryfikowano</string>
|
||||
<!--Panic mode-->
|
||||
<string name="panic_mode_title">Awaryjny dostęp</string>
|
||||
<!--Errors-->
|
||||
<string name="error_no_internet">Brak połączenia z internetem</string>
|
||||
<string name="error_invalid_device_datetime">Wystąpił błąd. Sprawdź poprawność daty w urządzeniu</string>
|
||||
|
@ -869,6 +869,9 @@
|
||||
<string name="captcha_dialog_description"><b>Why am I seeing this?</b>\nThe register website from which Wulkanowy downloads data displays the same screen as above, so Wulkanowy must also show it to be able to download data from this website. There\'s no way around it</string>
|
||||
<string name="captcha_verified_message">Verified successfully</string>
|
||||
|
||||
<!--Panic mode-->
|
||||
<string name="panic_mode_title">Emergency access</string>
|
||||
|
||||
|
||||
<!--Errors-->
|
||||
<string name="error_no_internet">No internet connection</string>
|
||||
|
Loading…
Reference in New Issue
Block a user