Search in sources :

Example 1 with PreferenceManager

use of com.example.clown.utilities.PreferenceManager in project Skool by NhatTruongK15.

the class SignInActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {

        @Override
        public void onActivityResult(ActivityResult result) {
        }
    });
    preferenceManager = new PreferenceManager(getApplicationContext());
    // check if we've already logined
    if (preferenceManager.getBoolean(Constants.KEY_IS_SIGNED_IN)) {
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intent);
        finish();
    }
    binding = ActivitySignInBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    setListener();
}
Also used : Intent(android.content.Intent) ActivityResult(androidx.activity.result.ActivityResult) PreferenceManager(com.example.clown.utilities.PreferenceManager) ActivityResultCallback(androidx.activity.result.ActivityResultCallback)

Example 2 with PreferenceManager

use of com.example.clown.utilities.PreferenceManager in project Skool by NhatTruongK15.

the class SignUpActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    final String TAG = "mCallBack";
    super.onCreate(savedInstanceState);
    binding = ActivitySignUpBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    preferenceManager = new PreferenceManager(getApplicationContext());
    mAuth = FirebaseAuth.getInstance();
    // set up mCallback
    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential credential) {
            // This callback will be invoked in two situations:
            // 1 - Instant verification. In some cases the phone number can be instantly
            // verified without needing to send or enter a verification code.
            // 2 - Auto-retrieval. On some devices Google Play services can automatically
            // detect the incoming verification SMS and perform verification without
            // user action.
            Log.d(TAG, "onVerificationCompleted:" + credential);
            signInWithPhoneAuthCredential(credential);
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            // This callback is invoked in an invalid request for verification is made,
            // for instance if the the phone number format is not valid.
            Log.w(TAG, "onVerificationFailed", e);
            if (e instanceof FirebaseAuthInvalidCredentialsException) {
            // Invalid request
            } else if (e instanceof FirebaseTooManyRequestsException) {
            // The SMS quota for the project has been exceeded
            }
        // Show a message and update the UI
        }

        @Override
        public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) {
            // The SMS verification code has been sent to the provided phone number, we
            // now need to ask the user to enter the code and then construct a credential
            // by combining the code with a verification ID.
            Log.d(TAG, "onCodeSent:" + verificationId);
            // Save verification ID and resending token so we can use them later
            mVerificationId = verificationId;
            mResendToken = token;
            pd.dismiss();
            binding.verificationLayout.setVisibility(View.VISIBLE);
            binding.userInfoLayout.setVisibility(View.GONE);
            binding.resendContent.setText("didn't see smsCode?");
            binding.verificationCodeEditText.setHint("Please enter your smsCode we sent \n +84" + binding.inputPhoneNumb.getText().subSequence(1, binding.inputPhoneNumb.getText().length()));
        }
    };
    // set up progressdialog
    pd = new ProgressDialog(this);
    pd.setTitle("Please wait...");
    pd.setCanceledOnTouchOutside(false);
    // setup view
    binding.verificationLayout.setVisibility(View.GONE);
    binding.userInfoLayout.setVisibility(View.VISIBLE);
    // listener
    setListener();
}
Also used : FirebaseException(com.google.firebase.FirebaseException) FirebaseTooManyRequestsException(com.google.firebase.FirebaseTooManyRequestsException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) ProgressDialog(android.app.ProgressDialog) PreferenceManager(com.example.clown.utilities.PreferenceManager)

Example 3 with PreferenceManager

use of com.example.clown.utilities.PreferenceManager in project Skool by NhatTruongK15.

the class ChatActivity method init.

private void init() {
    preferenceManager = new PreferenceManager(getApplicationContext());
    chatMessages = new ArrayList<>();
    chatAdapter = new ChatAdapter(chatMessages, preferenceManager.getString(Constants.KEY_DOCUMENT_REFERENCE_ID), getBitmapFromEncodeString(receiverUser.image));
    binding.chatRecyclerView.setAdapter(chatAdapter);
    database = FirebaseFirestore.getInstance();
}
Also used : ChatAdapter(com.example.clown.adapter.ChatAdapter) PreferenceManager(com.example.clown.utilities.PreferenceManager)

Example 4 with PreferenceManager

use of com.example.clown.utilities.PreferenceManager in project Skool by NhatTruongK15.

the class GroupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group);
    binding = ActivityGroupBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    preferenceManager = new PreferenceManager(getApplicationContext());
    setListener();
}
Also used : PreferenceManager(com.example.clown.utilities.PreferenceManager)

Example 5 with PreferenceManager

use of com.example.clown.utilities.PreferenceManager in project Skool by NhatTruongK15.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    preferenceManager = new PreferenceManager(getApplicationContext());
    init();
    loadUserDetails();
    getToken();
    setListener();
    listenConversation();
}
Also used : PreferenceManager(com.example.clown.utilities.PreferenceManager)

Aggregations

PreferenceManager (com.example.clown.utilities.PreferenceManager)9 ProgressDialog (android.app.ProgressDialog)2 FirebaseException (com.google.firebase.FirebaseException)2 FirebaseTooManyRequestsException (com.google.firebase.FirebaseTooManyRequestsException)2 FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)2 PhoneAuthCredential (com.google.firebase.auth.PhoneAuthCredential)2 PhoneAuthProvider (com.google.firebase.auth.PhoneAuthProvider)2 Intent (android.content.Intent)1 ActivityResult (androidx.activity.result.ActivityResult)1 ActivityResultCallback (androidx.activity.result.ActivityResultCallback)1 ChatAdapter (com.example.clown.adapter.ChatAdapter)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1