Extract NotificationService
This commit is contained in:
parent
b06a3d47fb
commit
29f36b883a
|
@ -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 NumberInfoService numberInfoService;
|
||||
private final NotificationService notificationService;
|
||||
|
||||
private boolean isOffHook;
|
||||
|
||||
public PhoneStateHandler(Settings settings, NumberInfoService numberInfoService) {
|
||||
public PhoneStateHandler(Settings settings, NumberInfoService numberInfoService,
|
||||
NotificationService notificationService) {
|
||||
this.settings = settings;
|
||||
this.numberInfoService = numberInfoService;
|
||||
this.notificationService = notificationService;
|
||||
}
|
||||
|
||||
public void onRinging(Context context, String phoneNumber) {
|
||||
|
@ -53,7 +56,7 @@ public class PhoneStateHandler {
|
|||
blocked = PhoneUtils.rejectCall(context);
|
||||
|
||||
if (blocked) {
|
||||
notifyBlocked(context, numberInfo);
|
||||
notificationService.notifyCallBlocked(numberInfo);
|
||||
|
||||
numberInfoService.blockedCall(numberInfo);
|
||||
|
||||
|
@ -62,7 +65,7 @@ public class PhoneStateHandler {
|
|||
}
|
||||
|
||||
if (!blocked && showNotifications) {
|
||||
startIndication(context, numberInfo);
|
||||
notificationService.startCallIndication(numberInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,21 +82,9 @@ public class PhoneStateHandler {
|
|||
|
||||
isOffHook = false;
|
||||
|
||||
stopAllIndication(context);
|
||||
notificationService.stopAllCallsIndication();
|
||||
|
||||
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 dummydomain.yetanothercallblocker.NotificationService;
|
||||
import dummydomain.yetanothercallblocker.PermissionHelper;
|
||||
import dummydomain.yetanothercallblocker.PhoneStateHandler;
|
||||
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
||||
|
@ -148,7 +149,11 @@ public class Config {
|
|||
communityDatabase, featuredDatabase, contactsProvider, blacklistService);
|
||||
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;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import dummydomain.yetanothercallblocker.NotificationService;
|
||||
import dummydomain.yetanothercallblocker.PhoneStateHandler;
|
||||
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
||||
import dummydomain.yetanothercallblocker.sia.model.CommunityReviewsLoader;
|
||||
|
@ -23,6 +26,9 @@ public class YacbHolder {
|
|||
|
||||
private static NumberInfoService numberInfoService;
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static NotificationService notificationService;
|
||||
|
||||
private static PhoneStateHandler phoneStateHandler;
|
||||
|
||||
static void setWebService(WebService webService) {
|
||||
|
@ -61,6 +67,10 @@ public class YacbHolder {
|
|||
YacbHolder.numberInfoService = numberInfoService;
|
||||
}
|
||||
|
||||
static void setNotificationService(NotificationService notificationService) {
|
||||
YacbHolder.notificationService = notificationService;
|
||||
}
|
||||
|
||||
static void setPhoneStateHandler(PhoneStateHandler phoneStateHandler) {
|
||||
YacbHolder.phoneStateHandler = phoneStateHandler;
|
||||
}
|
||||
|
@ -101,6 +111,10 @@ public class YacbHolder {
|
|||
return numberInfoService;
|
||||
}
|
||||
|
||||
public static NotificationService getNotificationService() {
|
||||
return notificationService;
|
||||
}
|
||||
|
||||
public static PhoneStateHandler getPhoneStateHandler() {
|
||||
return phoneStateHandler;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue