diff --git a/build.gradle b/build.gradle index a6efd41c5b..1e605fdbc0 100644 --- a/build.gradle +++ b/build.gradle @@ -87,6 +87,7 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.6.4' implementation 'com.google.guava:guava:28.2-android' implementation 'com.github.AppIntro:AppIntro:6.0.0' + implementation "androidx.browser:browser:1.3.0" implementation fileTree(include: ['libwebrtc-m85.aar'], dir: 'libs') } diff --git a/src/main/java/eu/siacs/conversations/ui/AboutActivity.java b/src/main/java/eu/siacs/conversations/ui/AboutActivity.java index cadfa2fb54..c6e88ef63b 100644 --- a/src/main/java/eu/siacs/conversations/ui/AboutActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/AboutActivity.java @@ -1,8 +1,8 @@ package eu.siacs.conversations.ui; -import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.text.SpannableStringBuilder; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; @@ -11,23 +11,24 @@ import java.util.Calendar; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; +import eu.siacs.conversations.ui.util.CustomTab; +import eu.siacs.conversations.ui.util.MyLinkify; import eu.siacs.conversations.utils.ThemeHelper; import me.drakeet.support.toast.ToastCompat; public class AboutActivity extends XmppActivity { - private Button privacyButton; - private Button termsOfUseButton; private TextView aboutmessage; + private TextView libraries; @Override protected void refreshUiReal() { - + showText(); } @Override void onBackendConnected() { - + showText(); } @Override @@ -37,30 +38,44 @@ public class AboutActivity extends XmppActivity { setContentView(R.layout.activity_about); setSupportActionBar(findViewById(R.id.toolbar)); configureActionBar(getSupportActionBar()); - aboutmessage = findViewById(R.id.aboutmessage); - String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); - aboutmessage.setText(getString(R.string.pref_about_message, year)); - - privacyButton = findViewById(R.id.show_privacy_policy); + libraries = findViewById(R.id.libraries); + Button privacyButton = findViewById(R.id.show_privacy_policy); privacyButton.setOnClickListener(view -> { try { final Uri uri = Uri.parse(Config.privacyURL); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(browserIntent); + CustomTab.openTab(this, uri, isDarkTheme()); } catch (Exception e) { ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); } }); - termsOfUseButton = findViewById(R.id.show_terms_of_use); + Button termsOfUseButton = findViewById(R.id.show_terms_of_use); termsOfUseButton.setOnClickListener(view -> { try { final Uri uri = Uri.parse(Config.termsOfUseURL); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(browserIntent); + CustomTab.openTab(this, uri, isDarkTheme()); } catch (Exception e) { ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); } }); } + + @Override + protected void onStart() { + super.onStart(); + showText(); + } + + private void showText() { + final String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); + SpannableStringBuilder aboutMessage = new SpannableStringBuilder(getString(R.string.pref_about_message, year)); + MyLinkify.addLinks(aboutMessage, false); + aboutmessage.setText(aboutMessage); + aboutmessage.setAutoLinkMask(0); + + SpannableStringBuilder libs = new SpannableStringBuilder(getString(R.string.pref_about_libraries)); + MyLinkify.addLinks(libs, false); + libraries.setText(libs); + libraries.setAutoLinkMask(0); + } } \ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java index 3ded1d1b46..c32eb3d8f5 100644 --- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java @@ -39,6 +39,7 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.http.NoSSLv3SocketFactory; import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.util.CustomTab; import eu.siacs.conversations.utils.WakeLockHelper; import me.drakeet.support.toast.ToastCompat; @@ -145,10 +146,12 @@ public class UpdaterActivity extends XmppActivity { startActivity(marketIntent); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } else { - uri = Uri.parse("https://" + blabber()); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(browserIntent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + try { + uri = Uri.parse("https://" + blabber()); + CustomTab.openTab(this, uri, isDarkTheme()); + } catch (Exception e) { + ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); + } } } else if (store != null && store.equalsIgnoreCase(FDroid)) { Uri uri = Uri.parse("https://f-droid.org/de/packages/" + getString(R.string.applicationId) + "/"); @@ -160,9 +163,11 @@ public class UpdaterActivity extends XmppActivity { overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } else { uri = Uri.parse("https://" + blabber()); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(browserIntent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + try { + CustomTab.openTab(this, uri, isDarkTheme()); + } catch (Exception e) { + ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); + } } } else { ToastCompat.makeText(getApplicationContext(), getText(R.string.download_started), Toast.LENGTH_LONG).show(); @@ -176,12 +181,9 @@ public class UpdaterActivity extends XmppActivity { .setNeutralButton(R.string.changelog, (dialog, id) -> { Uri uri = Uri.parse(Config.CHANGELOG_URL); // missing 'http://' will cause crash try { - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + CustomTab.openTab(this, uri, isDarkTheme()); } catch (Exception e) { - e.printStackTrace(); + ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); } finally { //restart updater to show dialog again after coming back after opening changelog recreate(); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 13eac9b4b7..5dfe6f825c 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -81,6 +81,7 @@ import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.UpdateService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; +import eu.siacs.conversations.ui.util.CustomTab; import eu.siacs.conversations.ui.util.PresenceSelector; import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.utils.AccountUtils; @@ -301,9 +302,11 @@ public abstract class XmppActivity extends ActionBarActivity { startActivity(marketIntent); } else { uri = Uri.parse("http://www.openkeychain.org/"); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(browserIntent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + try { + CustomTab.openTab(this, uri, isDarkTheme()); + } catch (Exception e) { + ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); + } } finish(); }); diff --git a/src/main/java/eu/siacs/conversations/ui/text/FixedURLSpan.java b/src/main/java/eu/siacs/conversations/ui/text/FixedURLSpan.java index 92c95b1c9f..75080bb9e4 100644 --- a/src/main/java/eu/siacs/conversations/ui/text/FixedURLSpan.java +++ b/src/main/java/eu/siacs/conversations/ui/text/FixedURLSpan.java @@ -32,9 +32,7 @@ package eu.siacs.conversations.ui.text; import android.annotation.SuppressLint; import android.content.ActivityNotFoundException; import android.content.Context; -import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.text.Editable; import android.text.Spanned; import android.text.style.URLSpan; @@ -46,6 +44,8 @@ import java.util.Arrays; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.ui.ConversationsActivity; +import eu.siacs.conversations.ui.util.CustomTab; +import eu.siacs.conversations.utils.ThemeHelper; import me.drakeet.support.toast.ToastCompat; @SuppressLint("ParcelCreator") @@ -75,13 +75,8 @@ public class FixedURLSpan extends URLSpan { return; } } - final Intent intent = new Intent(Intent.ACTION_VIEW, uri); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); - } - //intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); try { - context.startActivity(intent); + CustomTab.openTab(context, uri, ThemeHelper.isDark(ThemeHelper.find(context))); widget.playSoundEffect(0); } catch (ActivityNotFoundException e) { ToastCompat.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); diff --git a/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java b/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java index befdf9fe38..87a8c14e67 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java @@ -2,7 +2,6 @@ package eu.siacs.conversations.ui.util; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -24,6 +23,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.ui.ConversationsActivity; import eu.siacs.conversations.ui.WelcomeActivity; +import eu.siacs.conversations.utils.ThemeHelper; import me.drakeet.support.toast.ToastCompat; public class UpdateHelper { @@ -78,8 +78,10 @@ public class UpdateHelper { SaveMessageShown(activity, blabber_message); try { final Uri uri = Uri.parse(Config.migrationURL); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); - activity.startActivity(browserIntent); + try {CustomTab.openTab(activity, uri, ThemeHelper.isDark(ThemeHelper.find(activity))); + } catch (Exception e) { + ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); + } showNewInstalledDialog(activity); } catch (Exception e) { ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG).show(); diff --git a/src/main/java/eu/siacs/conversations/ui/widget/RichLinkView.java b/src/main/java/eu/siacs/conversations/ui/widget/RichLinkView.java index fbec9e8229..e8bac4b6c4 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/RichLinkView.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/RichLinkView.java @@ -1,8 +1,6 @@ package eu.siacs.conversations.ui.widget; -import android.content.ActivityNotFoundException; import android.content.Context; -import android.content.Intent; import android.net.Uri; import android.os.Build; import android.util.AttributeSet; @@ -19,8 +17,10 @@ import com.squareup.picasso.Picasso; import eu.siacs.conversations.R; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.util.CustomTab; import eu.siacs.conversations.utils.MetaData; import eu.siacs.conversations.utils.RichPreview; +import eu.siacs.conversations.utils.ThemeHelper; import me.drakeet.support.toast.ToastCompat; @@ -138,11 +138,10 @@ public class RichLinkView extends RelativeLayout { } private void richLinkClicked() { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(main_url)); try { - context.startActivity(intent); - } catch (ActivityNotFoundException e) { - ToastCompat.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG).show(); + CustomTab.openTab(this.context, Uri.parse(main_url), ThemeHelper.isDark(ThemeHelper.find(this.context))); + } catch (Exception e) { + ToastCompat.makeText(this.context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); } } diff --git a/src/main/res/layout/activity_about.xml b/src/main/res/layout/activity_about.xml index 519951850a..d372b10171 100644 --- a/src/main/res/layout/activity_about.xml +++ b/src/main/res/layout/activity_about.xml @@ -69,7 +69,6 @@ android:layout_marginRight="@dimen/activity_horizontal_margin" android:autoLink="web" android:fontFamily="monospace" - android:linksClickable="true" android:paddingBottom="@dimen/activity_vertical_margin" android:textAppearance="@style/TextAppearance.Conversations.Body1" android:textSize="?attr/TextSizeBody" @@ -118,9 +117,7 @@ android:layout_marginRight="@dimen/activity_horizontal_margin" android:autoLink="web" android:fontFamily="monospace" - android:linksClickable="true" android:paddingBottom="@dimen/activity_vertical_margin" - android:text="@string/pref_about_libraries" android:textAppearance="@style/TextAppearance.Conversations.Body1" android:textSize="?attr/TextSizeBody" android:typeface="monospace" />