dodawanie i pobieranie notatki do bazy
This commit is contained in:
parent
fb203f9bb6
commit
6ba51b80d1
@ -75,6 +75,6 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
return super.getItemViewType(position);
|
return position;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ import java.util.List;
|
|||||||
public interface NoteDao {
|
public interface NoteDao {
|
||||||
|
|
||||||
@Query("SELECT * FROM note_table")
|
@Query("SELECT * FROM note_table")
|
||||||
LiveData<List<NoteEntity>> getNotes();
|
List<NoteEntity> getNotes();
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
void insert(NoteEntity noteEntity);
|
void insert(NoteEntity noteEntity);
|
||||||
|
@ -5,6 +5,7 @@ import androidx.room.ColumnInfo;
|
|||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -14,7 +15,7 @@ https://developer.android.com/codelabs/android-room-with-a-view#4
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@Entity(tableName = "note_table")
|
@Entity(tableName = "note_table")
|
||||||
public class NoteEntity {
|
public class NoteEntity implements Serializable {
|
||||||
|
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
@ColumnInfo(name = "id")
|
@ColumnInfo(name = "id")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.example.notatkon;
|
package com.example.notatkon.note;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -8,11 +8,11 @@ import android.view.View;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.example.notatkon.database.NoteEntity;
|
import com.example.notatkon.R;
|
||||||
|
import com.example.notatkon.entities.NoteEntity;
|
||||||
import com.example.notatkon.database.NoteRoomDatabase;
|
import com.example.notatkon.database.NoteRoomDatabase;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -31,6 +31,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
REQUEST_CODE_NEW_NOTE
|
REQUEST_CODE_NEW_NOTE
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getAllNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Toolbar toolbar = findViewById(R.id.toolbar);
|
//Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
@ -103,14 +105,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//pobranie notatek z bazy i wyswietlanie na ekranie
|
//pobranie notatek z bazy i wyswietlanie na ekranie
|
||||||
private void getNotes() {
|
private void getAllNotes() {
|
||||||
|
|
||||||
class GetNotesTask extends AsyncTask<Void, Void, List<NoteEntity>> {
|
class GetNotesTask extends AsyncTask<Void, Void, List<NoteEntity>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<NoteEntity> doInBackground(Void... voids) {
|
protected List<NoteEntity> doInBackground(Void... voids) {
|
||||||
//return null;
|
//return null;
|
||||||
return (List<NoteEntity>) NoteRoomDatabase
|
return NoteRoomDatabase
|
||||||
.getNoteRoomDatabase(getApplicationContext())
|
.getNoteRoomDatabase(getApplicationContext())
|
||||||
.noteDao().getNotes();
|
.noteDao().getNotes();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user