-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditnoteactivity.java
More file actions
101 lines (84 loc) · 3.95 KB
/
editnoteactivity.java
File metadata and controls
101 lines (84 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.example.notesapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;
import java.util.HashMap;
import java.util.Map;
public class editnoteactivity extends AppCompatActivity {
Intent data ;
private EditText medittitlenote , meditcontenttext;
private FloatingActionButton floatingActionButton;
FirebaseUser firebaseUser;
FirebaseFirestore firebaseFirestore;
FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editnoteactivity);
data = getIntent();
medittitlenote=findViewById(R.id.edittitlenote);
firebaseUser=FirebaseAuth.getInstance().getCurrentUser();
firebaseFirestore=FirebaseFirestore.getInstance();
firebaseAuth=FirebaseAuth.getInstance();
meditcontenttext=findViewById(R.id.editcontenttext);
floatingActionButton=findViewById(R.id.saveeditnote);
Toolbar toolbar = findViewById(R.id.toolbarodeditnote);
setSupportActionBar(toolbar);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
String notetitle=data.getStringExtra("title");
String noteContent=data.getStringExtra("content");
meditcontenttext.setText(noteContent);
medittitlenote.setText(notetitle);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String newtitle = medittitlenote.getText().toString();
String newcontent=meditcontenttext.getText().toString();
if (newtitle.isEmpty()||newcontent.isEmpty()){
Toast.makeText(getApplicationContext(), "Something is Empty", Toast.LENGTH_SHORT).show();
return;
}
else
{
DocumentReference documentReference=firebaseFirestore.collection("notes").document(firebaseUser.getUid()).collection("myNotes").document(data.getStringExtra("noteId"));
Map<String ,Object> note= new HashMap<>();
note.put("title",newtitle);
note.put("content",newcontent);
documentReference.set(note).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void avoid) {
Toast.makeText(getApplicationContext(),"Note is Updated",Toast.LENGTH_SHORT).show();
startActivity(new Intent(editnoteactivity.this,notesactivity.class));
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(),"Failed to update",Toast.LENGTH_SHORT).show();
}
});
}
// Toast.makeText(getApplicationContext(), "savebutton click", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId()==android.R.id.home){
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
}