├── settings.gradle ├── .idea ├── .gitignore ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── compiler.xml ├── kotlinc.xml ├── vcs.xml ├── studiobot.xml ├── AndroidProjectSystem.xml ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── migrations.xml ├── inspectionProfiles │ └── Project_Default.xml ├── deploymentTargetDropDown.xml ├── gradle.xml ├── runConfigurations │ └── AppEngine_Debug.xml ├── runConfigurations.xml ├── deploymentTargetSelector.xml ├── appInsightsSettings.xml ├── androidTestResultsUserPreferences.xml ├── jarRepositories.xml └── misc.xml ├── backend ├── src │ ├── main │ │ ├── webapp │ │ │ ├── robots.txt │ │ │ ├── favicon.ico │ │ │ ├── WEB-INF │ │ │ │ ├── cron.xml │ │ │ │ ├── logging.properties │ │ │ │ ├── appengine-web.xml │ │ │ │ └── web.xml │ │ │ ├── index.html │ │ │ ├── admin │ │ │ │ └── index.html │ │ │ └── privacy_policy.html │ │ └── java │ │ │ └── eu │ │ │ └── zkkn │ │ │ └── android │ │ │ └── kaktus │ │ │ └── backend │ │ │ ├── TimeInfo.kt │ │ │ ├── ServletContextHolder.kt │ │ │ ├── EmailLog.java │ │ │ ├── RegistrationRecord.java │ │ │ ├── ManualNotificationsServlet.kt │ │ │ ├── ParseResult.java │ │ │ ├── Bootstrapper.kt │ │ │ ├── EndpointsServlet.java │ │ │ ├── Utils.java │ │ │ └── FcmSender.kt │ └── test │ │ └── java │ │ └── eu │ │ └── zkkn │ │ └── android │ │ └── kaktus │ │ └── backend │ │ └── CheckServletTest.java ├── appengine-settings.gradle.sample ├── .gitignore └── build.gradle ├── logo ├── kaktus-dobijecka.png ├── sunglasses.svg ├── cactus-1f335.svg ├── kaktus-dobijecka.svg ├── feature-graphic.svg └── feature-graphic-unofficial.svg ├── app ├── src │ ├── main │ │ ├── ic_launcher-web.png │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ ├── ic_open.png │ │ │ │ ├── ic_cancel.png │ │ │ │ └── ic_notification.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── ic_open.png │ │ │ │ ├── ic_cancel.png │ │ │ │ └── ic_notification.png │ │ │ ├── raw │ │ │ │ ├── third_party_licenses │ │ │ │ └── third_party_license_metadata │ │ │ ├── drawable-xhdpi │ │ │ │ ├── ic_open.png │ │ │ │ ├── ic_cancel.png │ │ │ │ └── ic_notification.png │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── ic_open.png │ │ │ │ ├── ic_cancel.png │ │ │ │ └── ic_notification.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xxxhdpi │ │ │ │ ├── ic_cancel.png │ │ │ │ ├── ic_open.png │ │ │ │ └── ic_notification.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── xml │ │ │ │ ├── backup_descriptor.xml │ │ │ │ └── backup_rules.xml │ │ │ ├── values-v35 │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── colors.xml │ │ │ │ └── strings.xml │ │ │ ├── values-v33 │ │ │ │ └── strings.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── drawable │ │ │ │ ├── ic_close.xml │ │ │ │ └── ic_logo.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ ├── drawable-anydpi-v24 │ │ │ │ ├── ic_cancel.xml │ │ │ │ └── ic_open.xml │ │ │ └── layout │ │ │ │ └── activity_about.xml │ │ ├── java │ │ │ └── eu │ │ │ │ └── zkkn │ │ │ │ └── android │ │ │ │ └── kaktus │ │ │ │ ├── fcm │ │ │ │ ├── FcmHelper.java │ │ │ │ ├── FcmSubscriptionWorker.kt │ │ │ │ └── MyFcmListenerService.java │ │ │ │ ├── Config.java.sample │ │ │ │ ├── LastNotification.java │ │ │ │ ├── CancelNotificationReceiver.kt │ │ │ │ ├── SemaphoreView.java │ │ │ │ ├── AboutActivity.java │ │ │ │ ├── DebugInfoDialog.kt │ │ │ │ ├── Helper.java │ │ │ │ ├── NotificationHelper.java │ │ │ │ ├── FirebaseAnalyticsHelper.java │ │ │ │ └── Preferences.java │ │ └── AndroidManifest.xml │ ├── beta │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ ├── debug │ │ └── res │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── donottranslate.xml │ ├── test │ │ └── java │ │ │ └── eu │ │ │ └── zkkn │ │ │ └── kaktus │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── eu │ │ └── zkkn │ │ └── android │ │ └── kaktus │ │ ├── ExampleInstrumentedTest.java │ │ └── MainActivityTest.java ├── .gitignore ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew └── licenses └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':backend' 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | -------------------------------------------------------------------------------- /backend/src/main/webapp/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /logo/kaktus-dobijecka.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/logo/kaktus-dobijecka.png -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/beta/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Kaktus Dobíječka+ 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/debug/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Kaktus Dobíječka++ 3 | 4 | -------------------------------------------------------------------------------- /backend/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/backend/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-hdpi/ic_open.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-mdpi/ic_open.png -------------------------------------------------------------------------------- /app/src/main/res/raw/third_party_licenses: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/raw/third_party_licenses -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-hdpi/ic_cancel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-mdpi/ic_cancel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xhdpi/ic_open.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xxhdpi/ic_open.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xhdpi/ic_cancel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xxhdpi/ic_cancel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xxxhdpi/ic_cancel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xxxhdpi/ic_open.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-hdpi/ic_notification.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-mdpi/ic_notification.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xhdpi/ic_notification.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xxhdpi/ic_notification.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdenda/kaktus-dobijecka/HEAD/app/src/main/res/drawable-xxxhdpi/ic_notification.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/studiobot.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.apk 3 | 4 | # Those files contain private IDs and keys 5 | firebase-crashreporting.json 6 | google-services.json 7 | google-services.json.old 8 | src/main/java/eu/zkkn/android/kaktus/Config.java 9 | -------------------------------------------------------------------------------- /backend/src/main/java/eu/zkkn/android/kaktus/backend/TimeInfo.kt: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus.backend 2 | 3 | import java.time.ZonedDateTime 4 | 5 | data class TimeInfo(val start: ZonedDateTime, val end: ZonedDateTime) 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | /.idea/caches/ 3 | /.idea/dictionaries/ 4 | /.idea/libraries/ 5 | /build/ 6 | /captures/ 7 | /release/ 8 | *.iml 9 | /local.properties 10 | /.idea/workspace.xml 11 | .DS_Store 12 | .externalNativeBuild 13 | -------------------------------------------------------------------------------- /backend/appengine-settings.gradle.sample: -------------------------------------------------------------------------------- 1 | // App Engine Settings Variables 2 | 3 | ext { 4 | googleCloudProjectId = 'YOUR_APP_ENGINE_PROJECT_ID' 5 | adminEmail = 'YOUR_EMAIL@example.com' 6 | fcmServerKey = 'YOUR_FCM_SERVER_KEY' 7 | } 8 | -------------------------------------------------------------------------------- /.idea/AndroidProjectSystem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/xml/backup_descriptor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values-v35/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jul 12 12:18:36 CEST 2025 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /app/src/debug/res/values/donottranslate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | debug.kaktus.zkkn.eu 4 | eu.zkkn.android.kaktus.debug.provider 5 | -------------------------------------------------------------------------------- /app/src/main/java/eu/zkkn/android/kaktus/fcm/FcmHelper.java: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus.fcm; 2 | 3 | /** 4 | * 5 | */ 6 | public class FcmHelper { 7 | 8 | //TODO: Move to common module with backend 9 | public static final String FCM_TOPIC_NOTIFICATIONS = "notifications"; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /.idea/migrations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-v35/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Aby k tomu nedošlo, je potřeba v nastavení "O aplikaci" pro tuto appku, v sekci "Nastavení nepoužívaných aplikací" vypnout volbu "Správa nepoužívané aplikace". 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-v33/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Aby k tomu nedošlo, je potřeba v nastavení "O aplikaci" pro tuto appku, v sekci "Nastavení nepoužívaných aplikací" vypnout volbu "Pozastavit aktivitu při nepoužívání". 4 | 5 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | backend.iml 3 | 4 | # appengine-settings.gradle contains private IDs and keys 5 | appengine-settings.gradle 6 | 7 | # local_db.bin can't be under /build directory because every new build would delete it 8 | local_db.bin 9 | 10 | # private key file for Firebase service account 11 | src/main/webapp/WEB-INF/serviceAccountKey.json 12 | -------------------------------------------------------------------------------- /backend/src/main/webapp/WEB-INF/cron.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /cron/check 5 | Check Kaktus page 6 | every 30 minutes 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 128dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 |

15 | Zásady ochrany osobních údajů 16 |

17 |

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 |

33 | 44 |
45 |

46 | Kontakt 47 |

48 |

49 | Pokud máte nějaký dotaz či připomínku k těmto zásadám ochrany osobních údajů neváhejte mě 50 | kontaktovat na zkkn.apps+kaktus@gmail.com. 52 |

53 | 54 | 55 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | org.gradle.jvmargs=-Xmx2048m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | org.gradle.parallel=true 20 | 21 | # When set to true the Gradle daemon is used to run the build. 22 | # For local developer builds this is our favorite property. 23 | org.gradle.daemon=true 24 | 25 | # Only relevant projects are configured which results in faster builds for large multi-projects. 26 | org.gradle.configureondemand=true 27 | 28 | # Uploading ProGuard mapping files with Gradle 29 | # This is the path to the Private Key, which can be generated at 30 | # https://console.firebase.google.com/project/_/settings/serviceaccounts/crashreporting 31 | # We have to use this since we can't manually upload mapping.txt files until at least one crash 32 | # or error is reported for a given app version, but the Gradle task doesn't have this limitation. 33 | # Run command following this pattern to both build the APK and upload its mapping file: 34 | # ./gradlew :app:firebaseUploadProguardMapping 35 | # For example: ./gradlew :app:firebaseUploadReleaseProguardMapping 36 | FirebaseServiceAccountFilePath=firebase-crashreporting.json 37 | 38 | # If you have any Maven dependencies that have not been migrated to the AndroidX namespace, 39 | # the Android Studio build system also migrates those dependencies for you 40 | # when you set the following two flags to true 41 | android.useAndroidX=true 42 | android.enableJetifier=true 43 | 44 | # Generate R classes for resources defined in the current module only 45 | android.nonTransitiveRClass=false 46 | 47 | # Generate R classes with non-final fields by default 48 | android.nonFinalResIds=false 49 | 50 | # Java toolchain locations from environment variables 51 | org.gradle.java.installations.fromEnv=JAVA_HOME_21,JAVA_HOME_17,JAVA_HOME_8,JAVA_HOME 52 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 39 | 40 | 41 | 42 | 43 | 44 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/java/eu/zkkn/android/kaktus/AboutActivity.java: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.text.method.LinkMovementMethod; 6 | import android.view.View; 7 | import android.view.Window; 8 | import android.widget.TextView; 9 | 10 | import com.google.firebase.analytics.FirebaseAnalytics; 11 | 12 | import androidx.appcompat.app.AppCompatActivity; 13 | 14 | //TODO add licences (needs play services v11.2.0) 15 | // https://developers.google.com/android/guides/opensource 16 | // res/raw/third_party_licenses 17 | 18 | public class AboutActivity extends AppCompatActivity { 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | supportRequestWindowFeature(Window.FEATURE_NO_TITLE); 24 | setContentView(R.layout.activity_about); 25 | 26 | final FirebaseAnalyticsHelper firebaseAnalytics = new FirebaseAnalyticsHelper( 27 | FirebaseAnalytics.getInstance(this)); 28 | 29 | findViewById(R.id.ib_close).setOnClickListener(v -> finish()); 30 | 31 | ((TextView) findViewById(R.id.tv_version)).setText( 32 | getString(R.string.about_version, BuildConfig.VERSION_NAME)); 33 | ((TextView) findViewById(R.id.tv_privacy_policy_link)).setMovementMethod( 34 | LinkMovementMethod.getInstance()); 35 | ((TextView) findViewById(R.id.tv_sources_link)).setMovementMethod( 36 | LinkMovementMethod.getInstance()); 37 | 38 | // donations 39 | final View donation = findViewById(R.id.ll_donation); 40 | String number = String.format("%s\u00A0%s\u00A0%s", Config.DONATION_NUMBER.substring(0, 3), 41 | Config.DONATION_NUMBER.substring(3, 6), Config.DONATION_NUMBER.substring(6, 9)); 42 | ((TextView) findViewById(R.id.tv_donationText)).setText( 43 | getString(R.string.donation_text, number)); 44 | final Intent kaktusAppIntent = Helper.getAppIntent(this, Config.KAKTUS_APP_ID); 45 | findViewById(R.id.bt_donate).setOnClickListener(v -> { 46 | firebaseAnalytics.logEvent(FirebaseAnalyticsHelper.EVENT_DONATE_ABOUT); 47 | Helper.copyToClipboard(AboutActivity.this, Config.DONATION_NUMBER); 48 | startActivity(kaktusAppIntent); 49 | }); 50 | // hide donation box if any notification has ben received yet, 51 | // or the official Kaktus app is not installed 52 | if (LastNotification.load(this) == null || kaktusAppIntent == null) { 53 | donation.setVisibility(View.GONE); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | -------------------------------------------------------------------------------- /backend/build.gradle: -------------------------------------------------------------------------------- 1 | // App Engine Backend build file 2 | plugins { 3 | id 'org.jetbrains.kotlin.jvm' 4 | id 'com.google.cloud.tools.appengine-appenginewebxml' 5 | } 6 | 7 | apply from: 'appengine-settings.gradle' 8 | 9 | //TODO: compileJava {options.encoding = "UTF-8"} 10 | 11 | // give test dependencies access to compileOnly dependencies to emulate providedCompile 12 | configurations { 13 | testImplementation.extendsFrom compileOnly 14 | } 15 | 16 | dependencies { 17 | 18 | def appEngineVersion = '2.0.36' 19 | 20 | compileOnly 'javax.servlet:javax.servlet-api:4.0.1' 21 | compileOnly "com.google.appengine:appengine-resources:$appEngineVersion" 22 | 23 | implementation "com.google.appengine:appengine-api-1.0-sdk:$appEngineVersion" 24 | implementation 'com.google.firebase:firebase-admin:9.5.0' 25 | //noinspection NewerVersionAvailable: GradleDependency v6.0 breaks local dev environment 26 | implementation 'com.googlecode.objectify:objectify:5.1.25' //TODO v6.0 27 | implementation 'org.jsoup:jsoup:1.21.1' 28 | implementation 'com.googlecode.json-simple:json-simple:1.1.1' 29 | implementation 'javax.activation:activation:1.1.1' // necessary for sending emails 30 | 31 | //noinspection NewerVersionAvailable: GradleDependency v5.12.0 breaks tests 32 | testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4' 33 | 34 | } 35 | 36 | war { 37 | filesMatching('WEB-INF/appengine-web.xml') { 38 | expand 'fcmKey': fcmServerKey, 'email': adminEmail 39 | } 40 | } 41 | 42 | /* 43 | Make sure you are authenticated with the correct account, 44 | if there's a Permissions error during AppEngine deploy. 45 | Run command: gcloud auth list 46 | and then: gcloud config set account `ACCOUNT` 47 | */ 48 | appengine { 49 | run { 50 | host = '0.0.0.0' 51 | automaticRestart = true 52 | //TODO: this doesn't work, so the jvmFlag has to be used instead 53 | //datastorePath = "$rootDir/backend/local_db.bin" 54 | jvmFlags = [ 55 | "-Ddatastore.backing_store=$rootDir/backend/local_db.bin".toString(), 56 | "-Dappengine.fullscan.seconds=5".toString(), 57 | //"-Xdebug".toString(), "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005".toString() 58 | ] 59 | } 60 | deploy { 61 | projectId = "$googleCloudProjectId" 62 | version = 52 63 | // keep the old version running, do the switch manually in administration 64 | stopPreviousVersion = false 65 | promote = false 66 | } 67 | } 68 | 69 | sourceCompatibility = JavaVersion.VERSION_17 70 | targetCompatibility = JavaVersion.VERSION_17 71 | 72 | kotlin { 73 | jvmToolchain(17) 74 | } 75 | 76 | compileTestJava { 77 | options.encoding = "UTF-8" 78 | } 79 | 80 | test { 81 | useJUnitPlatform() 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/eu/zkkn/android/kaktus/DebugInfoDialog.kt: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus 2 | 3 | import android.content.Context 4 | import android.content.DialogInterface 5 | import android.view.View 6 | import android.widget.ProgressBar 7 | import android.widget.Toast 8 | import androidx.appcompat.app.AlertDialog 9 | import androidx.lifecycle.lifecycleScope 10 | import com.google.firebase.installations.FirebaseInstallations 11 | import kotlinx.coroutines.Dispatchers 12 | import kotlinx.coroutines.launch 13 | import kotlinx.coroutines.tasks.await 14 | import kotlinx.coroutines.withContext 15 | import org.json.JSONObject 16 | import java.text.SimpleDateFormat 17 | import java.util.Date 18 | import java.util.Locale 19 | 20 | 21 | class DebugInfoDialog(val context: Context) { 22 | 23 | fun show() { 24 | val builder = AlertDialog.Builder(context) 25 | 26 | val title = context.getString(R.string.dialog_debug_info_title) 27 | val progressBar = ProgressBar(context) 28 | 29 | builder.setTitle(title) 30 | builder.setView(progressBar) 31 | builder.setPositiveButton(R.string.dialog_debug_info_button_ok) { dialog, _ -> 32 | dialog.dismiss() 33 | } 34 | // message and neutral button must be set in builder, so they could be used later 35 | builder.setMessage("") 36 | builder.setNeutralButton(R.string.dialog_debug_info_copy_to_clipboard) { _, _ -> 37 | Toast.makeText(context, R.string.dialog_debug_info_copy_unavailable, Toast.LENGTH_SHORT).show() 38 | } 39 | 40 | val subscribed = Preferences.isSubscribedToNotifications(context) 41 | val lastRefresh = Preferences.getLastSubscriptionRefreshTime(context) 42 | var firebaseId: String 43 | 44 | val dialog: AlertDialog = builder.show().apply { 45 | // disable copy button since it shouldn't be used until all info is loaded 46 | getButton(DialogInterface.BUTTON_NEUTRAL).isEnabled = false 47 | } 48 | 49 | dialog.lifecycleScope.launch { 50 | withContext(Dispatchers.IO) { 51 | firebaseId = FirebaseInstallations.getInstance().id.await() 52 | } 53 | 54 | progressBar.visibility = View.GONE 55 | 56 | dialog.getButton(DialogInterface.BUTTON_NEUTRAL).apply { 57 | setOnClickListener { _ -> 58 | val json = JSONObject() 59 | json.put("instanceId", firebaseId) 60 | json.put("lastRefresh", 61 | SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US) 62 | .format(Date(lastRefresh))) 63 | json.put("subscribed", subscribed) 64 | Helper.copyToClipboard(context, title, json.toString()) 65 | } 66 | isEnabled = true 67 | } 68 | 69 | dialog.setMessage(Helper.formatHtml( 70 | "
%1\$s

%2\$s

%3\$s


* %4\$s", 71 | context.getString(R.string.dialog_debug_info_firebase_instance_id, firebaseId), 72 | context.getString(R.string.dialog_debug_info_refresh_time, lastRefresh), 73 | context.getString(R.string.dialog_debug_info_topic_subscription, subscribed), 74 | context.getString(R.string.dialog_debug_info_warning))) 75 | 76 | } 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /backend/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | admin 9 | /admin/* 10 | 11 | 12 | admin 13 | 14 | 15 | CONFIDENTIAL 16 | 17 | 18 | 19 | 20 | cron 21 | /cron/* 22 | 23 | 24 | admin 25 | 26 | 27 | 28 | 29 | tasks 30 | /tasks/* 31 | 32 | 33 | admin 34 | 35 | 36 | 37 | 38 | 39 | ObjectifyFilter 40 | com.googlecode.objectify.ObjectifyFilter 41 | 42 | 43 | ObjectifyFilter 44 | /* 45 | 46 | 47 | 48 | EndpointsServlet 49 | eu.zkkn.android.kaktus.backend.EndpointsServlet 50 | 51 | 52 | EndpointsServlet 53 | /_ah/api/* 54 | 55 | 56 | 57 | ManualNotificationsServlet 58 | eu.zkkn.android.kaktus.backend.ManualNotificationsServlet 59 | 60 | 61 | ManualNotificationsServlet 62 | /admin/send-notifications 63 | 64 | 65 | 66 | 67 | CheckServlet 68 | eu.zkkn.android.kaktus.backend.CheckServlet 69 | 70 | 71 | CheckServlet 72 | /cron/check 73 | 74 | 75 | 76 | 77 | FcmSender 78 | eu.zkkn.android.kaktus.backend.FcmSender 79 | 80 | 81 | FcmSender 82 | /tasks/fcm-sender 83 | 84 | 85 | 86 | 87 | index.html 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /app/src/main/java/eu/zkkn/android/kaktus/Helper.java: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus; 2 | 3 | import android.content.ClipData; 4 | import android.content.ClipboardManager; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.text.Html; 10 | import android.text.Spanned; 11 | import android.text.format.DateFormat; 12 | 13 | import androidx.annotation.NonNull; 14 | import androidx.annotation.Nullable; 15 | import androidx.appcompat.app.AlertDialog; 16 | 17 | import java.util.Date; 18 | import java.util.Locale; 19 | 20 | 21 | /** 22 | * Collection of useful methods 23 | */ 24 | public class Helper { 25 | 26 | /** 27 | * Formats the date as a string with date and time. It respect the localization of device. 28 | * 29 | * @param context the application context 30 | * @param date the date to format 31 | * @return the formatted string 32 | */ 33 | @NonNull 34 | public static String formatDate(Context context, Date date) { 35 | return DateFormat.getLongDateFormat(context).format(date) 36 | + " " + DateFormat.getTimeFormat(context).format(date); 37 | } 38 | 39 | /** 40 | * Returns app identification for User-Agent HTTP header 41 | * @return string for User-Agent header 42 | */ 43 | public static String getUserAgent() { 44 | // don't add build type if it is release 45 | //noinspection ConstantConditions 46 | String buildType = "release".equals(BuildConfig.BUILD_TYPE) ? "" : " " + BuildConfig.BUILD_TYPE; 47 | return String.format(Locale.US, "App/%s-%d%s (%s %s; Android/%s)", BuildConfig.VERSION_NAME, 48 | BuildConfig.VERSION_CODE, buildType, Build.MANUFACTURER, Build.MODEL, Build.VERSION.RELEASE); 49 | } 50 | 51 | public static Spanned formatHtml(String formatWithHtml, Object... args) { 52 | String htmlText = String.format(formatWithHtml, args); 53 | Spanned spanned; 54 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 55 | spanned = Html.fromHtml(htmlText, Html.FROM_HTML_MODE_LEGACY); 56 | } else { 57 | spanned = Html.fromHtml(htmlText); 58 | } 59 | return spanned; 60 | } 61 | 62 | public static void copyToClipboard(Context context, String text) { 63 | copyToClipboard(context, text, text); 64 | } 65 | 66 | public static void copyToClipboard(Context context, String label, String text) { 67 | ClipboardManager clipboard = 68 | (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 69 | clipboard.setPrimaryClip(ClipData.newPlainText(label, text)); 70 | } 71 | 72 | public static void showAlert(Context context, String title, String message) { 73 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 74 | builder.setTitle(title); 75 | builder.setMessage(message); 76 | builder.setPositiveButton(R.string.generic_alert_button_ok, 77 | (dialog, which) -> dialog.dismiss() 78 | ); 79 | builder.show(); 80 | } 81 | 82 | 83 | public static void viewUri(Context context, @NonNull String uri) { 84 | context = context.getApplicationContext(); 85 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 86 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 87 | if (intent.resolveActivity(context.getPackageManager()) != null) { 88 | context.startActivity(intent); 89 | } 90 | } 91 | 92 | @Nullable 93 | public static Intent getAppIntent(Context context, String packageName) { 94 | return context.getPackageManager().getLaunchIntentForPackage(packageName); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /backend/src/main/java/eu/zkkn/android/kaktus/backend/Utils.java: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus.backend; 2 | 3 | import com.google.appengine.api.utils.SystemProperty; 4 | 5 | import java.io.UnsupportedEncodingException; 6 | import java.util.Properties; 7 | 8 | import javax.annotation.Nonnull; 9 | import javax.mail.Message; 10 | import javax.mail.MessagingException; 11 | import javax.mail.Session; 12 | import javax.mail.Transport; 13 | import javax.mail.internet.InternetAddress; 14 | import javax.mail.internet.MimeMessage; 15 | 16 | 17 | public class Utils { 18 | 19 | public static String getAppId() { 20 | return SystemProperty.applicationId.get(); 21 | } 22 | 23 | public static InternetAddress getLocalEmail(String user) throws UnsupportedEncodingException { 24 | String address = user + "@" + getAppId() + ".appspotmail.com"; 25 | String personal = "Kaktus Dobijecka " + user; 26 | return new InternetAddress(address, personal, "UTF-8"); 27 | } 28 | 29 | public static boolean sendEmail(String from, String to, String subject, String text) { 30 | try { 31 | 32 | Message message = new MimeMessage(Session.getDefaultInstance(new Properties(), null)); 33 | message.setFrom(getLocalEmail(from)); 34 | message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); 35 | message.setSubject(subject); 36 | message.setText(text); 37 | Transport.send(message); 38 | return true; 39 | 40 | } catch (UnsupportedEncodingException | MessagingException e) { 41 | // ignore exceptions and return false 42 | } 43 | return false; 44 | } 45 | 46 | /** 47 | * To determine whether your code is running in production or in the local development server 48 | * @return true if this run on a production server; false otherwise 49 | */ 50 | public static boolean isProduction() { 51 | return SystemProperty.Environment.Value.Production == SystemProperty.environment.value(); 52 | } 53 | 54 | static String cropText(@Nonnull String text, int maxLength) { 55 | text = text.trim(); 56 | // if the text is longer than the limit, crop it and add the three dots symbol at the end 57 | if (text.length() > maxLength) { 58 | text = text.substring(0, maxLength - 1) + "\u2026"; 59 | } 60 | return text; 61 | } 62 | 63 | 64 | /** 65 | * Waits a given number of milliseconds (of uptimeMillis) before returning. 66 | * Similar to {@link java.lang.Thread#sleep(long)}, but does not throw 67 | * {@link InterruptedException}; {@link Thread#interrupt()} events are 68 | * deferred until the next interruptible operation. Does not return until 69 | * at least the specified number of milliseconds has elapsed. 70 | * 71 | * Copied from Android SystemClock.sleep() 72 | * 73 | * @param ms to sleep before returning, in milliseconds of uptime. 74 | */ 75 | public static void sleep(long ms) { 76 | long start = System.currentTimeMillis(); 77 | long duration = ms; 78 | boolean interrupted = false; 79 | do { 80 | try { 81 | Thread.sleep(duration); 82 | } 83 | catch (InterruptedException e) { 84 | interrupted = true; 85 | } 86 | duration = start + ms - System.currentTimeMillis(); 87 | } while (duration > 0); 88 | 89 | if (interrupted) { 90 | // Important: we don't want to quietly eat an interrupt() event, 91 | // so we make sure to re-interrupt the thread so that the next 92 | // call to Thread.sleep() or Object.wait() will be interrupted. 93 | Thread.currentThread().interrupt(); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/eu/zkkn/android/kaktus/NotificationHelper.java: -------------------------------------------------------------------------------- 1 | package eu.zkkn.android.kaktus; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Notification; 5 | import android.app.NotificationChannel; 6 | import android.app.NotificationManager; 7 | import android.content.Context; 8 | import android.content.pm.PackageManager; 9 | import android.graphics.Color; 10 | import android.os.Build; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.RequiresApi; 14 | import androidx.core.app.ActivityCompat; 15 | import androidx.core.app.NotificationCompat; 16 | import androidx.core.app.NotificationManagerCompat; 17 | import androidx.core.content.ContextCompat; 18 | 19 | 20 | public class NotificationHelper { 21 | 22 | public static final String DOBIJECKA_CHANNEL_ID = "dobijecka"; 23 | public static final int DOBIJECKA_NOTIFICATION_ID = 1; 24 | 25 | 26 | // NotificationManagerCompat uses app context, so it doesn't leak activity nor service 27 | @SuppressLint("StaticFieldLeak") 28 | private static NotificationManagerCompat sNotificationManager; 29 | 30 | 31 | public static NotificationCompat.Builder getDefaultBuilder(Context context, String channelId) { 32 | if (!channelExists(context, channelId) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 33 | createChannel(context, channelId); 34 | } 35 | return new NotificationCompat.Builder(context, channelId) 36 | .setSmallIcon(R.drawable.ic_notification) 37 | .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) 38 | .setContentTitle(context.getString(R.string.app_name)) 39 | .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); 40 | } 41 | 42 | public static boolean areNotificationsEnabled(Context context) { 43 | return getNotificationManager(context).areNotificationsEnabled(); 44 | } 45 | 46 | public static void createChannel(Context context) { 47 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 48 | createChannel(context, DOBIJECKA_CHANNEL_ID); 49 | } 50 | } 51 | 52 | public static void notify(Context ctx, int notificationId, @NonNull Notification notification) { 53 | // Check Notification permission 54 | if (ActivityCompat.checkSelfPermission(ctx, android.Manifest.permission.POST_NOTIFICATIONS) 55 | != PackageManager.PERMISSION_GRANTED) { 56 | return; 57 | } 58 | getNotificationManager(ctx).notify(notificationId, notification); 59 | } 60 | 61 | private static NotificationManagerCompat getNotificationManager(Context context) { 62 | if (sNotificationManager == null) { 63 | sNotificationManager = NotificationManagerCompat.from(context.getApplicationContext()); 64 | } 65 | return sNotificationManager; 66 | } 67 | 68 | private static boolean channelExists(Context context, String channelId) { 69 | return getNotificationManager(context).getNotificationChannel(channelId) != null; 70 | } 71 | 72 | @RequiresApi(api = Build.VERSION_CODES.O) 73 | private static void createChannel(Context context, String channelId) { 74 | NotificationChannel channel; 75 | 76 | if (DOBIJECKA_CHANNEL_ID.equals(channelId)) { 77 | channel = new NotificationChannel(channelId, 78 | context.getString(R.string.notification_channel_name), 79 | NotificationManager.IMPORTANCE_DEFAULT); 80 | channel.enableLights(true); 81 | channel.setLightColor(Color.GREEN); 82 | } else { 83 | throw new RuntimeException("Unknown Notification Channel ID"); 84 | } 85 | 86 | getNotificationManager(context).createNotificationChannel(channel); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Kaktus Dobíječka 3 | 4 | OK 5 | Storno 6 | 7 | Podpořte Kaktus Dobíječku 8 | Slouží ti tahle appka dobře a máš díky dobíječce tolik kreditu, že nevíš co s ním? \u263a Co takhle ho trochu darovat na její podporu?\n\nPosílat ho můžete přes oficiální Kaktus appku. V menu vyberte položku \"Poslat\u00A0kredit\" a zadejte telefonní číslo %s.\n\nKaždá koruna se počítá! Díky!!! 9 | Skrýt 10 | Kopírovat tel. číslo a\notevřít Kaktus appku 11 | 12 | Informace pro uživatele 13 | 14 | Otevřít nastavení 15 | Oznámení jsou blokována 16 | Zobrazení oznámení z aplikace je blokováno. V nastavení aplikace zkontrolujte sekce Oznámení a Oprávnění, že je tam vše povoleno, tak aby se upozornění správně zobrazovala. 17 | Omezení nepoužívaných aplikací 18 | Protože typicky stačí jen sledovat upozornění z appky a není potřeba ji vůbec spouštět, mohl by ji android vyhodnotit jako nepoužívanou a začít blokovat zobrazení jejích upozornění. 19 | 20 | Aby k tomu nedošlo, je potřeba v nastavení "O aplikaci" pro tuto appku, dole v sekci "Nepoužívané aplikace" vypnout volbu "Odebrat oprávnění a uvolnit místo". 21 | 22 | Upozornění na dobíječku 23 | Zatím nebylo přijato žádné upozornění. 24 | 25 | Toto zařízení bohužel není podporováno. Aplikace vyžaduje Služby Google Play, které zde nejsou dostupné. 26 | Příjem upozornění je aktivní. 27 | Probíhá přihlášení k odběru upozornění … 28 | Registrace pro příjem upozornení se zatím nepodařila. Za chvíli to zkusíme znovu … 29 | 30 | Povolit oznámení 31 | Aby aplikace mohla zobrazovat upozornění na dobíječku, je potřeba pro ni povolit odesílání oznámení, jinak nebude fungovat. 32 | OK 33 | 34 | Technické info 35 | ID: %s 36 | Obnoveno: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS 37 | Přihlášeno: %b 38 | Informace sdílejte jen s důvěryhodnými osobami! 39 | Kopírovat 40 | Technické informace nejsou dostupné 41 | OK 42 | 43 | Přijato 44 | 45 | Zobrazit na webu 46 | Skrýt 47 | 48 | O aplikaci 49 | Zavřít 50 | Verze: %s 51 | Zdrojové kódy 52 | Ochrana soukromí 53 | 54 | Upozornění na dobíječku 55 | 56 | 57 | -------------------------------------------------------------------------------- /logo/cactus-1f335.svg: -------------------------------------------------------------------------------- 1 | image/svg+xml 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | // Android Application build file 2 | 3 | // Android app 4 | apply plugin: 'com.android.application' 5 | // Kotlin 6 | apply plugin: 'kotlin-android' 7 | 8 | apply plugin: 'com.google.gms.google-services' 9 | // Firebase Crashlytics 10 | apply plugin: 'com.google.firebase.crashlytics' 11 | 12 | 13 | android { 14 | namespace 'eu.zkkn.android.kaktus' 15 | compileSdk 36 16 | buildToolsVersion = '36.0.0' 17 | defaultConfig { 18 | applicationId "eu.zkkn.android.kaktus" 19 | minSdkVersion 19 20 | //noinspection OldTargetApi test on Android 16 21 | targetSdkVersion 35 // Android 15 22 | versionCode 53 23 | versionName '0.21.2' 24 | resourceConfigurations += ['en', 'cs'] 25 | vectorDrawables.useSupportLibrary = true 26 | testApplicationId "eu.zkkn.android.kaktus.test" 27 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 28 | } 29 | buildTypes { 30 | debug { 31 | applicationIdSuffix '.debug' 32 | // SDK 21 is required for native support of Multidex 33 | // so this might break debug builds on older devices 34 | multiDexEnabled true 35 | aaptOptions.cruncherEnabled = false 36 | } 37 | beta { 38 | initWith debug //copy properties from debug 39 | applicationIdSuffix '.beta' 40 | // enable resources shrinking, ProGuard and PNG crunching 41 | shrinkResources true 42 | minifyEnabled true 43 | // ProGuard optimization introduces certain risks, so test thoroughly and 44 | // use it only for beta builds (for now) 45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 46 | aaptOptions.cruncherEnabled = true 47 | } 48 | release { 49 | // enable shrinking of code and resources 50 | shrinkResources true 51 | minifyEnabled true 52 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 53 | } 54 | } 55 | buildFeatures { 56 | buildConfig true 57 | } 58 | productFlavors { 59 | } 60 | compileOptions { 61 | sourceCompatibility = '1.8' 62 | targetCompatibility = '1.8' 63 | } 64 | kotlinOptions { 65 | jvmTarget = '1.8' 66 | } 67 | } 68 | 69 | dependencies { 70 | 71 | def work_version = "2.9.1" 72 | 73 | // Kotlin 74 | implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" 75 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.10.2" 76 | 77 | implementation fileTree(include: ['*.jar'], dir: 'libs') 78 | 79 | //noinspection GradleDependency v1.15.0 needs minSdkVersion 21 80 | implementation 'androidx.core:core-ktx:1.13.1' 81 | //noinspection GradleDependency v1.7.0 needs minSdkVersion 21 82 | implementation 'androidx.appcompat:appcompat:1.6.1' 83 | implementation 'androidx.cardview:cardview:1.0.0' 84 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 85 | //noinspection GradleDependency v2.9.0 needs minSdkVersion 21 86 | implementation "androidx.lifecycle:lifecycle-common:2.8.7" 87 | //noinspection GradleDependency v2.2.0 needs minSdkVersion 21 88 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 89 | //noinspection GradleDependency v2.10.0 needs minSdkVersion 21 90 | implementation "androidx.work:work-runtime:$work_version" 91 | //noinspection GradleDependency v2.10.0 needs minSdkVersion 21 92 | implementation "androidx.work:work-runtime-ktx:$work_version" 93 | //noinspection GradleDependency v2.10.0 needs minSdkVersion 21 94 | implementation "androidx.work:work-gcm:$work_version" 95 | //noinspection GradleDependency v18.5.0 needs minSdkVersion 21 96 | implementation 'com.google.android.gms:play-services-base:18.4.0' 97 | implementation 'com.google.guava:guava:33.4.8-android' 98 | 99 | // Import the BoM for the Firebase platform 100 | //noinspection GradleDependency v33.0.0 needs minSdkVersion 21 101 | implementation platform('com.google.firebase:firebase-bom:32.8.1') 102 | implementation 'com.google.firebase:firebase-analytics' 103 | implementation 'com.google.firebase:firebase-config' 104 | implementation 'com.google.firebase:firebase-crashlytics' 105 | implementation 'com.google.firebase:firebase-messaging-ktx' 106 | 107 | testImplementation 'junit:junit:4.13.2' 108 | androidTestImplementation 'androidx.test:rules:1.6.1' 109 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' 110 | 111 | } 112 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 36 | 60 | 61 | 62 | 63 | 64 | 65 | 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 |