diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-13 18:17:15 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-13 18:17:15 -0600 |
commit | 2f23203099cd152c36571a39c42ff3056c13484c (patch) | |
tree | b3fe1d68b439600b39753c4e6b5cf2b4ab8aa7fb /androidApp/src/main | |
parent | 2fef9e4abfcfa2895ba4f4c082fe7a7a10acebac (diff) | |
download | etbsa-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')
4 files changed, 69 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 diff --git a/androidApp/src/main/res/drawable/icon_notify.xml b/androidApp/src/main/res/drawable/icon_notify.xml new file mode 100644 index 0000000..c92915e --- /dev/null +++ b/androidApp/src/main/res/drawable/icon_notify.xml @@ -0,0 +1,28 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:aapt="http://schemas.android.com/aapt" + android:width="24dp" + android:height="24dp" + android:viewportWidth="31.75" + android:viewportHeight="31.75"> + <path + android:pathData="m16.7714,15.5323c5.3724,1.0493 7.469,14.6249 7.469,14.6249 0,0 -0.3949,-10.5539 -8.531,-11.6354 -6.4938,-0.8632 -11.1417,7.5606 -11.1417,7.5606 0,0 6.9261,-11.581 12.2037,-10.5502z" + android:strokeLineJoin="bevel" + android:strokeWidth="1.8058915" + android:fillColor="#ff3232" + android:strokeColor="#ff3232" + android:strokeLineCap="butt"/> + <path + android:pathData="m18.261,8.9784c5.3724,1.0493 7.469,14.6249 7.469,14.6249 0,0 -0.3949,-10.5539 -8.531,-11.6354 -6.4938,-0.8632 -11.1417,7.5606 -11.1417,7.5606 0,0 6.9261,-11.581 12.2037,-10.5502z" + android:strokeLineJoin="bevel" + android:strokeWidth="1.8058915" + android:fillColor="#ff3232" + android:strokeColor="#ff3232" + android:strokeLineCap="butt"/> + <path + android:pathData="m19.6015,2.4245c5.3724,1.0493 7.469,14.6249 7.469,14.6249 0,0 -0.3949,-10.5539 -8.531,-11.6354 -6.4938,-0.8632 -11.1417,7.5606 -11.1417,7.5606 0,0 6.9261,-11.581 12.2037,-10.5502z" + android:strokeLineJoin="bevel" + android:strokeWidth="1.8058915" + android:fillColor="#ff3232" + android:strokeColor="#ff3232" + android:strokeLineCap="butt"/> +</vector> diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index b8080f5..5f39ce1 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -20,6 +20,9 @@ https://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga </string> + <string name="notification_channel_id" translatable="false">default</string> + <string name="notification_channel" translatable="false">Default</string> + <!-- LoginActivity --> <string name="login_username">Username</string> <string name="login_password">Password</string> |