diff --git a/app/src/main/java/doubledotlabs/butteryslack/data/AttachmentData.java b/app/src/main/java/doubledotlabs/butteryslack/data/AttachmentData.java index daedf80..68dbb6c 100644 --- a/app/src/main/java/doubledotlabs/butteryslack/data/AttachmentData.java +++ b/app/src/main/java/doubledotlabs/butteryslack/data/AttachmentData.java @@ -1,7 +1,6 @@ package doubledotlabs.butteryslack.data; import android.content.Context; -import android.content.Intent; import android.net.Uri; import android.os.Build; import android.support.annotation.Nullable; @@ -20,6 +19,7 @@ import org.json.simple.JSONObject; import doubledotlabs.butteryslack.R; +import doubledotlabs.butteryslack.utils.CustomTabsBuilder; import doubledotlabs.butteryslack.utils.SlackMovementMethod; import doubledotlabs.butteryslack.utils.SlackUtils; @@ -133,9 +133,9 @@ public void onBindViewHolder(ViewHolder holder, int position) { @Override public void onClick(View v) { if (titleLink != null) - getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(titleLink))); + CustomTabsBuilder.open(getContext(), Uri.parse(titleLink)); else if (authorLink != null) - getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authorLink))); + CustomTabsBuilder.open(getContext(), Uri.parse(authorLink)); } public static class ViewHolder extends ItemData.ViewHolder { diff --git a/app/src/main/java/doubledotlabs/butteryslack/utils/CustomTabsBuilder.java b/app/src/main/java/doubledotlabs/butteryslack/utils/CustomTabsBuilder.java new file mode 100644 index 0000000..d594252 --- /dev/null +++ b/app/src/main/java/doubledotlabs/butteryslack/utils/CustomTabsBuilder.java @@ -0,0 +1,18 @@ +package doubledotlabs.butteryslack.utils; + +import android.content.Context; +import android.net.Uri; +import android.support.customtabs.CustomTabsIntent; +import android.support.v4.content.ContextCompat; + +import doubledotlabs.butteryslack.R; + +public class CustomTabsBuilder { + + public static void open(Context context, Uri uri) { + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary)); + builder.build().launchUrl(context, uri); + } + +} diff --git a/app/src/main/java/doubledotlabs/butteryslack/utils/SlackMovementMethod.java b/app/src/main/java/doubledotlabs/butteryslack/utils/SlackMovementMethod.java index 2a52bbd..27c7fdc 100644 --- a/app/src/main/java/doubledotlabs/butteryslack/utils/SlackMovementMethod.java +++ b/app/src/main/java/doubledotlabs/butteryslack/utils/SlackMovementMethod.java @@ -1,6 +1,5 @@ package doubledotlabs.butteryslack.utils; -import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; @@ -63,7 +62,7 @@ public boolean onSingleTapConfirmed(MotionEvent event) { if (Patterns.PHONE.matcher(linkText).matches()) { //TODO: phone links } else if (Patterns.WEB_URL.matcher(linkText).matches()) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(linkText))); + CustomTabsBuilder.open(activity, Uri.parse(linkText)); } else if (Patterns.EMAIL_ADDRESS.matcher(linkText).matches()) { //TODO: email links } else if (linkText.startsWith("@")) {