Add number of reviews to the reviews screen title

Also on the debug screen.

Thanks to an anonymous contributor.
This commit is contained in:
xynngh 2019-07-21 21:03:30 +04:00
parent 7fc36f4fc5
commit 0f5b7e3509
10 changed files with 182 additions and 15 deletions

View File

@ -1,13 +1,17 @@
package dummydomain.yetanothercallblocker; package dummydomain.yetanothercallblocker;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import java.util.HashMap;
import java.util.Map;
import dummydomain.yetanothercallblocker.sia.DatabaseSingleton; import dummydomain.yetanothercallblocker.sia.DatabaseSingleton;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem; import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabaseItem; import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabaseItem;
@ -17,10 +21,12 @@ public class DebugActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_debug); setContentView(R.layout.activity_debug);
hideSummary();
} }
public void onQueryDbButtonClick(View view) { public void onQueryDbButtonClick(View view) {
setResult(""); setResult("");
hideSummary();
new AsyncTask<Void, Void, CommunityDatabaseItem>() { new AsyncTask<Void, Void, CommunityDatabaseItem>() {
@Override @Override
@ -33,14 +39,33 @@ public class DebugActivity extends AppCompatActivity {
@Override @Override
protected void onPostExecute(CommunityDatabaseItem item) { protected void onPostExecute(CommunityDatabaseItem item) {
setResult(item != null ? item.toString() String string;
: DebugActivity.this.getString(R.string.debug_not_found)); if (item != null) {
string = item.getNumber() + "\n";
if (item.getUnknownData() != 0) {
string += "unknownData=" + item.getUnknownData() + "\n";
}
NumberCategory category = NumberCategory.getById(item.getCategory());
if (category != null) {
string += DebugActivity.this.getString(category.getStringId());
} else {
string += "category=" + item.getCategory() + "\n";
}
displaySummary(item);
} else {
string = DebugActivity.this.getString(R.string.debug_not_found);
}
setResult(string);
} }
}.execute(); }.execute();
} }
public void onQueryFeaturedDbButtonClick(View view) { public void onQueryFeaturedDbButtonClick(View view) {
setResult(""); setResult("");
hideSummary();
new AsyncTask<Void, Void, FeaturedDatabaseItem>() { new AsyncTask<Void, Void, FeaturedDatabaseItem>() {
@Override @Override
@ -65,6 +90,7 @@ public class DebugActivity extends AppCompatActivity {
public void onUpdateDbButtonClick(View view) { public void onUpdateDbButtonClick(View view) {
setResult(""); setResult("");
hideSummary();
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
@ -90,4 +116,22 @@ public class DebugActivity extends AppCompatActivity {
this.<TextView>findViewById(R.id.debugResultsTextView).setText(result); this.<TextView>findViewById(R.id.debugResultsTextView).setText(result);
} }
private void hideSummary() {
findViewById(R.id.reviews_summary).setVisibility(View.GONE);
}
private void displaySummary(CommunityDatabaseItem item) {
View summary = DebugActivity.this.findViewById(R.id.reviews_summary);
summary.setVisibility(View.VISIBLE);
Map<Integer, Integer> map = new HashMap<>();
map.put(R.id.summary_text_negative, item.getNegativeRatingsCount());
map.put(R.id.summary_text_neutral, item.getNeutralRatingsCount());
map.put(R.id.summary_text_positive, item.getPositiveRatingsCount());
for (Map.Entry<Integer, Integer> e: map.entrySet()) {
((TextView) summary.findViewById(e.getKey())).setText(
String.valueOf(e.getValue()));
}
}
} }

View File

@ -8,6 +8,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import java.util.List; import java.util.List;
@ -40,7 +42,9 @@ public class ReviewsActivity extends AppCompatActivity {
final String paramNumber = getIntent().getStringExtra(PARAM_NUMBER); final String paramNumber = getIntent().getStringExtra(PARAM_NUMBER);
setText(getString(R.string.reviews_loading, paramNumber)); findViewById(R.id.reviews_summary).setVisibility(View.GONE);
setTitle(paramNumber);
setText(getString(R.string.reviews_loading));
listViewAdapter = new CustomListViewAdapter(); listViewAdapter = new CustomListViewAdapter();
reviewsList = findViewById(R.id.reviews_list); reviewsList = findViewById(R.id.reviews_list);
@ -56,19 +60,49 @@ public class ReviewsActivity extends AppCompatActivity {
@Override @Override
protected void onPostExecute(List<CommunityReview> reviews) { protected void onPostExecute(List<CommunityReview> reviews) {
setText(paramNumber); setText("");
handleReviews(reviews); handleReviews(reviews);
} }
}.execute(); }.execute();
} }
private void setText(String text) { private void setText(String text) {
this.<TextView>findViewById(R.id.text_view).setText(text); TextView textView = this.findViewById(R.id.text_view);
textView.setText(text);
textView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
} }
private void handleReviews(List<CommunityReview> reviews) { private void handleReviews(List<CommunityReview> reviews) {
listViewAdapter.setItems(reviews); listViewAdapter.setItems(reviews);
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
displaySummary(reviews);
}
private void displaySummary(List<CommunityReview> reviews) {
int[] ratings = {0, 0, 0};
int[] resIds = {
R.id.summary_text_negative,
R.id.summary_text_neutral,
R.id.summary_text_positive
};
for (CommunityReview review : reviews) {
switch (review.getRating()) {
case NEGATIVE:
ratings[0]++;
break;
case NEUTRAL:
ratings[1]++;
break;
case POSITIVE:
ratings[2]++;
break;
}
}
View summary = findViewById(R.id.reviews_summary);
summary.setVisibility(View.VISIBLE);
for (int i = 0; i < resIds.length; i++) {
((TextView) summary.findViewById(resIds[i])).setText(String.valueOf(ratings[i]));
}
} }
} }

View File

@ -47,7 +47,12 @@
android:id="@+id/debugResultsTextView" android:id="@+id/debugResultsTextView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="" /> tools:text="Some data" />
<include layout="@layout/reviews_summary"
android:layout_marginTop="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>

View File

@ -23,6 +23,8 @@
app:layout_scrollFlags="scroll|exitUntilCollapsed" app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar"> app:toolbarId="@+id/toolbar">
<include layout="@layout/reviews_summary"/>
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -25,6 +25,8 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/reviews_list" android:id="@+id/reviews_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"
android:paddingLeft="@dimen/item_padding"
android:paddingRight="@dimen/item_padding"/>
</LinearLayout> </LinearLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>

View File

@ -9,9 +9,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="top|center_horizontal" android:layout_gravity="top|center_horizontal"
android:layout_marginTop="6dp" android:layout_marginTop="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginBottom="10dp"
android:tint="@color/rateNeutral" android:tint="@color/rateNeutral"
android:src="@drawable/ic_thumbs_up_down_black_24dp"/> android:src="@drawable/ic_thumbs_up_down_black_24dp"/>
<LinearLayout <LinearLayout
@ -20,7 +20,6 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:layout_marginRight="6dp"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/reviews_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:layout_collapseMode="parallax"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_thumb_down_black_24dp"
android:tint="@color/rateNegative" />
<TextView
android:id="@+id/summary_text_negative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="16dp"
tools:text="0" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_thumbs_up_down_black_24dp"
android:tint="@color/rateNeutral" />
<TextView
android:id="@+id/summary_text_neutral"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="16dp"
tools:text="0" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_thumb_up_black_24dp"
android:tint="@color/ratePositive" />
<TextView
android:id="@+id/summary_text_positive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="16dp"
tools:text="0" />
</LinearLayout>
</LinearLayout>

View File

@ -32,7 +32,7 @@
<string name="debug_update_result">Обновление завершено. Версия: %d</string> <string name="debug_update_result">Обновление завершено. Версия: %d</string>
<string name="incoming_call_notifications_enabled">Отображать уведомление при входящих</string> <string name="incoming_call_notifications_enabled">Отображать уведомление при входящих</string>
<string name="title_activity_reviews">Отзывы</string> <string name="title_activity_reviews">Отзывы</string>
<string name="reviews_loading">%s загрузка</string> <string name="reviews_loading">Загружаем отзывы</string>
<string name="general_settings">Основные настройки</string> <string name="general_settings">Основные настройки</string>
<string name="sia_category_fax">Факс</string> <string name="sia_category_fax">Факс</string>
<string name="sia_category_nuisance">Злонамеренный</string> <string name="sia_category_nuisance">Злонамеренный</string>

View File

@ -4,9 +4,9 @@
<color name="colorPrimaryDark">#00574B</color> <color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color> <color name="colorAccent">#D81B60</color>
<color name="ratePositive">#1b5e1f</color> <color name="ratePositive">#679f41</color>
<color name="rateNeutral">#ffb300</color> <color name="rateNeutral">#ffb300</color>
<color name="rateNegative">#ff0000</color> <color name="rateNegative">#d40000</color>
<color name="rateUnknown">#999999</color> <color name="rateUnknown">#999999</color>
<color name="notFound">#999999</color> <color name="notFound">#999999</color>
</resources> </resources>

View File

@ -44,7 +44,7 @@
<string name="sia_category_safe_nonprofit">Safe nonprofit</string> <string name="sia_category_safe_nonprofit">Safe nonprofit</string>
<string name="title_activity_reviews">Reviews</string> <string name="title_activity_reviews">Reviews</string>
<string name="reviews_loading">%s loading</string> <string name="reviews_loading">Loading reviews</string>
<string name="general_settings">General settings</string> <string name="general_settings">General settings</string>