Skip to content

Commit

Permalink
added chrome custom tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Apr 17, 2017
1 parent 5cf6a14 commit ac52cc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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("@")) {
Expand Down

0 comments on commit ac52cc2

Please sign in to comment.