Add a WebView for those who do not have Chrome installed.

This commit is contained in:
Alex Ning 2021-03-11 22:08:27 +08:00
parent 231530c6eb
commit 2d4b308e39
20 changed files with 243 additions and 20 deletions

View File

@ -32,7 +32,13 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
<activity android:name=".activities.SuicidePreventionActivity"
<activity
android:name=".activities.WebViewActivity"
android:label=""
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.SuicidePreventionActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity

View File

@ -53,6 +53,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity;
import ml.docilealligator.infinityforreddit.activities.WebViewActivity;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
import ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.fragments.FollowedUsersListingFragment;
@ -254,4 +255,6 @@ public interface AppComponent {
void inject(ViewPostDetailFragment viewPostDetailFragment);
void inject(SuicidePreventionActivity suicidePreventionActivity);
void inject(WebViewActivity webViewActivity);
}

View File

@ -20,9 +20,9 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class LinkResolverActivity extends AppCompatActivity {
@ -264,7 +264,7 @@ public class LinkResolverActivity extends AppCompatActivity {
if (handleError) {
openInCustomTabs(uri, pm, false);
} else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
openInWebView(uri);
}
}
}
@ -312,15 +312,21 @@ public class LinkResolverActivity extends AppCompatActivity {
if (handleError) {
openInBrowser(uri, pm, false);
} else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
openInWebView(uri);
}
}
} else {
if (handleError) {
openInBrowser(uri, pm, false);
} else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
openInWebView(uri);
}
}
}
private void openInWebView(Uri uri) {
Intent intent = new Intent(this, WebViewActivity.class);
intent.setData(uri);
startActivity(intent);
}
}

View File

@ -0,0 +1,173 @@
package ml.docilealligator.infinityforreddit.activities;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.InflateException;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.r0adkll.slidr.Slidr;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LollipopBugFixedWebView;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class WebViewActivity extends BaseActivity {
@BindView(R.id.coordinator_layout_web_view_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_web_view_activity)
AppBarLayout appBarLayout;
@BindView(R.id.toolbar_web_view_activity)
Toolbar toolbar;
@BindView(R.id.web_view_web_view_activity)
LollipopBugFixedWebView webView;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
private String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.activity_web_view);
} catch (InflateException ie) {
Log.e("LoginActivity", "Failed to inflate LoginActivity: " + ie.getMessage());
Toast.makeText(WebViewActivity.this, R.string.no_system_webview_error, Toast.LENGTH_SHORT).show();
finish();
return;
}
ButterKnife.bind(this);
applyCustomTheme();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
Slidr.attach(this);
}
setSupportActionBar(toolbar);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
url = getIntent().getDataString();
toolbar.setTitle(url);
webView.loadUrl(url);
WebViewClient client = new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
WebViewActivity.this.url = url;
toolbar.setTitle(url);
}
@Override
public void onPageFinished(WebView view, String url) {
toolbar.setTitle(view.getTitle());
}
};
webView.setWebViewClient(client);
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
Drawable closeIcon = Utils.getTintedDrawable(this, R.drawable.ic_close_black_24dp, mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
toolbar.setNavigationIcon(closeIcon);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.web_view_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.action_share_link_web_view_activity) {
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(intent, getString(R.string.share)));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show();
}
return true;
} else if (item.getItemId() == R.id.action_copy_link_web_view_activity) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newPlainText("simple text", url);
clipboard.setPrimaryClip(clip);
Toast.makeText(this, R.string.copy_success, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, R.string.copy_link_failed, Toast.LENGTH_SHORT).show();
}
return true;
}
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (webView.canGoBack()) {
webView.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}

View File

@ -42,8 +42,7 @@
<ml.docilealligator.infinityforreddit.customviews.LollipopBugFixedWebView
android:id="@+id/webview_login_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="@+id/coordinator_layout_web_view_activity"
tools:context=".activities.WebViewActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_web_view_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_web_view_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" />
</com.google.android.material.appbar.AppBarLayout>
<ml.docilealligator.infinityforreddit.customviews.LollipopBugFixedWebView
android:id="@+id/web_view_web_view_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_share_link_web_view_activity"
android:orderInCategory="1"
android:title="@string/action_share_link"
app:showAsAction="never" />
<item
android:id="@+id/action_copy_link_web_view_activity"
android:orderInCategory="2"
android:title="@string/action_copy_link"
app:showAsAction="never" />
</menu>

View File

@ -212,7 +212,6 @@
<string name="sort_time_month">"Monat"</string>
<string name="sort_time_year">"Jahr"</string>
<string name="sort_time_all_time">"Gesamter Zeitraum"</string>
<string name="no_browser_found">"Kein Browser gefunden"</string>
<string name="no_activity_found_for_share">"Es gibt keine App, die diese Teilen-Aktion unterstützt"</string>
<string name="archived_post_vote_unavailable">"Archivierter Beitrag. Abstimmung nicht verfügbar."</string>
<string name="archived_post_comment_unavailable">"Archivierter Beitrag. Kommentieren nicht verfügbar."</string>

View File

@ -214,7 +214,6 @@ Toca para reintentar."</string>
<string name="sort_time_month">"Mes"</string>
<string name="sort_time_year">"Año"</string>
<string name="sort_time_all_time">"Todo el tiempo"</string>
<string name="no_browser_found">"No se encontró un navegador"</string>
<string name="no_activity_found_for_share">"No se encontró ninguna aplicación para compartir"</string>
<string name="archived_post_vote_unavailable">"Publicación archivada. Votar no está disponible"</string>
<string name="archived_post_comment_unavailable">"Publicación archivada. Comentar no está disponible "</string>

View File

@ -225,7 +225,6 @@ Appuyez pour réessayer."</string>
<string name="sort_time_month">"Mois"</string>
<string name="sort_time_year">"Année"</string>
<string name="sort_time_all_time">"Tout le temps"</string>
<string name="no_browser_found">"Aucun navigatuer trouvé"</string>
<!-- Fuzzy -->
<string name="no_activity_found_for_share">"Il n'y a pas d'application qui peut gérer l'action de partage"</string>

View File

@ -234,7 +234,6 @@ Behavior -->
<!-- I translated it to 'timeless' or 'irrelevant of time'. -->
<string name="sort_time_all_time">"असामयिक"</string>
<string name="no_browser_found">"कोई ब्राउजर नहीं मिला"</string>
<string name="no_activity_found_for_share">"कोई ऐसी एप्प उपलब्ध नहीं है जो साझा कर सके "</string>
<string name="archived_post_vote_unavailable">"संग्रहित पोस्ट। वोट अनुपलब्ध।"</string>
<string name="archived_post_comment_unavailable">"संग्रहित पोस्ट। टिप्पणी अनुपलब्ध।"</string>

View File

@ -211,7 +211,6 @@
<string name="sort_time_month">"Mjesec"</string>
<string name="sort_time_year">"Godina"</string>
<string name="sort_time_all_time">"Svo vrijeme"</string>
<string name="no_browser_found">"Preglednik nije pronađen"</string>
<string name="no_activity_found_for_share">"Nema aplikacije koja može podijeliti ovo"</string>
<string name="archived_post_vote_unavailable">"Arhivirana objava. Glasanje nedostupno."</string>
<string name="archived_post_comment_unavailable">"Arhivirana objava. Komentiranje nedostupno."</string>

View File

@ -218,7 +218,6 @@ Clicca per riprovare."</string>
<string name="sort_time_month">"Mese"</string>
<string name="sort_time_year">"Anno"</string>
<string name="sort_time_all_time">"Sempre"</string>
<string name="no_browser_found">"Nessun browser trovato"</string>
<string name="no_activity_found_for_share">"Non esiste un'app in grado di gestire l'azione di condivisione"</string>
<string name="archived_post_vote_unavailable">"Post archiviato. Non è possibile votare."</string>
<string name="archived_post_comment_unavailable">"Post archiviato. Non è possibile commentare."</string>

View File

@ -236,7 +236,6 @@
<string name="sort_time_month">"1ヶ月"</string>
<string name="sort_time_year">"1年"</string>
<string name="sort_time_all_time">"全て"</string>
<string name="no_browser_found">"ブラウザが見つかりませんでした"</string>
<string name="no_activity_found_for_share">"共有に使用できるアプリが見つかりませんでした"</string>
<string name="archived_post_vote_unavailable">"アーカイブされた投稿です。評価は無効です。"</string>
<string name="archived_post_comment_unavailable">"アーカイブされた投稿です。コメントは無効です。"</string>

View File

@ -205,7 +205,6 @@
<string name="sort_time_month">Maand</string>
<string name="sort_time_year">Jaar</string>
<string name="sort_time_all_time">Aller Tijden</string>
<string name="no_browser_found">Geen browser gevonden</string>
<string name="no_activity_found_for_share">Er is geen app die de deelactie aankan</string>
<string name="archived_post_vote_unavailable">Gearchiveerd post. Stem niet beschikbaar.</string>
<string name="archived_post_comment_unavailable">Gearchiveerd post. Opmerking niet beschikbaar.</string>

View File

@ -210,7 +210,6 @@
<string name="sort_time_month">"Miesiąc"</string>
<string name="sort_time_year">"Rok"</string>
<string name="sort_time_all_time">"Od początku"</string>
<string name="no_browser_found">"Nie znaleziono przeglądarki"</string>
<string name="no_activity_found_for_share">"Brak aplikacji zdolnej do udostępnienia"</string>
<string name="archived_post_vote_unavailable">"Post zarchiwizowany. Nie można dać upvote."</string>
<string name="archived_post_comment_unavailable">"Post zarchiwizowany. Nie można skomentować."</string>

View File

@ -213,7 +213,6 @@ Toque para tentar novamente."</string>
<string name="sort_time_month">"Mês"</string>
<string name="sort_time_year">"Ano"</string>
<string name="sort_time_all_time">"Desde o começo"</string>
<string name="no_browser_found">"Nenhum navegador encontrado"</string>
<string name="no_activity_found_for_share">"Não há nenhum app que possa realizar a ação compartilhada"</string>
<string name="archived_post_vote_unavailable">"Post arquivado. Não é possível votar."</string>
<string name="archived_post_comment_unavailable">"Post arquivado. Não é possível comentar."</string>

View File

@ -220,7 +220,6 @@ Tekrar denemek için tıklayın."</string>
<string name="sort_time_month">"Ay"</string>
<string name="sort_time_year">"Yıl"</string>
<string name="sort_time_all_time">"Tüm Zamanlar"</string>
<string name="no_browser_found">"Tarayıcı bulunamadı"</string>
<string name="no_activity_found_for_share">"Paylaşma eylemini gerçekleştirebilecek uygulama yok"</string>
<string name="archived_post_vote_unavailable">"Arşivlenmiş gönderi. Oy kullanım dışı."</string>
<string name="archived_post_comment_unavailable">"Arşivlenmiş gönderi. Yorum kullanım dışı."</string>

View File

@ -218,7 +218,6 @@
<string name="sort_time_month">"月"</string>
<string name="sort_time_year">"年"</string>
<string name="sort_time_all_time">"所有时间"</string>
<string name="no_browser_found">"未找到浏览器"</string>
<string name="no_activity_found_for_share">"找不到共享的app"</string>
<string name="archived_post_vote_unavailable">"帖子已存档,无法投票"</string>
<string name="archived_post_comment_unavailable">"帖子已存档,无法评论"</string>

View File

@ -79,6 +79,8 @@
<string name="action_save_to_database">Save to Database</string>
<string name="action_read_all_messages">Read All Messages</string>
<string name="action_add_to_multireddit">Add to Multireddit</string>
<string name="action_share_link">Share Link</string>
<string name="action_copy_link">Copy Link</string>
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
<string name="retrieve_token_error">Error Retrieving the token</string>
@ -256,7 +258,6 @@
<string name="sort_time_year">Year</string>
<string name="sort_time_all_time">All Time</string>
<string name="no_browser_found">No browser found</string>
<string name="no_activity_found_for_share">There is no app that can handle the share action</string>
<string name="archived_post_vote_unavailable">Archived post. Vote unavailable.</string>