Commit 715f057d authored by 9731301's avatar 9731301

add listeners for delete notes and some other components

parent bdfadfbc
...@@ -10,9 +10,9 @@ import androidx.room.Room; ...@@ -10,9 +10,9 @@ import androidx.room.Room;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -24,6 +24,7 @@ import com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.Note; ...@@ -24,6 +24,7 @@ import com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.NoteDataBase; import com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.NoteDataBase;
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 com.google.android.material.snackbar.Snackbar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -40,6 +41,7 @@ public class AllNotesActivity extends AppCompatActivity { ...@@ -40,6 +41,7 @@ public class AllNotesActivity extends AppCompatActivity {
private MyAdaptor myAdaptor; private MyAdaptor myAdaptor;
private List<Note> notes; private List<Note> notes;
private List<MyNote> myNotes; private List<MyNote> myNotes;
public static MyNote myChosenNote;
public static NoteDataBase noteDataBase; public static NoteDataBase noteDataBase;
...@@ -77,6 +79,7 @@ public class AllNotesActivity extends AppCompatActivity { ...@@ -77,6 +79,7 @@ public class AllNotesActivity extends AppCompatActivity {
} }
public void addListeners() { public void addListeners() {
addNoteButton.setOnClickListener(new View.OnClickListener() { addNoteButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -84,11 +87,12 @@ public class AllNotesActivity extends AppCompatActivity { ...@@ -84,11 +87,12 @@ public class AllNotesActivity extends AppCompatActivity {
showAddAlert(); showAddAlert();
} }
}); });
//todo add listener for long click //update the data base
//todo add listener to recyclerView // add listener to recyclerView
myAdaptor.setOnItemClickListener(new OnItemClickListener() { myAdaptor.setOnItemClickListener(new OnItemClickListener() {
@Override @Override
public void onItemClicked(MyNote myNote) { public void onItemClicked(MyNote myNote) {
myChosenNote = myNote;
//set noteFragment data //set noteFragment data
final Bundle bundle = new Bundle(); final Bundle bundle = new Bundle();
bundle.putString("title", myNote.getTitle()); bundle.putString("title", myNote.getTitle());
...@@ -104,8 +108,53 @@ public class AllNotesActivity extends AppCompatActivity { ...@@ -104,8 +108,53 @@ public class AllNotesActivity extends AppCompatActivity {
} }
@Override @Override
public void onItemLongClick(MyNote item) { public void onItemLongClicked(MyNote myNote) {
customToolbarOption.setVisibility(View.VISIBLE);
allNoteToolBar.setVisibility(View.GONE);
myChosenNote = myNote;
}
});
//add listener to custom toolbar option and set being achieved or not to be saved in database
customToolbarOption.setCustomToolbarOptionListener(new CustomToolbarOptionListener() {
@Override
public void onStarClicked(ImageView yellowS, ImageView blackS) {
if (yellowS.getVisibility() == View.VISIBLE){
yellowS.setVisibility(View.GONE);
blackS.setVisibility(View.VISIBLE);
myChosenNote.setAchieved(false);
}
else {
yellowS.setVisibility(View.VISIBLE);
blackS.setVisibility(View.GONE);
myChosenNote.setAchieved(true);
}
}
@Override
public void onDeleteClicked(final ImageView imageView) {
AlertDialog.Builder alert = new AlertDialog.Builder(AllNotesActivity.this);
alert.setMessage("are you sure you wanna delete it ??? ");
alert.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
noteDataBase.noteDao().deleteNote(notes.get(myNotes.indexOf(myChosenNote)));
init();
}
});
alert.setNegativeButton("no", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
alert.show();
}
@Override
public void onCloseClicked(ImageView imageView ) {
customToolbarOption.setVisibility(View.GONE);
allNoteToolBar.setVisibility(View.VISIBLE);
} }
}); });
} }
...@@ -156,4 +205,7 @@ public class AllNotesActivity extends AppCompatActivity { ...@@ -156,4 +205,7 @@ public class AllNotesActivity extends AppCompatActivity {
} }
} }
public MyNote getMyChosenNote() {
return myChosenNote;
}
} }
\ No newline at end of file
...@@ -12,8 +12,8 @@ import com.example.mynotepad.R; ...@@ -12,8 +12,8 @@ import com.example.mynotepad.R;
public class CustomToolbarOption extends LinearLayout implements View.OnClickListener { public class CustomToolbarOption extends LinearLayout implements View.OnClickListener {
private View rootView; private View rootView;
private ImageView blackStarImg , yellowStarImg , deleteImg; private ImageView blackStarImg , yellowStarImg , deleteImg , closeImg;
private FrameLayout star; private CustomToolbarOptionListener customToolbarOptionListener;
public CustomToolbarOption(Context context) { public CustomToolbarOption(Context context) {
super(context); super(context);
...@@ -30,20 +30,40 @@ public class CustomToolbarOption extends LinearLayout implements View.OnClickLis ...@@ -30,20 +30,40 @@ public class CustomToolbarOption extends LinearLayout implements View.OnClickLis
blackStarImg = findViewById(R.id.black_star); blackStarImg = findViewById(R.id.black_star);
yellowStarImg = findViewById(R.id.yellow_star); yellowStarImg = findViewById(R.id.yellow_star);
deleteImg = findViewById(R.id.deleteImg); deleteImg = findViewById(R.id.deleteImg);
star = findViewById(R.id.star); closeImg = findViewById(R.id.closeImg);
setStarColor(); //todo setStarColor();
}
yellowStarImg.setOnClickListener(this);
blackStarImg.setOnClickListener(this);
deleteImg.setOnClickListener(this);
closeImg.setOnClickListener(this);
private void setStarColor() {
} }
/* private void setStarColor() {
if (AllNotesActivity.myChosenNote.isAchieved()){
blackStarImg.setVisibility(GONE);
yellowStarImg.setVisibility(VISIBLE);
}
else {
blackStarImg.setVisibility(VISIBLE);
yellowStarImg.setVisibility(GONE);
}
}*/
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if ( view.getId() == star.getId()){ if (customToolbarOptionListener != null){
//Todo if note is achived yellow if (view.getId() == closeImg.getId())
} customToolbarOptionListener.onCloseClicked(closeImg);
else if (view.getId() == deleteImg.getId()){ if (view.getId() == deleteImg.getId())
//Todo customToolbarOptionListener.onDeleteClicked(deleteImg);
if (view.getId() == yellowStarImg.getId() || view.getId() == blackStarImg.getId())
customToolbarOptionListener.onStarClicked(yellowStarImg , blackStarImg);
} }
} }
public void setCustomToolbarOptionListener(CustomToolbarOptionListener customToolbarOptionListener) {
this.customToolbarOptionListener = customToolbarOptionListener;
}
} }
package com.example.mynotepad.MenuFeatures.AllNotes;
import android.widget.ImageView;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote;
public interface CustomToolbarOptionListener {
void onStarClicked(ImageView yellowS , ImageView blackS);
void onDeleteClicked(ImageView imageView);
void onCloseClicked(ImageView imageView);
}
...@@ -56,19 +56,21 @@ public class MyAdaptor extends RecyclerView.Adapter<MyAdaptor.ViewHolder> { ...@@ -56,19 +56,21 @@ public class MyAdaptor extends RecyclerView.Adapter<MyAdaptor.ViewHolder> {
descriptionTV = itemView.findViewById(R.id.descriptionTv); descriptionTV = itemView.findViewById(R.id.descriptionTv);
isAchieved = false; isAchieved = false;
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
} }
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (onItemClickListener != null) if (onItemClickListener != null){
onItemClickListener.onItemClicked(notes.get(getAdapterPosition())); onItemClickListener.onItemClicked(notes.get(getAdapterPosition()));
}
} }
@Override @Override
public boolean onLongClick(View view) { public boolean onLongClick(View view) {
if (onItemClickListener != null) if (onItemClickListener != null)
onItemClickListener.onItemLongClick(notes.get(getAdapterPosition())); onItemClickListener.onItemLongClicked(notes.get(getAdapterPosition()));
return false; return true;
} }
} }
......
...@@ -22,4 +22,8 @@ public class MyNote { ...@@ -22,4 +22,8 @@ public class MyNote {
public boolean isAchieved() { public boolean isAchieved() {
return isAchieved; return isAchieved;
} }
public void setAchieved(boolean achieved) {
isAchieved = achieved;
}
} }
...@@ -2,5 +2,5 @@ package com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView; ...@@ -2,5 +2,5 @@ package com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView;
public interface OnItemClickListener { public interface OnItemClickListener {
void onItemClicked(MyNote item); void onItemClicked(MyNote item);
void onItemLongClick(MyNote item); void onItemLongClicked(MyNote item);
} }
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#9983B5DD"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout <RelativeLayout
...@@ -28,27 +27,31 @@ ...@@ -28,27 +27,31 @@
<RelativeLayout <RelativeLayout
android:id="@+id/main" android:id="@+id/main"
android:layout_below="@+id/toolBarId"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#77347C74"> android:layout_below="@+id/toolBarId"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="-4dp"
android:layout_marginEnd="-2dp"
android:layout_marginRight="-2dp"
android:background="#77A9D1CD">
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="356dp"
android:layout_height="wrap_content" android:layout_height="271dp"
android:layout_centerHorizontal="true" android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:src="@drawable/stones" /> android:src="@drawable/stones" />
<TextView <TextView
android:id="@+id/wlcTxt" android:id="@+id/wlcTxt"
android:layout_width="194dp" android:layout_width="211dp"
android:layout_height="65dp" android:layout_height="73dp"
android:layout_above="@+id/imageView" android:layout_above="@+id/imageView"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="173dp" android:layout_marginTop="173dp"
android:layout_marginBottom="45dp" /> android:layout_marginBottom="37dp" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
......
...@@ -2,15 +2,25 @@ ...@@ -2,15 +2,25 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="40dp"
android:background="#9983B5DD" android:background="#32648C"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView
android:id="@+id/closeImg"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:src="@drawable/close" />
<FrameLayout <FrameLayout
android:id="@+id/star" android:id="@+id/star"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentRight="true" android:layout_alignRight="@+id/closeImg"
android:layout_marginRight="20dp"> android:layout_marginRight="40dp">
<ImageView <ImageView
android:id="@+id/black_star" android:id="@+id/black_star"
...@@ -21,18 +31,18 @@ ...@@ -21,18 +31,18 @@
<ImageView <ImageView
android:id="@+id/yellow_star" android:id="@+id/yellow_star"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="35dp"
android:src="@drawable/yellow_star" /> android:src="@drawable/yellow_star" />
</FrameLayout> </FrameLayout>
<ImageView <ImageView
android:id="@+id/deleteImg"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignRight="@id/star" android:layout_alignRight="@id/star"
android:layout_marginRight="40dp" android:layout_marginRight="40dp"
android:src="@drawable/bin" android:src="@drawable/bin" />
android:id="@+id/deleteImg"/>
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
...@@ -7,29 +7,20 @@ ...@@ -7,29 +7,20 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_marginTop="10dp">
<EditText <EditText
android:id="@+id/myTitle" android:id="@+id/myTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_weight="3"
android:ems="10"
android:hint="title "
android:textSize="24dp" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="title"
android:textSize="24dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="10dp"/>
</LinearLayout>
<FrameLayout <FrameLayout
android:layout_width="440dp" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<EditText <EditText
......
...@@ -5,4 +5,5 @@ ...@@ -5,4 +5,5 @@
<string name="all_notes">all notes</string> <string name="all_notes">all notes</string>
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="title">title</string>
</resources> </resources>
\ 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