Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OreoCompatNotificationChannelProvider.java « background « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6874e76eeb4956b10d47d2da72ea01ddbaa4684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.mapswithme.maps.background;

import android.annotation.TargetApi;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import androidx.annotation.NonNull;

import com.mapswithme.maps.R;

import java.util.Objects;

@TargetApi(Build.VERSION_CODES.O)
public class OreoCompatNotificationChannelProvider extends StubNotificationChannelProvider
{
  private static final String AUTH_NOTIFICATION_CHANNEL = "auth_notification_channel";
  private static final String DOWNLOADING_NOTIFICATION_CHANNEL = "downloading_notification_channel";

  OreoCompatNotificationChannelProvider(@NonNull Application app)
  {
    super(app, AUTH_NOTIFICATION_CHANNEL, DOWNLOADING_NOTIFICATION_CHANNEL);
  }

  @Override
  public void setUGCChannel()
  {
    String name = getApplication().getString(R.string.notification_channel_ugc);
    setChannelInternal(getUGCChannel(), name);
  }

  private void setChannelInternal(@NonNull String id, @NonNull String name)
  {
    NotificationManager notificationManager = getApplication().getSystemService(NotificationManager.class);
    NotificationChannel channel = Objects.requireNonNull(notificationManager)
                                         .getNotificationChannel(id);
    if (channel == null)
      channel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT);
    else
      channel.setName(name);
    notificationManager.createNotificationChannel(channel);
  }

  @Override
  public void setDownloadingChannel()
  {
    String name = getApplication().getString(R.string.notification_channel_downloader);
    setChannelInternal(getDownloadingChannel(), name);
  }
}