Kaktus dobíječka je aplikace pro android, která rozesílá oznámení o akci, při které když si
9 | dobiješ svůj kredit, tak ti Kaktus zdvojnásobí dobíjenou částku.
10 | Více informací o této akci najdeš na webu kaktusu.
11 |
Pokud se chceš zúčastnit testování aplikace, tak se musíš nejdříve
12 | přihlásit.
13 |
Jestli už jsi jako tester přihlášený, tak si aplikaci můžeš stáhnout z
14 | Google Play.
18 | Kaktus Dobíječka byla vytvořena jako aplikace s otevřenýmy zdrojovými kódy.
19 | Aplikace je poskytována zdarma a "tak jak je", bez záruky jakéhokoliv druhu.
20 |
21 |
22 | Pokud není uvedeno jinak, nebo to není ze situace zřejmé, aplikace samotná neuchovává
23 | v souvislosti se svým provozem žádné osobní údaje.
24 |
25 |
26 | Aplikace však pro svou správnou funkci, hlášení chyb a sběr informací o používaných funkcích
27 | využívá služby třetích stran, které se řídí svými zásadami ochrany osobních údajů.
28 |
29 |
30 |
31 | Zásady ochrany osobních údajů služeb třetích stran:
32 |
66 |
67 |
--------------------------------------------------------------------------------
/backend/src/main/java/eu/zkkn/android/kaktus/backend/FcmSender.kt:
--------------------------------------------------------------------------------
1 | package eu.zkkn.android.kaktus.backend
2 |
3 | import com.google.appengine.api.taskqueue.QueueFactory
4 | import com.google.appengine.api.taskqueue.RetryOptions
5 | import com.google.appengine.api.taskqueue.TaskOptions
6 | import com.google.auth.oauth2.GoogleCredentials
7 | import com.google.firebase.FirebaseApp
8 | import com.google.firebase.FirebaseOptions
9 | import com.google.firebase.messaging.AndroidConfig
10 | import com.google.firebase.messaging.FcmOptions
11 | import com.google.firebase.messaging.FirebaseMessaging
12 | import com.google.firebase.messaging.Message
13 | import java.time.format.DateTimeFormatter
14 | import java.util.logging.Logger
15 | import javax.servlet.http.HttpServlet
16 | import javax.servlet.http.HttpServletRequest
17 | import javax.servlet.http.HttpServletResponse
18 |
19 |
20 | /**
21 | * Firebase cloud messages sender
22 | * If used as a Push Queue Task the limit for execution is 10 min, otherwise it's 1 min
23 | */
24 | class FcmSender : HttpServlet() {
25 |
26 | private val log = Logger.getLogger(this::class.java.name)
27 |
28 | private val firebaseMessaging: FirebaseMessaging by lazy {
29 | val googleCredentials = GoogleCredentials.fromStream(
30 | ServletContextHolder.getServletContext()
31 | .getResourceAsStream("/WEB-INF/serviceAccountKey.json")
32 | )
33 | val options = FirebaseOptions.builder().setCredentials(googleCredentials).build()
34 | FirebaseMessaging.getInstance(FirebaseApp.initializeApp(options))
35 | }
36 |
37 | override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
38 | log.info("Start sending FCMs")
39 | val message: String? = req.getParameter(PARAM_MESSAGE_NAME)
40 | val debug: Boolean = req.getParameter(PARAM_DEBUG_NAME).toBoolean()
41 | val start: String? = req.getParameter(PARAM_START_NAME)
42 | val end: String? = req.getParameter(PARAM_END_NAME)
43 |
44 | if (message != null && message.trim().isNotEmpty()) {
45 | // Send message to topic for notifications
46 | val topic = if (Utils.isProduction() && !debug) "notifications" else "notifications-debug"
47 | sendTopicNotification(topic, message, start, end)
48 | } else {
49 | log.warning("The message to send is empty.")
50 | }
51 | log.info("Finish Sending FCMs")
52 | }
53 |
54 | private fun sendTopicNotification(topicName: String, message: String, start: String?, end: String?) {
55 | val fcmMessage = Message.builder()
56 | .setTopic(topicName)
57 | .putData("type", "notification")
58 | .putData("message", Utils.cropText(message, 1000))
59 | .putData("uri", CheckServlet.KAKTUS_DOBIJECKA_URL)
60 | .putData("start", start ?: "")
61 | .putData("end", end ?: "")
62 | .setAndroidConfig(
63 | AndroidConfig.builder()
64 | .setPriority(AndroidConfig.Priority.HIGH)
65 | .build()
66 | )
67 | .setFcmOptions(FcmOptions.withAnalyticsLabel(topicName))
68 | .build()
69 |
70 |
71 | log.info("Send message to topic: $topicName")
72 | val messageId = send(fcmMessage)
73 | if (messageId.isNullOrEmpty()) {
74 | log.severe("Error when sending message to $topicName")
75 | }
76 | if (messageId != null) log.info("Message ID: $messageId")
77 | }
78 |
79 | private fun send(message: Message): String? {
80 | // perform only a dry run if not in production
81 | val dryRun = !Utils.isProduction()
82 | if (dryRun) log.warning("FCM messages are sent only from Production environment")
83 | return firebaseMessaging.send(message, dryRun)
84 | }
85 |
86 |
87 | companion object {
88 |
89 | private const val PARAM_MESSAGE_NAME = "msg"
90 | private const val PARAM_DEBUG_NAME = "debug"
91 | private const val PARAM_START_NAME = "start"
92 | private const val PARAM_END_NAME = "end"
93 |
94 | @JvmStatic @JvmOverloads
95 | fun sendFcmToAll(message: String?, timeInfo: TimeInfo? = null, debug: Boolean = false) {
96 | QueueFactory.getDefaultQueue().add(
97 | TaskOptions.Builder.withUrl("/tasks/fcm-sender")
98 | .param(PARAM_MESSAGE_NAME, message)
99 | .param(PARAM_DEBUG_NAME, debug.toString())
100 | .param(PARAM_START_NAME,
101 | timeInfo?.start?.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) ?: ""
102 | )
103 | .param(PARAM_END_NAME,
104 | timeInfo?.end?.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) ?: ""
105 | )
106 | .retryOptions(RetryOptions.Builder.withTaskRetryLimit(3))
107 | )
108 | }
109 |
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/zkkn/android/kaktus/fcm/FcmSubscriptionWorker.kt:
--------------------------------------------------------------------------------
1 | package eu.zkkn.android.kaktus.fcm
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.util.Log
6 | import androidx.localbroadcastmanager.content.LocalBroadcastManager
7 | import androidx.work.*
8 | import com.google.firebase.crashlytics.FirebaseCrashlytics
9 | import com.google.firebase.ktx.Firebase
10 | import com.google.firebase.messaging.FirebaseMessaging
11 | import com.google.firebase.messaging.ktx.messaging
12 | import eu.zkkn.android.kaktus.BuildConfig
13 | import eu.zkkn.android.kaktus.Config
14 | import eu.zkkn.android.kaktus.Preferences
15 | import kotlinx.coroutines.Dispatchers
16 | import kotlinx.coroutines.tasks.await
17 | import kotlinx.coroutines.withContext
18 | import java.util.concurrent.TimeUnit
19 |
20 |
21 | class FcmSubscriptionWorker(
22 | private val appContext: Context,
23 | params: WorkerParameters
24 | ) : CoroutineWorker(appContext, params) {
25 |
26 |
27 | companion object {
28 |
29 | const val WORKER_HAS_FINISHED = "WorkerHasFinished"
30 | const val PERIODIC_WORK_VERSION = 3
31 |
32 | private const val PERIODIC_WORK_NAME = "eu.zkkn.android.kaktus.work.PERIODIC_REFRESH"
33 |
34 | @JvmStatic
35 | fun runSubscribeToTopics(context: Context) {
36 | val sendTokenTask = OneTimeWorkRequest.Builder(FcmSubscriptionWorker::class.java)
37 | .setConstraints(
38 | Constraints.Builder()
39 | .setRequiredNetworkType(NetworkType.CONNECTED)
40 | .build()
41 | )
42 | .build()
43 | Log.d(Config.TAG, "FcmSubscriptionWorker.runSubscribeToTopics()")
44 | WorkManager.getInstance(context).enqueue(sendTokenTask)
45 | }
46 |
47 | @JvmStatic
48 | fun schedulePeriodicSubscriptionRefresh(context: Context) {
49 | if (Preferences.isPeriodicSubscriptionRefreshEnabled(context)) return
50 |
51 | Log.d(Config.TAG, "Schedule periodic refresh for FCM topic subscriptions")
52 | val workManager = WorkManager.getInstance(context)
53 | workManager.enqueueUniquePeriodicWork(
54 | PERIODIC_WORK_NAME,
55 | ExistingPeriodicWorkPolicy.UPDATE,
56 | PeriodicWorkRequest.Builder(FcmSubscriptionWorker::class.java, 28, TimeUnit.DAYS, 4, TimeUnit.DAYS)
57 | .addTag(PERIODIC_WORK_NAME)
58 | .setBackoffCriteria(
59 | BackoffPolicy.EXPONENTIAL,
60 | WorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS * 4,
61 | TimeUnit.MILLISECONDS
62 | )
63 | .setConstraints(
64 | Constraints.Builder()
65 | .setRequiredNetworkType(NetworkType.CONNECTED)
66 | .setRequiresCharging(true)
67 | .build()
68 | )
69 | .build()
70 | )
71 | Preferences.setPeriodicSubscriptionRefresh(context)
72 | }
73 |
74 | }
75 |
76 | override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
77 | var result = Result.success()
78 |
79 | try {
80 | // Get updated InstanceID token.
81 | val token: String = Firebase.messaging.token.await()
82 | Log.i(Config.TAG, "FCM Registration Token: $token")
83 |
84 | val firebaseMessaging = FirebaseMessaging.getInstance()
85 |
86 | // subscribe to notifications
87 | firebaseMessaging.subscribeToTopic(FcmHelper.FCM_TOPIC_NOTIFICATIONS)
88 |
89 | // and also to debug notifications if this is a debug build
90 | if (BuildConfig.DEBUG) {
91 | firebaseMessaging.subscribeToTopic("${FcmHelper.FCM_TOPIC_NOTIFICATIONS}-debug")
92 | }
93 |
94 | Preferences.setFcmToken(applicationContext, token)
95 | Preferences.setSubscribedToNotifications(applicationContext, true)
96 | Preferences.setLastSubscriptionRefresh(applicationContext)
97 |
98 | //TODO: send test FCM to make sure the device can receive our messages
99 |
100 | } catch (e: Exception) {
101 |
102 | Log.d(Config.TAG, "Failed attempt to subscribe for Topic notifications", e)
103 | FirebaseCrashlytics.getInstance().recordException(e)
104 |
105 | // If an exception happens while fetching the new token or updating our registration data
106 | // on a third-party server, this ensures that we'll attempt the update at a later time.
107 | result = Result.retry()
108 |
109 | }
110 |
111 | // Notify UI that registration has completed.
112 | LocalBroadcastManager.getInstance(appContext)
113 | .sendBroadcast(Intent(WORKER_HAS_FINISHED))
114 |
115 | return@withContext result
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/zkkn/android/kaktus/fcm/MyFcmListenerService.java:
--------------------------------------------------------------------------------
1 | package eu.zkkn.android.kaktus.fcm;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.Uri;
7 | import android.text.TextUtils;
8 | import android.util.Log;
9 |
10 | import com.google.firebase.analytics.FirebaseAnalytics;
11 | import com.google.firebase.messaging.FirebaseMessagingService;
12 | import com.google.firebase.messaging.RemoteMessage;
13 |
14 | import java.util.Date;
15 | import java.util.Map;
16 | import java.util.concurrent.TimeUnit;
17 |
18 | import androidx.annotation.NonNull;
19 | import androidx.annotation.Nullable;
20 | import androidx.core.app.NotificationCompat;
21 | import androidx.localbroadcastmanager.content.LocalBroadcastManager;
22 |
23 | import eu.zkkn.android.kaktus.CancelNotificationReceiver;
24 | import eu.zkkn.android.kaktus.Config;
25 | import eu.zkkn.android.kaktus.FirebaseAnalyticsHelper;
26 | import eu.zkkn.android.kaktus.LastNotification;
27 | import eu.zkkn.android.kaktus.MainActivity;
28 | import eu.zkkn.android.kaktus.NotificationHelper;
29 | import eu.zkkn.android.kaktus.R;
30 |
31 |
32 | public class MyFcmListenerService extends FirebaseMessagingService {
33 |
34 | public static final String FCM_MESSAGE_RECEIVED = "fcmMessageReceived";
35 |
36 |
37 | @Override
38 | public void onNewToken(@NonNull String token) {
39 | FcmSubscriptionWorker.runSubscribeToTopics(this);
40 | }
41 |
42 | @Override
43 | public void onMessageReceived(RemoteMessage remoteMessage) {
44 | //TODO: with the new Task Queue sender the same message can be in some rare circumstances sent multiple times
45 | Map data = remoteMessage.getData();
46 | //Warning: App versions 0.4.6 (15) and bellow doesn't filter notifications nor support URI
47 | String type = data.get("type");
48 | if ("notification".equals(type)) {
49 | long sentTime = remoteMessage.getSentTime();
50 | String from = remoteMessage.getFrom();
51 | String message = data.get("message");
52 | String uri = data.get("uri");
53 |
54 | Log.d(Config.TAG, "From: " + from + ", Type: " + type + "Time: "
55 | + sentTime + ", Message: " + message + ", URI: " + uri);
56 |
57 | // save it as the last notification
58 | LastNotification.save(this, new LastNotification.Notification(
59 | new Date(sentTime), new Date(), message, uri, from));
60 |
61 | // Notify UI that a new FCM message was received.
62 | LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(FCM_MESSAGE_RECEIVED));
63 |
64 | // show notification if the message is fresh
65 | if (sentTime > (System.currentTimeMillis() - TimeUnit.HOURS.toMillis(12))) {
66 | showNotification(this, message, uri);
67 | }
68 | }
69 |
70 | // Send events to Firebase Analytics
71 | FirebaseAnalyticsHelper firebaseAnalytics = new FirebaseAnalyticsHelper(
72 | FirebaseAnalytics.getInstance(this));
73 | firebaseAnalytics.logEvent(FirebaseAnalyticsHelper.EVENT_FCM_RECEIVED, type);
74 | if (remoteMessage.getPriority() != remoteMessage.getOriginalPriority()) {
75 | firebaseAnalytics.logEvent(FirebaseAnalyticsHelper.EVENT_FCM_PRIORITY_CHANGED);
76 | }
77 | }
78 |
79 |
80 | protected static void showNotification(Context context, String message, @Nullable String uri) {
81 | Context ctx = context.getApplicationContext();
82 |
83 | int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
84 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
85 | pendingIntentFlags |= PendingIntent.FLAG_IMMUTABLE;
86 | }
87 |
88 | NotificationCompat.Builder builder = NotificationHelper
89 | .getDefaultBuilder(ctx, NotificationHelper.DOBIJECKA_CHANNEL_ID)
90 | .setContentText(message)
91 | .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
92 | .setAutoCancel(true);
93 |
94 | PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0,
95 | new Intent(ctx, MainActivity.class), pendingIntentFlags);
96 | builder.setContentIntent(pendingIntent);
97 |
98 | // add action if URI is not empty and intent for that URI can be resolved
99 | Intent action = null;
100 | if (!TextUtils.isEmpty(uri)) {
101 | action = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
102 | }
103 | if (action != null && action.resolveActivity(ctx.getPackageManager()) != null) {
104 | builder.addAction(R.drawable.ic_open, ctx.getString(R.string.notification_action_view),
105 | PendingIntent.getActivity(ctx, 0, action, pendingIntentFlags));
106 | }
107 |
108 | Intent actionCancel = CancelNotificationReceiver.getIntent(
109 | ctx, NotificationHelper.DOBIJECKA_NOTIFICATION_ID);
110 | builder.addAction(R.drawable.ic_cancel, ctx.getString(R.string.notification_action_cancel),
111 | PendingIntent.getBroadcast(ctx, NotificationHelper.DOBIJECKA_NOTIFICATION_ID,
112 | actionCancel, pendingIntentFlags));
113 |
114 | NotificationHelper.notify(ctx, NotificationHelper.DOBIJECKA_NOTIFICATION_ID,
115 | builder.build());
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/zkkn/android/kaktus/FirebaseAnalyticsHelper.java:
--------------------------------------------------------------------------------
1 | package eu.zkkn.android.kaktus;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.google.firebase.analytics.FirebaseAnalytics;
6 |
7 | import java.lang.annotation.Retention;
8 | import java.lang.annotation.RetentionPolicy;
9 |
10 | import androidx.annotation.IntDef;
11 | import androidx.annotation.NonNull;
12 |
13 |
14 | public class FirebaseAnalyticsHelper {
15 |
16 | @Retention(RetentionPolicy.SOURCE)
17 | @IntDef({EVENT_SYNC_OFF, EVENT_SYNC_ON, EVENT_FB_REFRESH, EVENT_DOBIJECKA_WEB, EVENT_KAKTUS_FB,
18 | EVENT_HIDE_DONATION, EVENT_DONATE, EVENT_DONATE_ABOUT, EVENT_FCM_RECEIVED,
19 | EVENT_FCM_PRIORITY_CHANGED})
20 | public @interface Event {}
21 | public static final int EVENT_SYNC_OFF = 1;
22 | public static final int EVENT_SYNC_ON = 2;
23 | public static final int EVENT_FB_REFRESH = 3;
24 | public static final int EVENT_DOBIJECKA_WEB = 4;
25 | public static final int EVENT_KAKTUS_FB = 5;
26 | public static final int EVENT_HIDE_DONATION = 6;
27 | public static final int EVENT_DONATE = 7;
28 | public static final int EVENT_DONATE_ABOUT = 8;
29 | public static final int EVENT_FCM_RECEIVED = 9;
30 | public static final int EVENT_FCM_PRIORITY_CHANGED = 10;
31 |
32 | private final FirebaseAnalytics mFirebaseAnalytics;
33 |
34 |
35 | public FirebaseAnalyticsHelper(FirebaseAnalytics firebaseAnalytics) {
36 | this.mFirebaseAnalytics = firebaseAnalytics;
37 | }
38 |
39 | public void logEvent(@Event int event) {
40 | logEvent(event, new Bundle());
41 | }
42 |
43 | public void logEvent(@Event int event, String contentType) {
44 | Bundle params = new Bundle(1);
45 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
46 | logEvent(event, params);
47 | }
48 |
49 | private void logEvent(@Event int event, @NonNull Bundle params) {
50 | String name;
51 | switch (event) {
52 | case EVENT_SYNC_OFF:
53 | name = FirebaseAnalytics.Event.SELECT_CONTENT;
54 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "settings_fb_sync");
55 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "CheckBox");
56 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "disable");
57 | break;
58 | case EVENT_SYNC_ON:
59 | name = FirebaseAnalytics.Event.SELECT_CONTENT;
60 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "settings_fb_sync");
61 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "CheckBox");
62 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "enable");
63 | break;
64 | case EVENT_FB_REFRESH:
65 | name = FirebaseAnalytics.Event.SELECT_CONTENT;
66 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "main_fb_refresh");
67 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Button");
68 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "refresh");
69 | break;
70 | case EVENT_DOBIJECKA_WEB:
71 | name = FirebaseAnalytics.Event.VIEW_ITEM;
72 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "main_notification");
73 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "CardView");
74 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "dobijecka_web");
75 | break;
76 | case EVENT_KAKTUS_FB:
77 | name = FirebaseAnalytics.Event.VIEW_ITEM;
78 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "main_fb_post");
79 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "CardView");
80 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "kaktus_fb");
81 | break;
82 | case EVENT_HIDE_DONATION:
83 | name = FirebaseAnalytics.Event.SELECT_CONTENT;
84 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "main_donation_hide");
85 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Button");
86 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "hide");
87 | break;
88 | case EVENT_DONATE:
89 | name = FirebaseAnalytics.Event.SELECT_CONTENT;
90 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "main_donation_send");
91 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Button");
92 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "make_donation");
93 | break;
94 | case EVENT_DONATE_ABOUT:
95 | name = FirebaseAnalytics.Event.SELECT_CONTENT;
96 | params.putString(FirebaseAnalytics.Param.ITEM_ID, "about_donation_send");
97 | params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Button");
98 | params.putString(FirebaseAnalytics.Param.ITEM_NAME, "make_donation");
99 | break;
100 | case EVENT_FCM_RECEIVED:
101 | name = "fcm_message_received";
102 | break;
103 | case EVENT_FCM_PRIORITY_CHANGED:
104 | name = "fcm_message_priority_changed";
105 | break;
106 | default:
107 | throw new RuntimeException("Unsupported Firebase Analytics Event ID: " + event);
108 | }
109 |
110 | mFirebaseAnalytics.logEvent(name, params);
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
28 |
29 |
43 |
44 |
56 |
57 |
69 |
70 |
89 |
90 |
109 |
110 |
121 |
122 |
130 |
131 |
141 |
142 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_logo.xml:
--------------------------------------------------------------------------------
1 |
6 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
85 |
89 |
93 |
97 |
101 |
102 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/zkkn/android/kaktus/Preferences.java:
--------------------------------------------------------------------------------
1 | package eu.zkkn.android.kaktus;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.preference.PreferenceManager;
6 | import android.text.TextUtils;
7 |
8 | import androidx.annotation.IntDef;
9 |
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.RetentionPolicy;
12 | import java.util.Date;
13 |
14 | import eu.zkkn.android.kaktus.LastNotification.Notification;
15 | import eu.zkkn.android.kaktus.fcm.FcmSubscriptionWorker;
16 |
17 | //TODO: Migrate to DataStore
18 |
19 | /**
20 | * App settings
21 | */
22 | public class Preferences {
23 |
24 | @Retention(RetentionPolicy.SOURCE)
25 | @IntDef({SYNC_NOT_SET, SYNC_DISABLED, SYNC_ENABLED})
26 | public @interface SyncStatus {}
27 | public static final int SYNC_NOT_SET = 0;
28 | public static final int SYNC_DISABLED = 1;
29 | public static final int SYNC_ENABLED = 2;
30 |
31 | /**
32 | * FCM token
33 | */
34 | private static final String PREF_KEY_FCM_TOKEN = "fcmToken";
35 |
36 | /**
37 | * Boolean preference that indicates whether FCM token has been sent to the backend server
38 | */
39 | private static final String PREF_KEY_FCM_SENT_TOKEN_TO_SERVER = "fcmSentTokenToServer";
40 |
41 | /**
42 | * Boolean preference that indicates whether the device is subscribed to topic "notifications"
43 | */
44 | private static final String PREF_KEY_FCM_TOPIC_NOTIFICATIONS = "fcmTopicNotifications-1";
45 |
46 | /**
47 | * Time when was the last notification sent
48 | */
49 | private static final String PREF_KEY_LAST_NOTIFICATION_SENT_TIME = "lastNotificationDate";
50 |
51 | /**
52 | * Time when was the last notification received
53 | */
54 | private static final String PREF_KEY_LAST_NOTIFICATION_RECEIVED_TIME =
55 | "lastNotificationReceivedTime";
56 |
57 | /**
58 | * Text of the last received notification
59 | */
60 | private static final String PREF_KEY_LAST_NOTIFICATION_TEXT = "lastNotificationText";
61 |
62 | /**
63 | * URI for the last received notification
64 | */
65 | private static final String PREF_KEY_LAST_NOTIFICATION_URI = "lastNotificationUri";
66 |
67 | /**
68 | * Sender of the last received notification
69 | */
70 | private static final String PREF_KEY_LAST_NOTIFICATION_FROM = "lastNotificationFrom";
71 |
72 | /**
73 | * Preference that indicates whether synchronization is enabled
74 | */
75 | private static final String PREF_KEY_SYNCHRONIZATION_STATUS = "synchronizationEnabled";
76 |
77 | // Keep old keys for last FB post
78 | private static final String PREF_KEY_LAST_FB_POST_DATE = "lastKaktusFbPostDate";
79 | private static final String PREF_KEY_LAST_FB_POST_TEXT = "lastKaktusFbPostText";
80 | private static final String PREF_KEY_LAST_FB_POST_IMAGE_URL = "lastKaktusFbPostImageUrl";
81 |
82 | /**
83 | * First call to determine firs run
84 | */
85 | private static final String PREF_KEY_FIRST = "firstCall-1";
86 |
87 | /**
88 | * Don't show the donation message anymore
89 | * It is not used currently
90 | */
91 | private static final String PREF_KEY_HIDE_DONATION = "hideDonation";
92 |
93 | /**
94 | * Don't show the last post on Facebook page
95 | */
96 | private static final String PREF_KEY_HIDE_FACEBOOK_INFO = "hideLastKaktusFbPostInfo";
97 |
98 | private static final String PREF_KEY_PERIODIC_SUBSCRIPTION_REFRESH =
99 | "periodicSubscriptionRefresh-v" + FcmSubscriptionWorker.PERIODIC_WORK_VERSION;
100 | private static final String PREF_KEY_LAST_SUBSCRIPTION_REFRESH =
101 | "lastSubscriptionRefreshTime-v" + FcmSubscriptionWorker.PERIODIC_WORK_VERSION;
102 |
103 |
104 | private static SharedPreferences sPreferences;
105 |
106 | private static SharedPreferences getPref(Context context) {
107 | if (sPreferences == null) {
108 | sPreferences = PreferenceManager.getDefaultSharedPreferences(
109 | context.getApplicationContext());
110 | }
111 | return sPreferences;
112 | }
113 |
114 | /**
115 | * @deprecated FCM tokens are no longer used
116 | */
117 | public static void setFcmToken(Context context, String token) {
118 | getPref(context).edit().putString(PREF_KEY_FCM_TOKEN, token).apply();
119 | }
120 |
121 |
122 | @Deprecated
123 | public static String getFcmToken(Context context) {
124 | return getPref(context).getString(PREF_KEY_FCM_TOKEN, "");
125 | }
126 |
127 | public static void setSubscribedToNotifications(Context context, boolean isSubscribed) {
128 | getPref(context).edit().putBoolean(PREF_KEY_FCM_TOPIC_NOTIFICATIONS, isSubscribed).apply();
129 | }
130 |
131 | public static boolean isSubscribedToNotifications(Context context) {
132 | return getPref(context).getBoolean(PREF_KEY_FCM_TOPIC_NOTIFICATIONS, false);
133 | }
134 |
135 | public static void setLastNotification(Context context, Notification notification) {
136 | getPref(context).edit()
137 | .putLong(PREF_KEY_LAST_NOTIFICATION_SENT_TIME, notification.sent.getTime())
138 | .putLong(PREF_KEY_LAST_NOTIFICATION_RECEIVED_TIME, notification.received.getTime())
139 | .putString(PREF_KEY_LAST_NOTIFICATION_TEXT, notification.text)
140 | .putString(PREF_KEY_LAST_NOTIFICATION_URI, notification.uri)
141 | .putString(PREF_KEY_LAST_NOTIFICATION_FROM, notification.from)
142 | .apply();
143 | }
144 |
145 | public static Notification getLastNotification(Context context) {
146 | SharedPreferences preferences = getPref(context);
147 | long sentTimeMs = preferences.getLong(PREF_KEY_LAST_NOTIFICATION_SENT_TIME, 0);
148 | long receivedTimeMs = preferences.getLong(PREF_KEY_LAST_NOTIFICATION_RECEIVED_TIME, 0);
149 | String text = preferences.getString(PREF_KEY_LAST_NOTIFICATION_TEXT, null);
150 | String uri = preferences.getString(PREF_KEY_LAST_NOTIFICATION_URI, null);
151 | String from = preferences.getString(PREF_KEY_LAST_NOTIFICATION_FROM, null);
152 |
153 | // if there's no last notification
154 | if (sentTimeMs == 0 || TextUtils.isEmpty(text)) return null;
155 |
156 | return new Notification(new Date(sentTimeMs), new Date(receivedTimeMs), text, uri, from);
157 | }
158 |
159 | public static void setSyncStatus(Context context, @SyncStatus int status) {
160 | getPref(context).edit().putInt(PREF_KEY_SYNCHRONIZATION_STATUS, status).apply();
161 | }
162 |
163 | @SyncStatus
164 | public static int getSyncStatus(Context context) {
165 | // annotation check would return error if we didn't check returned value
166 | @SyncStatus int status = getPref(context).getInt(PREF_KEY_SYNCHRONIZATION_STATUS, SYNC_NOT_SET);
167 | return (status == SYNC_DISABLED || status == SYNC_ENABLED) ? status : SYNC_NOT_SET;
168 | }
169 |
170 | /**
171 | * Check if this is the first time this function is called
172 | * @param context Context
173 | * @return true if this is the first time when this function was called, false otherwise
174 | */
175 | public static boolean isFirst(Context context) {
176 | SharedPreferences preferences = getPref(context);
177 | boolean first = preferences.getBoolean(PREF_KEY_FIRST, true);
178 | preferences.edit().putBoolean(PREF_KEY_FIRST, false).apply();
179 | return first;
180 | }
181 |
182 | public static boolean isDonationHidden(Context context) {
183 | return getPref(context).getBoolean(PREF_KEY_HIDE_DONATION, false);
184 | }
185 |
186 | public static void setDonationHidden(Context context, boolean hide) {
187 | getPref(context).edit().putBoolean(PREF_KEY_HIDE_DONATION, hide).apply();
188 | }
189 |
190 | public static void setPeriodicSubscriptionRefresh(Context context) {
191 | getPref(context).edit().putLong(
192 | PREF_KEY_PERIODIC_SUBSCRIPTION_REFRESH, System.currentTimeMillis()).apply();
193 | }
194 |
195 | public static boolean isPeriodicSubscriptionRefreshEnabled(Context context) {
196 | return 0L != getPref(context).getLong(PREF_KEY_PERIODIC_SUBSCRIPTION_REFRESH, 0L);
197 | }
198 |
199 | public static void setLastSubscriptionRefresh(Context context) {
200 | getPref(context).edit().putLong(
201 | PREF_KEY_LAST_SUBSCRIPTION_REFRESH, System.currentTimeMillis()).apply();
202 | }
203 |
204 | public static long getLastSubscriptionRefreshTime(Context context) {
205 | return getPref(context).getLong(PREF_KEY_LAST_SUBSCRIPTION_REFRESH, 0L);
206 | }
207 |
208 | }
209 |
--------------------------------------------------------------------------------
/logo/kaktus-dobijecka.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
243 |
--------------------------------------------------------------------------------
/logo/feature-graphic.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
264 |
--------------------------------------------------------------------------------
/backend/src/test/java/eu/zkkn/android/kaktus/backend/CheckServletTest.java:
--------------------------------------------------------------------------------
1 | package eu.zkkn.android.kaktus.backend;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
5 | import static org.junit.jupiter.api.Assertions.assertNull;
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
7 |
8 | import org.junit.jupiter.api.Test;
9 |
10 | import java.time.LocalDate;
11 | import java.time.Month;
12 | import java.time.ZoneId;
13 | import java.time.ZonedDateTime;
14 | import java.util.Date;
15 |
16 |
17 | class CheckServletTest {
18 |
19 | @Test
20 | void textMatchesPattern_false() {
21 | assertFalse(CheckServlet.textMatchesPattern(""));
22 | assertFalse(CheckServlet.textMatchesPattern("Test"));
23 | assertFalse(CheckServlet.textMatchesPattern("dneska"));
24 | assertFalse(CheckServlet.textMatchesPattern(" dvojnásob "));
25 | assertFalse(CheckServlet.textMatchesPattern("15. 9."));
26 | assertFalse(CheckServlet.textMatchesPattern(" 15.9. "));
27 | assertFalse(CheckServlet.textMatchesPattern(" 15. 9. "));
28 | assertFalse(CheckServlet.textMatchesPattern(" 2. 2. 2023 "));
29 | assertFalse(CheckServlet.textMatchesPattern("2x dneska 15. 9."));
30 | assertFalse(CheckServlet.textMatchesPattern("*Bonusový kredit za dobití z, kvůli technickým problémům původně zrušené dobíječky, 9. 6. 2023 mezi 15 a 18 hodinou bude připsán do půlnoci 12. 6. 2023. Omlouváme se za případné nepříjemnosti."));
31 | }
32 |
33 | @Test
34 | void textMatchesPattern_true() {
35 | assertTrue(CheckServlet.textMatchesPattern("Pokud si dneska 22.7. od 16:00 do 20:00 hodin dobiješ alespoň 200 Kč, dáme ti dvojnásob."));
36 | assertTrue(CheckServlet.textMatchesPattern("Pokud si dneska 30. 5. 2023 od 16:00 do 18:00 hodin dobiješ alespoň 200 Kč, dáme ti dvojnásob ;)"));
37 | // Stačí dobít dnes 20. 6. mezi 15 a 17 hodinou 200 - 500 kaček a pak už jen rozjet pořádný pekla s dvojnásobným kreditem. 😈💚
38 | assertTrue(CheckServlet.textMatchesPattern("Stačí dobít dnes 20. 6. mezi 15 a 17 hodinou 200 - 500 kaček a pak už jen rozjet pořádný pekla s dvojnásobným kreditem. \uD83D\uDE08\uD83D\uDC9A"));
39 | // Postačí, když si dneska 26. 6. dobiješ za 200 - 500 Kč mezi 17 a 19 a my ti aktivujem 2x tolik.🤩
40 | assertTrue(CheckServlet.textMatchesPattern("Postačí, když si dneska 26. 6. dobiješ za 200 - 500 Kč mezi 17 a 19 a my ti aktivujem 2x tolik.\uD83E\uDD29"));
41 | // Stačí dnes 11. 7. naladit 200 - 500 kaček mezi 16 a 19 hodinou a Kaktus ti nabrnkne 2x takovej nářez.🔥
42 | assertTrue(CheckServlet.textMatchesPattern("Stačí dnes 11. 7. naladit 200 - 500 kaček mezi 16 a 19 hodinou a Kaktus ti nabrnkne 2x takovej nářez.\uD83D\uDD25"));
43 | // Udělej randál 💦 s dvojitym kreditem! Postačí dnes 25. 7. dobít mezi 17 a 19 hodinou 200 - 500 kaček a my ti nalejem 2x tolik.💦💸
44 | assertTrue(CheckServlet.textMatchesPattern("Udělej randál \uD83D\uDCA6 s dvojitym kreditem! Postačí dnes 25. 7. dobít mezi 17 a 19 hodinou 200 - 500 kaček a my ti nalejem 2x tolik.\uD83D\uDCA6\uD83D\uDCB8"));
45 | // Probuď v sobě kreditovýho ninju! 🐢 Dobij si dnes 10. 8. od 17 do 20 hodin 2 až 5 kil a nauč se prastarýmu umění dvojitýho kreditu.
46 | assertTrue(CheckServlet.textMatchesPattern("Probuď v sobě kreditovýho ninju! \uD83D\uDC22 Dobij si dnes 10. 8. od 17 do 20 hodin 2 až 5 kil a nauč se prastarýmu umění dvojitýho kreditu."));
47 |
48 | // This text doesn't contain any date
49 | // Udělej ze svýho kreditu pořádný žihadlo. 😎 Podráždi ho 2 až 5 stovkama mezi 16 a 18 hodinou a my už ti píchnem, aby byl 2x takovej. 🐝
50 | //assertTrue(CheckServlet.textMatchesPattern("Udělej ze svýho kreditu pořádný žihadlo. \uD83D\uDE0E Podráždi ho 2 až 5 stovkama mezi 16 a 18 hodinou a my už ti píchnem, aby byl 2x takovej. \uD83D\uDC1D"));
51 | // But it was later fixed, and the date was added
52 | // Udělej ze svýho kreditu pořádný žihadlo. 😎 Podráždi ho 2 až 5 stovkama dneska 21. 8. mezi 16 a 18 hodinou a my už ti píchnem, aby byl 2x takovej. 🐝
53 | assertTrue(CheckServlet.textMatchesPattern("Udělej ze svýho kreditu pořádný žihadlo. \uD83D\uDE0E Podráždi ho 2 až 5 stovkama dneska 21. 8. mezi 16 a 18 hodinou a my už ti píchnem, aby byl 2x takovej. \uD83D\uDC1D"));
54 |
55 | // Nakopni svůj kredit dvakrát takovou náloží. 💥 Dobij dnes 13. 9. mezi 17 a 19 hodinou 200 až 500 Kč a my ti nasolíme 🧂 tuplovanou sumu, ani nemrkneš. 🦾🌵
56 | assertTrue(CheckServlet.textMatchesPattern("Nakopni svůj kredit dvakrát takovou náloží. \uD83D\uDCA5 Dobij dnes 13. 9. mezi 17 a 19 hodinou 200 až 500 Kč a my ti nasolíme \uD83E\uDDC2 tuplovanou sumu, ani nemrkneš. \uD83E\uDDBE\uD83C\uDF35"));
57 |
58 | // Udělej díru do světa 🌍 nebo jiný libovolný planety s dvojitym kreditem. Stačí chytit dobíječku dneska 19. 8. mezi 17 a 19 hodinou a pyšnit se intergalaktickou 🚀 porcí kreditu.
59 | assertTrue(CheckServlet.textMatchesPattern("Udělej díru do světa \uD83C\uDF0D nebo jiný libovolný planety s dvojitym kreditem. Stačí chytit dobíječku dneska 19. 8. mezi 17 a 19 hodinou a pyšnit se intergalaktickou \uD83D\uDE80 porcí kreditu."));
60 |
61 | // Vejdi v dobíječkový pokušení. Dvojitej kredit, dneska 26. 11. mezi 16. - 18. hodinou a dobítí za 200 - 500 Kč. Ty víš, co máš dělat. 👹
62 | assertTrue(CheckServlet.textMatchesPattern("Vejdi v dobíječkový pokušení. Dvojitej kredit, dneska 26. 11. mezi 16. - 18. hodinou a dobítí za 200 - 500 Kč. Ty víš, co máš dělat. \uD83D\uDC79"));
63 |
64 | // Budoucnost je tady. 🚀 Od teď umíme klonovat kredity! Vyzkoušej to i ty dnes 10. 3. mezi 17 a 20. Stačí dobít 200 - 500 Kč a máš jednou tolik. 😎🤟
65 | assertTrue(CheckServlet.textMatchesPattern("Budoucnost je tady. \uD83D\uDE80 Od teď umíme klonovat kredity! Vyzkoušej to i ty dnes 10. 3. mezi 17 a 20. Stačí dobít 200 - 500 Kč a máš jednou tolik. \uD83D\uDE0E\uD83E\uDD1F"));
66 |
67 | }
68 |
69 | @Test
70 | void linkMatchesPattern_false() {
71 | assertFalse(CheckServlet.linkMatchesPattern(""));
72 | assertFalse(CheckServlet.linkMatchesPattern("Test"));
73 | assertFalse(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_04062025.pdf&filename=OP-Odmena-za-dobiti-FB_04062025.pdf+"));
74 | assertFalse(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_00062025.pdf&filename=OP-Odmena-za-dobiti-FB_00062025.pdf"));
75 | assertFalse(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_01132025.pdf&filename=OP-Odmena-za-dobiti-FB_01132025.pdf"));
76 | assertFalse(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_32122025.pdf&filename=OP-Odmena-za-dobiti-FB_32122025.pdf"));
77 | //TODO assertFalse(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_29022025.pdf&filename=OP-Odmena-za-dobiti-FB_29022025.pdf"));
78 | }
79 |
80 | @Test
81 | void linkMatchesPattern_true() {
82 | assertTrue(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_04062025.pdf&filename=OP-Odmena-za-dobiti-FB_04062025.pdf"));
83 | assertTrue(CheckServlet.linkMatchesPattern("https://www.mujkaktus.cz/api/download?docUrl=%2Fapi%2Fdocuments%2Ffile%2FOP-Odmena-za-dobiti-FB_31122025.pdf&filename=OP-Odmena-za-dobiti-FB_31122025.pdf"));
84 | }
85 |
86 | @Test
87 | void containsDate_false() {
88 | assertFalse(CheckServlet.containsDate("9.7.2025 16:00 - 18:00", new Date()));
89 | assertFalse(CheckServlet.containsDate("9.7.2025 16:00 - 18:00", Date.from(LocalDate.of(2025, Month.JULY, 7).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
90 | assertFalse(CheckServlet.containsDate("9. 7. 2025 16:00 - 18:00", Date.from(LocalDate.of(2025, Month.JUNE, 9).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
91 | assertFalse(CheckServlet.containsDate("9. 7. 25 16:00 - 18:00", Date.from(LocalDate.of(2024, Month.JULY, 9).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
92 | }
93 |
94 | @Test
95 | void containsDate_true() {
96 | assertTrue(CheckServlet.containsDate("9.7.2025 16:00 - 18:00", Date.from(LocalDate.of(2025, Month.JULY, 9).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
97 | assertTrue(CheckServlet.containsDate("31. 12. 2025 00:00 - 23:59", Date.from(LocalDate.of(2025, Month.DECEMBER, 31).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
98 | assertTrue(CheckServlet.containsDate("31.12.25 00:00 - 23:59", Date.from(LocalDate.of(2025, Month.DECEMBER, 31).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
99 | assertTrue(CheckServlet.containsDate("9. 7. 25 16:00 - 18:00", Date.from(LocalDate.of(2025, Month.JULY, 9).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
100 | assertTrue(CheckServlet.containsDate("Dobíječka 9.7.2025 16:00 - 18:00", Date.from(LocalDate.of(2025, Month.JULY, 9).atStartOfDay(ZoneId.of("Europe/Prague")).toInstant())));
101 | }
102 |
103 | @Test
104 | void timeInfoMatchesPattern_false() {
105 | assertFalse(CheckServlet.timeInfoMatchesPattern(""));
106 | assertFalse(CheckServlet.timeInfoMatchesPattern("Test"));
107 | assertFalse(CheckServlet.timeInfoMatchesPattern("32.12.2025 16:00 - 18:00"));
108 | assertFalse(CheckServlet.timeInfoMatchesPattern("1. 13. 2025 16:00 - 18:00"));
109 | assertFalse(CheckServlet.timeInfoMatchesPattern("1.1.25 00:60 - 18:00"));
110 | assertFalse(CheckServlet.timeInfoMatchesPattern("1.1.2025 16 - 25"));
111 | assertFalse(CheckServlet.timeInfoMatchesPattern(" 9.7.2025 16:00 - 18:00 "));
112 | //TODO assertFalse(CheckServlet.timeInfoMatchesPattern("29.2.2025 16:00 - 18:00"));
113 | }
114 |
115 | @Test
116 | void timeInfoMatchesPattern_true() {
117 | assertTrue(CheckServlet.timeInfoMatchesPattern("9.7.2025 16:00 - 18:00"));
118 | assertTrue(CheckServlet.timeInfoMatchesPattern("31.12.2099 00:00 - 23:59"));
119 | assertTrue(CheckServlet.timeInfoMatchesPattern("9.7.25 16:00 - 18:00"));
120 | assertTrue(CheckServlet.timeInfoMatchesPattern("9. 7. 2025 16:00 - 18:00"));
121 | assertTrue(CheckServlet.timeInfoMatchesPattern("9.7.2025 6:00 - 8:00"));
122 | assertTrue(CheckServlet.timeInfoMatchesPattern("9.7.2025 06:30 - 08:30"));
123 | assertTrue(CheckServlet.timeInfoMatchesPattern("9.7.2025 16 - 18"));
124 | assertTrue(CheckServlet.timeInfoMatchesPattern("9.7.25 16 - 18"));
125 | assertTrue(CheckServlet.timeInfoMatchesPattern("9. 7. 25 6 - 8"));
126 | assertTrue(CheckServlet.timeInfoMatchesPattern("9. 7. 25 06 - 08"));
127 | }
128 |
129 | @Test
130 | void parseTimeInfo_error() {
131 | assertNull(CheckServlet.parseTimeInfo(""));
132 | assertNull(CheckServlet.parseTimeInfo("Test"));
133 | assertNull(CheckServlet.parseTimeInfo("31.2.2025 16:00 - 18:00"));
134 | }
135 |
136 | @Test
137 | void parseTimeInfo_ok() {
138 | TimeInfo timeInfo = new TimeInfo(
139 | ZonedDateTime.of(2025, 7, 9, 16, 0, 0, 0, ZoneId.of("Europe/Prague")),
140 | ZonedDateTime.of(2025, 7, 9, 18, 0, 0, 0, ZoneId.of("Europe/Prague")));
141 |
142 | assertEquals(timeInfo, CheckServlet.parseTimeInfo("9.7.2025 16:00 - 18:00"));
143 | assertEquals(timeInfo, CheckServlet.parseTimeInfo("9. 7. 2025 16:00 - 18:00"));
144 |
145 | // TODO:
146 | //assertEquals(timeInfo, CheckServlet.parseTimeInfo("9. 7. 2025 16 - 18"));
147 | //assertEquals(timeInfo, CheckServlet.parseTimeInfo("9. 7. 25 16 - 18"));
148 | // and other cases from timeInfoMatchesPattern_true()
149 | }
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/licenses/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/logo/feature-graphic-unofficial.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
264 |
--------------------------------------------------------------------------------