<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.simonvt.cathode.notification;

import android.app.IntentService;
import android.app.NotificationManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import javax.inject.Inject;
import net.simonvt.cathode.CathodeApp;
import net.simonvt.cathode.jobqueue.JobManager;
import net.simonvt.cathode.provider.DatabaseContract.EpisodeColumns;
import net.simonvt.cathode.provider.EpisodeDatabaseHelper;
import net.simonvt.cathode.provider.ProviderSchematic.Episodes;
import net.simonvt.cathode.remote.action.shows.CheckInEpisode;
import net.simonvt.cathode.util.WakeLock;
import timber.log.Timber;

public class NotificationActionService extends IntentService {

  static final String LOCK_TAG = "NotificationActionService";

  @Inject JobManager jobManager;

  @Inject EpisodeDatabaseHelper episodeHelper;

  public NotificationActionService() {
    super("NotificationActionService");
  }

  @Override public void onCreate() {
    super.onCreate();
    CathodeApp.inject(this);
  }

  @Override public void onDestroy() {
    WakeLock.release(this, LOCK_TAG);
    super.onDestroy();
  }

  @Override protected void onHandleIntent(Intent intent) {
    final String action = intent.getAction();
    final int notificationId =
        intent.getIntExtra(NotificationActionReceiver.EXTRA_NOTIFICATION_ID, -1);
    final long id = intent.getLongExtra(NotificationActionReceiver.EXTRA_ID, -1L);

    switch (action) {
      case NotificationActionReceiver.ACTION_CHECK_IN: {
        Timber.d("Action check in");
        final long traktId = episodeHelper.getTraktId(id);
        CheckInEpisode checkInJob = new CheckInEpisode(traktId, null, false, false, false);
        jobManager.addJobNow(checkInJob);

        NotificationManager nm =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (notificationId > -1) {
          int notificationCount = -1;
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            notificationCount =
                NotificationService.getGroupNotificationCount(nm, NotificationService.GROUP);<commit_msg>If intent is null, return immediately.<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.simonvt.cathode.notification;

import android.app.IntentService;
import android.app.NotificationManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import javax.inject.Inject;
import net.simonvt.cathode.CathodeApp;
import net.simonvt.cathode.jobqueue.JobManager;
import net.simonvt.cathode.provider.DatabaseContract.EpisodeColumns;
import net.simonvt.cathode.provider.EpisodeDatabaseHelper;
import net.simonvt.cathode.provider.ProviderSchematic.Episodes;
import net.simonvt.cathode.remote.action.shows.CheckInEpisode;
import net.simonvt.cathode.util.WakeLock;
import timber.log.Timber;

public class NotificationActionService extends IntentService {

  static final String LOCK_TAG = "NotificationActionService";

  @Inject JobManager jobManager;

  @Inject EpisodeDatabaseHelper episodeHelper;

  public NotificationActionService() {
    super("NotificationActionService");
  }

  @Override public void onCreate() {
    super.onCreate();
    CathodeApp.inject(this);
  }

  @Override public void onDestroy() {
    WakeLock.release(this, LOCK_TAG);
    super.onDestroy();
  }

  @Override protected void onHandleIntent(Intent intent) {
    if (intent == null) {
      return;
    }

    final String action = intent.getAction();
    final int notificationId =
        intent.getIntExtra(NotificationActionReceiver.EXTRA_NOTIFICATION_ID, -1);
    final long id = intent.getLongExtra(NotificationActionReceiver.EXTRA_ID, -1L);

    switch (action) {
      case NotificationActionReceiver.ACTION_CHECK_IN: {
        Timber.d("Action check in");
        final long traktId = episodeHelper.getTraktId(id);
        CheckInEpisode checkInJob = new CheckInEpisode(traktId, null, false, false, false);
        jobManager.addJobNow(checkInJob);

        NotificationManager nm =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (notificationId > -1) {
          int notificationCount = -1;
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            notificationCount =
                NotificationService.getGroupNotificationCount(nm, NotificationService.GROUP);
{'fraction_non_alphanumeric': 0.08815182688896772, 'fraction_numerical': 0.004256828662646328, 'mean_word_length': 4.140382862351869, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5221210', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1558, 'n_words': 412}