This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private static final String NAME_KEY = "Name"; | |
private static final String EMAIL_KEY = "Email"; | |
private static final String PHONE_KEY = "Phone"; | |
FirebaseFirestore db; | |
TextView textDisplay; | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void addNewContact(){ | |
Map<String, Object>newContact = new HashMap<>(); | |
newContact.put(NAME_KEY, "John"); | |
newContact.put(EMAIL_KEY, "[email protected]"); | |
newContact.put(PHONE_KEY, "080-0808-009"); | |
db.collection("PhoneBook").document("Contacts").set(newContact) | |
.addOnSuccessListener(new OnSuccessListener<Void>() { | |
@Override | |
public void onSuccess(Void aVoid) { | |
Toast.makeText(MainActivity.this, "User Registered", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ReadSingleContact() { | |
DocumentReference user = db.collection("PhoneBook").document("Contacts"); | |
user.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { | |
@Override | |
public void onComplete(@NonNull Task<DocumentSnapshot> task) { | |
if (task.isSuccessful()){ | |
DocumentSnapshot doc = task.getResult(); | |
StringBuilder fields = new StringBuilder(""); | |
fields.append("Name: ").append(doc.get("Name")); | |
fields.append("\nEmail: ").append(doc.get("Email")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void UpdateData() { | |
DocumentReference contact = db.collection("PhoneBook").document("Contacts"); | |
contact.update(NAME_KEY, "Kenny"); | |
contact.update(EMAIL_KEY, "[email protected]"); | |
contact.update(PHONE_KEY, "090-911-419") | |
.addOnSuccessListener(new OnSuccessListener<Void>() { | |
@Override | |
public void onSuccess(Void aVoid) { | |
Toast.makeText(MainActivity.this, "Updated Successfully", | |
Toast.LENGTH_SHORT).show(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void addRealtimeUpdate() { | |
DocumentReference contactListener = db.collection("PhoneBook").document("Contacts"); | |
contactListener.addSnapshotListener(new EventListener<DocumentSnapshot>() { | |
@Override | |
public void onEvent(DocumentSnapshot documentSnapshot, FirebaseFirestoreException e) { | |
if (e != null ){ | |
Log.d("ERROR", e.getMessage()); | |
return; | |
} | |
if (documentSnapshot != null && documentSnapshot.exists()){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:layout_margin="16dp" | |
tools:context="com.example.ekene.firestore.MainActivity"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private static final String NAME_KEY = "Name"; | |
private static final String EMAIL_KEY = "Email"; | |
private static final String PHONE_KEY = "Phone"; | |
FirebaseFirestore db; | |
TextView textDisplay; | |
TextView message; | |
EditText name, email, phone; | |
Button save; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void addNewContact(){ | |
save = findViewById(R.id.save); | |
name = findViewById(R.id.name); | |
email = findViewById(R.id.email); | |
phone = findViewById(R.id.phone); | |
String mName = name.getText().toString(); | |
String mEmail = email.getText().toString(); | |
String mPhone = phone.getText().toString(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void addRealtimeUpdate() { | |
DocumentReference contactListener = db.collection("PhoneBook").document("Contacts"); | |
contactListener.addSnapshotListener(new EventListener<DocumentSnapshot>() { | |
@Override | |
public void onEvent(DocumentSnapshot documentSnapshot, FirebaseFirestoreException e) { | |
if (e != null ){ | |
Log.d("ERROR", e.getMessage()); | |
return; | |
} | |
if (documentSnapshot != null && documentSnapshot.exists()){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compile 'com.android.support:cardview-v7:26.0.+' | |
compile 'com.squareup.picasso:picasso:2.5.2' | |
compile group: 'com.cloudinary', name: 'cloudinary-android', version: '1.20.0' |
OlderNewer