Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
My notepad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9731301
My notepad
Commits
bdfadfbc
Commit
bdfadfbc
authored
Sep 24, 2020
by
9731301
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get data in activity andset it in fragment with bundle
parent
69310e71
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
158 additions
and
37 deletions
+158
-37
AllNotesActivity.java
...ple/mynotepad/MenuFeatures/AllNotes/AllNotesActivity.java
+34
-21
MyAdaptor.java
...d/MenuFeatures/AllNotes/MyNoteRecyclerView/MyAdaptor.java
+73
-1
MyNote.java
...epad/MenuFeatures/AllNotes/MyNoteRecyclerView/MyNote.java
+21
-0
OnItemClickListener.java
...ures/AllNotes/MyNoteRecyclerView/OnItemClickListener.java
+1
-1
NoteFragment.java
...le/mynotepad/MenuFeatures/AllNotes/Note/NoteFragment.java
+22
-8
all_notes_bg.xml
app/src/main/res/drawable/all_notes_bg.xml
+1
-1
row_bg.xml
app/src/main/res/drawable/row_bg.xml
+2
-2
activity_all_notes.xml
app/src/main/res/layout/activity_all_notes.xml
+2
-1
custom_item_row.xml
app/src/main/res/layout/custom_item_row.xml
+2
-2
No files found.
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/AllNotesActivity.java
View file @
bdfadfbc
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
;
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentTransaction
;
import
androidx.fragment.app.FragmentTransaction
;
...
@@ -10,24 +8,18 @@ import androidx.recyclerview.widget.RecyclerView;
...
@@ -10,24 +8,18 @@ import androidx.recyclerview.widget.RecyclerView;
import
androidx.room.Room
;
import
androidx.room.Room
;
import
android.app.AlertDialog
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.
view.LayoutInflater
;
import
android.
util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.Adapter
;
import
android.widget.AdapterView
;
import
android.widget.ArrayAdapter
;
import
android.widget.FrameLayout
;
import
android.widget.FrameLayout
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyAdaptor
;
import
com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote
;
import
com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.OnItemClickListener
;
import
com.example.mynotepad.MenuFeatures.AllNotes.Note.NoteFragment
;
import
com.example.mynotepad.MenuFeatures.AllNotes.Note.NoteFragment
;
import
com.example.mynotepad.MenuFeatures.AllNotes.Note.NoteRecyclerView.MyAdaptor
;
import
com.example.mynotepad.MenuFeatures.AllNotes.Note.NoteRecyclerView.MyNote
;
import
com.example.mynotepad.MenuFeatures.AllNotes.NotesDataBase.Note
;
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
;
...
@@ -71,15 +63,17 @@ public class AllNotesActivity extends AppCompatActivity {
...
@@ -71,15 +63,17 @@ public class AllNotesActivity extends AppCompatActivity {
allNoteListAndTitle
=
findViewById
(
R
.
id
.
allNoteListAndTitle
);
allNoteListAndTitle
=
findViewById
(
R
.
id
.
allNoteListAndTitle
);
fragPlace
=
findViewById
(
R
.
id
.
fragmentPlace
);
fragPlace
=
findViewById
(
R
.
id
.
fragmentPlace
);
fragPlace
.
setVisibility
(
View
.
GONE
);
fragPlace
.
setVisibility
(
View
.
GONE
);
addListeners
();
// show list with recycler view
// show list with recycler view
recyclerView
=
findViewById
(
R
.
id
.
recyclerView
);
recyclerView
=
findViewById
(
R
.
id
.
recyclerView
);
LinearLayoutManager
linearLayoutManager
=
new
LinearLayoutManager
(
this
,
LinearLayoutManager
.
VERTICAL
,
false
);
LinearLayoutManager
linearLayoutManager
=
new
LinearLayoutManager
(
this
,
LinearLayoutManager
.
VERTICAL
,
false
);
myAdaptor
=
new
MyAdaptor
(
myNotes
,
this
);
myAdaptor
=
new
MyAdaptor
(
myNotes
);
recyclerView
.
setAdapter
(
myAdaptor
);
recyclerView
.
setAdapter
(
myAdaptor
);
recyclerView
.
setLayoutManager
(
linearLayoutManager
);
recyclerView
.
setLayoutManager
(
linearLayoutManager
);
addListeners
();
}
}
...
@@ -92,6 +86,28 @@ public class AllNotesActivity extends AppCompatActivity {
...
@@ -92,6 +86,28 @@ public class AllNotesActivity extends AppCompatActivity {
});
});
//todo add listener for long click //update the data base
//todo add listener for long click //update the data base
//todo add listener to recyclerView
//todo add listener to recyclerView
myAdaptor
.
setOnItemClickListener
(
new
OnItemClickListener
()
{
@Override
public
void
onItemClicked
(
MyNote
myNote
)
{
//set noteFragment data
final
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"title"
,
myNote
.
getTitle
());
bundle
.
putString
(
"bodyTxt"
,
myNote
.
getDescription
());
final
NoteFragment
newNoteFrag
=
new
NoteFragment
();
newNoteFrag
.
setArguments
(
bundle
);
//change the fragment
fragPlace
.
setVisibility
(
View
.
VISIBLE
);
allNoteListAndTitle
.
setVisibility
(
View
.
GONE
);
addNoteButton
.
hide
();
replaceFragment
(
newNoteFrag
);
}
@Override
public
void
onItemLongClick
(
MyNote
item
)
{
}
});
}
}
...
@@ -124,11 +140,7 @@ public class AllNotesActivity extends AppCompatActivity {
...
@@ -124,11 +140,7 @@ public class AllNotesActivity extends AppCompatActivity {
replaceFragment
(
newNoteFrag
);
replaceFragment
(
newNoteFrag
);
}
}
private
void
showChosenNote
()
{
public
void
replaceFragment
(
Fragment
fragment
)
{
//ToDo replcae fragment and update database
}
private
void
replaceFragment
(
Fragment
fragment
)
{
fragmentTransaction
=
getSupportFragmentManager
().
beginTransaction
();
fragmentTransaction
=
getSupportFragmentManager
().
beginTransaction
();
fragmentTransaction
.
replace
(
fragPlace
.
getId
(),
fragment
);
fragmentTransaction
.
replace
(
fragPlace
.
getId
(),
fragment
);
fragmentTransaction
.
commit
();
fragmentTransaction
.
commit
();
...
@@ -139,8 +151,9 @@ public class AllNotesActivity extends AppCompatActivity {
...
@@ -139,8 +151,9 @@ public class AllNotesActivity extends AppCompatActivity {
notes
=
noteDataBase
.
noteDao
().
getAll
();
notes
=
noteDataBase
.
noteDao
().
getAll
();
myNotes
=
new
ArrayList
<>();
myNotes
=
new
ArrayList
<>();
for
(
Note
note
:
notes
)
{
for
(
Note
note
:
notes
)
{
MyNote
myNote
=
new
MyNote
(
note
.
getTitle
()
,
note
.
getDescription
()
,
note
.
isAchieved
());
MyNote
myNote
=
new
MyNote
(
note
.
getTitle
()
,
note
.
getDescription
()
,
note
.
isAchieved
());
myNotes
.
add
(
myNote
);
myNotes
.
add
(
myNote
);
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/MyNoteRecyclerView/MyAdaptor.java
View file @
bdfadfbc
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
.
MyNoteRecyclerView
;
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
.
MyNoteRecyclerView
;
public
class
MyAdaptor
{
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.TextView
;
import
androidx.annotation.NonNull
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.example.mynotepad.R
;
import
java.util.List
;
public
class
MyAdaptor
extends
RecyclerView
.
Adapter
<
MyAdaptor
.
ViewHolder
>
{
private
List
<
MyNote
>
notes
;
private
OnItemClickListener
onItemClickListener
;
public
MyAdaptor
(
List
<
MyNote
>
notes
)
{
this
.
notes
=
notes
;
}
@NonNull
@Override
public
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
View
view
=
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
R
.
layout
.
custom_item_row
,
parent
,
false
);
return
new
ViewHolder
(
view
);
}
@Override
public
void
onBindViewHolder
(
ViewHolder
holder
,
int
position
)
{
holder
.
titleTV
.
setText
(
notes
.
get
(
position
).
getTitle
());
holder
.
descriptionTV
.
setText
(
notes
.
get
(
position
).
getDescription
());
holder
.
isAchieved
=
notes
.
get
(
position
).
isAchieved
();
}
@Override
public
int
getItemCount
()
{
return
notes
.
size
();
}
public
void
setOnItemClickListener
(
OnItemClickListener
onItemClickListener
)
{
this
.
onItemClickListener
=
onItemClickListener
;
}
class
ViewHolder
extends
RecyclerView
.
ViewHolder
implements
View
.
OnClickListener
,
View
.
OnLongClickListener
{
protected
TextView
titleTV
,
descriptionTV
;
protected
boolean
isAchieved
;
public
ViewHolder
(
View
itemView
)
{
super
(
itemView
);
titleTV
=
itemView
.
findViewById
(
R
.
id
.
titleTv
);
descriptionTV
=
itemView
.
findViewById
(
R
.
id
.
descriptionTv
);
isAchieved
=
false
;
itemView
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
view
)
{
if
(
onItemClickListener
!=
null
)
onItemClickListener
.
onItemClicked
(
notes
.
get
(
getAdapterPosition
()));
}
@Override
public
boolean
onLongClick
(
View
view
)
{
if
(
onItemClickListener
!=
null
)
onItemClickListener
.
onItemLongClick
(
notes
.
get
(
getAdapterPosition
()));
return
false
;
}
}
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/MyNoteRecyclerView/MyNote.java
View file @
bdfadfbc
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
.
MyNoteRecyclerView
;
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
.
MyNoteRecyclerView
;
public
class
MyNote
{
public
class
MyNote
{
private
String
title
,
description
;
private
boolean
isAchieved
;
public
MyNote
(
String
title
,
String
description
,
boolean
isAchieved
)
{
this
.
title
=
title
;
this
.
description
=
description
;
this
.
isAchieved
=
isAchieved
;
}
public
String
getTitle
()
{
return
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
boolean
isAchieved
()
{
return
isAchieved
;
}
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/MyNoteRecyclerView/OnItemClickListener.java
View file @
bdfadfbc
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
.
MyNoteRecyclerView
;
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
.
MyNoteRecyclerView
;
public
interface
RecyclerViewOn
ClickListener
{
public
interface
OnItem
ClickListener
{
void
onItemClicked
(
MyNote
item
);
void
onItemClicked
(
MyNote
item
);
void
onItemLongClick
(
MyNote
item
);
void
onItemLongClick
(
MyNote
item
);
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/Note/NoteFragment.java
View file @
bdfadfbc
...
@@ -4,6 +4,8 @@ import android.app.AlertDialog;
...
@@ -4,6 +4,8 @@ import android.app.AlertDialog;
import
android.content.DialogInterface
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.Fragment
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -35,9 +37,9 @@ public class NoteFragment extends Fragment {
...
@@ -35,9 +37,9 @@ public class NoteFragment extends Fragment {
}
}
@Override
@Override
public
void
on
Pause
(
)
{
public
void
on
ViewCreated
(
@NonNull
View
view
,
@Nullable
Bundle
savedInstanceState
)
{
//Todo show massage dialog if u did not save it
super
.
onViewCreated
(
view
,
savedInstanceState
);
s
uper
.
onPause
();
s
etTitleAndBodyTxt
();
}
}
private
void
init
(
View
view
)
{
private
void
init
(
View
view
)
{
...
@@ -54,9 +56,7 @@ public class NoteFragment extends Fragment {
...
@@ -54,9 +56,7 @@ public class NoteFragment extends Fragment {
}
}
private
void
showAlert
()
{
private
void
showAlert
(){
final
AlertDialog
.
Builder
alert
=
new
AlertDialog
.
Builder
(
getContext
());
final
AlertDialog
.
Builder
alert
=
new
AlertDialog
.
Builder
(
getContext
());
alert
.
setTitle
(
"new note :"
);
alert
.
setTitle
(
"new note :"
);
alert
.
setMessage
(
"Do you want to save the note ?"
);
alert
.
setMessage
(
"Do you want to save the note ?"
);
...
@@ -66,12 +66,17 @@ public class NoteFragment extends Fragment {
...
@@ -66,12 +66,17 @@ public class NoteFragment extends Fragment {
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
saveNote
();
saveNote
();
Toast
.
makeText
(
getActivity
(),
"saved"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getActivity
(),
"saved"
,
Toast
.
LENGTH_SHORT
).
show
();
getActivity
().
finish
();
}
}
});
});
alert
.
setNegativeButton
(
"no"
,
new
DialogInterface
.
OnClickListener
()
{
alert
.
setNegativeButton
(
"no"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
dialogInterface
.
cancel
();
dialogInterface
.
cancel
();
if
(
getActivity
()
!=
null
)
getActivity
().
finish
();
}
}
});
});
alert
.
show
();
alert
.
show
();
...
@@ -79,7 +84,16 @@ public class NoteFragment extends Fragment {
...
@@ -79,7 +84,16 @@ public class NoteFragment extends Fragment {
private
void
saveNote
()
{
private
void
saveNote
()
{
note
=
new
Note
(
titleTxt
.
getText
().
toString
(),
bodyTxt
.
getText
().
toString
()
,
false
);
note
=
new
Note
(
titleTxt
.
getText
().
toString
(),
bodyTxt
.
getText
().
toString
(),
false
);
AllNotesActivity
.
noteDataBase
.
noteDao
().
insertNote
(
note
);
AllNotesActivity
.
noteDataBase
.
noteDao
().
insertNote
(
note
);
}
}
private
void
setTitleAndBodyTxt
()
{
Bundle
bundle
=
getArguments
();
if
(
bundle
!=
null
)
{
titleTxt
.
setText
(
bundle
.
getString
(
"title"
));
bodyTxt
.
setText
(
bundle
.
getString
(
"bodyTxt"
));
}
}
}
}
\ No newline at end of file
app/src/main/res/drawable/all_notes_bg.xml
View file @
bdfadfbc
...
@@ -6,6 +6,6 @@
...
@@ -6,6 +6,6 @@
<solid
android:color=
"#76A0C3"
/>
<solid
android:color=
"#76A0C3"
/>
<stroke
<stroke
android:width=
"13dp"
android:width=
"13dp"
android:color=
"#
99
83B5DD"
/>
android:color=
"#
48
83B5DD"
/>
<corners
android:radius=
"0dp"
/>
<corners
android:radius=
"0dp"
/>
</shape>
</shape>
\ No newline at end of file
app/src/main/res/drawable/row_bg.xml
View file @
bdfadfbc
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
android:shape=
"rectangle"
>
<solid
android:color=
"#83B5DD"
/>
<solid
android:color=
"#83B5DD"
/>
<stroke
<stroke
android:width=
"15dp"
android:width=
"15dp"
android:color=
"#
6A
83B5DD"
/>
android:color=
"#
48
83B5DD"
/>
<corners
android:radius=
"0dp"
/>
<corners
android:radius=
"0dp"
/>
</shape>
</shape>
\ No newline at end of file
app/src/main/res/layout/activity_all_notes.xml
View file @
bdfadfbc
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
android:background=
"@drawable/all_notes_bg"
android:background=
"@drawable/all_notes_bg"
android:gravity=
"center"
android:gravity=
"center"
android:text=
"@string/all_notes"
android:text=
"@string/all_notes"
android:textColor=
"#020930"
android:textSize=
"20dp"
/>
android:textSize=
"20dp"
/>
<com.example.mynotepad.MenuFeatures.AllNotes.CustomToolbarOption
<com.example.mynotepad.MenuFeatures.AllNotes.CustomToolbarOption
...
@@ -45,7 +46,7 @@
...
@@ -45,7 +46,7 @@
android:id=
"@+id/recyclerView"
android:id=
"@+id/recyclerView"
android:layout_width=
"409dp"
android:layout_width=
"409dp"
android:layout_height=
"601dp"
android:layout_height=
"601dp"
android:background=
"#
99
83B5DD"
android:background=
"#
48
83B5DD"
tools:layout_editor_absoluteX=
"1dp"
tools:layout_editor_absoluteX=
"1dp"
tools:layout_editor_absoluteY=
"1dp"
/>
tools:layout_editor_absoluteY=
"1dp"
/>
...
...
app/src/main/res/layout/custom_item_row.xml
View file @
bdfadfbc
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"
57
dp"
android:layout_height=
"
60
dp"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
android:background=
"@drawable/row_bg"
>
android:background=
"@drawable/row_bg"
>
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
android:layout_marginLeft=
"12dp"
android:layout_marginLeft=
"12dp"
android:lines=
"1"
android:lines=
"1"
android:text=
"body text"
android:text=
"body text"
android:textSize=
"1
5
dp"
/>
android:textSize=
"1
2
dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment