<commit_before>package yuku.alkitab.base.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import gnu.trove.set.TLongSet;
import gnu.trove.set.hash.TLongHashSet;
import yuku.afw.storage.Preferences;
import yuku.alkitab.base.App;
import yuku.alkitab.base.U;
import yuku.alkitab.base.ac.HelpActivity;
import yuku.alkitab.base.storage.Prefkey;
import yuku.alkitab.debug.BuildConfig;
import yuku.alkitab.debug.R;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public abstract class Announce {
	static final String TAG = Announce.class.getSimpleName();

	public static final int AUTO_CHECK_INTERVAL_SECONDS = BuildConfig.DEBUG ? 60 : 86400 /* 1 days */;

	public static void checkAnnouncements() {
		final int lastCheck = Preferences.getInt(Prefkey.announce_last_check, 0);
		if (lastCheck != 0 && (Sqlitil.nowDateTime() - lastCheck) < AUTO_CHECK_INTERVAL_SECONDS) {
			Log.d(TAG, "@@checkAnnouncements exit because it was recently checked");
			return;
		}

		new Thread(() -> {
			try {
				SystemClock.sleep(10000); // wait 10 seconds
				checkAnnouncements_worker();
			} catch (Exception e) { // handle all exceptions, because we don't want the main app to crash because of this.
				Log.d(TAG, "@@checkAnnouncements", e);
			}
		}).start();
	}

	static class Announcement {
		public long id;
		public String title;
		public int createTime;
	}

	static class AnnounceCheckResult {
		public boolean success;
		public String message;
		public Announcement[] announcements;
	}

	private static void checkAnnouncements_worker() throws Exception {
		final List<Announcement> unreadAnnouncements = new ArrayList<>();

		{
			final AnnounceCheckResult result = getAnnouncements();
			if (!result.success) {
				Log.d(TAG, "Announce check returns success=false: " + result.message);
				if (result.message != null) {
					Toast.makeText(App.context, "Announce: " + result.message, Toast.LENGTH_LONG).show();
				}
				return;
			}

			if (result.announcements != null) {
				final TLongSet read = getReadAnnouncementIds();<commit_msg>Remove erroneous Toast<commit_after>package yuku.alkitab.base.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import gnu.trove.set.TLongSet;
import gnu.trove.set.hash.TLongHashSet;
import yuku.afw.storage.Preferences;
import yuku.alkitab.base.App;
import yuku.alkitab.base.U;
import yuku.alkitab.base.ac.HelpActivity;
import yuku.alkitab.base.storage.Prefkey;
import yuku.alkitab.debug.BuildConfig;
import yuku.alkitab.debug.R;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public abstract class Announce {
	static final String TAG = Announce.class.getSimpleName();

	public static final int AUTO_CHECK_INTERVAL_SECONDS = BuildConfig.DEBUG ? 60 : 86400 /* 1 days */;

	public static void checkAnnouncements() {
		final int lastCheck = Preferences.getInt(Prefkey.announce_last_check, 0);
		if (lastCheck != 0 && (Sqlitil.nowDateTime() - lastCheck) < AUTO_CHECK_INTERVAL_SECONDS) {
			Log.d(TAG, "@@checkAnnouncements exit because it was recently checked");
			return;
		}

		new Thread(() -> {
			try {
				SystemClock.sleep(10000); // wait 10 seconds
				checkAnnouncements_worker();
			} catch (Exception e) { // handle all exceptions, because we don't want the main app to crash because of this.
				Log.d(TAG, "@@checkAnnouncements", e);
			}
		}).start();
	}

	static class Announcement {
		public long id;
		public String title;
		public int createTime;
	}

	static class AnnounceCheckResult {
		public boolean success;
		public String message;
		public Announcement[] announcements;
	}

	private static void checkAnnouncements_worker() throws Exception {
		final List<Announcement> unreadAnnouncements = new ArrayList<>();

		{
			final AnnounceCheckResult result = getAnnouncements();
			if (!result.success) {
				Log.d(TAG, "Announce check returns success=false: " + result.message);
				return;
			}

			if (result.announcements != null) {
				final TLongSet read = getReadAnnouncementIds();
{'fraction_non_alphanumeric': 0.10829730286184888, 'fraction_numerical': 0.0074119827053736875, 'mean_word_length': 4.675233644859813, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4330171', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1523, 'n_words': 370}