Refactoring: category names

This commit is contained in:
xynngh 2020-06-14 13:14:06 +04:00
parent 8bbf82a7fe
commit 711298c899
6 changed files with 81 additions and 45 deletions

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.Collections;
import java.util.List;
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
import dummydomain.yetanothercallblocker.sia.model.CommunityReview;
class CustomListViewAdapter extends RecyclerView.Adapter<CustomListViewAdapter.CommunityReviewViewHolder> {
@ -55,7 +56,7 @@ class CustomListViewAdapter extends RecyclerView.Adapter<CustomListViewAdapter.C
}
public void bind(CommunityReview item) {
tvNumberCategory.setText(item.getCategory().getStringId());
tvNumberCategory.setText(SiaNumberCategoryUtils.getNameResId(item.getCategory()));
String title = item.getTitle();
if (TextUtils.isEmpty(title)) {
tvTitle.setVisibility(View.GONE);

View File

@ -16,6 +16,7 @@ import org.greenrobot.eventbus.ThreadMode;
import java.util.Date;
import dummydomain.yetanothercallblocker.data.DatabaseSingleton;
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabase;
@ -86,7 +87,7 @@ public class DebugActivity extends AppCompatActivity {
NumberCategory category = NumberCategory.getById(item.getCategory());
if (category != null) {
string += DebugActivity.this.getString(category.getStringId());
string += SiaNumberCategoryUtils.getName(DebugActivity.this, category);
} else {
string += "category=" + item.getCategory() + "\n";
}

View File

@ -11,6 +11,7 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import dummydomain.yetanothercallblocker.data.NumberInfo;
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
import static dummydomain.yetanothercallblocker.IntentHelper.clearTop;
@ -32,7 +33,7 @@ public class InfoDialogHelper {
: null;
if (category != null && category != NumberCategory.NONE) {
categoryView.setText(NumberCategory.getString(context, category));
categoryView.setText(SiaNumberCategoryUtils.getName(context, category));
} else {
categoryView.setVisibility(View.GONE);
}

View File

@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.List;
import dummydomain.yetanothercallblocker.data.NumberInfo;
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
@ -135,7 +136,7 @@ public class NotificationHelper {
NumberCategory category = NumberCategory.getById(communityItem.getCategory());
if (category != null && category != NumberCategory.NONE) {
title += " - " + NumberCategory.getString(context, category);
title += " - " + SiaNumberCategoryUtils.getName(context, category);
}
}

View File

@ -0,0 +1,50 @@
package dummydomain.yetanothercallblocker.data;
import android.content.Context;
import androidx.annotation.StringRes;
import dummydomain.yetanothercallblocker.R;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
public class SiaNumberCategoryUtils {
public static String getName(Context context, NumberCategory category) {
return context.getString(getNameResId(category));
}
@StringRes
public static int getNameResId(NumberCategory category) {
if (category == null) {
return R.string.sia_category_none;
}
switch (category) {
case NONE: return R.string.sia_category_none;
case TELEMARKETER: return R.string.sia_category_telemarketer;
case DEPT_COLLECTOR: return R.string.sia_category_dept_collector;
case SILENT_CALL: return R.string.sia_category_silent;
case NUISANCE_CALL: return R.string.sia_category_nuisance;
case UNSOLICITED_CALL: return R.string.sia_category_unsolicited;
case CALL_CENTER: return R.string.sia_category_call_center;
case FAX_MACHINE: return R.string.sia_category_fax;
case NON_PROFIT: return R.string.sia_category_nonprofit;
case POLITICAL: return R.string.sia_category_political;
case SCAM: return R.string.sia_category_scam;
case PRANK: return R.string.sia_category_prank;
case SMS: return R.string.sia_category_sms;
case SURVEY: return R.string.sia_category_survey;
case OTHER: return R.string.sia_category_other;
case FINANCE_SERVICE: return R.string.sia_category_financial_service;
case COMPANY: return R.string.sia_category_company;
case SERVICE: return R.string.sia_category_service;
case ROBOCALL: return R.string.sia_category_robocall;
// TODO: check: these are probably not present in the db
case SAFE_PERSONAL: return R.string.sia_category_safe_personal;
case SAFE_COMPANY: return R.string.sia_category_safe_company;
case SAFE_NONPROFIT: return R.string.sia_category_safe_nonprofit;
default: throw new RuntimeException("Category not implemented: " + category);
}
}
}

View File

@ -1,52 +1,41 @@
package dummydomain.yetanothercallblocker.sia.model;
import android.content.Context;
import androidx.annotation.StringRes;
import dummydomain.yetanothercallblocker.R;
public enum NumberCategory {
NONE(0, R.string.sia_category_none),
TELEMARKETER(1, R.string.sia_category_telemarketer),
DEPT_COLLECTOR(2, R.string.sia_category_dept_collector),
SILENT_CALL(3, R.string.sia_category_silent),
NUISANCE_CALL(4, R.string.sia_category_nuisance),
UNSOLICITED_CALL(5, R.string.sia_category_unsolicited),
CALL_CENTER(6, R.string.sia_category_call_center),
FAX_MACHINE(7, R.string.sia_category_fax),
NON_PROFIT(8, R.string.sia_category_nonprofit),
POLITICAL(9, R.string.sia_category_political),
SCAM(10, R.string.sia_category_scam),
PRANK(11, R.string.sia_category_prank),
SMS(12, R.string.sia_category_sms),
SURVEY(13, R.string.sia_category_survey),
OTHER(14, R.string.sia_category_other),
FINANCE_SERVICE(15, R.string.sia_category_financial_service),
COMPANY(16, R.string.sia_category_company),
SERVICE(17, R.string.sia_category_service),
ROBOCALL(18, R.string.sia_category_robocall),
NONE(0),
TELEMARKETER(1),
DEPT_COLLECTOR(2),
SILENT_CALL(3),
NUISANCE_CALL(4),
UNSOLICITED_CALL(5),
CALL_CENTER(6),
FAX_MACHINE(7),
NON_PROFIT(8),
POLITICAL(9),
SCAM(10),
PRANK(11),
SMS(12),
SURVEY(13),
OTHER(14),
FINANCE_SERVICE(15),
COMPANY(16),
SERVICE(17),
ROBOCALL(18),
// TODO: check: these are probably not present in the db
SAFE_PERSONAL(100, R.string.sia_category_safe_personal),
SAFE_COMPANY(101, R.string.sia_category_safe_company),
SAFE_NONPROFIT(102, R.string.sia_category_safe_nonprofit);
SAFE_PERSONAL(100),
SAFE_COMPANY(101),
SAFE_NONPROFIT(102);
private int id;
private @StringRes int stringId;
NumberCategory(int id, int stringId) {
NumberCategory(int id) {
this.id = id;
this.stringId = stringId;
}
public int getId() {
return id;
}
public @StringRes int getStringId() {
return stringId;
}
public static NumberCategory getById(int id) {
for (NumberCategory category : values()) {
if (category.getId() == id) return category;
@ -54,11 +43,4 @@ public enum NumberCategory {
return null;
}
public static String getString(Context context, NumberCategory category) {
@StringRes int stringId = category != null
? category.getStringId() : R.string.sia_category_none;
return context.getString(stringId);
}
}