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;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.EditText;
......@@ -9,29 +10,35 @@ import android.widget.TextView;
import android.widget.Toast;
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 java.util.ArrayList;
import java.util.List;
public class CreateNewFolderDialog {
private TextView cancel , done;
private TextView cancel, done;
private EditText folderName;
private Activity activity;
private final OnFolderCreatedListener listener;
public void showDialog(Activity activity){
this.activity = activity;
Dialog dialog = new Dialog(activity);
public CreateNewFolderDialog(OnFolderCreatedListener listener) {
this.listener = listener;
}
public void showDialog(Context context) {
Dialog dialog = new Dialog(context);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog_create_new_folder);
cancel = dialog.findViewById(R.id.cancel);
done = dialog.findViewById(R.id.done);
folderName = dialog.findViewById(R.id.folderName);
addListener(dialog);
addListener(dialog ,context);
dialog.show();
}
private void addListener(final Dialog dialog) {
private void addListener(final Dialog dialog , final Context context) {
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -42,33 +49,37 @@ public class CreateNewFolderDialog {
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (folderNameIsAcceptable(folderName.getText().toString())) {
//save new folder in sharedPreferences
ArrayList<String> foldersArray = MainActivity.sharedPreferencesClass.getArrayFolders(activity,"folders");
if (foldersArray == null)// if it is the first folder we are creating this array will be null
foldersArray = new ArrayList<>();
foldersArray.add(folderName.getText().toString());
MainActivity.sharedPreferencesClass.saveArrayFolders(activity ,foldersArray , "folders");
if (folderNameIsAcceptable(folderName.getText().toString() , context)) {
//save new folder in dataBase
FoldersEntity folder = new FoldersEntity(folderName.getText().toString());
NoteDataBase.getInstance(context).foldersDAO().insertFolder(folder); // such this method
listener.onCreated(folder);
dialog.dismiss();
}
}
});
}
private boolean folderNameIsAcceptable(String newFolderName) {
if (!newFolderName.equals("")){
ArrayList<String> foldersArray = MainActivity.sharedPreferencesClass.getArrayFolders(activity,"folders");
if (foldersArray == null)return true;//if it is first time we wanna create a folder no need to check being unique
for (String folderName : foldersArray){
if (folderName.equals(newFolderName)) {
Toast.makeText(activity , "this folder already exists" , Toast.LENGTH_SHORT).show();
private boolean folderNameIsAcceptable(String newFolderName , Context context) {
if (!newFolderName.equals("")) {
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
for (int i = 0; i < foldersArray.size(); i++) {
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 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;
}
public interface OnFolderCreatedListener {
void onCreated(FoldersEntity folder);
}
}
......@@ -6,16 +6,19 @@ import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.FoldersEntity;
import com.example.mynotepad.R;
import java.util.ArrayList;
import java.util.List;
public class FolderRecyclerViewAdapter extends RecyclerView.Adapter<FolderRecyclerViewAdapter.ViewHolder> {
private ArrayList<String> foldersName;
private List<FoldersEntity> foldersName;
private Context context;
private OnFolderClickListener onFolderClickListener;
public FolderRecyclerViewAdapter(ArrayList<String> foldersName , Context context) {
public FolderRecyclerViewAdapter(List<FoldersEntity> foldersName , Context context) {
this.foldersName = foldersName;
this.context = context;
}
......@@ -29,7 +32,7 @@ public class FolderRecyclerViewAdapter extends RecyclerView.Adapter<FolderRecycl
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.folderName.setText(foldersName.get(position));
holder.folderName.setText(foldersName.get(position).getFolderName());
}
@Override
......
package com.example.mynotepad.Dialogs.FoldersCustomDialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
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;
public class FoldersDialog {
public class FoldersDialog extends Dialog{
private RecyclerView recyclerView;
private LinearLayout addNewFolder;
private String selectedFolderName;
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.setCancelable(true);
dialog.setContentView(R.layout.dialog_folders);
addNewFolder = dialog.findViewById(R.id.addFolder);
recyclerView = dialog.findViewById(R.id.recyclerView2);
if (MainActivity.sharedPreferencesClass.getArrayFolders(activity,"folders")!= null) {
folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(MainActivity.sharedPreferencesClass.getArrayFolders(activity, "folders"), activity);
folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(NoteDataBase.getInstance(context).foldersDAO().getAllFolders(), context);
recyclerView.setAdapter(folderRecyclerViewAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() {
@Override
public void itemClicked(String folderName) {
selectedFolderName = folderName;
dialog.dismiss();
}
});
@Override
public void itemLongClicked() {
}
});
dialog.show();
addNewFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CreateNewFolderDialog createNewFolderDialog = new CreateNewFolderDialog();
createNewFolderDialog.showDialog(activity);
folderRecyclerViewAdapter.notifyDataSetChanged();
CreateNewFolderDialog createNewFolderDialog = new CreateNewFolderDialog(new CreateNewFolderDialog.OnFolderCreatedListener() {
@Override
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;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.FoldersEntity;
public interface OnFolderClickListener {
void itemClicked(String folderName);
void itemLongClicked();
}
......@@ -27,7 +27,7 @@ import com.google.android.material.navigation.NavigationView;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public static NoteDataBase noteDataBase;
private NoteDataBase noteDataBase;
private DrawerLayout drawerLayout;
private ImageView theme;
private NavigationView navigationView;
......@@ -59,8 +59,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
private void init() {
noteDataBase = Room.databaseBuilder(this, NoteDataBase.class, "RoomDb").fallbackToDestructiveMigration().allowMainThreadQueries().build();
noteDataBase = NoteDataBase.getInstance(this);
drawerLayout = findViewById(R.id.drawerLayout);
Toolbar toolbar = findViewById(R.id.toolbar_main);
navigationView = findViewById(R.id.main_menu);//menu drawer in ui
......
......@@ -23,6 +23,7 @@ import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecycl
import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView.OnArchivedItemClickListener;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
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.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
......@@ -34,8 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class ArchivedNoesListFragment extends Fragment {
private FloatingActionButton addNoteButton;
......@@ -117,7 +116,7 @@ public class ArchivedNoesListFragment extends Fragment {
bundle.putString("noteDateType", item.getType());
//change the fragment
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
final Bundle bundle = new Bundle();
bundle.putString("title", item.getTitle());
......@@ -171,15 +170,15 @@ public class ArchivedNoesListFragment extends Fragment {
private void updateToUnarchiveInDataBase() {
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")) {
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() {
entityNotes = noteDataBase.noteDao().getAll();
entityNotes = NoteDataBase.getInstance(getContext()).noteDao().getAll();
myNotes = new ArrayList<>();
for (Note note : entityNotes) {
MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived(), note.getID() , note.getFolders());
......@@ -189,7 +188,7 @@ public class ArchivedNoesListFragment extends Fragment {
private void setAllDateNoteListAndTitles() {
//get data from database to set in recyclerView
entityDates = noteDataBase.dateNoreDAO().getAllDateNotes();
entityDates = NoteDataBase.getInstance(getContext()).dateNoreDAO().getAllDateNotes();
myDates = new ArrayList<>();
for (DateEntity dateEntity : entityDates) {
MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID() , dateEntity.getFolders());
......
package com.example.mynotepad.MenuFeatures.AllNotes;
import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.NonNull;
......@@ -23,6 +22,7 @@ import com.example.mynotepad.Dialogs.CustomDialog;
import com.example.mynotepad.Dialogs.FoldersCustomDialog.FoldersDialog;
import com.example.mynotepad.Dialogs.onCustomDialogClickListener;
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.MyNote;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.OnAllNotesItemClickListener;
......@@ -35,7 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class AllNotesListFragment extends Fragment {
......@@ -51,7 +50,6 @@ public class AllNotesListFragment extends Fragment {
private NavController navController;
private LinearLayout allNotesListLayout;
private CustomDialog customDialog;
public static Activity activityyyyyyyyyyyy;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
......@@ -66,7 +64,6 @@ public class AllNotesListFragment extends Fragment {
init(view);
setBg(Utils.sTheme);
addListeners();
activityyyyyyyyyyyy = getActivity();
}
......@@ -159,8 +156,7 @@ public class AllNotesListFragment extends Fragment {
@Override
public void onFolderClicked() {
FoldersDialog foldersDialog = new FoldersDialog();
foldersDialog.showDialog(getActivity());
FoldersDialog foldersDialog = new FoldersDialog(getContext());
}
});
}
......@@ -176,7 +172,7 @@ public class AllNotesListFragment extends Fragment {
customDialog.setOnCustomDialogClickListener(new onCustomDialogClickListener() {
@Override
public void yesClicked() {
noteDataBase.noteDao().deleteNote(note);
NoteDataBase.getInstance(getContext()).noteDao().deleteNote(note);
myNotes.remove(myChosenNote);
myAdaptor.notifyDataSetChanged();
}
......@@ -205,7 +201,7 @@ public class AllNotesListFragment extends Fragment {
}
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());
}
......@@ -238,7 +234,7 @@ public class AllNotesListFragment extends Fragment {
private void setAllNoteListAndTitles() {
entityNotes = noteDataBase.noteDao().getAll();
entityNotes = NoteDataBase.getInstance(getContext()).noteDao().getAll();
myNotes = new ArrayList<>();
for (Note note : entityNotes) {
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;
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
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})
public abstract class NoteDataBase extends RoomDatabase {
private static NoteDataBase instance;
public abstract NoteDAO noteDao();
public abstract DateNoreDAO dateNoreDAO();
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
import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesListFragment;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
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.Utils;
import com.example.mynotepad.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import static com.example.mynotepad.MainActivity.noteDataBase;
/**
* A simple {@link Fragment} subclass.
......@@ -101,10 +101,10 @@ public class NoteFragment extends Fragment {
else if (type.equals("noteDate")) {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
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
} 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());
}
}
......@@ -123,10 +123,10 @@ public class NoteFragment extends Fragment {
private void saveNote() {
if (isAnewNote) {
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();
} 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());
Toast.makeText(getActivity(), "updated", Toast.LENGTH_SHORT).show();
}
......@@ -136,10 +136,10 @@ public class NoteFragment extends Fragment {
private void saveCalenderNote() {
if (isAnewNote) {
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();
} 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() );
Toast.makeText(getActivity(), "updated", Toast.LENGTH_SHORT).show();
}
......
package com.example.mynotepad.MenuFeatures.Calender;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
......@@ -21,6 +21,7 @@ import android.widget.LinearLayout;
import android.widget.Toast;
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.OnCalenderItemClickListener;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
......@@ -33,8 +34,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class CalenderNotesListFragment extends Fragment {
......@@ -178,7 +177,7 @@ public class CalenderNotesListFragment extends Fragment {
alert.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
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);
myAdaptor.notifyDataSetChanged();
}
......@@ -209,13 +208,13 @@ public class CalenderNotesListFragment extends Fragment {
}
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() {
//get data from database to set in recyclerView
entityDates = noteDataBase.dateNoreDAO().getAllDateNotes();
entityDates = NoteDataBase.getInstance(getContext()).dateNoreDAO().getAllDateNotes();
myDates = new ArrayList<>();
for (DateEntity dateEntity : entityDates) {
MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID() , dateEntity.getFolders());
......
......@@ -21,6 +21,7 @@ import android.widget.Toast;
import com.alirezaafkar.sundatepicker.DatePicker;
import com.alirezaafkar.sundatepicker.interfaces.DateSetListener;
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.Utils;
import com.example.mynotepad.R;
......@@ -29,8 +30,6 @@ import com.google.android.material.snackbar.Snackbar;
import java.util.Calendar;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class TimePickerFragment extends Fragment {
private DateEntity dateEntity;
......@@ -137,6 +136,6 @@ public class TimePickerFragment extends Fragment {
private void saveDateNote() {
//todo save in data base
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;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
......@@ -15,19 +13,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.example.mynotepad.Dialogs.FoldersCustomDialog.FolderRecyclerViewAdapter;
import com.example.mynotepad.Dialogs.FoldersCustomDialog.OnFolderClickListener;
import com.example.mynotepad.MainActivity;
import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesListFragment;
import com.example.mynotepad.MainActivity;;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
import com.example.mynotepad.MenuFeatures.Utils;
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 {
......@@ -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) {
listLayout = view.findViewById(R.id.allNoteListLayout);
recyclerView = view.findViewById(R.id.recyclerView);
......@@ -60,34 +62,82 @@ public class FoldersListFragment extends Fragment {
customToolbarOption.setVisibility(View.GONE);
allNoteToolBar = view.findViewById(R.id.toolbar);
allNoteToolBar.setEnabled(false);
// if (MainActivity.sharedPreferencesClass.getArrayFolders(getActivity(),"folders")!= null) {
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());
folderRecyclerViewAdapter = new FolderRecyclerViewAdapter(NoteDataBase.getInstance(getContext()).foldersDAO().getAllFolders(), getActivity());
recyclerView.setAdapter(folderRecyclerViewAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() {
@Override
public void itemClicked(String folderName) {
// folderRecyclerViewAdapter.setOnFolderClickListener(new OnFolderClickListener() {
// @Override
// 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;
import com.example.mynotepad.Dialogs.AddTxtToPicsDialog.AddTextToPicDialog;
import com.example.mynotepad.Dialogs.AddTxtToPicsDialog.OnSavePicListenerClick;
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.Pics.Camera.CameraActivity;
import com.example.mynotepad.MenuFeatures.Utils;
......@@ -35,7 +36,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static com.example.mynotepad.MainActivity.noteDataBase;
import static com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity.getOutputMediaFile;
public class ChoosingPicsFragment extends Fragment {
......@@ -144,7 +144,7 @@ public class ChoosingPicsFragment extends Fragment {
@Override
public void saveClicked(String 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;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.example.mynotepad.Dialogs.CustomDialog;
import com.example.mynotepad.Dialogs.onCustomDialogClickListener;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.NoteDataBase;
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.Pics.PicsActivity;
import com.example.mynotepad.R;
......@@ -28,7 +24,6 @@ import com.example.mynotepad.R;
import java.util.ArrayList;
import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class NotedPicsListFragment extends Fragment {
......@@ -62,7 +57,7 @@ public class NotedPicsListFragment extends Fragment {
}
private void setData() {
picsEntityList = noteDataBase.picsDao().getAllPicsNotes();
picsEntityList = NoteDataBase.getInstance(getContext()).picsDao().getAllPicsNotes();
myGalleryPics = new ArrayList<>();
for (PicsEntity picsEntity : picsEntityList) {
MyGalleryPic myGalleryPic = new MyGalleryPic(picsEntity.getUrl(), picsEntity.getTxt());
......@@ -102,7 +97,7 @@ public class NotedPicsListFragment extends Fragment {
customDialog.setOnCustomDialogClickListener(new onCustomDialogClickListener() {
@Override
public void yesClicked() {
noteDataBase.picsDao().deletePicsNote(pic);
NoteDataBase.getInstance(getContext()).picsDao().deletePicsNote(pic);
myGalleryPics.remove(myChosenPic);
adapter.notifyDataSetChanged();
}
......
......@@ -28,22 +28,4 @@ public class SharedPreferencesClass {
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 @@
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:background="?colorOnPrimary"
android:background="@drawable/bg_row_simple"
android:layout_marginLeft="5dp"
android:layout_margin="5dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
......@@ -23,5 +24,6 @@
android:layout_weight="4"
android:text="@string/txt"
android:textSize="20dp"
android:gravity="center_vertical"/>
android:gravity="center_vertical"
android:layout_marginRight="20dp"/>
</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