mirror of
https://codeberg.org/monocles/monocles_chat.git
synced 2025-01-29 00:14:12 +01:00
integrate customTabs for links
https://developers.google.com/web/android/custom-tabs
This commit is contained in:
parent
1bcaf21db0
commit
b4361f0c8d
8 changed files with 64 additions and 50 deletions
|
@ -87,6 +87,7 @@ dependencies {
|
||||||
implementation 'com.squareup.retrofit2:converter-gson:2.6.4'
|
implementation 'com.squareup.retrofit2:converter-gson:2.6.4'
|
||||||
implementation 'com.google.guava:guava:28.2-android'
|
implementation 'com.google.guava:guava:28.2-android'
|
||||||
implementation 'com.github.AppIntro:AppIntro:6.0.0'
|
implementation 'com.github.AppIntro:AppIntro:6.0.0'
|
||||||
|
implementation "androidx.browser:browser:1.3.0"
|
||||||
implementation fileTree(include: ['libwebrtc-m85.aar'], dir: 'libs')
|
implementation fileTree(include: ['libwebrtc-m85.aar'], dir: 'libs')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -11,23 +11,24 @@ import java.util.Calendar;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
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 eu.siacs.conversations.utils.ThemeHelper;
|
||||||
import me.drakeet.support.toast.ToastCompat;
|
import me.drakeet.support.toast.ToastCompat;
|
||||||
|
|
||||||
public class AboutActivity extends XmppActivity {
|
public class AboutActivity extends XmppActivity {
|
||||||
|
|
||||||
private Button privacyButton;
|
|
||||||
private Button termsOfUseButton;
|
|
||||||
private TextView aboutmessage;
|
private TextView aboutmessage;
|
||||||
|
private TextView libraries;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refreshUiReal() {
|
protected void refreshUiReal() {
|
||||||
|
showText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
|
showText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,30 +38,44 @@ public class AboutActivity extends XmppActivity {
|
||||||
setContentView(R.layout.activity_about);
|
setContentView(R.layout.activity_about);
|
||||||
setSupportActionBar(findViewById(R.id.toolbar));
|
setSupportActionBar(findViewById(R.id.toolbar));
|
||||||
configureActionBar(getSupportActionBar());
|
configureActionBar(getSupportActionBar());
|
||||||
|
|
||||||
aboutmessage = findViewById(R.id.aboutmessage);
|
aboutmessage = findViewById(R.id.aboutmessage);
|
||||||
String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
|
libraries = findViewById(R.id.libraries);
|
||||||
aboutmessage.setText(getString(R.string.pref_about_message, year));
|
Button privacyButton = findViewById(R.id.show_privacy_policy);
|
||||||
|
|
||||||
privacyButton = findViewById(R.id.show_privacy_policy);
|
|
||||||
privacyButton.setOnClickListener(view -> {
|
privacyButton.setOnClickListener(view -> {
|
||||||
try {
|
try {
|
||||||
final Uri uri = Uri.parse(Config.privacyURL);
|
final Uri uri = Uri.parse(Config.privacyURL);
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
CustomTab.openTab(this, uri, isDarkTheme());
|
||||||
startActivity(browserIntent);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
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 -> {
|
termsOfUseButton.setOnClickListener(view -> {
|
||||||
try {
|
try {
|
||||||
final Uri uri = Uri.parse(Config.termsOfUseURL);
|
final Uri uri = Uri.parse(Config.termsOfUseURL);
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
CustomTab.openTab(this, uri, isDarkTheme());
|
||||||
startActivity(browserIntent);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -39,6 +39,7 @@ import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.http.NoSSLv3SocketFactory;
|
import eu.siacs.conversations.http.NoSSLv3SocketFactory;
|
||||||
import eu.siacs.conversations.persistance.FileBackend;
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
|
import eu.siacs.conversations.ui.util.CustomTab;
|
||||||
import eu.siacs.conversations.utils.WakeLockHelper;
|
import eu.siacs.conversations.utils.WakeLockHelper;
|
||||||
import me.drakeet.support.toast.ToastCompat;
|
import me.drakeet.support.toast.ToastCompat;
|
||||||
|
|
||||||
|
@ -145,10 +146,12 @@ public class UpdaterActivity extends XmppActivity {
|
||||||
startActivity(marketIntent);
|
startActivity(marketIntent);
|
||||||
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
||||||
} else {
|
} else {
|
||||||
uri = Uri.parse("https://" + blabber());
|
try {
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
uri = Uri.parse("https://" + blabber());
|
||||||
startActivity(browserIntent);
|
CustomTab.openTab(this, uri, isDarkTheme());
|
||||||
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
} 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)) {
|
} else if (store != null && store.equalsIgnoreCase(FDroid)) {
|
||||||
Uri uri = Uri.parse("https://f-droid.org/de/packages/" + getString(R.string.applicationId) + "/");
|
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);
|
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
||||||
} else {
|
} else {
|
||||||
uri = Uri.parse("https://" + blabber());
|
uri = Uri.parse("https://" + blabber());
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
try {
|
||||||
startActivity(browserIntent);
|
CustomTab.openTab(this, uri, isDarkTheme());
|
||||||
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
} catch (Exception e) {
|
||||||
|
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ToastCompat.makeText(getApplicationContext(), getText(R.string.download_started), Toast.LENGTH_LONG).show();
|
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) -> {
|
.setNeutralButton(R.string.changelog, (dialog, id) -> {
|
||||||
Uri uri = Uri.parse(Config.CHANGELOG_URL); // missing 'http://' will cause crash
|
Uri uri = Uri.parse(Config.CHANGELOG_URL); // missing 'http://' will cause crash
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
CustomTab.openTab(this, uri, isDarkTheme());
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivity(intent);
|
|
||||||
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
||||||
} finally {
|
} finally {
|
||||||
//restart updater to show dialog again after coming back after opening changelog
|
//restart updater to show dialog again after coming back after opening changelog
|
||||||
recreate();
|
recreate();
|
||||||
|
|
|
@ -81,6 +81,7 @@ import eu.siacs.conversations.services.QuickConversationsService;
|
||||||
import eu.siacs.conversations.services.UpdateService;
|
import eu.siacs.conversations.services.UpdateService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
|
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.PresenceSelector;
|
||||||
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
|
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
|
||||||
import eu.siacs.conversations.utils.AccountUtils;
|
import eu.siacs.conversations.utils.AccountUtils;
|
||||||
|
@ -301,9 +302,11 @@ public abstract class XmppActivity extends ActionBarActivity {
|
||||||
startActivity(marketIntent);
|
startActivity(marketIntent);
|
||||||
} else {
|
} else {
|
||||||
uri = Uri.parse("http://www.openkeychain.org/");
|
uri = Uri.parse("http://www.openkeychain.org/");
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
try {
|
||||||
startActivity(browserIntent);
|
CustomTab.openTab(this, uri, isDarkTheme());
|
||||||
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
} catch (Exception e) {
|
||||||
|
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,9 +32,7 @@ package eu.siacs.conversations.ui.text;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.style.URLSpan;
|
import android.text.style.URLSpan;
|
||||||
|
@ -46,6 +44,8 @@ import java.util.Arrays;
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.ui.ConversationsActivity;
|
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;
|
import me.drakeet.support.toast.ToastCompat;
|
||||||
|
|
||||||
@SuppressLint("ParcelCreator")
|
@SuppressLint("ParcelCreator")
|
||||||
|
@ -75,13 +75,8 @@ public class FixedURLSpan extends URLSpan {
|
||||||
return;
|
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 {
|
try {
|
||||||
context.startActivity(intent);
|
CustomTab.openTab(context, uri, ThemeHelper.isDark(ThemeHelper.find(context)));
|
||||||
widget.playSoundEffect(0);
|
widget.playSoundEffect(0);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
ToastCompat.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
ToastCompat.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -2,7 +2,6 @@ package eu.siacs.conversations.ui.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -24,6 +23,7 @@ import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.ui.ConversationsActivity;
|
import eu.siacs.conversations.ui.ConversationsActivity;
|
||||||
import eu.siacs.conversations.ui.WelcomeActivity;
|
import eu.siacs.conversations.ui.WelcomeActivity;
|
||||||
|
import eu.siacs.conversations.utils.ThemeHelper;
|
||||||
import me.drakeet.support.toast.ToastCompat;
|
import me.drakeet.support.toast.ToastCompat;
|
||||||
|
|
||||||
public class UpdateHelper {
|
public class UpdateHelper {
|
||||||
|
@ -78,8 +78,10 @@ public class UpdateHelper {
|
||||||
SaveMessageShown(activity, blabber_message);
|
SaveMessageShown(activity, blabber_message);
|
||||||
try {
|
try {
|
||||||
final Uri uri = Uri.parse(Config.migrationURL);
|
final Uri uri = Uri.parse(Config.migrationURL);
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
try {CustomTab.openTab(activity, uri, ThemeHelper.isDark(ThemeHelper.find(activity)));
|
||||||
activity.startActivity(browserIntent);
|
} catch (Exception e) {
|
||||||
|
ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
showNewInstalledDialog(activity);
|
showNewInstalledDialog(activity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG).show();
|
ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG).show();
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package eu.siacs.conversations.ui.widget;
|
package eu.siacs.conversations.ui.widget;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
@ -19,8 +17,10 @@ import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
|
import eu.siacs.conversations.ui.util.CustomTab;
|
||||||
import eu.siacs.conversations.utils.MetaData;
|
import eu.siacs.conversations.utils.MetaData;
|
||||||
import eu.siacs.conversations.utils.RichPreview;
|
import eu.siacs.conversations.utils.RichPreview;
|
||||||
|
import eu.siacs.conversations.utils.ThemeHelper;
|
||||||
import me.drakeet.support.toast.ToastCompat;
|
import me.drakeet.support.toast.ToastCompat;
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,11 +138,10 @@ public class RichLinkView extends RelativeLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void richLinkClicked() {
|
private void richLinkClicked() {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(main_url));
|
|
||||||
try {
|
try {
|
||||||
context.startActivity(intent);
|
CustomTab.openTab(this.context, Uri.parse(main_url), ThemeHelper.isDark(ThemeHelper.find(this.context)));
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (Exception e) {
|
||||||
ToastCompat.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG).show();
|
ToastCompat.makeText(this.context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,6 @@
|
||||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||||
android:autoLink="web"
|
android:autoLink="web"
|
||||||
android:fontFamily="monospace"
|
android:fontFamily="monospace"
|
||||||
android:linksClickable="true"
|
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:textAppearance="@style/TextAppearance.Conversations.Body1"
|
android:textAppearance="@style/TextAppearance.Conversations.Body1"
|
||||||
android:textSize="?attr/TextSizeBody"
|
android:textSize="?attr/TextSizeBody"
|
||||||
|
@ -118,9 +117,7 @@
|
||||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||||
android:autoLink="web"
|
android:autoLink="web"
|
||||||
android:fontFamily="monospace"
|
android:fontFamily="monospace"
|
||||||
android:linksClickable="true"
|
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:text="@string/pref_about_libraries"
|
|
||||||
android:textAppearance="@style/TextAppearance.Conversations.Body1"
|
android:textAppearance="@style/TextAppearance.Conversations.Body1"
|
||||||
android:textSize="?attr/TextSizeBody"
|
android:textSize="?attr/TextSizeBody"
|
||||||
android:typeface="monospace" />
|
android:typeface="monospace" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue