Skip to content

Commit 8a13264

Browse files
committed
.k files added
1 parent e5ee228 commit 8a13264

File tree

10 files changed

+282
-1
lines changed

10 files changed

+282
-1
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
*.class
77
*.iml
88
*.idea/
9-
*.kt
109
*.json
1110
build/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.redconefinal
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.redconefinal", appContext.packageName)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.example.redconefinal
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.widget.Toast
6+
import androidx.appcompat.app.AppCompatActivity
7+
import androidx.recyclerview.widget.LinearLayoutManager
8+
import androidx.recyclerview.widget.RecyclerView
9+
import com.google.firebase.firestore.FirebaseFirestore
10+
11+
class AlertData : AppCompatActivity() {
12+
private lateinit var recyclerView: RecyclerView
13+
private lateinit var db: FirebaseFirestore
14+
private lateinit var userList: ArrayList<User>
15+
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
setContentView(R.layout.activity_alert_data)
19+
20+
recyclerView = findViewById(R.id.recyclerview)
21+
recyclerView.layoutManager = LinearLayoutManager(this)
22+
userList = ArrayList()
23+
db = FirebaseFirestore.getInstance()
24+
25+
fetchDataFromFirestore()
26+
}
27+
28+
private fun fetchDataFromFirestore() {
29+
db.collection("files").get()
30+
.addOnSuccessListener { documents ->
31+
for (document in documents) {
32+
val user = document.toObject(User::class.java)
33+
userList.add(user)
34+
}
35+
recyclerView.adapter = MyAdapter(userList) { user ->
36+
val intent = Intent(this@AlertData, AlertDetails::class.java)
37+
intent.putExtra("user", user)
38+
startActivity(intent)
39+
}
40+
}
41+
.addOnFailureListener { exception ->
42+
Toast.makeText(this, "Error fetching data: ${exception.message}", Toast.LENGTH_SHORT).show()
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example.redconefinal
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import android.widget.Toast
6+
import com.bumptech.glide.Glide
7+
import com.example.redconefinal.databinding.ActivityAlertDetailsBinding
8+
9+
class AlertDetails : AppCompatActivity() {
10+
private lateinit var binding: ActivityAlertDetailsBinding
11+
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
binding = ActivityAlertDetailsBinding.inflate(layoutInflater)
15+
setContentView(binding.root)
16+
17+
val user = intent.getParcelableExtra<User>("user")
18+
19+
if (user != null) {
20+
binding.nameTextView.text = user.name
21+
binding.locationTextView.text = user.Location
22+
binding.datetimeTextView.text = user.datetime
23+
24+
Glide.with(this)
25+
.load(user.image)
26+
.into(binding.imageView)
27+
} else {
28+
Toast.makeText(this, "User data not found", Toast.LENGTH_SHORT).show()
29+
finish()
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.example.redconefinal
2+
3+
import android.app.Notification
4+
import android.app.NotificationChannel
5+
import android.app.NotificationManager
6+
import android.app.PendingIntent
7+
import android.content.Context
8+
import android.content.Intent
9+
import android.os.Build
10+
import android.util.Log
11+
import androidx.core.app.NotificationCompat
12+
import com.google.firebase.messaging.FirebaseMessagingService
13+
import com.google.firebase.messaging.RemoteMessage
14+
15+
class FirebaseMsgService : FirebaseMessagingService() {
16+
private val CHANNEL_ID = "push_noti"
17+
18+
override fun onNewToken(token: String) {
19+
super.onNewToken(token)
20+
Log.d("FirebaseMsgService", "Refreshed token: $token")
21+
}
22+
23+
override fun onMessageReceived(remoteMessage: RemoteMessage) {
24+
super.onMessageReceived(remoteMessage)
25+
Log.d("FirebaseMsgService", "Message received: ${remoteMessage.data}")
26+
27+
remoteMessage.notification?.let {
28+
Log.d("FirebaseMsgService", "Notification Title: ${it.title}, Body: ${it.body}")
29+
pushNotification(it.title, it.body)
30+
} ?: Log.d("FirebaseMsgService", "No notification payload")
31+
}
32+
33+
private fun pushNotification(title: String?, msg: String?) {
34+
val nm = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
35+
36+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
37+
val name = "Custom Channel"
38+
val descriptionText = "Channel for Push Notifications"
39+
val importance = NotificationManager.IMPORTANCE_HIGH
40+
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
41+
description = descriptionText
42+
}
43+
nm?.createNotificationChannel(channel)
44+
}
45+
46+
val intent = Intent(this, MainActivity::class.java).apply {
47+
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
48+
}
49+
val pendingIntent = PendingIntent.getActivity(this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
50+
51+
val notification: Notification = NotificationCompat.Builder(this, CHANNEL_ID)
52+
.setSmallIcon(R.drawable.rc1)
53+
.setContentTitle(title)
54+
.setContentText(msg)
55+
.setPriority(NotificationCompat.PRIORITY_HIGH)
56+
.setContentIntent(pendingIntent)
57+
.setAutoCancel(true)
58+
.build()
59+
60+
val notificationId = 1
61+
nm?.notify(notificationId, notification)
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.example.redconefinal
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.util.Log
6+
import android.view.View
7+
import androidx.activity.enableEdgeToEdge
8+
import androidx.appcompat.app.AppCompatActivity
9+
import com.google.firebase.FirebaseApp
10+
import com.google.firebase.messaging.FirebaseMessaging
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
enableEdgeToEdge()
17+
setContentView(R.layout.activity_main)
18+
FirebaseApp.initializeApp(this)
19+
20+
// Set click listener for the button
21+
findViewById<View>(R.id.startButton).setOnClickListener {
22+
secondpage(it)
23+
}
24+
25+
// Subscribe all users to the 'all_users' topic
26+
FirebaseMessaging.getInstance().subscribeToTopic("all_users")
27+
.addOnCompleteListener { task ->
28+
if (task.isSuccessful) {
29+
Log.d("MainActivity", "Subscribed to topic 'all_users'")
30+
} else {
31+
Log.e("MainActivity", "Failed to subscribe to topic 'all_users'", task.exception)
32+
}
33+
}
34+
35+
// Retrieve the FCM token (optional)
36+
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
37+
if (!task.isSuccessful) {
38+
Log.e("FirebaseMsgService", "Fetching FCM registration token failed", task.exception)
39+
return@addOnCompleteListener
40+
}
41+
42+
// Get new FCM registration token
43+
val token = task.result
44+
Log.d("FirebaseMsgService", "FCM registration token: $token")
45+
}
46+
}
47+
48+
fun secondpage(view: View) {
49+
val intent = Intent(this, AlertData::class.java)
50+
startActivity(intent)
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.example.redconefinal
2+
3+
import android.view.LayoutInflater
4+
import android.view.ViewGroup
5+
import androidx.recyclerview.widget.RecyclerView
6+
import com.example.redconefinal.databinding.ListItemBinding
7+
8+
class MyAdapter(private val userList: List<User>, private val onItemClick: (User) -> Unit) :
9+
RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
10+
11+
class MyViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root)
12+
13+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
14+
val binding = ListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
15+
return MyViewHolder(binding)
16+
}
17+
18+
override fun getItemCount(): Int {
19+
return userList.size
20+
}
21+
22+
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
23+
val currentItem = userList[position]
24+
holder.binding.nameTextView.text = currentItem.name
25+
holder.binding.datetimeTextView.text = currentItem.datetime
26+
holder.binding.locationTextView.text = currentItem.Location
27+
holder.itemView.setOnClickListener {
28+
onItemClick(currentItem)
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.redconefinal
2+
3+
import android.os.Parcelable
4+
import kotlinx.parcelize.Parcelize
5+
6+
@Parcelize
7+
data class User(
8+
val name: String? = null,
9+
val datetime: String? = null,
10+
val Location: String? = null,
11+
val image: String? = null
12+
) : Parcelable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.example.redconefinal
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* See [testing documentation](http://d.android.com/tools/testing).
11+
*/
12+
class ExampleUnitTest {
13+
@Test
14+
fun addition_isCorrect() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

0 commit comments

Comments
 (0)