aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java173
3 files changed, 186 insertions, 4 deletions
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