Skip to content

Commit

Permalink
feat(android): Remove all gms usages and use guava instead
Browse files Browse the repository at this point in the history
  • Loading branch information
meypod committed Sep 4, 2022
1 parent 8622f84 commit c5083e3
Show file tree
Hide file tree
Showing 12 changed files with 579 additions and 422 deletions.
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ dependencies {
api 'androidx.annotation:annotation:1.3.0' // https://developer.android.com/jetpack/androidx/releases/annotation
api "com.squareup.okhttp3:okhttp:3.12.12" // okhttp must stay on 3.12.x to support minSdkVersion < 21
api 'androidx.concurrent:concurrent-futures:1.1.0' // https://developer.android.com/jetpack/androidx/releases/concurrent
api 'com.google.android.gms:play-services-tasks:18.0.1' // https://developers.google.com/android/guides/releases
api 'androidx.work:work-runtime:2.7.1' // https://developer.android.com/jetpack/androidx/releases/work
api 'com.facebook.fresco:fresco:2.6.0' // https://github.com/facebook/fresco/releases

implementation("com.google.guava:guava:31.1-android") // https://github.com/google/guava
implementation 'androidx.core:core:1.6.0'

def room_version = '2.3.0' // https://developer.android.com/jetpack/androidx/releases/room
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Expand Down
79 changes: 39 additions & 40 deletions android/src/main/java/app/notifee/core/ChannelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,28 @@
import app.notifee.core.model.ChannelModel;
import app.notifee.core.utility.ColorUtils;
import app.notifee.core.utility.ResourceUtils;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ChannelManager {

private static String TAG = "ChannelManager";
private static ExecutorService executorService = Executors.newCachedThreadPool();
private static ListeningExecutorService lExecutorService = MoreExecutors.listeningDecorator(
executorService);

static Task<Void> createChannel(ChannelModel channelModel) {
return Tasks.call(
executorService,
() -> {
if (Build.VERSION.SDK_INT < 26) {
return null;
}
static ListenableFuture<Void> createChannel(ChannelModel channelModel) {
return lExecutorService.submit(
() -> {
if (Build.VERSION.SDK_INT < 26) {
return null;
}

NotificationChannel channel =
new NotificationChannel(
Expand Down Expand Up @@ -99,21 +102,19 @@ static Task<Void> createChannel(ChannelModel channelModel) {
});
}

static Task<Void> createChannels(List<ChannelModel> channelModels) {
return Tasks.call(
executorService,
static ListenableFuture<Void> createChannels(List<ChannelModel> channelModels) {
return lExecutorService.submit(
() -> {
for (ChannelModel channelModel : channelModels) {
Tasks.await(createChannel(channelModel));
createChannel(channelModel).get();
}

return null;
});
}

static Task<Void> createChannelGroup(ChannelGroupModel channelGroupModel) {
return Tasks.call(
executorService,
static ListenableFuture<Void> createChannelGroup(ChannelGroupModel channelGroupModel) {
return lExecutorService.submit(
() -> {
if (Build.VERSION.SDK_INT < 26) {
return null;
Expand All @@ -133,16 +134,16 @@ static Task<Void> createChannelGroup(ChannelGroupModel channelGroupModel) {
});
}

static Task<Void> createChannelGroups(List<ChannelGroupModel> channelGroupModels) {
return Tasks.call(
executorService,
static ListenableFuture<Void> createChannelGroups(
List<ChannelGroupModel> channelGroupModels) {
return lExecutorService.submit(
() -> {
if (Build.VERSION.SDK_INT < 26) {
return null;
}

for (ChannelGroupModel channelGroupModel : channelGroupModels) {
Tasks.await(createChannelGroup(channelGroupModel));
createChannelGroup(channelGroupModel).get();
}

return null;
Expand All @@ -159,9 +160,8 @@ static void deleteChannelGroup(@NonNull String channelGroupId) {
.deleteNotificationChannelGroup(channelGroupId);
}

static Task<List<Bundle>> getChannels() {
return Tasks.call(
executorService,
static ListenableFuture<List<Bundle>> getChannels() {
return lExecutorService.submit(
() -> {
List<NotificationChannel> channels =
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
Expand All @@ -180,9 +180,8 @@ static Task<List<Bundle>> getChannels() {
});
}

static Task<Bundle> getChannel(String channelId) {
return Tasks.call(
executorService,
static ListenableFuture<Bundle> getChannel(String channelId) {
return lExecutorService.submit(
() -> {
NotificationChannel channel =
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
Expand All @@ -192,9 +191,8 @@ static Task<Bundle> getChannel(String channelId) {
});
}

static Task<Boolean> isChannelBlocked(String channelId) {
return Tasks.call(
executorService,
static ListenableFuture<Boolean> isChannelBlocked(String channelId) {
return lExecutorService.submit(
() -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false;

Expand All @@ -210,9 +208,8 @@ static Task<Boolean> isChannelBlocked(String channelId) {
});
}

static Task<Boolean> isChannelCreated(String channelId) {
return Tasks.call(
executorService,
static ListenableFuture<Boolean> isChannelCreated(String channelId) {
return lExecutorService.submit(
() -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false;

Expand All @@ -224,9 +221,8 @@ static Task<Boolean> isChannelCreated(String channelId) {
});
}

static Task<List<Bundle>> getChannelGroups() {
return Tasks.call(
executorService,
static ListenableFuture<List<Bundle>> getChannelGroups() {
return lExecutorService.submit(
() -> {
List<NotificationChannelGroup> channelGroups =
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
Expand All @@ -245,13 +241,12 @@ static Task<List<Bundle>> getChannelGroups() {
});
}

static Task<Bundle> getChannelGroup(String channelGroupId) {
return Tasks.call(
executorService,
static ListenableFuture<Bundle> getChannelGroup(String channelGroupId) {
return lExecutorService.submit(
() -> {
NotificationChannelGroup channelGroup =
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
.getNotificationChannelGroup(channelGroupId);
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
.getNotificationChannelGroup(channelGroupId);

return convertChannelGroupToBundle(channelGroup);
});
Expand Down Expand Up @@ -349,4 +344,8 @@ private static Bundle convertChannelGroupToBundle(NotificationChannelGroup chann

return channelGroupBundle;
}

public static ListeningExecutorService getListeningExecutorService() {
return lExecutorService;
}
}
Loading

0 comments on commit c5083e3

Please sign in to comment.