dodano funkcję usunięcia notatki i wyświetlanie okna dialogowego
This commit is contained in:
parent
273b92b490
commit
df64b16800
@ -5,6 +5,7 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="disableWrapperSourceDistributionNotification" value="true" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="1.8" />
|
||||
|
@ -46,4 +46,6 @@ dependencies {
|
||||
//Room - biblioteka do baza danych
|
||||
implementation "androidx.room:room-runtime:2.2.5"
|
||||
annotationProcessor "androidx.room:room-compiler:2.2.5"
|
||||
// RecyclerView
|
||||
implementation "androidx.recyclerview:recyclerview:1.1.0"
|
||||
}
|
@ -10,12 +10,15 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Notatkon">
|
||||
<activity
|
||||
android:name=".CreateNote"
|
||||
android:screenOrientation="portrait" />
|
||||
android:name=".note.CreateNote"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:name=".note.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Notatkon.NoActionBar">
|
||||
android:theme="@style/Theme.Notatkon.NoActionBar"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
@ -16,14 +16,13 @@ import com.example.notatkon.entities.NoteEntity;
|
||||
@Database(entities = {NoteEntity.class},
|
||||
version = 1,
|
||||
exportSchema = false)
|
||||
|
||||
public abstract class NoteRoomDatabase extends RoomDatabase {
|
||||
|
||||
public abstract NoteDao noteDao();
|
||||
|
||||
private static NoteRoomDatabase noteRoomDatabase;
|
||||
|
||||
public static synchronized NoteRoomDatabase getNoteRoomDatabase(final Context context) {
|
||||
public static synchronized NoteRoomDatabase getNoteRoomDatabase(Context context) {
|
||||
if (noteRoomDatabase == null) {
|
||||
noteRoomDatabase = Room.databaseBuilder(
|
||||
context,
|
||||
|
@ -17,8 +17,7 @@ https://developer.android.com/codelabs/android-room-with-a-view#4
|
||||
@Entity(tableName = "note_table")
|
||||
public class NoteEntity implements Serializable {
|
||||
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id")
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private int id;
|
||||
|
||||
@ColumnInfo(name = "title")
|
||||
|
@ -96,11 +96,11 @@ public class CreateNote extends AppCompatActivity {
|
||||
private void saveNote() {
|
||||
|
||||
if (noteTitle.getText().toString().trim().isEmpty()) {
|
||||
Toast.makeText(this, "Nie może być puste!", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, "Tytuł nie może być pusty!", 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();
|
||||
Toast.makeText(this, "Podtytuł/notatka nie mogą być puste!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -161,12 +161,17 @@ public class CreateNote extends AppCompatActivity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
|
||||
showDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
https://developer.android.com/guide/topics/ui/dialogs#CustomLayout
|
||||
*/
|
||||
|
||||
private void showDialog() {
|
||||
|
||||
if (deleteNote == null) {
|
||||
|
@ -69,7 +69,7 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
|
||||
noteRecycler.setAdapter(noteAdapter);
|
||||
|
||||
// wyświetl na początku wszystkie notatki z bazy
|
||||
getAllNotes(REQUEST_SHOW_NOTE);
|
||||
getAllNotes(REQUEST_SHOW_NOTE, false);
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
|
||||
// pobranie notatek z bazy i wyswietlanie na ekranie
|
||||
// przekazujemy request jako parametr by przekazać potem kod
|
||||
// wyświetlajacy wszystkie notatki lub aktywność edycji notatki
|
||||
private void getAllNotes(int requestCode) {
|
||||
private void getAllNotes(int requestCode, final boolean isDeleted) {
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
class GetNotesTask extends AsyncTask<Void, Void, List<NoteEntity>> {
|
||||
@ -123,9 +123,16 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
|
||||
noteAdapter.notifyItemInserted(0);
|
||||
noteRecycler.smoothScrollToPosition(0);
|
||||
} else if (requestCode == REQUEST_EDIT_NOTE) {
|
||||
//usuń notatkę z wybranej pozycji i dodaj ostatnią
|
||||
//z tej samej pozycji z bazy
|
||||
noteEntityList.remove(notePosition);
|
||||
noteEntityList.add(notePosition, noteEntities.get(notePosition));
|
||||
noteAdapter.notifyItemChanged(notePosition);
|
||||
if (isDeleted) {
|
||||
noteAdapter.notifyItemRemoved(notePosition);
|
||||
} else {
|
||||
noteEntityList.add(notePosition, noteEntities.get(notePosition));
|
||||
noteAdapter.notifyItemChanged(notePosition);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,10 +144,10 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
// sprawdzamy request i przechodzimy do odpowiedniego widoku
|
||||
if (requestCode == REQUEST_CODE_NEW_NOTE && resultCode == RESULT_OK) {
|
||||
getAllNotes(REQUEST_CODE_NEW_NOTE);
|
||||
getAllNotes(REQUEST_CODE_NEW_NOTE, false);
|
||||
} else if (requestCode == REQUEST_EDIT_NOTE && resultCode == RESULT_OK) {
|
||||
if(data != null) {
|
||||
getAllNotes(REQUEST_EDIT_NOTE);
|
||||
getAllNotes(REQUEST_EDIT_NOTE, data.getBooleanExtra("isDeleted", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<menu 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"
|
||||
tools:context="com.example.notatkon.MainActivity">
|
||||
tools:context="com.example.notatkon.note.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
|
@ -13,9 +13,11 @@
|
||||
<color name="colorAccent">#F6D499</color>
|
||||
<color name="colorHint">#7B7B7B</color>
|
||||
<color name="colorQuickActionsBackground">#F7F7F7</color>
|
||||
<color name="colorBottomToolbar">#0288D1</color>
|
||||
<color name="colorDialogWindow">#717171</color>
|
||||
<color name="colorIcon">#070707</color>
|
||||
<color name="colorSubtitle">#CECECE</color>
|
||||
<color name="colorNoteColor">#FFFFFF</color>
|
||||
<color name="colorNoteColor">#FFF59D</color>
|
||||
<color name="colorSubtitleText">#FAFAFA</color>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user