Skip to content

Commit

Permalink
Fix phone number linking in Android 8.1, fixes #213 (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
dektar authored Mar 1, 2025
1 parent 457757a commit 6cb247a
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.google.android.material.snackbar.Snackbar;

import androidx.core.app.NavUtils;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.text.TextUtils;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -39,7 +43,6 @@
import org.a5calls.android.a5calls.util.MarkdownUtil;
import org.a5calls.android.a5calls.view.GridItemDecoration;

import java.util.ArrayList;
import java.util.List;

import static org.a5calls.android.a5calls.controller.IssueActivity.KEY_ISSUE;
Expand Down Expand Up @@ -156,7 +159,7 @@ public void onOutcomeClicked(Outcome outcome) {
binding.outcomeList.addItemDecoration(new GridItemDecoration(gridPadding,
getSpanCount(RepCallActivity.this)));

new AnalyticsManager().trackPageview(String.format("/issue/%s/%s/", mIssue.slug,c.id), this);
new AnalyticsManager().trackPageview(String.format("/issue/%s/%s/", mIssue.slug, c.id), this);
}

@Override
Expand Down Expand Up @@ -211,8 +214,8 @@ private void setupContactUi(int index, boolean expandLocalSection) {
.placeholder(R.drawable.baseline_person_52)
.into(binding.repImage);
}
binding.phoneNumber.setText(contact.phone);
Linkify.addLinks(binding.phoneNumber, Linkify.PHONE_NUMBERS);

linkPhoneNumber(binding.phoneNumber, contact.phone);

if (expandLocalSection) {
binding.localOfficeButton.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -323,7 +326,7 @@ private void expandLocalOfficeSection(Contact contact) {
TextView numberView = (TextView) localOfficeInfo.findViewById(
R.id.field_office_number);
numberView.setText(contact.field_offices[i].phone);
Linkify.addLinks(numberView, Linkify.PHONE_NUMBERS);
linkPhoneNumber(numberView, contact.field_offices[i].phone);
if (!TextUtils.isEmpty(contact.field_offices[i].city)) {
((TextView) localOfficeInfo.findViewById(R.id.field_office_city)).setText(
"- " + contact.field_offices[i].city);
Expand Down Expand Up @@ -374,4 +377,11 @@ private int getSpanCount(Activity activity) {

return (int) (displayMetrics.widthPixels / minButtonWidth);
}

private static void linkPhoneNumber(TextView textView, String phoneNumber) {
textView.setText(phoneNumber);
Linkify.addLinks(textView, Patterns.PHONE, "tel:",
Linkify.sPhoneNumberMatchFilter,
Linkify.sPhoneNumberTransformFilter);
}
}

0 comments on commit 6cb247a

Please sign in to comment.