Skip to content

Commit

Permalink
fix: Random QRs threw error
Browse files Browse the repository at this point in the history
  • Loading branch information
vendz committed Apr 13, 2023
1 parent a132a94 commit 5269016
Show file tree
Hide file tree
Showing 33 changed files with 148 additions and 247 deletions.
Binary file modified APP/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified APP/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified APP/.gradle/file-system.probe
Binary file not shown.
Binary file removed APP/app/release/app-release.apk
Binary file not shown.
20 changes: 0 additions & 20 deletions APP/app/release/output-metadata.json

This file was deleted.

Binary file added APP/app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 35 additions & 6 deletions APP/app/src/main/java/com/vandit/reservatio/CameraFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vandit.reservatio

import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
Expand All @@ -17,6 +18,9 @@ import com.budiyev.android.codescanner.CodeScanner
import com.budiyev.android.codescanner.DecodeCallback
import com.budiyev.android.codescanner.ScanMode
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.database.*
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
import com.vandit.reservatio.databinding.FragmentCameraBinding
Expand All @@ -26,6 +30,8 @@ private const val CAMERA_REQUEST_CODE = 101
class CameraFragment : Fragment() {
lateinit var binding: FragmentCameraBinding
private lateinit var codeScanner: CodeScanner
private lateinit var database: FirebaseDatabase
private lateinit var myRef: DatabaseReference

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -42,6 +48,15 @@ class CameraFragment : Fragment() {
setupPermissions()

val sharedPref = activity?.getPreferences(Context.MODE_PRIVATE) ?: return
val ai: ApplicationInfo? = context?.let {
context?.packageManager?.getApplicationInfo(
it.packageName,
PackageManager.GET_META_DATA
)
}
val value = ai?.metaData?.get("FIREBASE_URI")
val FIREBASE_URI = value.toString()
database = Firebase.database(FIREBASE_URI)

codeScanner = CodeScanner(requireActivity(), binding.scannerView)
codeScanner.apply {
Expand All @@ -55,13 +70,27 @@ class CameraFragment : Fragment() {

decodeCallback = DecodeCallback {
val prefs =
activity?.getSharedPreferences("TOKEN_PREF", FirebaseMessagingService.MODE_PRIVATE)
activity?.getSharedPreferences(
"TOKEN_PREF",
FirebaseMessagingService.MODE_PRIVATE
)
var token = prefs?.getString("token", "")
token = token?.replace("""[.:]""".toRegex(), "~_~")
sharedPref.edit().putString("restaurant", it.text).apply()
sharedPref.edit().putString("token", token).apply()
fragmentManager?.beginTransaction()
?.replace(R.id.nav_host_fragment, QueueFragment())?.commit()
token = token?.replace(".", "?")?.replace(":", "%")

myRef = database.getReference(it.toString())
myRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
val value = snapshot.value
if (value != null) {
sharedPref.edit().putString("restaurant", it.text).apply()
sharedPref.edit().putString("token", token).apply()
fragmentManager?.beginTransaction()
?.replace(R.id.nav_host_fragment, QueueFragment())?.commit()
}
}

override fun onCancelled(error: DatabaseError) = Unit
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {

override fun onNewToken(token: String) {
super.onNewToken(token)
Log.d("MyFCM.kt", "VANDIT => onNewToken:66 $token")

val editor = getSharedPreferences("TOKEN_PREF", MODE_PRIVATE).edit()
editor.putString("token", token)
editor.apply()
Expand Down
25 changes: 6 additions & 19 deletions APP/app/src/main/java/com/vandit/reservatio/QueueFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.google.firebase.database.*
import com.google.firebase.database.ktx.database
import com.google.firebase.database.ktx.getValue
import com.google.firebase.ktx.Firebase
import com.google.firebase.messaging.FirebaseMessaging
import com.vandit.reservatio.databinding.FragmentQueueBinding

class QueueFragment : Fragment() {
Expand All @@ -37,8 +36,10 @@ class QueueFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

val ai: ApplicationInfo? = context?.let {
context?.packageManager
?.getApplicationInfo(it.packageName, PackageManager.GET_META_DATA)
context?.packageManager?.getApplicationInfo(
it.packageName,
PackageManager.GET_META_DATA
)
}
val value = ai?.metaData?.get("FIREBASE_URI")
val FIREBASE_URI = value.toString()
Expand All @@ -51,8 +52,7 @@ class QueueFragment : Fragment() {

var userName = "$name-$token"

database =
Firebase.database(FIREBASE_URI)
database = Firebase.database(FIREBASE_URI)
myRef = database.getReference(restaurant.toString())

if (un == null) {
Expand All @@ -69,7 +69,6 @@ class QueueFragment : Fragment() {
}

binding.leaveBTN.setOnClickListener {

myRef.get().addOnCompleteListener {
val resultValue = it.result as DataSnapshot
val value = resultValue.getValue<HashMap<String, Int>>()
Expand All @@ -93,17 +92,6 @@ class QueueFragment : Fragment() {

myRef.child(userName).removeValue()
myRef.setValue(value)

FirebaseMessaging.getInstance()
.unsubscribeFromTopic(token!!)
.addOnCompleteListener { task1 ->
if (!task1.isSuccessful) {
Log.d(
"QueueFragment.kt",
"VANDIT => onViewCreated:105 => unSubscription failed"
)
}
}
}

with(sharedPref.edit()) {
Expand All @@ -123,7 +111,6 @@ class QueueFragment : Fragment() {
val resultValue = it.result as DataSnapshot
val value = resultValue.getValue<HashMap<String, Int>>()
val size = value?.size

val map = mapOf(username to size!!)
myRef.updateChildren(map)
}
Expand All @@ -136,7 +123,7 @@ class QueueFragment : Fragment() {
val x = value?.filterKeys { it == un }
if (x != null) {
val flag = sharedPref.getInt("flag", 0)
if(flag == 1 && x.values.isEmpty()){
if (flag == 1 && x.values.isEmpty()) {
with(sharedPref.edit()) {
putString("username", null)
putBoolean("inQueue", false)
Expand Down
30 changes: 0 additions & 30 deletions APP/app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

Loading

0 comments on commit 5269016

Please sign in to comment.