Cleanup + pull to refresh on web view

This commit is contained in:
Jay 2020-01-13 01:05:04 -08:00
parent d4ae7d2825
commit 4b8373367b
4 changed files with 28 additions and 14 deletions

View File

@ -8,14 +8,12 @@ import android.graphics.Bitmap
import android.graphics.Color import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.PersistableBundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.webkit.WebView import android.webkit.WebView
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
@ -98,6 +96,9 @@ class WebViewActivity : BaseActivity() {
0, insets.systemWindowInsetBottom 0, insets.systemWindowInsetBottom
) )
} }
swipe_refresh.setOnRefreshListener {
refreshPage()
}
content.setOnApplyWindowInsetsListener { v, insets -> content.setOnApplyWindowInsetsListener { v, insets ->
window.statusBarColor = getResourceColor(R.attr.colorPrimary) window.statusBarColor = getResourceColor(R.attr.colorPrimary)
@ -122,6 +123,8 @@ class WebViewActivity : BaseActivity() {
insets insets
} }
swipe_refresh.isEnabled = false
if (bundle == null) { if (bundle == null) {
val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource ?: return val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource ?: return
val url = intent.extras!!.getString(URL_KEY) ?: return val url = intent.extras!!.getString(URL_KEY) ?: return
@ -136,11 +139,14 @@ class WebViewActivity : BaseActivity() {
super.onPageFinished(view, url) super.onPageFinished(view, url)
invalidateOptionsMenu() invalidateOptionsMenu()
title = view?.title title = view?.title
swipe_refresh.isEnabled = true
swipe_refresh?.isRefreshing = false
} }
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon) super.onPageStarted(view, url, favicon)
invalidateOptionsMenu() invalidateOptionsMenu()
//swipe_refresh.isEnabled = false
} }
} }
val marginB = webview.marginBottom val marginB = webview.marginBottom
@ -160,6 +166,10 @@ class WebViewActivity : BaseActivity() {
webview.restoreState(bundle) webview.restoreState(bundle)
} }
} }
private fun refreshPage() {
swipe_refresh.isRefreshing = true
webview.reload()
}
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)

View File

@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/web_view_layout" android:id="@+id/web_view_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"> android:fitsSystemWindows="true"
<LinearLayout android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:orientation="vertical" android:orientation="vertical"
android:id="@+id/web_linear_layout" android:id="@+id/web_linear_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:fitsSystemWindows="true" android:layout_height="wrap_content">
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
@ -23,10 +26,14 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@id/swipe_refresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView <WebView
android:id="@+id/webview" android:id="@+id/webview"
@ -35,4 +42,6 @@
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -161,7 +161,6 @@
<string name="services">Services</string> <string name="services">Services</string>
<!-- Advanced section --> <!-- Advanced section -->
<string name="used_cache">Utilisé : %1$s</string> <string name="used_cache">Utilisé : %1$s</string>
<string name="cache_deleted">Cache effacé. %1$d fichiers ont été supprimés</string>
<string name="cache_delete_error">Une erreur est survenue lors de l\'effacement du cache</string> <string name="cache_delete_error">Une erreur est survenue lors de l\'effacement du cache</string>
<string name="pref_clear_cookies">Effacer cookies</string> <string name="pref_clear_cookies">Effacer cookies</string>
<string name="cookies_cleared">Cookies effacés</string> <string name="cookies_cleared">Cookies effacés</string>
@ -363,7 +362,6 @@
<string name="backup_choice">Que voulez-vous sauvegarder ?</string> <string name="backup_choice">Que voulez-vous sauvegarder ?</string>
<string name="invalid_combination">Le défaut ne peut pas être selectionné avec des autres catégories</string> <string name="invalid_combination">Le défaut ne peut pas être selectionné avec des autres catégories</string>
<string name="delete_downloads_for_manga">Supprimer les chapitres téléchargés ?</string> <string name="delete_downloads_for_manga">Supprimer les chapitres téléchargés ?</string>
<string name="notification_new_chapters_text">Pour %1$d chapitres</string>
<string name="track">Suivi</string> <string name="track">Suivi</string>
<string name="action_sort_total">Nombre de chapitres</string> <string name="action_sort_total">Nombre de chapitres</string>
<string name="short_recent_updates">Mises à jour</string> <string name="short_recent_updates">Mises à jour</string>
@ -478,16 +476,12 @@ Assurez-vous que vous êtes connecté à des sources qui le demande avant de com
<string name="filter_mode_overlay">Interface</string> <string name="filter_mode_overlay">Interface</string>
<string name="label_help">Aide</string> <string name="label_help">Aide</string>
<string name="pref_library_update_prioritization">Ordre de mise à jour de la librairie</string> <string name="pref_library_update_prioritization">Ordre de mise à jour de la librairie</string>
<string name="pref_library_update_prioritization_summary">Sélectionnez l\'ordre auquel Tachiyomi doit vérifier les mises à jour</string>
<string name="system_theme">Par défaut système</string> <string name="system_theme">Par défaut système</string>
<string name="system_darkblue_theme">Par défaut système (Bleu foncé)</string> <string name="system_darkblue_theme">Par défaut système (Bleu foncé)</string>
<string name="system_amoled_theme">Par défaut système (AMOLED)</string> <string name="system_amoled_theme">Par défaut système (AMOLED)</string>
<string name="pref_library_update_prioritization">Ordre de mise à jour de la bibliothèque</string>
<string name="pref_library_update_prioritization_summary">Sélectionnez l\'ordre dans lequel Tachiyomi doit vérifier si des mises à jour sont disponibles</string>
<string name="filter_mode_lighten">Densité/Éclaircir</string> <string name="filter_mode_lighten">Densité/Éclaircir</string>
<string name="filter_mode_darken">Brûlé / Assombri</string> <string name="filter_mode_darken">Brûlé / Assombri</string>
<string name="action_forward">Suivant</string> <string name="action_webview_forward">Suivant</string>
<string name="action_refresh">Actualiser</string>
<string name="no_results_found">Aucun résultats trouvés</string> <string name="no_results_found">Aucun résultats trouvés</string>
<string name="migration_selection_prompt">Sélectionner une source depuis laquelle migrer</string> <string name="migration_selection_prompt">Sélectionner une source depuis laquelle migrer</string>
</resources> </resources>

View File

@ -168,6 +168,7 @@
<string name="pref_library_update_categories">Categories to include in global update</string> <string name="pref_library_update_categories">Categories to include in global update</string>
<string name="all">All</string> <string name="all">All</string>
<string name="pref_library_update_prioritization">Library update order</string> <string name="pref_library_update_prioritization">Library update order</string>
<string name="pref_library_update_prioritization_summary">Select the order in which Tachiyomi checks for update</string>
<string name="pref_library_update_restriction">Library update restrictions</string> <string name="pref_library_update_restriction">Library update restrictions</string>
<string name="pref_library_update_restriction_summary">Update only when the conditions are met</string> <string name="pref_library_update_restriction_summary">Update only when the conditions are met</string>
<string name="wifi">Wi-Fi</string> <string name="wifi">Wi-Fi</string>