Skip to content

Commit

Permalink
Merge pull request #8 from binayshaw7777/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
binayshaw7777 authored Aug 21, 2023
2 parents c4c34bb + 0e690ac commit 92c6b29
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 75 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -89,6 +90,8 @@ 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")
implementation 'com.google.firebase:firebase-messaging-ktx:23.2.1'


//Room Database
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
android:theme="@style/Theme.JusTap"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true" />
<activity
android:name=".ui.introduction.onboarding.OnboardingScreen"
android:exported="false" />
Expand Down Expand Up @@ -78,6 +81,27 @@
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

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

</intent-filter>
</service>

<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:enabled="true"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>

</application>

</manifest>
5 changes: 5 additions & 0 deletions app/src/main/java/com/binay/shaw/justap/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/binay/shaw/justap/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ 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
import android.widget.EditText
import android.widget.Toast
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


Expand All @@ -33,6 +38,15 @@ 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())
Toast.makeText(requireContext(), getString(R.string.anErrorOccurred), Toast.LENGTH_SHORT).show()
}
}


private fun showNoInternetDialog() {
Alerter.create(requireActivity())
Expand Down
35 changes: 32 additions & 3 deletions app/src/main/java/com/binay/shaw/justap/helper/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ 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
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
Expand Down Expand Up @@ -272,9 +279,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) {
Expand Down Expand Up @@ -325,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")
}
}

}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class SettingsFragment : BaseFragment() {

positiveOption.setOnClickListener {
bottomSheet.dismiss()
clearDataAndLogout()
Util.clearDataAndLogout(lifecycleScope, requireContext(), requireActivity())
}
negativeOption.setOnClickListener {
bottomSheet.dismiss()
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<string name="justap_is_the_quickest_and_most_efficient_way_to_exchange_details_with_others_just_tap_and_scan">JusTap दूसरों के साथ सोशल अकाउंट का आदान-प्रदान करने का सबसे तेज़ और सबसे कुशल तरीका है। बस टैप करें और स्कैन करें।</string>
<string name="all_in_one_place">सभी एक ही स्थान पर</string>
<string name="keep_all_your_contact_info_and_social_links_in_one_convenient_location_with_justap_stay_organized_and_connected">जस्टैप के साथ अपने सभी संपर्क जानकारी और सामाजिक लिंक को एक सुविधाजनक स्थान पर रखें। संगठित और जुड़े रहें।</string>
<string name="default_notification_channel_id">justap</string>

<string name="country_flag">Country Flag</string>
<string name="change_language">भाषा बदलें</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<string name="change_language">Change Language</string>
<string name="please_select_any_one_from_the_options">Please select any one from the options</string>
<string name="modal_handle">Modal Handle</string>
<string name="default_notification_channel_id">justap</string>

<string-array name="account_names">
<item>Phone</item>
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 92c6b29

Please sign in to comment.