From e1cc5b46d11d921125d3173ced24829f599f5a5e Mon Sep 17 00:00:00 2001 From: xynngh Date: Sat, 20 Jul 2019 21:46:24 +0400 Subject: [PATCH] Improve reviews list and add Russian localization Thanks to an anonymous contributor --- README.md | 6 ++ app/build.gradle | 3 + .../CustomListViewAdapter.java | 95 +++++++++++++++++++ .../yetanothercallblocker/IconAndColor.java | 23 +++++ .../ReviewsActivity.java | 43 ++++----- .../sia/model/database/CommunityDatabase.java | 5 +- app/src/main/res/layout/activity_main.xml | 55 ++++++++--- app/src/main/res/layout/content_reviews.xml | 24 +++-- app/src/main/res/layout/review_item.xml | 44 +++++++++ app/src/main/res/values-ru/strings.xml | 50 ++++++++++ app/src/main/res/values/colors.xml | 6 ++ app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 5 +- 13 files changed, 314 insertions(+), 46 deletions(-) create mode 100644 app/src/main/java/dummydomain/yetanothercallblocker/CustomListViewAdapter.java create mode 100644 app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java create mode 100644 app/src/main/res/layout/review_item.xml create mode 100644 app/src/main/res/values-ru/strings.xml diff --git a/README.md b/README.md index ddb419f..e0ce72d 100644 --- a/README.md +++ b/README.md @@ -93,10 +93,16 @@ git clone https://gitlab.com/xynngh/YetAnotherCallBlocker_data Sym-link the assets: +Linux ``` cd YetAnotherCallBlocker/app/src/main/assets/ ln -s ../../../../../YetAnotherCallBlocker_data/assets/sia . ``` +Windows +``` +cd YetAnotherCallBlocker\app\src\main\assets +mklink /d sia ..\..\..\..\..\YetAnotherCallBlocker_data\assets\sia +``` **or** copy the whole directory `YetAnotherCallBlocker_data/assets/sia` into `YetAnotherCallBlocker/app/src/main/assets/`. diff --git a/app/build.gradle b/app/build.gradle index 1713751..d0a32ef 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,6 +19,9 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + lintOptions { + disable 'MissingTranslation' + } } dependencies { diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/CustomListViewAdapter.java b/app/src/main/java/dummydomain/yetanothercallblocker/CustomListViewAdapter.java new file mode 100644 index 0000000..c6e41f1 --- /dev/null +++ b/app/src/main/java/dummydomain/yetanothercallblocker/CustomListViewAdapter.java @@ -0,0 +1,95 @@ +package dummydomain.yetanothercallblocker; + +import android.content.res.ColorStateList; +import android.support.annotation.NonNull; +import android.support.v4.widget.ImageViewCompat; +import android.support.v7.widget.AppCompatImageView; +import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.Collections; +import java.util.List; + +import dummydomain.yetanothercallblocker.sia.model.CommunityReview; +import dummydomain.yetanothercallblocker.sia.model.NumberRating; + +class CustomListViewAdapter extends RecyclerView.Adapter { + + private List reviewsList = Collections.emptyList(); + + public void setItems(List reviewsList) { + this.reviewsList = reviewsList; + } + + @NonNull + @Override + public CommunityReviewViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()) + .inflate(R.layout.review_item, viewGroup, false); + return new CommunityReviewViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull CommunityReviewViewHolder viewHolder, int i) { + viewHolder.bind(reviewsList.get(i)); + } + + @Override + public int getItemCount() { + return reviewsList.size(); + } + + class CommunityReviewViewHolder extends RecyclerView.ViewHolder { + + AppCompatImageView ivRating; + TextView tvNumberCategory, tvTitle, tvDescription; + + public CommunityReviewViewHolder(@NonNull View itemView) { + super(itemView); + ivRating = itemView.findViewById(R.id.rating_icon); + tvNumberCategory = itemView.findViewById(R.id.number_category); + tvTitle = itemView.findViewById(R.id.review_title); + tvDescription = itemView.findViewById(R.id.review_comment); + } + + public void bind(CommunityReview item) { + tvNumberCategory.setText(item.getCategory().getStringId()); + String title = item.getTitle(); + if (TextUtils.isEmpty(title)) { + tvTitle.setVisibility(View.GONE); + } else { + tvTitle.setText(title); + tvTitle.setVisibility(View.VISIBLE); + } + String comment = item.getComment(); + if (TextUtils.isEmpty(comment)) { + tvDescription.setVisibility(View.GONE); + } else { + tvDescription.setText(comment); + tvDescription.setVisibility(View.VISIBLE); + } + + IconAndColor iconAndColor = getRatingIconData(item.getRating()); + ivRating.setImageResource(iconAndColor.getIconResId()); + ImageViewCompat.setImageTintList(ivRating, ColorStateList.valueOf( + itemView.getContext().getResources().getColor(iconAndColor.getColorResId()))); + } + + protected IconAndColor getRatingIconData(NumberRating rating) { + switch (rating) { + case NEUTRAL: + case UNKNOWN: + return IconAndColor.of(R.drawable.ic_thumbs_up_down_black_24dp, R.color.rateNeutral); + case POSITIVE: + return IconAndColor.of(R.drawable.ic_thumb_up_black_24dp, R.color.ratePositive); + case NEGATIVE: + return IconAndColor.of(R.drawable.ic_thumb_down_black_24dp, R.color.rateNegative); + } + return IconAndColor.of(R.drawable.ic_thumbs_up_down_black_24dp, R.color.notFound); + } + } +} diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java b/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java new file mode 100644 index 0000000..c9efb73 --- /dev/null +++ b/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java @@ -0,0 +1,23 @@ +package dummydomain.yetanothercallblocker; + +class IconAndColor { + private int iconResId; + private int colorResId; + + public IconAndColor(int icon, int color) { + this.iconResId = icon; + this.colorResId = color; + } + + static IconAndColor of(int icon, int color) { + return new IconAndColor(icon, color); + } + + public int getIconResId() { + return iconResId; + } + + public int getColorResId() { + return colorResId; + } +} diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java b/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java index 03c2797..c3c67c5 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java @@ -5,18 +5,23 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.DividerItemDecoration; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.widget.TextView; import java.util.List; import dummydomain.yetanothercallblocker.sia.model.CommunityReview; import dummydomain.yetanothercallblocker.sia.model.CommunityReviewsLoader; -import dummydomain.yetanothercallblocker.sia.model.NumberCategory; public class ReviewsActivity extends AppCompatActivity { private static final String PARAM_NUMBER = "param_number"; + private CustomListViewAdapter listViewAdapter; + private RecyclerView reviewsList; + public static Intent getNumberIntent(Context context, String number) { Intent intent = new Intent(context, ReviewsActivity.class); intent.putExtra(PARAM_NUMBER, number); @@ -35,7 +40,13 @@ public class ReviewsActivity extends AppCompatActivity { final String paramNumber = getIntent().getStringExtra(PARAM_NUMBER); - setText("Loading"); + setText(getString(R.string.reviews_loading, paramNumber)); + + listViewAdapter = new CustomListViewAdapter(); + reviewsList = findViewById(R.id.reviews_list); + reviewsList.setLayoutManager(new LinearLayoutManager(this)); + reviewsList.setAdapter(listViewAdapter); + reviewsList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); new AsyncTask>() { @Override @@ -45,33 +56,19 @@ public class ReviewsActivity extends AppCompatActivity { @Override protected void onPostExecute(List reviews) { - setText(reviewsToString(ReviewsActivity.this, reviews)); + setText(paramNumber); + handleReviews(reviews); } }.execute(); } - private void setText(String mainPart) { - TextView textView = findViewById(R.id.text_view); - textView.setText(getHeader() + "\n\n" + mainPart); + private void setText(String text) { + this.findViewById(R.id.text_view).setText(text); } - private String getHeader() { - return "Reviews for " + getIntent().getStringExtra(PARAM_NUMBER); - } - - private static String reviewsToString(Context context, List reviews) { - StringBuilder sb = new StringBuilder(); - - for (CommunityReview review : reviews) { - sb.append(review.getAuthor()).append('\n'); - sb.append(review.getRating()).append('\n'); - sb.append(NumberCategory.getString(context, review.getCategory())).append('\n'); - sb.append(review.getTitle()).append('\n'); - sb.append(review.getComment()).append('\n'); - sb.append('\n'); - } - - return sb.toString(); + private void handleReviews(List reviews) { + listViewAdapter.setItems(reviews); + listViewAdapter.notifyDataSetChanged(); } } diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabase.java b/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabase.java index 2cca622..c92bec5 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabase.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabase.java @@ -1,5 +1,7 @@ package dummydomain.yetanothercallblocker.sia.model.database; +import android.annotation.SuppressLint; +import android.support.annotation.Nullable; import android.util.SparseArray; import org.slf4j.Logger; @@ -39,6 +41,7 @@ public class CommunityDatabase extends AbstractDatabase secondarySliceCache = new SparseArray<>(); + @SuppressLint("UseSparseArrays") // uses null as a special value private SparseArray existingSecondarySliceFiles = new SparseArray<>(); public int getEffectiveDbVersion() { @@ -153,7 +156,7 @@ public class CommunityDatabase extends AbstractDatabase - + android:layout_gravity="start" + android:layout_marginStart="@dimen/text_margin" + android:layout_marginLeft="@dimen/text_margin" + android:paddingTop="@dimen/item_padding" + android:text="@string/general_settings" + android:textAlignment="textStart" /> - + - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_reviews.xml b/app/src/main/res/layout/content_reviews.xml index e6fe868..523946e 100644 --- a/app/src/main/res/layout/content_reviews.xml +++ b/app/src/main/res/layout/content_reviews.xml @@ -8,11 +8,23 @@ tools:context=".ReviewsActivity" tools:showIn="@layout/activity_reviews"> - + + + + + diff --git a/app/src/main/res/layout/review_item.xml b/app/src/main/res/layout/review_item.xml new file mode 100644 index 0000000..e49bf02 --- /dev/null +++ b/app/src/main/res/layout/review_item.xml @@ -0,0 +1,44 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml new file mode 100644 index 0000000..a627ffd --- /dev/null +++ b/app/src/main/res/values-ru/strings.xml @@ -0,0 +1,50 @@ + + + Yet Another Call Blocker + Входящие вызовы + С нейтральной оценкой + Неизвестные (без оценки) + С плохой оценкой + Товары/маркетинг + Заблокированные вызовы + Сбор задолженностей + Немой вызов + Call-центр + Политика + Хулиганство + Опрос + Другое + Развод/мошенники + Финансовые услуги + Компания + Сервис/услуги + Робот/автомат + Некоммерческая орг-я + Блокировать нежелательные вызовы + Авто-обновление баз номеров + Открыть экран отладки + Отладка + Искать в общей базе + Искать в базе организаций + Показать online-отзывы + Обновить базы + Не найдено + Обновление завершено. Версия: %d + Отображать уведомление при входящих + Отзывы + %s загрузка… + Основные настройки + Факс + Злонамеренный + Нежелательный + Отриц. %d, положит. %d, нейтр. %d + Без категории + Отзывов нет + Нейтрально + Плохие отзывы + Блокировано + С хорошей оценкой + Показать причину блокировки + Из моего списка контактов + Одобрено + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 69b2233..a48d9c2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,10 @@ #008577 #00574B #D81B60 + + #1b5e1f + #ffb300 + #ff0000 + #999999 + #999999 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 65ad867..f7e2e04 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,5 @@ 180dp 16dp + 16dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d573bce..af87fb8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,6 +44,9 @@ Safe nonprofit Reviews + %s loading… + + General settings Incoming call notifications enabled Block unwanted calls @@ -54,7 +57,7 @@ Query DB Query featured DB Load reviews (online) - 74995861192 + 74995861192 Manually update DB Not found Update finished; DB ver: %d