Add "add review (web)" button

This commit is contained in:
xynngh 2020-06-24 14:15:17 +04:00
parent 3c2479dba5
commit b02f3b6ad0
7 changed files with 69 additions and 14 deletions

View File

@ -39,7 +39,7 @@ dependencies {
implementation 'org.conscrypt:conscrypt-android:2.4.0'
//noinspection GradleDependency: 3.12.* is the latest version compatible with Android <5
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:6d073c991c'
implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:09a9e7f824'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

View File

@ -3,6 +3,8 @@ package dummydomain.yetanothercallblocker;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@ -10,6 +12,7 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import dummydomain.yetanothercallblocker.data.DatabaseSingleton;
import dummydomain.yetanothercallblocker.data.NumberInfo;
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
@ -63,9 +66,20 @@ public class InfoDialogHelper {
ReviewsSummaryHelper.populateSummary(view.findViewById(R.id.reviews_summary),
numberInfo.communityDatabaseItem);
Runnable reviewsAction = () -> {
context.startActivity(clearTop(
ReviewsActivity.getNumberIntent(context, numberInfo.number)));
};
Runnable webReviewAction = () -> {
Uri uri = Uri.parse(DatabaseSingleton.getWebService().getWebReviewsUrlPart()
+ numberInfo.number);
IntentHelper.startActivity(context, new Intent(Intent.ACTION_VIEW, uri));
};
builder.setView(view)
.setNeutralButton(R.string.online_reviews, null)
.setNegativeButton(R.string.back, null);
.setPositiveButton(R.string.add_web_review, null)
.setNeutralButton(R.string.online_reviews, null);
if (onDismissListener != null) builder.setOnDismissListener(onDismissListener);
@ -73,24 +87,38 @@ public class InfoDialogHelper {
// avoid dismissing the original dialog on button press
Runnable action = () -> {
context.startActivity(clearTop(
ReviewsActivity.getNumberIntent(context, numberInfo.number)));
dialog.dismiss();
};
dialog.setOnShowListener(x -> {
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v -> {
if (numberInfo.contactItem != null) {
new AlertDialog.Builder(context)
.setTitle(R.string.load_reviews_confirmation_title)
.setMessage(R.string.load_reviews_confirmation_message)
.setPositiveButton(android.R.string.yes, (d1, w) -> action.run())
.setPositiveButton(android.R.string.yes, (d1, w) -> {
reviewsAction.run();
dialog.dismiss();
})
.setNegativeButton(android.R.string.no, null)
.show();
} else {
action.run();
reviewsAction.run();
dialog.dismiss();
}
});
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
if (numberInfo.contactItem != null) {
new AlertDialog.Builder(context)
.setTitle(R.string.load_reviews_confirmation_title)
.setMessage(R.string.load_reviews_confirmation_message)
.setPositiveButton(android.R.string.yes, (d1, w) -> {
webReviewAction.run();
dialog.dismiss();
})
.setNegativeButton(android.R.string.no, null)
.show();
} else {
webReviewAction.run();
dialog.dismiss();
}
});
});

View File

@ -6,8 +6,13 @@ import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class IntentHelper {
private static final Logger LOG = LoggerFactory.getLogger(IntentHelper.class);
public static Uri getUriForPhoneNumber(String number) {
return Uri.parse("tel:" + (!TextUtils.isEmpty(number) ? number : "private"));
}
@ -20,4 +25,12 @@ public class IntentHelper {
return intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
public static void startActivity(Context context, Intent intent) {
try {
context.startActivity(intent);
} catch (Exception e) {
LOG.warn("startActivity() error starting activity", e);
}
}
}

View File

@ -76,8 +76,8 @@ public class Config {
}
@Override
public String getCountry() {
return siaMetadata.getCountry(settings.getCountryCode()).code;
public SiaMetadata.Country getCountry() {
return siaMetadata.getCountry(settings.getCountryCode());
}
}
@ -90,6 +90,7 @@ public class Config {
wsParameterProvider.setSettings(settings);
WebService webService = new WebService(wsParameterProvider);
DatabaseSingleton.setWebService(webService);
DatabaseSingleton.setDbManager(new DbManager(storage, SIA_PATH_PREFIX));

View File

@ -12,11 +12,14 @@ import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseIte
import dummydomain.yetanothercallblocker.sia.model.database.DbManager;
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabase;
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabaseItem;
import dummydomain.yetanothercallblocker.sia.network.WebService;
public class DatabaseSingleton {
private static final Logger LOG = LoggerFactory.getLogger(DatabaseSingleton.class);
private static WebService webService;
private static DbManager dbManager;
private static SiaMetadata siaMetadata;
@ -29,6 +32,10 @@ public class DatabaseSingleton {
private static ContactsProvider contactsProvider;
static void setWebService(WebService webService) {
DatabaseSingleton.webService = webService;
}
static void setDbManager(DbManager dbManager) {
DatabaseSingleton.dbManager = dbManager;
}
@ -53,6 +60,10 @@ public class DatabaseSingleton {
DatabaseSingleton.contactsProvider = contactsProvider;
}
public static WebService getWebService() {
return webService;
}
public static DbManager getDbManager() {
return dbManager;
}

View File

@ -65,6 +65,7 @@
<string name="secondary_db_updating">Обновение базы номеров…</string>
<string name="recent_calls">Недавние вызовы</string>
<string name="online_reviews">Online-отзывы</string>
<string name="add_web_review">Добавить отзыв (веб)</string>
<string name="back">Назад</string>
<string name="no">Нет</string>
<string name="load_reviews_confirmation_title">Вы уверены?</string>

View File

@ -70,6 +70,7 @@
<string name="recent_calls">Recent calls</string>
<string name="online_reviews">Online reviews</string>
<string name="add_web_review">Add review (web)</string>
<string name="back">Back</string>
<string name="no">No</string>