Commit 9bcd5ce8 authored by 9731301's avatar 9731301

save folders data in database

parent e17a86a1
...@@ -2,6 +2,7 @@ package com.example.mynotepad.Dialogs.FoldersCustomDialog; ...@@ -2,6 +2,7 @@ package com.example.mynotepad.Dialogs.FoldersCustomDialog;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
...@@ -9,29 +10,35 @@ import android.widget.TextView; ...@@ -9,29 +10,35 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.example.mynotepad.MainActivity; import com.example.mynotepad.MainActivity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.FoldersEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.R; import com.example.mynotepad.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class CreateNewFolderDialog { public class CreateNewFolderDialog {
private TextView cancel , done; private TextView cancel, done;
private EditText folderName; private EditText folderName;
private Activity activity; private final OnFolderCreatedListener listener;
public void showDialog(Activity activity){ public CreateNewFolderDialog(OnFolderCreatedListener listener) {
this.activity = activity; this.listener = listener;
Dialog dialog = new Dialog(activity); }
public void showDialog(Context context) {
Dialog dialog = new Dialog(context);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(true); dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog_create_new_folder); dialog.setContentView(R.layout.dialog_create_new_folder);
cancel = dialog.findViewById(R.id.cancel); cancel = dialog.findViewById(R.id.cancel);
done = dialog.findViewById(R.id.done); done = dialog.findViewById(R.id.done);
folderName = dialog.findViewById(R.id.folderName); folderName = dialog.findViewById(R.id.folderName);
addListener(dialog); addListener(dialog ,context);
dialog.show(); dialog.show();
} }
private void addListener(final Dialog dialog) { private void addListener(final Dialog dialog , final Context context) {
cancel.setOnClickListener(new View.OnClickListener() { cancel.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -42,33 +49,37 @@ public class CreateNewFolderDialog { ...@@ -42,33 +49,37 @@ public class CreateNewFolderDialog {
done.setOnClickListener(new View.OnClickListener() { done.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (folderNameIsAcceptable(folderName.getText().toString())) { if (folderNameIsAcceptable(folderName.getText().toString() , context)) {
//save new folder in sharedPreferences //save new folder in dataBase
ArrayList<String> foldersArray = MainActivity.sharedPreferencesClass.getArrayFolders(activity,"folders"); FoldersEntity folder = new FoldersEntity(folderName.getText().toString());
if (foldersArray == null)// if it is the first folder we are creating this array will be null NoteDataBase.getInstance(context).foldersDAO().insertFolder(folder); // such this method
foldersArray = new ArrayList<>(); listener.onCreated(folder);
foldersArray.add(folderName.getText().toString());
MainActivity.sharedPreferencesClass.saveArrayFolders(activity ,foldersArray , "folders");
dialog.dismiss(); dialog.dismiss();
} }
} }
}); });
} }
private boolean folderNameIsAcceptable(String newFolderName) { private boolean folderNameIsAcceptable(String newFolderName , Context context) {
if (!newFolderName.equals("")){ if (!newFolderName.equals("")) {
ArrayList<String> foldersArray = MainActivity.sharedPreferencesClass.getArrayFolders(activity,"folders"); List<FoldersEntity> foldersArray = NoteDataBase.getInstance(context).foldersDAO().getAllFolders();
if (foldersArray == null)return true;//if it is first time we wanna create a folder no need to check being unique if (foldersArray == null)
for (String folderName : foldersArray){ return true;//if it is first time we wanna create a folder no need to check being unique
if (folderName.equals(newFolderName)) { for (int i = 0; i < foldersArray.size(); i++) {
Toast.makeText(activity , "this folder already exists" , Toast.LENGTH_SHORT).show(); System.out.println(foldersArray.get(i).getFolderName());
if (foldersArray.get(i).getFolderName().equals(newFolderName)) {
Toast.makeText(context, "this folder already exists", Toast.LENGTH_SHORT).show();
return false; return false;
} }
} }
return true; return true;
} }
Toast.makeText(activity ,"you should enter a name to create new folder",Toast.LENGTH_SHORT).show(); Toast.makeText(context, "you should enter a name to create new folder", Toast.LENGTH_SHORT).show();
return false; return false;
} }
public interface OnFolderCreatedListener {
void onCreated(FoldersEntity folder);
}
} }
...@@ -6,16 +6,19 @@ import android.view.ViewGroup; ...@@ -6,16 +6,19 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.FoldersEntity;
import com.example.mynotepad.R; import com.example.mynotepad.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class FolderRecyclerViewAdapter extends RecyclerView.Adapter<FolderRecyclerViewAdapter.ViewHolder> { public class FolderRecyclerViewAdapter extends RecyclerView.Adapter<FolderRecyclerViewAdapter.ViewHolder> {
private ArrayList<String> foldersName; private List<FoldersEntity> foldersName;
private Context context; private Context context;
private OnFolderClickListener onFolderClickListener; private OnFolderClickListener onFolderClickListener;
public FolderRecyclerViewAdapter(ArrayList<String> foldersName , Context context) { public FolderRecyclerViewAdapter(List<FoldersEntity> foldersName , Context context) {
this.foldersName = foldersName; this.foldersName = foldersName;
this.context = context; this.context = context;
} }
...@@ -29,7 +32,7 @@ public class FolderRecyclerViewAdapter extends RecyclerView.Adapter<FolderRecycl ...@@ -29,7 +32,7 @@ public class FolderRecyclerViewAdapter extends RecyclerView.Adapter<FolderRecycl
@Override @Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.folderName.setText(foldersName.get(position)); holder.folderName.setText(foldersName.get(position).getFolderName());
} }
@Override @Override
......
package com.example.mynotepad.Dialogs.FoldersCustomDialog; package com.example.mynotepad.Dialogs.FoldersCustomDialog;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.example.mynotepad.MainActivity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.FoldersEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.R; import com.example.mynotepad.R;
public class FoldersDialog { public class FoldersDialog extends Dialog{
private RecyclerView recyclerView; private RecyclerView recyclerView;
private LinearLayout addNewFolder; private LinearLayout addNewFolder;
private String selectedFolderName; private String selectedFolderName;
private FolderRecyclerViewAdapter folderRecyclerViewAdapter; private FolderRecyclerViewAdapter folderRecyclerViewAdapter;
public void showDialog(final Activity activity){
final Dialog dialog = new Dialog(activity); public FoldersDialog(@NonNull final Context context) {
super(context);
final Dialog dialog = new Dialog(context);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(true); dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog_folders); dialog.setContentView(R.layout.dialog_folders);
addNewFolder = dialog.findViewById(R.id.addFolder); addNewFolder = dialog.findViewById(R.id.addFolder);
recyclerView = dialog.findViewById(R.id.recyclerView2); recyclerView = dialog.findViewById(R.id.recyclerView2);
if (MainActivity.sharedPreferencesClass.getArrayFolders(activity,"folders")!= null) { folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(NoteDataBase.getInstance(context).foldersDAO().getAllFolders(), context);
folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(MainActivity.sharedPreferencesClass.getArrayFolders(activity, "folders"), activity);
recyclerView.setAdapter(folderRecyclerViewAdapter); recyclerView.setAdapter(folderRecyclerViewAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)); recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() { folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() {
@Override @Override
public void itemClicked(String folderName) { public void itemClicked(String folderName) {
selectedFolderName = folderName; selectedFolderName = folderName;
dialog.dismiss(); dialog.dismiss();
} }
});
@Override
public void itemLongClicked() {
} }
});
dialog.show(); dialog.show();
addNewFolder.setOnClickListener(new View.OnClickListener() { addNewFolder.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
CreateNewFolderDialog createNewFolderDialog = new CreateNewFolderDialog(); CreateNewFolderDialog createNewFolderDialog = new CreateNewFolderDialog(new CreateNewFolderDialog.OnFolderCreatedListener() {
createNewFolderDialog.showDialog(activity); @Override
folderRecyclerViewAdapter.notifyDataSetChanged(); public void onCreated(FoldersEntity folder) {
folderRecyclerViewAdapter.notifyDataSetChanged(); // call this method back when you create the directory
}
});
createNewFolderDialog.showDialog(context);
} }
}); });
} }
......
package com.example.mynotepad.Dialogs.FoldersCustomDialog; package com.example.mynotepad.Dialogs.FoldersCustomDialog;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.FoldersEntity;
public interface OnFolderClickListener { public interface OnFolderClickListener {
void itemClicked(String folderName); void itemClicked(String folderName);
void itemLongClicked();
} }
...@@ -27,7 +27,7 @@ import com.google.android.material.navigation.NavigationView; ...@@ -27,7 +27,7 @@ import com.google.android.material.navigation.NavigationView;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public static NoteDataBase noteDataBase; private NoteDataBase noteDataBase;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private ImageView theme; private ImageView theme;
private NavigationView navigationView; private NavigationView navigationView;
...@@ -59,8 +59,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -59,8 +59,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
private void init() { private void init() {
noteDataBase = Room.databaseBuilder(this, NoteDataBase.class, "RoomDb").fallbackToDestructiveMigration().allowMainThreadQueries().build(); noteDataBase = NoteDataBase.getInstance(this);
drawerLayout = findViewById(R.id.drawerLayout); drawerLayout = findViewById(R.id.drawerLayout);
Toolbar toolbar = findViewById(R.id.toolbar_main); Toolbar toolbar = findViewById(R.id.toolbar_main);
navigationView = findViewById(R.id.main_menu);//menu drawer in ui navigationView = findViewById(R.id.main_menu);//menu drawer in ui
......
...@@ -23,6 +23,7 @@ import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecycl ...@@ -23,6 +23,7 @@ import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecycl
import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView.OnArchivedItemClickListener; import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView.OnArchivedItemClickListener;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote; import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate; import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption; import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
...@@ -34,8 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; ...@@ -34,8 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class ArchivedNoesListFragment extends Fragment { public class ArchivedNoesListFragment extends Fragment {
private FloatingActionButton addNoteButton; private FloatingActionButton addNoteButton;
...@@ -117,7 +116,7 @@ public class ArchivedNoesListFragment extends Fragment { ...@@ -117,7 +116,7 @@ public class ArchivedNoesListFragment extends Fragment {
bundle.putString("noteDateType", item.getType()); bundle.putString("noteDateType", item.getType());
//change the fragment //change the fragment
navController.navigate(R.id.action_archivedNoesListFragment_to_noteFragment3, bundle); navController.navigate(R.id.action_archivedNoesListFragment_to_noteFragment3, bundle);
} else if (item.getType().equals("date")) { } else if (item.getType().equals("date")) {//todo date should be removed
//set noteFragment data //set noteFragment data
final Bundle bundle = new Bundle(); final Bundle bundle = new Bundle();
bundle.putString("title", item.getTitle()); bundle.putString("title", item.getTitle());
...@@ -171,15 +170,15 @@ public class ArchivedNoesListFragment extends Fragment { ...@@ -171,15 +170,15 @@ public class ArchivedNoesListFragment extends Fragment {
private void updateToUnarchiveInDataBase() { private void updateToUnarchiveInDataBase() {
if (chosenDateOrNote.getType().equals("note")) { if (chosenDateOrNote.getType().equals("note")) {
noteDataBase.noteDao().updateNote(chosenDateOrNote.getTitle(), chosenDateOrNote.getDescription(), false, chosenDateOrNote.getId() , chosenDateOrNote.getFolders()); NoteDataBase.getInstance(getContext()).noteDao().updateNote(chosenDateOrNote.getTitle(), chosenDateOrNote.getDescription(), false, chosenDateOrNote.getId() , chosenDateOrNote.getFolders());
} else if (chosenDateOrNote.getType().equals("date")) { } else if (chosenDateOrNote.getType().equals("date")) {
noteDataBase.dateNoreDAO().updateDate(chosenDateOrNote.getTitle(), chosenDateOrNote.getDescription(), false, chosenDateOrNote.getId() , chosenDateOrNote.getFolders()); NoteDataBase.getInstance(getContext()).dateNoreDAO().updateDate(chosenDateOrNote.getTitle(), chosenDateOrNote.getDescription(), false, chosenDateOrNote.getId() , chosenDateOrNote.getFolders());
} }
} }
private void setAllNoteListAndTitles() { private void setAllNoteListAndTitles() {
entityNotes = noteDataBase.noteDao().getAll(); entityNotes = NoteDataBase.getInstance(getContext()).noteDao().getAll();
myNotes = new ArrayList<>(); myNotes = new ArrayList<>();
for (Note note : entityNotes) { for (Note note : entityNotes) {
MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived(), note.getID() , note.getFolders()); MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived(), note.getID() , note.getFolders());
...@@ -189,7 +188,7 @@ public class ArchivedNoesListFragment extends Fragment { ...@@ -189,7 +188,7 @@ public class ArchivedNoesListFragment extends Fragment {
private void setAllDateNoteListAndTitles() { private void setAllDateNoteListAndTitles() {
//get data from database to set in recyclerView //get data from database to set in recyclerView
entityDates = noteDataBase.dateNoreDAO().getAllDateNotes(); entityDates = NoteDataBase.getInstance(getContext()).dateNoreDAO().getAllDateNotes();
myDates = new ArrayList<>(); myDates = new ArrayList<>();
for (DateEntity dateEntity : entityDates) { for (DateEntity dateEntity : entityDates) {
MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID() , dateEntity.getFolders()); MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID() , dateEntity.getFolders());
......
package com.example.mynotepad.MenuFeatures.AllNotes; package com.example.mynotepad.MenuFeatures.AllNotes;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
...@@ -23,6 +22,7 @@ import com.example.mynotepad.Dialogs.CustomDialog; ...@@ -23,6 +22,7 @@ import com.example.mynotepad.Dialogs.CustomDialog;
import com.example.mynotepad.Dialogs.FoldersCustomDialog.FoldersDialog; import com.example.mynotepad.Dialogs.FoldersCustomDialog.FoldersDialog;
import com.example.mynotepad.Dialogs.onCustomDialogClickListener; import com.example.mynotepad.Dialogs.onCustomDialogClickListener;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyAllNotesAdaptor; import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyAllNotesAdaptor;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote; import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.OnAllNotesItemClickListener; import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.OnAllNotesItemClickListener;
...@@ -35,7 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; ...@@ -35,7 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class AllNotesListFragment extends Fragment { public class AllNotesListFragment extends Fragment {
...@@ -51,7 +50,6 @@ public class AllNotesListFragment extends Fragment { ...@@ -51,7 +50,6 @@ public class AllNotesListFragment extends Fragment {
private NavController navController; private NavController navController;
private LinearLayout allNotesListLayout; private LinearLayout allNotesListLayout;
private CustomDialog customDialog; private CustomDialog customDialog;
public static Activity activityyyyyyyyyyyy;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
...@@ -66,7 +64,6 @@ public class AllNotesListFragment extends Fragment { ...@@ -66,7 +64,6 @@ public class AllNotesListFragment extends Fragment {
init(view); init(view);
setBg(Utils.sTheme); setBg(Utils.sTheme);
addListeners(); addListeners();
activityyyyyyyyyyyy = getActivity();
} }
...@@ -159,8 +156,7 @@ public class AllNotesListFragment extends Fragment { ...@@ -159,8 +156,7 @@ public class AllNotesListFragment extends Fragment {
@Override @Override
public void onFolderClicked() { public void onFolderClicked() {
FoldersDialog foldersDialog = new FoldersDialog(); FoldersDialog foldersDialog = new FoldersDialog(getContext());
foldersDialog.showDialog(getActivity());
} }
}); });
} }
...@@ -176,7 +172,7 @@ public class AllNotesListFragment extends Fragment { ...@@ -176,7 +172,7 @@ public class AllNotesListFragment extends Fragment {
customDialog.setOnCustomDialogClickListener(new onCustomDialogClickListener() { customDialog.setOnCustomDialogClickListener(new onCustomDialogClickListener() {
@Override @Override
public void yesClicked() { public void yesClicked() {
noteDataBase.noteDao().deleteNote(note); NoteDataBase.getInstance(getContext()).noteDao().deleteNote(note);
myNotes.remove(myChosenNote); myNotes.remove(myChosenNote);
myAdaptor.notifyDataSetChanged(); myAdaptor.notifyDataSetChanged();
} }
...@@ -205,7 +201,7 @@ public class AllNotesListFragment extends Fragment { ...@@ -205,7 +201,7 @@ public class AllNotesListFragment extends Fragment {
} }
private void updatearchivedNotesInDataBase() { private void updatearchivedNotesInDataBase() {
noteDataBase.noteDao().updateNote(myChosenNote.getTitle(), myChosenNote.getDescription() NoteDataBase.getInstance(getContext()).noteDao().updateNote(myChosenNote.getTitle(), myChosenNote.getDescription()
, myChosenNote.isArchived(), myChosenNote.getId(), myChosenNote.getFolders()); , myChosenNote.isArchived(), myChosenNote.getId(), myChosenNote.getFolders());
} }
...@@ -238,7 +234,7 @@ public class AllNotesListFragment extends Fragment { ...@@ -238,7 +234,7 @@ public class AllNotesListFragment extends Fragment {
private void setAllNoteListAndTitles() { private void setAllNoteListAndTitles() {
entityNotes = noteDataBase.noteDao().getAll(); entityNotes = NoteDataBase.getInstance(getContext()).noteDao().getAll();
myNotes = new ArrayList<>(); myNotes = new ArrayList<>();
for (Note note : entityNotes) { for (Note note : entityNotes) {
MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived(), note.getID(), note.getFolders()); MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived(), note.getID(), note.getFolders());
......
package com.example.mynotepad.MenuFeatures.AllNotes.DataBase;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import java.util.List;
@Dao
public interface FoldersDAO {
// a method list type
@Query("SELECT * FROM FoldersEntity")
List<FoldersEntity> getAllFolders();
//insert data in database
@Insert
void insertFolder(FoldersEntity foldersEntity);
//delete data in database
@Delete
void deleteFolder(FoldersEntity foldersEntity);
//update data
@Query("UPDATE FoldersEntity SET folderName = :folderName Where ID = :id")
void updateDate(String folderName, int id);
}
package com.example.mynotepad.MenuFeatures.AllNotes.DataBase;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity
public class FoldersEntity {
@PrimaryKey(autoGenerate = true)
int ID;
@ColumnInfo(name = "FolderName")
String folderName;
public FoldersEntity(String folderName) {
this.folderName = folderName;
}
public int getID() {
return ID;
}
public String getFolderName() {
return folderName;
}
}
\ No newline at end of file
package com.example.mynotepad.MenuFeatures.AllNotes.DataBase; package com.example.mynotepad.MenuFeatures.AllNotes.DataBase;
import android.content.Context;
import androidx.room.Database; import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import androidx.room.TypeConverters; import androidx.room.TypeConverters;
@Database(entities = {Note.class, DateEntity.class ,PicsEntity.class},version = 1) @Database(entities = {Note.class, DateEntity.class ,PicsEntity.class , FoldersEntity.class},version = 1)
@TypeConverters({Converters.class}) @TypeConverters({Converters.class})
public abstract class NoteDataBase extends RoomDatabase { public abstract class NoteDataBase extends RoomDatabase {
private static NoteDataBase instance;
public abstract NoteDAO noteDao(); public abstract NoteDAO noteDao();
public abstract DateNoreDAO dateNoreDAO(); public abstract DateNoreDAO dateNoreDAO();
public abstract PicsDao picsDao(); public abstract PicsDao picsDao();
public abstract FoldersDAO foldersDAO();
public static NoteDataBase getInstance(Context context) {
if (instance == null)
instance = Room.databaseBuilder(context, NoteDataBase.class, "RoomDb")
.fallbackToDestructiveMigration()
.allowMainThreadQueries() // this code may block the main thread, every database transaction must be executed on background thread no
.build();// as long as this method is called no, if you remove this method then you should call every single method of your DAOs on a background thread
return instance;
}
} }
...@@ -21,12 +21,12 @@ import com.example.mynotepad.MenuFeatures.AllArchivedNotes.ArchivedNoesListFragm ...@@ -21,12 +21,12 @@ import com.example.mynotepad.MenuFeatures.AllArchivedNotes.ArchivedNoesListFragm
import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesListFragment; import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesListFragment;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.Calender.CalenderNotesListFragment; import com.example.mynotepad.MenuFeatures.Calender.CalenderNotesListFragment;
import com.example.mynotepad.MenuFeatures.Utils; import com.example.mynotepad.MenuFeatures.Utils;
import com.example.mynotepad.R; import com.example.mynotepad.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import static com.example.mynotepad.MainActivity.noteDataBase;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
...@@ -101,10 +101,10 @@ public class NoteFragment extends Fragment { ...@@ -101,10 +101,10 @@ public class NoteFragment extends Fragment {
else if (type.equals("noteDate")) { else if (type.equals("noteDate")) {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
if (noteDateType.equals("note")) { if (noteDateType.equals("note")) {
noteDataBase.noteDao().updateNote(titleTxt.getText().toString(), bodyTxt.getText().toString(), NoteDataBase.getInstance(getContext()).noteDao().updateNote(titleTxt.getText().toString(), bodyTxt.getText().toString(),
true, ArchivedNoesListFragment.chosenDateOrNote.getId() , null);//todo ooooooooooooooooooooooo true, ArchivedNoesListFragment.chosenDateOrNote.getId() , null);//todo ooooooooooooooooooooooo
} else if (noteDateType.equals("date")) { } else if (noteDateType.equals("date")) {
noteDataBase.dateNoreDAO().updateDate(titleTxt.getText().toString(), bodyTxt.getText().toString(), NoteDataBase.getInstance(getContext()).dateNoreDAO().updateDate(titleTxt.getText().toString(), bodyTxt.getText().toString(),
true, ArchivedNoesListFragment.chosenDateOrNote.getId() , ArchivedNoesListFragment.chosenDateOrNote.getFolders()); true, ArchivedNoesListFragment.chosenDateOrNote.getId() , ArchivedNoesListFragment.chosenDateOrNote.getFolders());
} }
} }
...@@ -123,10 +123,10 @@ public class NoteFragment extends Fragment { ...@@ -123,10 +123,10 @@ public class NoteFragment extends Fragment {
private void saveNote() { private void saveNote() {
if (isAnewNote) { if (isAnewNote) {
note = new Note(titleTxt.getText().toString(), bodyTxt.getText().toString(), false , null);//todo oooooooooooooooooooo add folders note = new Note(titleTxt.getText().toString(), bodyTxt.getText().toString(), false , null);//todo oooooooooooooooooooo add folders
noteDataBase.noteDao().insertNote(note); NoteDataBase.getInstance(getContext()).noteDao().insertNote(note);
Toast.makeText(getActivity(), "saved", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "saved", Toast.LENGTH_SHORT).show();
} else { } else {
noteDataBase.noteDao().updateNote(titleTxt.getText().toString(), bodyTxt.getText().toString(), NoteDataBase.getInstance(getContext()).noteDao().updateNote(titleTxt.getText().toString(), bodyTxt.getText().toString(),
AllNotesListFragment.myChosenNote.isArchived(), AllNotesListFragment.myChosenNote.getId() ,AllNotesListFragment.myChosenNote.getFolders()); AllNotesListFragment.myChosenNote.isArchived(), AllNotesListFragment.myChosenNote.getId() ,AllNotesListFragment.myChosenNote.getFolders());
Toast.makeText(getActivity(), "updated", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "updated", Toast.LENGTH_SHORT).show();
} }
...@@ -136,10 +136,10 @@ public class NoteFragment extends Fragment { ...@@ -136,10 +136,10 @@ public class NoteFragment extends Fragment {
private void saveCalenderNote() { private void saveCalenderNote() {
if (isAnewNote) { if (isAnewNote) {
dateEntity = new DateEntity(titleTxt.getText().toString(), bodyTxt.getText().toString(), false , null); // todo ooooooooooooooooooooooooooo add foldesr==rs dateEntity = new DateEntity(titleTxt.getText().toString(), bodyTxt.getText().toString(), false , null); // todo ooooooooooooooooooooooooooo add foldesr==rs
noteDataBase.dateNoreDAO().insertDateNote(dateEntity); NoteDataBase.getInstance(getContext()).dateNoreDAO().insertDateNote(dateEntity);
Toast.makeText(getActivity(), "saved", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "saved", Toast.LENGTH_SHORT).show();
} else { } else {
noteDataBase.dateNoreDAO().updateDate(titleTxt.getText().toString(), bodyTxt.getText().toString(), NoteDataBase.getInstance(getContext()).dateNoreDAO().updateDate(titleTxt.getText().toString(), bodyTxt.getText().toString(),
CalenderNotesListFragment.myChosenDateNote.isArchived(), CalenderNotesListFragment.myChosenDateNote.getId() ,CalenderNotesListFragment.myChosenDateNote.getFolders() ); CalenderNotesListFragment.myChosenDateNote.isArchived(), CalenderNotesListFragment.myChosenDateNote.getId() ,CalenderNotesListFragment.myChosenDateNote.getFolders() );
Toast.makeText(getActivity(), "updated", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "updated", Toast.LENGTH_SHORT).show();
} }
......
package com.example.mynotepad.MenuFeatures.Calender; package com.example.mynotepad.MenuFeatures.Calender;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
...@@ -21,6 +21,7 @@ import android.widget.LinearLayout; ...@@ -21,6 +21,7 @@ import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.MyCalenderAdaptor; import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.MyCalenderAdaptor;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.OnCalenderItemClickListener; import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.OnCalenderItemClickListener;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate; import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
...@@ -33,8 +34,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; ...@@ -33,8 +34,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class CalenderNotesListFragment extends Fragment { public class CalenderNotesListFragment extends Fragment {
...@@ -178,7 +177,7 @@ public class CalenderNotesListFragment extends Fragment { ...@@ -178,7 +177,7 @@ public class CalenderNotesListFragment extends Fragment {
alert.setPositiveButton("yes", new DialogInterface.OnClickListener() { alert.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
noteDataBase.dateNoreDAO().deleteDateNote(entityDates.get(myDates.indexOf(myChosenDateNote))); NoteDataBase.getInstance(getContext()).dateNoreDAO().deleteDateNote(entityDates.get(myDates.indexOf(myChosenDateNote)));
myDates.remove(myChosenDateNote); myDates.remove(myChosenDateNote);
myAdaptor.notifyDataSetChanged(); myAdaptor.notifyDataSetChanged();
} }
...@@ -209,13 +208,13 @@ public class CalenderNotesListFragment extends Fragment { ...@@ -209,13 +208,13 @@ public class CalenderNotesListFragment extends Fragment {
} }
private void updatearchivedDatesInDataBase() { private void updatearchivedDatesInDataBase() {
noteDataBase.dateNoreDAO().updateDate(myChosenDateNote.getDate(), myChosenDateNote.getDescription(), myChosenDateNote.isArchived(), myChosenDateNote.getId() , myChosenDateNote.getFolders()); NoteDataBase.getInstance(getContext()).dateNoreDAO().updateDate(myChosenDateNote.getDate(), myChosenDateNote.getDescription(), myChosenDateNote.isArchived(), myChosenDateNote.getId() , myChosenDateNote.getFolders());
} }
private void setAllDateNoteListAndTitles() { private void setAllDateNoteListAndTitles() {
//get data from database to set in recyclerView //get data from database to set in recyclerView
entityDates = noteDataBase.dateNoreDAO().getAllDateNotes(); entityDates = NoteDataBase.getInstance(getContext()).dateNoreDAO().getAllDateNotes();
myDates = new ArrayList<>(); myDates = new ArrayList<>();
for (DateEntity dateEntity : entityDates) { for (DateEntity dateEntity : entityDates) {
MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID() , dateEntity.getFolders()); MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID() , dateEntity.getFolders());
......
...@@ -21,6 +21,7 @@ import android.widget.Toast; ...@@ -21,6 +21,7 @@ import android.widget.Toast;
import com.alirezaafkar.sundatepicker.DatePicker; import com.alirezaafkar.sundatepicker.DatePicker;
import com.alirezaafkar.sundatepicker.interfaces.DateSetListener; import com.alirezaafkar.sundatepicker.interfaces.DateSetListener;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.Calender.Date; import com.example.mynotepad.MenuFeatures.Calender.Date;
import com.example.mynotepad.MenuFeatures.Utils; import com.example.mynotepad.MenuFeatures.Utils;
import com.example.mynotepad.R; import com.example.mynotepad.R;
...@@ -29,8 +30,6 @@ import com.google.android.material.snackbar.Snackbar; ...@@ -29,8 +30,6 @@ import com.google.android.material.snackbar.Snackbar;
import java.util.Calendar; import java.util.Calendar;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class TimePickerFragment extends Fragment { public class TimePickerFragment extends Fragment {
private DateEntity dateEntity; private DateEntity dateEntity;
...@@ -137,6 +136,6 @@ public class TimePickerFragment extends Fragment { ...@@ -137,6 +136,6 @@ public class TimePickerFragment extends Fragment {
private void saveDateNote() { private void saveDateNote() {
//todo save in data base //todo save in data base
dateEntity = new DateEntity(chosenDate.getText().toString(), description.getText().toString(), false , null);//todo ooooooooo add folders dateEntity = new DateEntity(chosenDate.getText().toString(), description.getText().toString(), false , null);//todo ooooooooo add folders
noteDataBase.dateNoreDAO().insertDateNote(dateEntity); NoteDataBase.getInstance(getContext()).dateNoreDAO().insertDateNote(dateEntity);
} }
} }
\ No newline at end of file
package com.example.mynotepad.MenuFeatures.Folders; package com.example.mynotepad.MenuFeatures.Folders;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
...@@ -15,19 +13,12 @@ import android.view.LayoutInflater; ...@@ -15,19 +13,12 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.example.mynotepad.Dialogs.FoldersCustomDialog.FolderRecyclerViewAdapter; import com.example.mynotepad.Dialogs.FoldersCustomDialog.FolderRecyclerViewAdapter;
import com.example.mynotepad.Dialogs.FoldersCustomDialog.OnFolderClickListener; import com.example.mynotepad.MainActivity;;
import com.example.mynotepad.MainActivity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesListFragment;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption; import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
import com.example.mynotepad.MenuFeatures.Utils; import com.example.mynotepad.MenuFeatures.Utils;
import com.example.mynotepad.R; import com.example.mynotepad.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
public class FoldersListFragment extends Fragment { public class FoldersListFragment extends Fragment {
...@@ -53,6 +44,17 @@ public class FoldersListFragment extends Fragment { ...@@ -53,6 +44,17 @@ public class FoldersListFragment extends Fragment {
} }
private void setBg(String sTheme) {
switch (sTheme) {
case "dark":
listLayout.setBackgroundResource(R.drawable.main_bg_dark);
break;
case "bright":
listLayout.setBackgroundResource(R.drawable.main_bg_bright);
break;
}
}
private void init(View view) { private void init(View view) {
listLayout = view.findViewById(R.id.allNoteListLayout); listLayout = view.findViewById(R.id.allNoteListLayout);
recyclerView = view.findViewById(R.id.recyclerView); recyclerView = view.findViewById(R.id.recyclerView);
...@@ -60,34 +62,82 @@ public class FoldersListFragment extends Fragment { ...@@ -60,34 +62,82 @@ public class FoldersListFragment extends Fragment {
customToolbarOption.setVisibility(View.GONE); customToolbarOption.setVisibility(View.GONE);
allNoteToolBar = view.findViewById(R.id.toolbar); allNoteToolBar = view.findViewById(R.id.toolbar);
allNoteToolBar.setEnabled(false); allNoteToolBar.setEnabled(false);
// if (MainActivity.sharedPreferencesClass.getArrayFolders(getActivity(),"folders")!= null) { folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(NoteDataBase.getInstance(getContext()).foldersDAO().getAllFolders(), getActivity());
SharedPreferences sharedPreferences = getActivity().getPreferences(Context.MODE_PRIVATE);
Gson gson = new Gson();
String json = sharedPreferences.getString("folders", null);
System.out.println(json+"+++++++++++++++++++++++++++++++++++++++++++++++");
Type type = new TypeToken<ArrayList<String>>() {}.getType();
ArrayList<String> a = gson.fromJson(json, type);
folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(a, getActivity());
recyclerView.setAdapter(folderRecyclerViewAdapter); recyclerView.setAdapter(folderRecyclerViewAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() { // folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() {
@Override // @Override
public void itemClicked(String folderName) { // public void itemClicked(String folderName) {
//
// }
// });
// }
} // private void addListeners() {
}); //
// } // // add listener to recyclerView
} // folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() {
// @Override
// public void itemClicked(String folderName) {
//
// if (item.getType().equals("note")) {
// //set noteFragment data
// final Bundle bundle = new Bundle();
// bundle.putString("title", item.getTitle());
// bundle.putString("bodyTxt", item.getDescription());
// bundle.putString("type", "noteDate");
// bundle.putString("noteDateType", item.getType());
// //change the fragment
// navController.navigate(R.id.action_archivedNoesListFragment_to_noteFragment3, bundle);
// } else if (item.getType().equals("date")) {
// //set noteFragment data
// final Bundle bundle = new Bundle();
// bundle.putString("title", item.getTitle());
// bundle.putString("bodyTxt", item.getDescription());
// bundle.putString("type", "noteDate");
// bundle.putString("noteDateType", item.getType());
// //change the fragment
// navController.navigate(R.id.action_archivedNoesListFragment_to_noteFragment3, bundle);
// }
//
// }
//
// @Override
// public void onItemLongClicked(DateOrNote item) {
// chosenDateOrNote = item;
// customToolbarOption.setVisibility(View.VISIBLE);
// customToolbarOption.hideRecycleBin();
// customToolbarOption.hideFolder();
// allNoteToolBar.setVisibility(View.GONE);
// }
// });
//
// //add listener to custom toolbar option and set being archived or not to be saved in database
// customToolbarOption.setCustomToolbarOptionListener(new CustomToolbarOptionListener() {
// @Override
// public void onStarClicked() {
// customToolbarOption.setBlackStar();
// myarchivedAdaptor.getDateOrNoteList().remove(chosenDateOrNote);
// updateToUnarchiveInDataBase();
// Toast.makeText(getContext(), "unarchived", Toast.LENGTH_SHORT).show();
// }
//
//
// @Override
// public void onDeleteClicked() {
// }
//
// @Override
// public void onCloseClicked() {
// closeClicked(customToolbarOption);
// }
//
// @Override
// public void onFolderClicked() {
//
// }
// });
// }
private void setBg(String sTheme) {
switch (sTheme) {
case "dark":
listLayout.setBackgroundResource(R.drawable.main_bg_dark);
break;
case "bright":
listLayout.setBackgroundResource(R.drawable.main_bg_bright);
break;
}
} }
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ import android.widget.Toast; ...@@ -23,6 +23,7 @@ import android.widget.Toast;
import com.example.mynotepad.Dialogs.AddTxtToPicsDialog.AddTextToPicDialog; import com.example.mynotepad.Dialogs.AddTxtToPicsDialog.AddTextToPicDialog;
import com.example.mynotepad.Dialogs.AddTxtToPicsDialog.OnSavePicListenerClick; import com.example.mynotepad.Dialogs.AddTxtToPicsDialog.OnSavePicListenerClick;
import com.example.mynotepad.MainActivity; import com.example.mynotepad.MainActivity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.PicsEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.PicsEntity;
import com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity; import com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity;
import com.example.mynotepad.MenuFeatures.Utils; import com.example.mynotepad.MenuFeatures.Utils;
...@@ -35,7 +36,6 @@ import java.io.IOException; ...@@ -35,7 +36,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import static com.example.mynotepad.MainActivity.noteDataBase;
import static com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity.getOutputMediaFile; import static com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity.getOutputMediaFile;
public class ChoosingPicsFragment extends Fragment { public class ChoosingPicsFragment extends Fragment {
...@@ -144,7 +144,7 @@ public class ChoosingPicsFragment extends Fragment { ...@@ -144,7 +144,7 @@ public class ChoosingPicsFragment extends Fragment {
@Override @Override
public void saveClicked(String editTextTxt) { public void saveClicked(String editTextTxt) {
PicsEntity picsEntity = new PicsEntity(newFilePath, editTextTxt); PicsEntity picsEntity = new PicsEntity(newFilePath, editTextTxt);
noteDataBase.picsDao().insertPicsNote(picsEntity); NoteDataBase.getInstance(getContext()).picsDao().insertPicsNote(picsEntity);
} }
}); });
} }
......
...@@ -12,15 +12,11 @@ import androidx.recyclerview.widget.RecyclerView; ...@@ -12,15 +12,11 @@ import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast;
import com.example.mynotepad.Dialogs.CustomDialog; import com.example.mynotepad.Dialogs.CustomDialog;
import com.example.mynotepad.Dialogs.onCustomDialogClickListener; import com.example.mynotepad.Dialogs.onCustomDialogClickListener;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.PicsEntity; import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.PicsEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.OnAllNotesItemClickListener;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption; import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
import com.example.mynotepad.MenuFeatures.Pics.PicsActivity; import com.example.mynotepad.MenuFeatures.Pics.PicsActivity;
import com.example.mynotepad.R; import com.example.mynotepad.R;
...@@ -28,7 +24,6 @@ import com.example.mynotepad.R; ...@@ -28,7 +24,6 @@ import com.example.mynotepad.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class NotedPicsListFragment extends Fragment { public class NotedPicsListFragment extends Fragment {
...@@ -62,7 +57,7 @@ public class NotedPicsListFragment extends Fragment { ...@@ -62,7 +57,7 @@ public class NotedPicsListFragment extends Fragment {
} }
private void setData() { private void setData() {
picsEntityList = noteDataBase.picsDao().getAllPicsNotes(); picsEntityList = NoteDataBase.getInstance(getContext()).picsDao().getAllPicsNotes();
myGalleryPics = new ArrayList<>(); myGalleryPics = new ArrayList<>();
for (PicsEntity picsEntity : picsEntityList) { for (PicsEntity picsEntity : picsEntityList) {
MyGalleryPic myGalleryPic = new MyGalleryPic(picsEntity.getUrl(), picsEntity.getTxt()); MyGalleryPic myGalleryPic = new MyGalleryPic(picsEntity.getUrl(), picsEntity.getTxt());
...@@ -102,7 +97,7 @@ public class NotedPicsListFragment extends Fragment { ...@@ -102,7 +97,7 @@ public class NotedPicsListFragment extends Fragment {
customDialog.setOnCustomDialogClickListener(new onCustomDialogClickListener() { customDialog.setOnCustomDialogClickListener(new onCustomDialogClickListener() {
@Override @Override
public void yesClicked() { public void yesClicked() {
noteDataBase.picsDao().deletePicsNote(pic); NoteDataBase.getInstance(getContext()).picsDao().deletePicsNote(pic);
myGalleryPics.remove(myChosenPic); myGalleryPics.remove(myChosenPic);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
......
...@@ -28,22 +28,4 @@ public class SharedPreferencesClass { ...@@ -28,22 +28,4 @@ public class SharedPreferencesClass {
Utils.sTheme = sharedPref.getString(activity.getString(R.string.saved_high_score_key), "bright"); Utils.sTheme = sharedPref.getString(activity.getString(R.string.saved_high_score_key), "bright");
} }
public void saveArrayFolders(Activity activity ,ArrayList<String> list, String key) {
sharedPreferences = activity.getSharedPreferences(key ,Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
Gson gson = new Gson();
String json = gson.toJson(list);
editor.remove(key);
editor.putString(key, json);
editor.apply();
}
public ArrayList<String> getArrayFolders(Activity activity ,String key) {
sharedPreferences = activity.getSharedPreferences(key ,Context.MODE_PRIVATE);
Gson gson = new Gson();
String json = sharedPreferences.getString(key, null);
System.out.println(json+"+++++++++++++++++++++++++++++++++++++++++++++++");
Type type = new TypeToken<ArrayList<String>>() {}.getType();
return gson.fromJson(json, type);
}
} }
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?colorOnPrimary"/>
<corners android:radius="20dp"/>
</shape>
\ No newline at end of file
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp" android:layout_height="80dp"
android:orientation="horizontal" android:orientation="horizontal"
android:background="?colorOnPrimary" android:background="@drawable/bg_row_simple"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_margin="5dp" android:layout_margin="5dp"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView <ImageView
...@@ -23,5 +24,6 @@ ...@@ -23,5 +24,6 @@
android:layout_weight="4" android:layout_weight="4"
android:text="@string/txt" android:text="@string/txt"
android:textSize="20dp" android:textSize="20dp"
android:gravity="center_vertical"/> android:gravity="center_vertical"
android:layout_marginRight="20dp"/>
</LinearLayout> </LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment