diff options
Diffstat (limited to 'app')
20 files changed, 243 insertions, 20 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e93c9c10..29a65fea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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 diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 78e661ee..8fa5d081 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -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); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index 6a76497b..db96c96e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -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); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java new file mode 100644 index 00000000..54106401 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java @@ -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); + } +}
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 2452a367..4c4d3e9f 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -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> diff --git a/app/src/main/res/layout/activity_web_view.xml b/app/src/main/res/layout/activity_web_view.xml new file mode 100644 index 00000000..36fd3f06 --- /dev/null +++ b/app/src/main/res/layout/activity_web_view.xml @@ -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>
\ No newline at end of file diff --git a/app/src/main/res/menu/web_view_activity.xml b/app/src/main/res/menu/web_view_activity.xml new file mode 100644 index 00000000..ad064161 --- /dev/null +++ b/app/src/main/res/menu/web_view_activity.xml @@ -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>
\ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 3368e0bc..c405ace2 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -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> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index b9a5e7b9..8b3a7dc8 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -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> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 87e351b7..f51f28cc 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -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> diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 3353c3fe..f3ea32bd 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -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> diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 306d9802..eaa6d80f 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -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> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 59e82ed3..ee8edb6d 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -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> diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 706ffd70..3644aafb 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -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> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 7a75292a..128e0f2e 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -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> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 4fe0ac4f..92837f0e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -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> diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 5aa3a923..2bf69360 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -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> diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index a607773a..485d3d66 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -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> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 85441699..3e85b7c7 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -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> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3295d811..6a5a6c85 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -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> |