mirror of
https://gitlab.com/xynngh/YetAnotherCallBlocker.git
synced 2025-06-05 22:19:12 +02:00
Extract NotificationService
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package dummydomain.yetanothercallblocker;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||||
|
|
||||||
|
public class NotificationService {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
public NotificationService(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startCallIndication(NumberInfo numberInfo) {
|
||||||
|
NotificationHelper.showIncomingCallNotification(context, numberInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopAllCallsIndication() {
|
||||||
|
NotificationHelper.hideIncomingCallNotification(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyCallBlocked(NumberInfo numberInfo) {
|
||||||
|
NotificationHelper.showBlockedCallNotification(context, numberInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -19,12 +19,15 @@ public class PhoneStateHandler {
|
|||||||
|
|
||||||
private final Settings settings;
|
private final Settings settings;
|
||||||
private final NumberInfoService numberInfoService;
|
private final NumberInfoService numberInfoService;
|
||||||
|
private final NotificationService notificationService;
|
||||||
|
|
||||||
private boolean isOffHook;
|
private boolean isOffHook;
|
||||||
|
|
||||||
public PhoneStateHandler(Settings settings, NumberInfoService numberInfoService) {
|
public PhoneStateHandler(Settings settings, NumberInfoService numberInfoService,
|
||||||
|
NotificationService notificationService) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.numberInfoService = numberInfoService;
|
this.numberInfoService = numberInfoService;
|
||||||
|
this.notificationService = notificationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRinging(Context context, String phoneNumber) {
|
public void onRinging(Context context, String phoneNumber) {
|
||||||
@@ -53,7 +56,7 @@ public class PhoneStateHandler {
|
|||||||
blocked = PhoneUtils.rejectCall(context);
|
blocked = PhoneUtils.rejectCall(context);
|
||||||
|
|
||||||
if (blocked) {
|
if (blocked) {
|
||||||
notifyBlocked(context, numberInfo);
|
notificationService.notifyCallBlocked(numberInfo);
|
||||||
|
|
||||||
numberInfoService.blockedCall(numberInfo);
|
numberInfoService.blockedCall(numberInfo);
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ public class PhoneStateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!blocked && showNotifications) {
|
if (!blocked && showNotifications) {
|
||||||
startIndication(context, numberInfo);
|
notificationService.startCallIndication(numberInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,21 +82,9 @@ public class PhoneStateHandler {
|
|||||||
|
|
||||||
isOffHook = false;
|
isOffHook = false;
|
||||||
|
|
||||||
stopAllIndication(context);
|
notificationService.stopAllCallsIndication();
|
||||||
|
|
||||||
postEvent(new CallEndedEvent());
|
postEvent(new CallEndedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startIndication(Context context, NumberInfo numberInfo) {
|
|
||||||
NotificationHelper.showIncomingCallNotification(context, numberInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopAllIndication(Context context) {
|
|
||||||
NotificationHelper.hideIncomingCallNotification(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyBlocked(Context context, NumberInfo numberInfo) {
|
|
||||||
NotificationHelper.showBlockedCallNotification(context, numberInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.NotificationService;
|
||||||
import dummydomain.yetanothercallblocker.PermissionHelper;
|
import dummydomain.yetanothercallblocker.PermissionHelper;
|
||||||
import dummydomain.yetanothercallblocker.PhoneStateHandler;
|
import dummydomain.yetanothercallblocker.PhoneStateHandler;
|
||||||
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
||||||
@@ -148,7 +149,11 @@ public class Config {
|
|||||||
communityDatabase, featuredDatabase, contactsProvider, blacklistService);
|
communityDatabase, featuredDatabase, contactsProvider, blacklistService);
|
||||||
YacbHolder.setNumberInfoService(numberInfoService);
|
YacbHolder.setNumberInfoService(numberInfoService);
|
||||||
|
|
||||||
YacbHolder.setPhoneStateHandler(new PhoneStateHandler(settings, numberInfoService));
|
NotificationService notificationService = new NotificationService(context);
|
||||||
|
YacbHolder.setNotificationService(notificationService);
|
||||||
|
|
||||||
|
YacbHolder.setPhoneStateHandler(
|
||||||
|
new PhoneStateHandler(settings, numberInfoService, notificationService));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
package dummydomain.yetanothercallblocker.data;
|
package dummydomain.yetanothercallblocker.data;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.NotificationService;
|
||||||
import dummydomain.yetanothercallblocker.PhoneStateHandler;
|
import dummydomain.yetanothercallblocker.PhoneStateHandler;
|
||||||
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.CommunityReviewsLoader;
|
import dummydomain.yetanothercallblocker.sia.model.CommunityReviewsLoader;
|
||||||
@@ -23,6 +26,9 @@ public class YacbHolder {
|
|||||||
|
|
||||||
private static NumberInfoService numberInfoService;
|
private static NumberInfoService numberInfoService;
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
private static NotificationService notificationService;
|
||||||
|
|
||||||
private static PhoneStateHandler phoneStateHandler;
|
private static PhoneStateHandler phoneStateHandler;
|
||||||
|
|
||||||
static void setWebService(WebService webService) {
|
static void setWebService(WebService webService) {
|
||||||
@@ -61,6 +67,10 @@ public class YacbHolder {
|
|||||||
YacbHolder.numberInfoService = numberInfoService;
|
YacbHolder.numberInfoService = numberInfoService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setNotificationService(NotificationService notificationService) {
|
||||||
|
YacbHolder.notificationService = notificationService;
|
||||||
|
}
|
||||||
|
|
||||||
static void setPhoneStateHandler(PhoneStateHandler phoneStateHandler) {
|
static void setPhoneStateHandler(PhoneStateHandler phoneStateHandler) {
|
||||||
YacbHolder.phoneStateHandler = phoneStateHandler;
|
YacbHolder.phoneStateHandler = phoneStateHandler;
|
||||||
}
|
}
|
||||||
@@ -101,6 +111,10 @@ public class YacbHolder {
|
|||||||
return numberInfoService;
|
return numberInfoService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NotificationService getNotificationService() {
|
||||||
|
return notificationService;
|
||||||
|
}
|
||||||
|
|
||||||
public static PhoneStateHandler getPhoneStateHandler() {
|
public static PhoneStateHandler getPhoneStateHandler() {
|
||||||
return phoneStateHandler;
|
return phoneStateHandler;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user