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;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
......@@ -24,6 +24,7 @@ import com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.Note;
import com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.NoteDataBase;
import com.example.mynotepad.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import java.util.ArrayList;
import java.util.List;
......@@ -40,6 +41,7 @@ public class AllNotesActivity extends AppCompatActivity {
private MyAdaptor myAdaptor;
private List<Note> notes;
private List<MyNote> myNotes;
public static MyNote myChosenNote;
public static NoteDataBase noteDataBase;
......@@ -77,6 +79,7 @@ public class AllNotesActivity extends AppCompatActivity {
}
public void addListeners() {
addNoteButton.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -84,11 +87,12 @@ public class AllNotesActivity extends AppCompatActivity {
showAddAlert();
}
});
//todo add listener for long click //update the data base
//todo add listener to recyclerView
// add listener to recyclerView
myAdaptor.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClicked(MyNote myNote) {
myChosenNote = myNote;
//set noteFragment data
final Bundle bundle = new Bundle();
bundle.putString("title", myNote.getTitle());
......@@ -104,8 +108,53 @@ public class AllNotesActivity extends AppCompatActivity {
}
@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 {
}
}
public MyNote getMyChosenNote() {
return myChosenNote;
}
}
\ No newline at end of file
......@@ -12,8 +12,8 @@ import com.example.mynotepad.R;
public class CustomToolbarOption extends LinearLayout implements View.OnClickListener {
private View rootView;
private ImageView blackStarImg , yellowStarImg , deleteImg;
private FrameLayout star;
private ImageView blackStarImg , yellowStarImg , deleteImg , closeImg;
private CustomToolbarOptionListener customToolbarOptionListener;
public CustomToolbarOption(Context context) {
super(context);
......@@ -30,20 +30,40 @@ public class CustomToolbarOption extends LinearLayout implements View.OnClickLis
blackStarImg = findViewById(R.id.black_star);
yellowStarImg = findViewById(R.id.yellow_star);
deleteImg = findViewById(R.id.deleteImg);
star = findViewById(R.id.star);
setStarColor();
closeImg = findViewById(R.id.closeImg);
//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
public void onClick(View view) {
if ( view.getId() == star.getId()){
//Todo if note is achived yellow
if (customToolbarOptionListener != null){
if (view.getId() == closeImg.getId())
customToolbarOptionListener.onCloseClicked(closeImg);
if (view.getId() == deleteImg.getId())
customToolbarOptionListener.onDeleteClicked(deleteImg);
if (view.getId() == yellowStarImg.getId() || view.getId() == blackStarImg.getId())
customToolbarOptionListener.onStarClicked(yellowStarImg , blackStarImg);
}
else if (view.getId() == deleteImg.getId()){
//Todo
}
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> {
descriptionTV = itemView.findViewById(R.id.descriptionTv);
isAchieved = false;
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
}
@Override
public void onClick(View view) {
if (onItemClickListener != null)
if (onItemClickListener != null){
onItemClickListener.onItemClicked(notes.get(getAdapterPosition()));
}
}
@Override
public boolean onLongClick(View view) {
if (onItemClickListener != null)
onItemClickListener.onItemLongClick(notes.get(getAdapterPosition()));
return false;
onItemClickListener.onItemLongClicked(notes.get(getAdapterPosition()));
return true;
}
}
......
......@@ -22,4 +22,8 @@ public class MyNote {
public boolean isAchieved() {
return isAchieved;
}
public void setAchieved(boolean achieved) {
isAchieved = achieved;
}
}
......@@ -2,5 +2,5 @@ package com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView;
public interface OnItemClickListener {
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 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9983B5DD"
android:orientation="vertical">
<RelativeLayout
......@@ -28,27 +27,31 @@
<RelativeLayout
android:id="@+id/main"
android:layout_below="@+id/toolBarId"
android:layout_width="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
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="356dp"
android:layout_height="271dp"
android:layout_centerInParent="true"
android:src="@drawable/stones" />
<TextView
android:id="@+id/wlcTxt"
android:layout_width="194dp"
android:layout_height="65dp"
android:layout_width="211dp"
android:layout_height="73dp"
android:layout_above="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="173dp"
android:layout_marginBottom="45dp" />
android:layout_marginBottom="37dp" />
</RelativeLayout>
</RelativeLayout>
......
......@@ -2,15 +2,25 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#9983B5DD"
android:background="#32648C"
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
android:id="@+id/star"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp">
android:layout_alignRight="@+id/closeImg"
android:layout_marginRight="40dp">
<ImageView
android:id="@+id/black_star"
......@@ -21,18 +31,18 @@
<ImageView
android:id="@+id/yellow_star"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="35dp"
android:src="@drawable/yellow_star" />
</FrameLayout>
<ImageView
android:id="@+id/deleteImg"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="@id/star"
android:layout_marginRight="40dp"
android:src="@drawable/bin"
android:id="@+id/deleteImg"/>
android:src="@drawable/bin" />
</RelativeLayout>
\ No newline at end of file
......@@ -7,29 +7,20 @@
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_marginTop="10dp">
<EditText
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
android:layout_width="440dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
......
......@@ -5,4 +5,5 @@
<string name="all_notes">all notes</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="title">title</string>
</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