summaryrefslogtreecommitdiff
path: root/org.fox.ttrss
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2015-11-30 04:29:36 +0300
committerAndrew Dolgov <[email protected]>2015-11-30 04:29:36 +0300
commit5205be67eb02330bcce2c9d6388d5a2d8c1d814e (patch)
treec4ccb3d6acbc5dfbadf34141e4cf87cebf08a2e9 /org.fox.ttrss
parent4b09961a303173eed338a3ef9f6974d2f932e120 (diff)
wip: add a dialog for opening link w/ chrome tabs or normally
Diffstat (limited to 'org.fox.ttrss')
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java83
-rwxr-xr-xorg.fox.ttrss/src/main/res/layout/dialog_open_link_askcb.xml14
-rwxr-xr-xorg.fox.ttrss/src/main/res/xml/preferences.xml11
3 files changed, 105 insertions, 3 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
index efef731d..76240781 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
@@ -2,8 +2,11 @@ package org.fox.ttrss;
import android.annotation.SuppressLint;
+import android.app.AlertDialog;
+import android.app.Dialog;
import android.app.PendingIntent;
import android.content.ComponentName;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
@@ -20,6 +23,8 @@ import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
+import android.view.View;
+import android.widget.CheckBox;
import android.widget.Toast;
import org.fox.ttrss.util.DatabaseHelper;
@@ -213,10 +218,8 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
});
}
- // uses chrome custom tabs when available
- public void openUri(Uri uri) {
+ private void openUriWithCustomTab(Uri uri) {
if (m_customTabClient != null) {
-
TypedValue tvBackground = new TypedValue();
getTheme().resolveAttribute(R.attr.colorPrimary, tvBackground, true);
@@ -240,6 +243,80 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
CustomTabsIntent intent = builder.build();
intent.launchUrl(this, uri);
+ }
+ }
+
+ // uses chrome custom tabs when available
+ public void openUri(final Uri uri) {
+ boolean enableCustomTabs = m_prefs.getBoolean("enable_custom_tabs", false);
+ final boolean askEveryTime = m_prefs.getBoolean("custom_tabs_ask_always", false);
+
+ if (enableCustomTabs && m_customTabClient != null) {
+
+ if (askEveryTime) {
+
+ View dialogView = View.inflate(this, R.layout.dialog_open_link_askcb, null);
+ final CheckBox askEveryTimeCB = (CheckBox) dialogView.findViewById(R.id.open_link_ask_checkbox);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(
+ CommonActivity.this)
+ .setTitle("Open link")
+ .setView(dialogView)
+ .setMessage(uri.toString())
+ .setPositiveButton("Quick preview",
+ new Dialog.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int which) {
+
+ if (!askEveryTimeCB.isChecked()) {
+ SharedPreferences.Editor editor = m_prefs.edit();
+ editor.putBoolean("custom_tabs_ask_always", false);
+ editor.apply();
+ }
+
+ openUriWithCustomTab(uri);
+
+ }
+ })
+ .setNegativeButton("Open with app",
+ new Dialog.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int which) {
+
+ if (!askEveryTimeCB.isChecked()) {
+ SharedPreferences.Editor editor = m_prefs.edit();
+ editor.putBoolean("custom_tabs_ask_always", false);
+ editor.putBoolean("enable_custom_tabs", false);
+ editor.apply();
+ }
+
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+
+ startActivity(intent);
+
+ }
+ });
+ /*.setNegativeButton(R.string.cancel,
+ new Dialog.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int which) {
+
+ if (!askEveryTimeCB.isChecked()) {
+ SharedPreferences.Editor editor = m_prefs.edit();
+ editor.putBoolean("custom_tabs_ask_always", false);
+ editor.apply();
+ }
+
+ }
+ });*/
+
+ AlertDialog dlg = builder.create();
+ dlg.show();
+
+ } else {
+ openUriWithCustomTab(uri);
+ }
+
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
diff --git a/org.fox.ttrss/src/main/res/layout/dialog_open_link_askcb.xml b/org.fox.ttrss/src/main/res/layout/dialog_open_link_askcb.xml
new file mode 100755
index 00000000..45fd2af5
--- /dev/null
+++ b/org.fox.ttrss/src/main/res/layout/dialog_open_link_askcb.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:layout_height="match_parent">
+
+ <CheckBox
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Ask me every time"
+ android:checked="true"
+ android:id="@+id/open_link_ask_checkbox" />
+</FrameLayout> \ No newline at end of file
diff --git a/org.fox.ttrss/src/main/res/xml/preferences.xml b/org.fox.ttrss/src/main/res/xml/preferences.xml
index e8fcdcb6..c9ffd79b 100755
--- a/org.fox.ttrss/src/main/res/xml/preferences.xml
+++ b/org.fox.ttrss/src/main/res/xml/preferences.xml
@@ -156,6 +156,17 @@
android:summary="@string/prefs_enable_fab_long"
android:title="@string/prefs_enable_fab" />
</PreferenceCategory>
+ <PreferenceCategory android:title="Opening links" >
+ <org.fox.ttrss.util.LessBrokenSwitchPreference
+ android:defaultValue="false"
+ android:key="enable_custom_tabs"
+ android:summary="Open external links with Chrome custom tabs (faster, used if available)"
+ android:title="Use quick preview" />
+ <org.fox.ttrss.util.LessBrokenSwitchPreference
+ android:defaultValue="false"
+ android:key="custom_tabs_ask_always"
+ android:title="Ask me every time" />
+ </PreferenceCategory>
<PreferenceCategory android:title="@string/offline_mode" >
<ListPreference
android:defaultValue="250"