From ad4ac84f6498d601809e1f8bc72ac87aa5d04d66 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Sat, 13 Mar 2021 17:37:29 +0100 Subject: Dialer: Move to SPN schema classes Change-Id: I2cd3706f64bf45a2a6dd53caa9d5da48cf93ea28 --- .../android/dialer/helplines/HelplineActivity.java | 15 ++++++++------ .../android/dialer/helplines/HelplineAdapter.java | 6 +++--- .../com/android/dialer/helplines/HelplineItem.java | 23 +++++++++++++--------- .../dialer/helplines/LoadHelplinesTask.java | 8 ++++---- .../dialer/helplines/utils/HelplineUtils.java | 14 ++++++------- 5 files changed, 37 insertions(+), 29 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/helplines/HelplineActivity.java b/java/com/android/dialer/helplines/HelplineActivity.java index 906b6fd2c..15e745d34 100755 --- a/java/com/android/dialer/helplines/HelplineActivity.java +++ b/java/com/android/dialer/helplines/HelplineActivity.java @@ -43,6 +43,8 @@ import com.android.dialer.R; import com.android.dialer.app.calllog.IntentProvider; import com.android.dialer.helplines.utils.HelplineUtils; +import org.lineageos.lib.phone.spn.Item; + import java.util.List; import static android.graphics.Paint.UNDERLINE_TEXT_FLAG; @@ -180,16 +182,17 @@ public class HelplineActivity extends Activity { } @Override - public void onItemClicked(@NonNull HelplineItem item) { + public void onItemClicked(@NonNull HelplineItem helplineItem) { LayoutInflater inflater = LayoutInflater.from(HelplineActivity.this); final View dialogView = inflater.inflate(R.layout.dialog_helpline_details, null); + Item item = helplineItem.getItem(); - fillOrHideDialogRow(item.getName(), dialogView, R.id.name_title, R.id.name); - fillOrHideDialogRow(item.get("organization"), dialogView, R.id.org_title, R.id.org); - fillOrHideDialogRow(HelplineUtils.getCategories(getResources(), item), + fillOrHideDialogRow(helplineItem.getName(), dialogView, R.id.name_title, R.id.name); + fillOrHideDialogRow(item.getOrganization(), dialogView, R.id.org_title, R.id.org); + fillOrHideDialogRow(HelplineUtils.getCategories(getResources(), helplineItem), dialogView, R.id.categories_title, R.id.categories); - fillOrHideDialogRow(item.get("number"), dialogView, R.id.number_title, R.id.number); - fillOrHideDialogRow(item.get("website"), dialogView, R.id.website_title, R.id.website, + fillOrHideDialogRow(item.getNumber(), dialogView, R.id.number_title, R.id.number); + fillOrHideDialogRow(item.getWebsite(), dialogView, R.id.website_title, R.id.website, true); mDialog = new AlertDialog.Builder(HelplineActivity.this) diff --git a/java/com/android/dialer/helplines/HelplineAdapter.java b/java/com/android/dialer/helplines/HelplineAdapter.java index 6dd748e9b..7a1a5637e 100644 --- a/java/com/android/dialer/helplines/HelplineAdapter.java +++ b/java/com/android/dialer/helplines/HelplineAdapter.java @@ -94,8 +94,8 @@ class HelplineAdapter extends RecyclerView.Adapter { @Override public boolean areItemsTheSame(int iOld, int iNew) { - String oldNumber = mOldList.get(iOld).get("number"); - String newNumber = mOldList.get(iNew).get("number"); + String oldNumber = mOldList.get(iOld).getItem().getNumber(); + String newNumber = mOldList.get(iNew).getItem().getNumber(); return oldNumber.equals(newNumber); } @@ -146,7 +146,7 @@ class HelplineAdapter extends RecyclerView.Adapter { mLanguageView.setText(languages); } - String number = item.get("number"); + String number = item.getItem().getNumber(); if (!TextUtils.isEmpty(number)) { mCallIcon.setVisibility(View.VISIBLE); mCallIcon.setOnClickListener(v -> { diff --git a/java/com/android/dialer/helplines/HelplineItem.java b/java/com/android/dialer/helplines/HelplineItem.java index 8ac4cc969..e8f3d9528 100644 --- a/java/com/android/dialer/helplines/HelplineItem.java +++ b/java/com/android/dialer/helplines/HelplineItem.java @@ -19,22 +19,27 @@ import android.content.res.Resources; import com.android.dialer.helplines.utils.HelplineUtils; -import org.lineageos.lib.phone.SensitivePhoneNumberInfo; +import org.lineageos.lib.phone.spn.Item; +/* When loading all the items we modify the name based on the subscription. + * Using the setter would modify it permanently, resulting in modifications on each load. + * Therefore we don't use Item directly but use this little helper class so the modified + * name can be stored + */ public class HelplineItem { - private final SensitivePhoneNumberInfo mInfo; + private final Item mItem; private final String mName; - public HelplineItem(Resources res, SensitivePhoneNumberInfo info, String countryIso) { - mInfo = info; - mName = HelplineUtils.getName(res, info, countryIso); + public HelplineItem(Resources res, Item item, String countryIso) { + mItem = item; + mName = HelplineUtils.getName(res, item, countryIso); } - public String getName() { - return mName; + public Item getItem() { + return mItem; } - public String get(String key) { - return mInfo.get(key); + public String getName() { + return mName; } } diff --git a/java/com/android/dialer/helplines/LoadHelplinesTask.java b/java/com/android/dialer/helplines/LoadHelplinesTask.java index 7cc0a0152..7c8de9c5a 100644 --- a/java/com/android/dialer/helplines/LoadHelplinesTask.java +++ b/java/com/android/dialer/helplines/LoadHelplinesTask.java @@ -23,8 +23,8 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.util.Log; -import org.lineageos.lib.phone.SensitivePhoneNumberInfo; import org.lineageos.lib.phone.SensitivePhoneNumbers; +import org.lineageos.lib.phone.spn.Item; import java.util.ArrayList; import java.util.Collections; @@ -72,11 +72,11 @@ public class LoadHelplinesTask extends AsyncTask pns = spn.getSensitivePnInfosForMcc(mcc); + ArrayList pns = spn.getSensitivePnInfosForMcc(mcc); int numPns = pns.size(); for (int i = 0; i < numPns; i++) { - SensitivePhoneNumberInfo info = pns.get(i); - helplineList.add(new HelplineItem(mResources, info, + Item item = pns.get(i); + helplineList.add(new HelplineItem(mResources, item, addCountryCode ? subCountryIso : "")); publishProgress(Math.round(i * 100 / numPns / subList.size())); } diff --git a/java/com/android/dialer/helplines/utils/HelplineUtils.java b/java/com/android/dialer/helplines/utils/HelplineUtils.java index 4ff20b93c..a31a9ec44 100644 --- a/java/com/android/dialer/helplines/utils/HelplineUtils.java +++ b/java/com/android/dialer/helplines/utils/HelplineUtils.java @@ -20,7 +20,7 @@ import android.text.TextUtils; import com.android.dialer.R; import com.android.dialer.helplines.HelplineItem; -import org.lineageos.lib.phone.SensitivePhoneNumberInfo; +import org.lineageos.lib.phone.spn.Item; import java.util.ArrayList; @@ -32,12 +32,12 @@ public class HelplineUtils { private static final String LANGUAGE_STR_FORMAT = "helpline_language_%s"; /* Get the name of the helpline, fall back to the number if not given */ - public static String getName(Resources res, SensitivePhoneNumberInfo info, String countryIso) { - if (info != null) { - String name = info.get("name"); + public static String getName(Resources res, Item item, String countryIso) { + if (item != null) { + String name = item.getName(); String displayName = !TextUtils.isEmpty(name) ? getDisplayString(res, name, NAME_STR_FORMAT) - : info.get("number"); + : item.getNumber(); if (!TextUtils.isEmpty(countryIso)) { return res.getString(R.string.helpline_name_format_country, displayName, countryIso); @@ -52,7 +52,7 @@ public class HelplineUtils { /* Split the given categories and translate them, fall back to "generic" if not given */ public static String getCategories(Resources res, HelplineItem item) { if (item != null) { - String str = getDisplayString(res, item.get("categories"), CATEGORY_STR_FORMAT); + String str = getDisplayString(res, item.getItem().getCategories(), CATEGORY_STR_FORMAT); if (!TextUtils.isEmpty(str)) { return str; } @@ -64,7 +64,7 @@ public class HelplineUtils { /* Split and translate the given languages, return empty string if not given */ public static String getLanguages(Resources res, HelplineItem item) { if (item != null) { - return getDisplayString(res, item.get("languages"), LANGUAGE_STR_FORMAT); + return getDisplayString(res, item.getItem().getLanguages(), LANGUAGE_STR_FORMAT); } return ""; -- cgit v1.2.3