Skip to content

Commit

Permalink
Added anonymous user signup on first start
Browse files Browse the repository at this point in the history
  • Loading branch information
50t0r25 committed May 13, 2022
1 parent 9b95992 commit d3b8612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/src/main/java/dz/notacompany/el_cous/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.firestore.Source
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
Expand All @@ -21,6 +23,7 @@ import java.util.concurrent.LinkedBlockingQueue
class MainActivity : AppCompatActivity() {

private val db = Firebase.firestore
private lateinit var auth: FirebaseAuth

private lateinit var loading: AlertDialog
var isAdmin = false
Expand All @@ -31,6 +34,8 @@ class MainActivity : AppCompatActivity() {
setTheme(R.style.Theme_ELCous) // Sets theme to override splash screen theme
super.onCreate(savedInstanceState)

auth = Firebase.auth

// Define the shared preferences
val sharedpref: SharedPreferences =
applicationContext.getSharedPreferences(
Expand Down Expand Up @@ -110,6 +115,14 @@ class MainActivity : AppCompatActivity() {
}
}

public override fun onStart() {
super.onStart()
// Check if user is signed in (non-null) and sign them up if they aren't.
if (auth.currentUser == null) {
auth.signInAnonymously()
}
}

// Replaces fragment while either clearing or adding to BackStack
fun replaceCurrentFragment(fragment: Fragment, clearBackStack : Boolean) =
supportFragmentManager.beginTransaction().apply {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<string name="welcome_text1">Simple, rapide et sécurisé</string>
<string name="welcome_button">C’est Parti !</string>
<string name="loading">Patientez svp…</string>
<string name="empty_database_error">Une erreur est survenue, Assurez vous que vous avez une connexion internet stable et réessayer.</string>
<string name="empty_database_error">Une erreur est survenue, Assurez que vous avez une connexion internet stable et réessayez.</string>
<string name="search_results">Résultat de la recherche:</string>
<string name="enter_admin_key">Veuillez saisir la clé administrateur:</string>
<string name="admin_key">Clé administrateur</string>
Expand Down

0 comments on commit d3b8612

Please sign in to comment.