Commit 618fc2ca authored by 9731301's avatar 9731301

change archived notes structure to navigation

parent 59b10593
package com.example.mynotepad.MenuFeatures.AllArchivedNotes;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView.DateOrNote;
import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView.MyArchivedAdaptor;
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.MyNoteRecyclerView.MyNote;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
import com.example.mynotepad.MenuFeatures.CustomToolbarOptionListener;
import com.example.mynotepad.R;
import java.util.ArrayList;
import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class ArchivedNoesListFragment extends Fragment {
private CustomToolbarOption customToolbarOption;
private FrameLayout allNoteToolBar;
private RecyclerView recyclerView;
private MyArchivedAdaptor myarchivedAdaptor;
private List<Note> entityNotes;
private List<DateEntity> entityDates;
private List<MyNote> myNotes;
private List<MyDate> myDates;
public static DateOrNote chosenDateOrNote;
private NavController navController;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_archived_noes_list, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
init(view);
}
private void init(View view) {
// get data from database
setAllNoteListAndTitles();
setAllDateNoteListAndTitles();
customToolbarOption = view.findViewById(R.id.customToolbarOption2);
customToolbarOption.setVisibility(View.GONE);
allNoteToolBar = view.findViewById(R.id.allNotesToolbar2);
allNoteToolBar.setEnabled(false);
navController = Navigation.findNavController(view);
// show list with recycler view
recyclerView = view.findViewById(R.id.recyclerView2);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
myarchivedAdaptor = new MyArchivedAdaptor(myNotes, myDates);
recyclerView.setAdapter(myarchivedAdaptor);
recyclerView.setLayoutManager(linearLayoutManager);
addListeners();
}
private void addListeners() {
// add listener to recyclerView
myarchivedAdaptor.setOnArchivedItemClickListener(new OnArchivedItemClickListener() {
@Override
public void onItemClicked(DateOrNote item) {
chosenDateOrNote = item;
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();
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);
}
});
}
private void updateToUnarchiveInDataBase() {
if (chosenDateOrNote.getType().equals("note")) {
noteDataBase.noteDao().updateNote(chosenDateOrNote.getTitle(), chosenDateOrNote.getDescription(), false, chosenDateOrNote.getId());
} else if (chosenDateOrNote.getType().equals("date")) {
noteDataBase.dateNoreDAO().updateDate(chosenDateOrNote.getTitle(), chosenDateOrNote.getDescription(), false, chosenDateOrNote.getId());
}
}
private void setAllNoteListAndTitles() {
entityNotes = noteDataBase.noteDao().getAll();
myNotes = new ArrayList<>();
for (Note note : entityNotes) {
MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived(), note.getID());
myNotes.add(myNote);
}
}
private void setAllDateNoteListAndTitles() {
//get data from database to set in recyclerView
entityDates = noteDataBase.dateNoreDAO().getAllDateNotes();
myDates = new ArrayList<>();
for (DateEntity dateEntity : entityDates) {
MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived(), dateEntity.getID());
myDates.add(myDate);
}
}
protected void closeClicked(CustomToolbarOption customToolbarOption) {
customToolbarOption.setVisibility(View.GONE);
allNoteToolBar.setVisibility(View.VISIBLE);
}
}
\ No newline at end of file
package com.example.mynotepad.MenuFeatures.AllArchivedNotes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView.*;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesActivity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote;
import com.example.mynotepad.MenuFeatures.AllNotes.Note.NoteFragment;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
import com.example.mynotepad.MenuFeatures.CustomToolbarOption;
import com.example.mynotepad.MenuFeatures.CustomToolbarOptionListener;
import com.example.mynotepad.R;
import java.util.ArrayList;
import java.util.List;
import static com.example.mynotepad.MainActivity.noteDataBase;
public class ArchivedNotesActivity extends AppCompatActivity {
private FrameLayout fragPlace;
private LinearLayout allNoteListAndTitle;
private CustomToolbarOption customToolbarOption;
private FrameLayout allNoteToolBar;
private RecyclerView recyclerView;
private MyArchivedAdaptor myarchivedAdaptor;
private List<Note> entityNotes;
private List<DateEntity> entityDates;
private List<MyNote> myNotes;
private List<MyDate> myDates;
private DateOrNote chosenDateOrNote;
private FragmentTransaction fragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_achived_notes);
init();
}
private void init() {
// get data from database
setAllNoteListAndTitles();
setAllDateNoteListAndTitles();
customToolbarOption = findViewById(R.id.customToolbarOption2);
customToolbarOption.setVisibility(View.GONE);
allNoteToolBar = findViewById(R.id.allNotesToolbar2);
allNoteToolBar.setEnabled(false);
allNoteListAndTitle = findViewById(R.id.allNoteListAndTitle2);
fragPlace = findViewById(R.id.fragmentPlace2);
fragPlace.setVisibility(View.GONE);
// show list with recycler view
recyclerView = findViewById(R.id.recyclerView2);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
myarchivedAdaptor = new MyArchivedAdaptor(myNotes, myDates);
recyclerView.setAdapter(myarchivedAdaptor);
recyclerView.setLayoutManager(linearLayoutManager);
addListeners();
}
private void addListeners() {
// add listener to recyclerView
myarchivedAdaptor.setOnArchivedItemClickListener(new OnArchivedItemClickListener() {
@Override
public void onItemClicked(DateOrNote item) {
chosenDateOrNote = item;
if (item.getType().equals("note")){
//set noteFragment data
final Bundle bundle = new Bundle();
bundle.putString("title", item.getTitle());
bundle.putString("bodyTxt", item.getDescription());
//change the fragment
fragPlace.setVisibility(View.VISIBLE);
allNoteListAndTitle.setVisibility(View.GONE);
//todo
}
else if (item.getType().equals("date")){
//todo go to fragment
}
}
@Override
public void onItemLongClicked(DateOrNote item) {
chosenDateOrNote = item;
customToolbarOption.setVisibility(View.VISIBLE);
customToolbarOption.hideRecycleBin();
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(ArchivedNotesActivity.this, "unarchived", Toast.LENGTH_SHORT).show();
}
@Override
public void onDeleteClicked() {
}
@Override
public void onCloseClicked() {
closeClicked(customToolbarOption);
}
});
}
private void updateToUnarchiveInDataBase() {
if (chosenDateOrNote.getType().equals("note")){
noteDataBase.noteDao().updateNote(chosenDateOrNote.getTitle() , chosenDateOrNote.getDescription() , false , chosenDateOrNote.getId());
}
else if(chosenDateOrNote.getType().equals("date")){
noteDataBase.dateNoreDAO().updateDate(chosenDateOrNote.getTitle() , chosenDateOrNote.getDescription() , false , chosenDateOrNote.getId());
}
}
private void setAllNoteListAndTitles() {
entityNotes = noteDataBase.noteDao().getAll();
myNotes = new ArrayList<>();
for (Note note : entityNotes) {
MyNote myNote = new MyNote(note.getTitle(), note.getDescription(), note.isarchived() , note.getID());
myNotes.add(myNote);
}
}
private void setAllDateNoteListAndTitles() {
//get data from database to set in recyclerView
entityDates = noteDataBase.dateNoreDAO().getAllDateNotes();
myDates = new ArrayList<>();
for (DateEntity dateEntity : entityDates) {
MyDate myDate = new MyDate(dateEntity.getDate(), dateEntity.getDescription(), dateEntity.isarchived() , dateEntity.getID());
myDates.add(myDate);
}
}
public void replaceFragment(Fragment fragment) {
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(fragPlace.getId(), fragment);
fragmentTransaction.commit();
}
protected void closeClicked(CustomToolbarOption customToolbarOption) {
customToolbarOption.setVisibility(View.GONE);
allNoteToolBar.setVisibility(View.VISIBLE);
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import com.example.mynotepad.MenuFeatures.AllArchivedNotes.ArchivedNoesListFragment;
import com.example.mynotepad.MenuFeatures.AllNotes.AllNotesListFragment;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.DateEntity;
import com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note;
......@@ -33,7 +34,7 @@ public class NoteFragment extends Fragment {
private EditText titleTxt, bodyTxt;
private FloatingActionButton back;
private boolean isAnewNote;
private String type;
private String type, noteDateType;
public NoteFragment() {
}
......@@ -81,6 +82,14 @@ public class NoteFragment extends Fragment {
saveNote();
else if (type.equals("date"))
saveCalenderNote();
else if (type.equals("noteDate")) {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
if (noteDateType.equals("note")) {
noteDataBase.noteDao().updateNote(titleTxt.getText().toString(), bodyTxt.getText().toString(), true, ArchivedNoesListFragment.chosenDateOrNote.getId());
} else if (noteDateType.equals("date")){
noteDataBase.dateNoreDAO().updateDate(titleTxt.getText().toString(), bodyTxt.getText().toString(), true, ArchivedNoesListFragment.chosenDateOrNote.getId());
}
}
if (getActivity() != null)
getActivity().onBackPressed();
}
......@@ -96,6 +105,7 @@ public class NoteFragment extends Fragment {
}
private void saveNote() {
if (isAnewNote) {
note = new Note(titleTxt.getText().toString(), bodyTxt.getText().toString(), false);
......@@ -127,6 +137,7 @@ public class NoteFragment extends Fragment {
titleTxt.setText(bundle.getString("title"));
bodyTxt.setText(bundle.getString("bodyTxt"));
type = bundle.getString("type");
noteDateType = bundle.getString("noteDateType");
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MenuFeatures.AllarchivedNotes.archivedNotesActivity">
tools:context=".MenuFeatures.AllArchivedNotes.ArchivedNotesActivity">
<FrameLayout
android:id="@+id/fragmentPlace2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/allNoteListAndTitle2"
<fragment
android:id="@+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/allNotesToolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView72"
android:layout_width="match_parent"
android:layout_height="50dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/index" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:enabled="false"
android:text="@string/archived"
android:textColor="#02091E"
android:textSize="26dp" />
</FrameLayout>
<com.example.mynotepad.MenuFeatures.CustomToolbarOption
android:id="@+id/customToolbarOption2"
android:layout_width="match_parent"
android:layout_height="50dp" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="409dp"
android:layout_height="match_parent"
android:background="#4883B5DD"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
</LinearLayout>
app:defaultNavHost="true"
app:navGraph="@navigation/nav_archived" />
</FrameLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MenuFeatures.AllArchivedNotes.ArchivedNoesListFragment">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/allNotesToolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView72"
android:layout_width="match_parent"
android:layout_height="50dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/index" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:enabled="false"
android:text="@string/archived"
android:textColor="#02091E"
android:textSize="26dp" />
</FrameLayout>
<com.example.mynotepad.MenuFeatures.CustomToolbarOption
android:id="@+id/customToolbarOption2"
android:layout_width="match_parent"
android:layout_height="50dp" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="409dp"
android:layout_height="match_parent"
android:background="#4883B5DD"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_archived"
app:startDestination="@id/archivedNoesListFragment">
<fragment
android:id="@+id/archivedNoesListFragment"
android:name="com.example.mynotepad.MenuFeatures.AllArchivedNotes.ArchivedNoesListFragment"
android:label="fragment_archived_noes_list"
tools:layout="@layout/fragment_archived_noes_list" >
<action
android:id="@+id/action_archivedNoesListFragment_to_noteFragment3"
app:destination="@id/noteFragment3"
app:exitAnim="@anim/fade_out"
app:enterAnim="@anim/slide_in"
app:popEnterAnim="@anim/fade_in"
app:popExitAnim="@anim/slide_out"/>
</fragment>
<fragment
android:id="@+id/noteFragment3"
android:name="com.example.mynotepad.MenuFeatures.AllNotes.Note.NoteFragment"
android:label="NoteFragment" />
</navigation>
\ No newline at end of file
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