Skip to content

Commit

Permalink
Added basic notifications app, added favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
TMDStudios committed Nov 3, 2024
1 parent d6babd8 commit 834a3a4
Show file tree
Hide file tree
Showing 40 changed files with 1,056 additions and 9 deletions.
39 changes: 33 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Virtual Environments
/local/venv
/core/venv
venv/

# Media files
*.avi
*.jpg
*.sqlite3
*.db

# Environment files
.env

# Logs
*.log
/local/*log*.txt
todo.txt

Expand All @@ -13,7 +22,6 @@ __pycache__/
*.pyc
*.pyo
*.pyd
*.pyc

# Compiled files
*.pyc
Expand All @@ -22,13 +30,11 @@ __pycache__/

# Static files collected by Django
staticfiles/
static/

# Django migrations (should be committed to version control)
# Django migrations
!*/migrations/__init__.py

# Log files
*.log

# Coverage reports
.coverage
.coverage.*
Expand Down Expand Up @@ -57,4 +63,25 @@ Desktop.ini
*.lock
*.gz
*.tar
*.zip
*.zip

# Gradle files
.gradle/
build/
app/build/
*.kotlin_metadata

# Local configuration
local.properties

# Miscellaneous binaries and archives
*.jar
*.war
*.zip
*.tar.gz
*.tgz
*.7z
*.class

# Google Services configuration
google-services.json
15 changes: 15 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions app/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions app/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id("com.android.application")
id("com.google.gms.google-services") // Ensure you have the Google services plugin
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.tmdstudios.mingsec"
compileSdk = 33

defaultConfig {
applicationId = "com.tmdstudios.mingsec"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
// Match this to the Compose version you're using
kotlinCompilerExtensionVersion = "1.4.3" // Update if necessary based on the Compose BOM
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.0")

// Use the Compose BOM for version management
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")

// Use the Firebase BOM for version management
implementation(platform("com.google.firebase:firebase-bom:33.5.1"))
implementation("com.google.firebase:firebase-messaging-ktx") // Removed version to use BOM

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
21 changes: 21 additions & 0 deletions app/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tmdstudios.mingsec

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.tmdstudios.mingsec", appContext.packageName)
}
}
37 changes: 37 additions & 0 deletions app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MingSec"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.MingSec">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>

</manifest>
24 changes: 24 additions & 0 deletions app/app/src/main/java/com/tmdstudios/mingsec/FCMTokenManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tmdstudios.mingsec

import com.google.firebase.messaging.FirebaseMessaging

object FCMTokenManager {
private var fcmToken: String? = null

fun getFCMToken(onTokenReceived: (String?) -> Unit) {
if (fcmToken != null) {
// If the token is already retrieved, return it
onTokenReceived(fcmToken)
} else {
// Fetch the token if not already available
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (task.isSuccessful) {
fcmToken = task.result
onTokenReceived(fcmToken)
} else {
onTokenReceived(null) // Handle the error
}
}
}
}
}
81 changes: 81 additions & 0 deletions app/app/src/main/java/com/tmdstudios/mingsec/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.tmdstudios.mingsec

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.tmdstudios.mingsec.ui.theme.MingSecTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
createNotificationChannel() // Create the notification channel

setContent {
MingSecTheme {
// Surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}
}
}

private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"default_channel",
"Default Channel",
NotificationManager.IMPORTANCE_DEFAULT
)
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(channel)
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
// State variable to hold the FCM token
var token by remember { mutableStateOf<String?>(null) }

LaunchedEffect(Unit) {
// Retrieve the FCM token
FCMTokenManager.getFCMToken { retrievedToken ->
token = retrievedToken // Update the state with the retrieved token
}
}

// Display the UI based on whether the token has been retrieved
if (token != null) {
GreetingWithToken(name, token!!, modifier) // Use !! to assert that token is not null
} else {
// Display a loading message or similar while the token is being fetched
Text(
text = "Hello $name!\nFetching FCM Token...",
modifier = modifier.padding(16.dp) // Add some padding for better readability
)
}
}

@Composable
fun GreetingWithToken(name: String, token: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!\nFCM Token: $token",
modifier = modifier.padding(16.dp) // Add some padding for better readability
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.tmdstudios.mingsec

import android.app.NotificationManager
import android.content.Context
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import androidx.core.app.NotificationCompat

class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
remoteMessage.notification?.let {
showNotification(it.title ?: "Notification", it.body ?: "")
}
}

private fun showNotification(title: String, message: String) {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationId = 1

val builder = NotificationCompat.Builder(this, "default_channel")
.setSmallIcon(R.mipmap.ic_launcher) // Ensure you have a drawable icon
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)

notificationManager.notify(notificationId, builder.build())
}

override fun onNewToken(token: String) {
super.onNewToken(token)
// Send the token to your server for later use
}
}
Loading

0 comments on commit 834a3a4

Please sign in to comment.