dodano wyświetlanie się zawartości istniejącej notatki w edytorze po kliknięciu
This commit is contained in:
parent
826e025f9e
commit
b514cad483
@ -39,11 +39,11 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
|
||||
|
||||
ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
noteTitle = (TextView) itemView.findViewById(R.id.note_title);
|
||||
noteSubtitle = (TextView) itemView.findViewById(R.id.note_subtitle);
|
||||
textDateTime = (TextView) itemView.findViewById(R.id.textDateTime);
|
||||
noteTitle = itemView.findViewById(R.id.note_title);
|
||||
noteSubtitle = itemView.findViewById(R.id.note_subtitle);
|
||||
textDateTime = itemView.findViewById(R.id.textDateTime);
|
||||
|
||||
viewNote = (LinearLayout) itemView.findViewById(R.id.viewNote);
|
||||
viewNote = itemView.findViewById(R.id.viewNote);
|
||||
}
|
||||
|
||||
// wpisz notatke
|
||||
|
@ -8,6 +8,7 @@ import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
@ -29,6 +30,8 @@ public class CreateNote extends AppCompatActivity {
|
||||
private EditText noteTitle, noteSubtitle, inputNote;
|
||||
private TextView textDataTime;
|
||||
|
||||
private NoteEntity selectedNote;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -61,23 +64,52 @@ public class CreateNote extends AppCompatActivity {
|
||||
saveNote();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (getIntent().getBooleanExtra("update", false)) {
|
||||
selectedNote = (NoteEntity) getIntent().getSerializableExtra("noteEntity");
|
||||
fillSelectedNote();
|
||||
}
|
||||
}
|
||||
|
||||
//przypisanie obecnej zawartosci notatki nowemu widokowi po kliknieciu
|
||||
private void fillSelectedNote() {
|
||||
noteTitle.setText(selectedNote.getTitle());
|
||||
noteSubtitle.setText(selectedNote.getSubtitle());
|
||||
inputNote.setText(selectedNote.getContent());
|
||||
textDataTime.setText(selectedNote.getDateTime());
|
||||
}
|
||||
|
||||
private void saveNote() {
|
||||
|
||||
if (noteTitle.getText().toString().trim().isEmpty()) {
|
||||
Toast.makeText(this, "Nie może być puste!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
} else if (noteSubtitle.getText().toString().trim().isEmpty()
|
||||
&& inputNote.getText().toString().trim().isEmpty()) {
|
||||
Toast.makeText(this, "Nie może być puste!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
//pobierz wpisywany tekst z textview
|
||||
final NoteEntity note = new NoteEntity();
|
||||
note.setTitle(noteTitle.getText().toString());
|
||||
note.setSubtitle(noteSubtitle.getText().toString());
|
||||
note.setContent(inputNote.getText().toString());
|
||||
note.setDateTime(textDataTime.getText().toString());
|
||||
final NoteEntity noteEntity = new NoteEntity();
|
||||
noteEntity.setTitle(noteTitle.getText().toString());
|
||||
noteEntity.setSubtitle(noteSubtitle.getText().toString());
|
||||
noteEntity.setContent(inputNote.getText().toString());
|
||||
noteEntity.setDateTime(textDataTime.getText().toString());
|
||||
|
||||
|
||||
if (selectedNote != null) {
|
||||
noteEntity.setId(selectedNote.getId());
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
class SaveNoteTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
NoteRoomDatabase.getNoteRoomDatabase(getApplicationContext()).noteDao().insert(note);
|
||||
NoteRoomDatabase.getNoteRoomDatabase(getApplicationContext()).noteDao().insert(noteEntity);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
|
||||
|
||||
public static final int REQUEST_CODE_NEW_NOTE = 1;
|
||||
public static final int REQUEST_EDIT_NOTE = 2;
|
||||
//public static final int REQUEST_SHOW_NOTE = 3;
|
||||
|
||||
private int notePosition = -1;
|
||||
|
||||
@ -72,11 +73,11 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
|
||||
|
||||
|
||||
@Override
|
||||
public void onNoteClicked(NoteEntity noteEntity, int position) {
|
||||
public void onNoteClicked(NoteEntity note, int position) {
|
||||
notePosition = position;
|
||||
Intent intent = new Intent(getApplicationContext(), CreateNote.class);
|
||||
intent.putExtra("update", true);
|
||||
intent.putExtra("noteEntity", noteEntity);
|
||||
intent.putExtra("noteEntity", note);
|
||||
startActivityForResult(intent, REQUEST_EDIT_NOTE);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user