From 645b9f3540fb924d5914e9c556820d58116ceb2c Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Mon, 21 Oct 2019 22:27:13 +0200 Subject: [PATCH] Add refresh layout to WebViewActivty with share and actualize menu items --- .../readrops/app/activities/ItemActivity.java | 2 +- .../app/activities/WebViewActivity.kt | 24 +++++++++++++++++++ app/src/main/res/drawable/ic_refresh.xml | 5 ++++ app/src/main/res/layout/activity_web_view.xml | 19 ++++++++++----- app/src/main/res/menu/item_menu.xml | 2 +- app/src/main/res/menu/webview_menu.xml | 17 +++++++++++++ app/src/main/res/values-fr-rFR/strings.xml | 4 +++- app/src/main/res/values/strings.xml | 4 +++- 8 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/ic_refresh.xml create mode 100644 app/src/main/res/menu/webview_menu.xml diff --git a/app/src/main/java/com/readrops/app/activities/ItemActivity.java b/app/src/main/java/com/readrops/app/activities/ItemActivity.java index e92058bd..956191d6 100644 --- a/app/src/main/java/com/readrops/app/activities/ItemActivity.java +++ b/app/src/main/java/com/readrops/app/activities/ItemActivity.java @@ -242,6 +242,6 @@ public class ItemActivity extends AppCompatActivity { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, itemWithFeed.getItem().getTitle() + " - " + itemWithFeed.getItem().getLink()); - startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); + startActivity(Intent.createChooser(shareIntent, getString(R.string.share_article))); } } diff --git a/app/src/main/java/com/readrops/app/activities/WebViewActivity.kt b/app/src/main/java/com/readrops/app/activities/WebViewActivity.kt index 28dc1acd..62e2d43c 100644 --- a/app/src/main/java/com/readrops/app/activities/WebViewActivity.kt +++ b/app/src/main/java/com/readrops/app/activities/WebViewActivity.kt @@ -1,9 +1,11 @@ package com.readrops.app.activities import android.annotation.SuppressLint +import android.content.Intent import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle +import android.view.Menu import android.view.MenuItem import android.webkit.WebResourceRequest import android.webkit.WebSettings @@ -30,6 +32,8 @@ class WebViewActivity : AppCompatActivity() { supportActionBar?.setBackgroundDrawable(ColorDrawable(actionBarColor)) setWebViewSettings() + binding.activityWebViewSwipe.setOnRefreshListener { binding.webView.reload() } + val url: String = intent.getStringExtra(WEB_URL) binding.webView.loadUrl(url) } @@ -51,8 +55,10 @@ class WebViewActivity : AppCompatActivity() { title = view?.title supportActionBar?.subtitle = Uri.parse(view?.url).host + binding.activityWebViewSwipe.isRefreshing = false super.onPageFinished(view, url) } + } } @@ -72,11 +78,29 @@ class WebViewActivity : AppCompatActivity() { finish() return true } + R.id.web_view_refresh -> { + binding.webView.reload() + } + R.id.web_view_share -> { + shareLink() + } } return super.onOptionsItemSelected(item) } + private fun shareLink() { + val intent = Intent(Intent.ACTION_SEND) + intent.type = "text/plain" + intent.putExtra(Intent.EXTRA_TEXT, binding.webView.url.toString()) + startActivity(Intent.createChooser(intent, getString(R.string.share_url))) + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.webview_menu, menu) + return true + } + companion object { const val WEB_URL = "webUrl" const val ACTION_BAR_COLOR = "actionBarColor" diff --git a/app/src/main/res/drawable/ic_refresh.xml b/app/src/main/res/drawable/ic_refresh.xml new file mode 100644 index 00000000..cc2d1e04 --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_web_view.xml b/app/src/main/res/layout/activity_web_view.xml index 2c99a076..0f065b19 100644 --- a/app/src/main/res/layout/activity_web_view.xml +++ b/app/src/main/res/layout/activity_web_view.xml @@ -21,16 +21,23 @@ - + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> - - + android:layout_height="match_parent"> + + + + + diff --git a/app/src/main/res/menu/item_menu.xml b/app/src/main/res/menu/item_menu.xml index c13d4645..65d0db12 100644 --- a/app/src/main/res/menu/item_menu.xml +++ b/app/src/main/res/menu/item_menu.xml @@ -10,7 +10,7 @@ diff --git a/app/src/main/res/menu/webview_menu.xml b/app/src/main/res/menu/webview_menu.xml new file mode 100644 index 00000000..5910fadd --- /dev/null +++ b/app/src/main/res/menu/webview_menu.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index 62e0ee82..635aa8d0 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -20,7 +20,7 @@ %1$s min Moins d\'une minute 1 min - Partager l\'article + Partager l\'article Ouvrir le lien Ajouter un dossier Dossier du flux @@ -91,5 +91,7 @@ Ouvrir les articles avec Vue web Navigateur externe + Actualiser + Partager le lien \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c5061624..266784d7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,7 +22,7 @@ Less than a minute 1 min ยท - Share Article + Share Article Open url Add folder Feed folder @@ -99,4 +99,6 @@ Open items in Webview External navigator + Actualize + Share url