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