From 6bbc8ed9a862cba3ae9afa7a68ce9c3a3110ee43 Mon Sep 17 00:00:00 2001 From: Binay Shaw Date: Sun, 20 Aug 2023 10:29:05 +0530 Subject: [PATCH 1/5] Fixed Util.vibrateDevice crash --- .../main/java/com/binay/shaw/justap/helper/Util.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/binay/shaw/justap/helper/Util.kt b/app/src/main/java/com/binay/shaw/justap/helper/Util.kt index b998ab3..2d509ad 100644 --- a/app/src/main/java/com/binay/shaw/justap/helper/Util.kt +++ b/app/src/main/java/com/binay/shaw/justap/helper/Util.kt @@ -26,6 +26,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.firebase.auth.FirebaseAuth +import com.google.firebase.crashlytics.FirebaseCrashlytics import com.tapadoo.alerter.Alerter import java.io.File import java.io.FileOutputStream @@ -272,9 +273,13 @@ object Util { @Suppress("DEPRECATION") @RequiresApi(Build.VERSION_CODES.S) fun vibrateDevice(duration: Long, context: Context) { - val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager - val vibrator = vibratorManager.defaultVibrator - vibrator.vibrate(duration) + try { + val vibratorManager = + context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as? VibratorManager + vibratorManager?.defaultVibrator?.vibrate(duration) + } catch (e: Exception) { + FirebaseCrashlytics.getInstance().recordException(e) + } } fun showNoInternet(activity: Activity) { From f2f6e44d2ce3d596c045784afd82939c24ffe2d1 Mon Sep 17 00:00:00 2001 From: Binay Shaw Date: Sun, 20 Aug 2023 10:47:58 +0530 Subject: [PATCH 2/5] Fixed HomeFragment$initObservers$2.invoke crash --- .../binay/shaw/justap/base/BaseFragment.kt | 12 ++++++++++ .../java/com/binay/shaw/justap/helper/Util.kt | 24 +++++++++++++++++++ .../settingsScreen/SettingsFragment.kt | 20 +--------------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt b/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt index c79085c..6e86bd1 100644 --- a/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt +++ b/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt @@ -3,6 +3,7 @@ package com.binay.shaw.justap.base import android.app.Activity import android.app.Dialog import android.content.Context +import android.os.Bundle import android.util.Log import android.view.View import android.view.inputmethod.InputMethodManager @@ -10,7 +11,10 @@ import android.widget.EditText import androidx.appcompat.app.AppCompatActivity import androidx.core.content.res.ResourcesCompat import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope import com.binay.shaw.justap.R +import com.binay.shaw.justap.helper.Util.clearDataAndLogout +import com.google.firebase.auth.FirebaseAuth import com.tapadoo.alerter.Alerter @@ -33,6 +37,14 @@ abstract class BaseFragment : Fragment() { return parentActivity } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val firebaseUserId = FirebaseAuth.getInstance().uid + if (firebaseUserId == null) { + clearDataAndLogout(lifecycleScope, requireContext(), requireActivity()) + } + } + private fun showNoInternetDialog() { Alerter.create(requireActivity()) diff --git a/app/src/main/java/com/binay/shaw/justap/helper/Util.kt b/app/src/main/java/com/binay/shaw/justap/helper/Util.kt index 2d509ad..14bca58 100644 --- a/app/src/main/java/com/binay/shaw/justap/helper/Util.kt +++ b/app/src/main/java/com/binay/shaw/justap/helper/Util.kt @@ -20,7 +20,10 @@ import android.view.View import android.widget.ImageView import androidx.annotation.RequiresApi import androidx.core.content.ContextCompat +import androidx.lifecycle.lifecycleScope import com.binay.shaw.justap.R +import com.binay.shaw.justap.data.LocalUserDatabase +import com.binay.shaw.justap.ui.authentication.signInScreen.SignInScreen import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -28,6 +31,9 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.firebase.auth.FirebaseAuth import com.google.firebase.crashlytics.FirebaseCrashlytics import com.tapadoo.alerter.Alerter +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import java.io.File import java.io.FileOutputStream import java.io.OutputStream @@ -330,4 +336,22 @@ object Util { context.startActivity(chooserIntent) } + fun clearDataAndLogout(scope: CoroutineScope, context: Context, activity: Activity) { + scope.launch(Dispatchers.Main) { + val sharedPreferences = + context.getSharedPreferences(Constants.qrPref, Context.MODE_PRIVATE) + val editor = sharedPreferences.edit() + editor.clear() + editor.apply() + val signOutFromFirebase = + launch(Dispatchers.IO) { FirebaseAuth.getInstance().signOut() } + signOutFromFirebase.join() + LocalUserDatabase.getDatabase(context).clearTables() + val intent = Intent(context, SignInScreen::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + context.startActivity(intent).also { activity.finish() } + log("Logged out") + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/binay/shaw/justap/ui/mainScreens/settingsScreen/SettingsFragment.kt b/app/src/main/java/com/binay/shaw/justap/ui/mainScreens/settingsScreen/SettingsFragment.kt index a09dad0..aef5555 100644 --- a/app/src/main/java/com/binay/shaw/justap/ui/mainScreens/settingsScreen/SettingsFragment.kt +++ b/app/src/main/java/com/binay/shaw/justap/ui/mainScreens/settingsScreen/SettingsFragment.kt @@ -278,7 +278,7 @@ class SettingsFragment : BaseFragment() { positiveOption.setOnClickListener { bottomSheet.dismiss() - clearDataAndLogout() + Util.clearDataAndLogout(lifecycleScope, requireContext(), requireActivity()) } negativeOption.setOnClickListener { bottomSheet.dismiss() @@ -288,24 +288,6 @@ class SettingsFragment : BaseFragment() { dialog.root.setBottomSheet(bottomSheet) } - private fun clearDataAndLogout() { - lifecycleScope.launch(Dispatchers.Main) { - val sharedPreferences = - requireContext().getSharedPreferences(Constants.qrPref, Context.MODE_PRIVATE) - val editor = sharedPreferences.edit() - editor.clear() - editor.apply() - val signOutFromFirebase = - launch(Dispatchers.IO) { FirebaseAuth.getInstance().signOut() } - signOutFromFirebase.join() - LocalUserDatabase.getDatabase(requireContext()).clearTables() - val intent = Intent(requireContext(), SignInScreen::class.java) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - startActivity(intent).also { requireActivity().finish() } - Util.log("Logged out") - } - } - override fun onDestroy() { super.onDestroy() _binding = null From 260043d4bc37ae7a873841f6fa5d977f2aa6b26f Mon Sep 17 00:00:00 2001 From: Binay Shaw Date: Sun, 20 Aug 2023 10:49:01 +0530 Subject: [PATCH 3/5] Added Toast for NullUserId response --- app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt b/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt index 6e86bd1..ecae23d 100644 --- a/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt +++ b/app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt @@ -8,6 +8,7 @@ import android.util.Log import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.EditText +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.content.res.ResourcesCompat import androidx.fragment.app.Fragment @@ -42,6 +43,7 @@ abstract class BaseFragment : Fragment() { val firebaseUserId = FirebaseAuth.getInstance().uid if (firebaseUserId == null) { clearDataAndLogout(lifecycleScope, requireContext(), requireActivity()) + Toast.makeText(requireContext(), getString(R.string.anErrorOccurred), Toast.LENGTH_SHORT).show() } } From 78eb41fa4eecad4e3a993b2cebb221c0502d0c75 Mon Sep 17 00:00:00 2001 From: Binay Shaw Date: Mon, 21 Aug 2023 13:50:40 +0530 Subject: [PATCH 4/5] Added Firebase Performance Tracing --- app/build.gradle | 2 ++ app/src/main/AndroidManifest.xml | 3 +++ app/src/main/java/com/binay/shaw/justap/base/BaseActivity.kt | 5 +++++ build.gradle | 1 + 4 files changed, 11 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index ed6e600..38b1ddd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,6 +6,7 @@ plugins { id 'androidx.navigation.safeargs.kotlin' id 'com.google.firebase.crashlytics' id 'kotlin-kapt' + id("com.google.firebase.firebase-perf") } android { @@ -89,6 +90,7 @@ dependencies { implementation 'com.google.firebase:firebase-crashlytics-ktx' implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-messaging:23.1.2' + implementation("com.google.firebase:firebase-perf-ktx") //Room Database diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ab228d4..8183d11 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,6 +21,9 @@ android:theme="@style/Theme.JusTap" android:usesCleartextTraffic="true" tools:targetApi="31"> + diff --git a/app/src/main/java/com/binay/shaw/justap/base/BaseActivity.kt b/app/src/main/java/com/binay/shaw/justap/base/BaseActivity.kt index 2a78a78..f0a5620 100644 --- a/app/src/main/java/com/binay/shaw/justap/base/BaseActivity.kt +++ b/app/src/main/java/com/binay/shaw/justap/base/BaseActivity.kt @@ -9,18 +9,23 @@ import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import com.binay.shaw.justap.helper.DarkMode +import com.google.firebase.perf.FirebasePerformance +import com.google.firebase.perf.metrics.Trace import java.util.Locale abstract class BaseActivity : AppCompatActivity() { fun setTheme() { + val trace: Trace = FirebasePerformance.getInstance().newTrace("Dark Mode Trace") + trace.start() val darkModeEnabled = DarkMode.getDarkMode(this) if (darkModeEnabled) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) } + trace.stop() } fun loadLocate() { diff --git a/build.gradle b/build.gradle index d1cdae0..f7629c4 100644 --- a/build.gradle +++ b/build.gradle @@ -10,4 +10,5 @@ plugins { id 'com.android.library' version '7.4.0' apply false id 'org.jetbrains.kotlin.android' version '1.8.10' apply false // id 'com.google.dagger.hilt.android' version '2.44' apply false + id("com.google.firebase.firebase-perf") version "1.4.2" apply false } \ No newline at end of file From 0e690ac3cdf68bb670807fc0887be92fbd1d5a2e Mon Sep 17 00:00:00 2001 From: Binay Shaw Date: Mon, 21 Aug 2023 14:35:56 +0530 Subject: [PATCH 5/5] Added Firebase Push notification --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 21 ++++ .../services/MyFirebaseMessagingService.kt | 100 ++++++++---------- app/src/main/res/values-hi/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 71 insertions(+), 53 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 38b1ddd..65c6ff8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,6 +91,7 @@ dependencies { implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-messaging:23.1.2' implementation("com.google.firebase:firebase-perf-ktx") + implementation 'com.google.firebase:firebase-messaging-ktx:23.2.1' //Room Database diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8183d11..3b72f7f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -81,6 +81,27 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/binay/shaw/justap/services/MyFirebaseMessagingService.kt b/app/src/main/java/com/binay/shaw/justap/services/MyFirebaseMessagingService.kt index 4b63ae9..4671307 100644 --- a/app/src/main/java/com/binay/shaw/justap/services/MyFirebaseMessagingService.kt +++ b/app/src/main/java/com/binay/shaw/justap/services/MyFirebaseMessagingService.kt @@ -1,77 +1,71 @@ package com.binay.shaw.justap.services +import android.app.NotificationChannel +import android.app.NotificationManager import android.app.PendingIntent import android.content.Intent +import android.graphics.BitmapFactory +import android.graphics.Color +import android.media.RingtoneManager +import android.os.Build import androidx.core.app.NotificationCompat import com.binay.shaw.justap.R -import com.binay.shaw.justap.helper.NotificationHelper -import com.binay.shaw.justap.helper.Util +import com.binay.shaw.justap.helper.Logger import com.binay.shaw.justap.ui.mainScreens.MainActivity +import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage class MyFirebaseMessagingService : FirebaseMessagingService() { - - private lateinit var notificationHelper: NotificationHelper - val channelId = "notification_channel_id" - val channelName = "notification_channel_name" - override fun onMessageReceived(remoteMessage: RemoteMessage) { - // Handle incoming notification - try { - if (remoteMessage.notification != null) { - showNotification( - remoteMessage.notification?.title, - remoteMessage.notification?.body - ) - } else { - showNotification(remoteMessage.data["title"], remoteMessage.data["message"]) - } - } catch (e: Exception) { - Util.log("Error: ${e.localizedMessage}") + remoteMessage.notification?.let { + sendNotification( + it.title, it.body + ) } } override fun onNewToken(token: String) { - super.onNewToken(token) - Util.log("New token: $token") - } - - private fun showNotification( - title: String?, - body: String? - ) { - notificationHelper = NotificationHelper(this) - notificationHelper.createNotificationChannel(channelId, channelName) - - if (title != null && body != null) { - val builder = createNotificationBuilder(title, body) - notificationHelper.showNotification(0, builder) - } + Logger.debugLog("Firebase Token: $token") + FirebaseMessaging.getInstance().subscribeToTopic(APP_UPDATES) } - private fun createNotificationBuilder( - title: String, - message: String - ): NotificationCompat.Builder { - // Create an Intent for the notification action - val intent = Intent(this, MainActivity::class.java).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - } + private fun sendNotification(messageTitle: String?, messageBody: String?) { + val intent = Intent(this, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) val pendingIntent = PendingIntent.getActivity( - this, - 0, - intent, - PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + this, 0 /* Request code */, intent, + PendingIntent.FLAG_IMMUTABLE ) - - // Create a NotificationCompat.Builder object - return NotificationCompat.Builder(this, channelId) - .setSmallIcon(R.drawable.notification_icon) - .setContentTitle(title) - .setContentText(message) - .setPriority(NotificationCompat.PRIORITY_DEFAULT) + val rawBitmap = BitmapFactory.decodeResource( + resources, + R.drawable.logo_light + ) + val channelId = resources.getString(R.string.default_notification_channel_id) + val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + val notificationBuilder = NotificationCompat.Builder(this, channelId) + .setSmallIcon(R.drawable.logo_light) + .setLargeIcon(rawBitmap) + .setColor(Color.parseColor("#f83d3a")) + .setSound(defaultSoundUri) + .setContentTitle(messageTitle) + .setContentText(messageBody) + .setAutoCancel(true) .setContentIntent(pendingIntent) + val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val channel = NotificationChannel( + channelId, + resources.getString(R.string.default_notification_channel_id), + NotificationManager.IMPORTANCE_DEFAULT + ) + notificationManager.createNotificationChannel(channel) + } + notificationManager.notify(0 , notificationBuilder.build()) + } + + companion object { + private const val APP_UPDATES = "app-updates" } } \ No newline at end of file diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 8971394..e6c3724 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -180,6 +180,7 @@ JusTap दूसरों के साथ सोशल अकाउंट का आदान-प्रदान करने का सबसे तेज़ और सबसे कुशल तरीका है। बस टैप करें और स्कैन करें। सभी एक ही स्थान पर जस्टैप के साथ अपने सभी संपर्क जानकारी और सामाजिक लिंक को एक सुविधाजनक स्थान पर रखें। संगठित और जुड़े रहें। + justap Country Flag भाषा बदलें diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afa5ce1..dba97de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -183,6 +183,7 @@ Change Language Please select any one from the options Modal Handle + justap Phone