aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-13 18:17:15 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-13 18:17:15 -0600
commit2f23203099cd152c36571a39c42ff3056c13484c (patch)
treeb3fe1d68b439600b39753c4e6b5cf2b4ab8aa7fb /androidApp/src/main/java
parent2fef9e4abfcfa2895ba4f4c082fe7a7a10acebac (diff)
downloadetbsa-trackermap-mobile-2f23203099cd152c36571a39c42ff3056c13484c.tar.gz
etbsa-trackermap-mobile-2f23203099cd152c36571a39c42ff3056c13484c.tar.bz2
etbsa-trackermap-mobile-2f23203099cd152c36571a39c42ff3056c13484c.zip
Introduced Google product flavor for FCM notifications
Diffstat (limited to 'androidApp/src/main/java')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt2
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt38
2 files changed, 38 insertions, 2 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
index cdb7102..4cbf8e5 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
@@ -19,7 +19,7 @@ import org.koin.core.logger.Level
import org.koin.dsl.module
@DelicateCoroutinesApi
-class TrackerApp : Application() {
+open class TrackerApp : Application() {
override fun onCreate() {
super.onCreate()
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt
index 674c2d3..185a444 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt
@@ -1,6 +1,6 @@
package mx.trackermap.TrackerMap.android.session
-import android.content.Intent
+import android.content.*
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -9,6 +9,8 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
+import androidx.localbroadcastmanager.content.LocalBroadcastManager
+import androidx.preference.PreferenceManager
import com.zhuinden.liveevent.observe
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.databinding.LoginBinding
@@ -20,6 +22,7 @@ class LoginFragment : Fragment() {
private var _binding: LoginBinding? = null
private val binding get() = _binding!!
private val loginViewModel: LoginViewModel by viewModel()
+ private lateinit var broadcastManager: LocalBroadcastManager
override fun onCreateView(
inflater: LayoutInflater,
@@ -35,9 +38,21 @@ class LoginFragment : Fragment() {
setupEvents()
setupObservers()
+ broadcastManager = LocalBroadcastManager.getInstance(activity!!)
loginViewModel.restoreSession()
}
+ override fun onStart() {
+ super.onStart()
+ val intentFilter = IntentFilter(EVENT_TOKEN)
+ broadcastManager.registerReceiver(broadcastReceiver, intentFilter)
+ }
+
+ override fun onStop() {
+ super.onStop()
+ broadcastManager.unregisterReceiver(broadcastReceiver)
+ }
+
override fun onDestroyView() {
super.onDestroyView()
_binding = null
@@ -72,6 +87,7 @@ class LoginFragment : Fragment() {
Toast.makeText(context, "Failed login", Toast.LENGTH_SHORT).show()
}
LoginViewModel.LoginState.Success -> {
+ broadcastManager.sendBroadcast(Intent(EVENT_LOGIN))
val activity = requireActivity()
val intent = Intent(activity.applicationContext, UnitsActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
@@ -81,4 +97,24 @@ class LoginFragment : Fragment() {
}
}
}
+
+ private val broadcastReceiver = object : BroadcastReceiver() {
+ override fun onReceive(p0: Context?, p1: Intent?) {
+ p1?.getStringExtra(KEY_TOKEN)?.let { token ->
+ PreferenceManager
+ .getDefaultSharedPreferences(activity)
+ .edit()
+ .putString(PREFERENCE_TOKEN, token)
+ .apply()
+ }
+ }
+ }
+
+ companion object {
+ const val EVENT_LOGIN = "eventLogin"
+ const val EVENT_TOKEN = "eventToken"
+ const val KEY_TOKEN = "keyToken"
+
+ const val PREFERENCE_TOKEN = "token"
+ }
} \ No newline at end of file