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
4738181f
Commit
4738181f
authored
Nov 08, 2020
by
9731301
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add gallery to show notedPics
parent
fe5d7417
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
205 additions
and
69 deletions
+205
-69
AllNotesListFragment.java
...mynotepad/MenuFeatures/AllNotes/AllNotesListFragment.java
+0
-5
Note.java
...xample/mynotepad/MenuFeatures/AllNotes/DataBase/Note.java
+34
-33
NoteDAO.java
...ple/mynotepad/MenuFeatures/AllNotes/DataBase/NoteDAO.java
+0
-4
NoteDataBase.java
...ynotepad/MenuFeatures/AllNotes/DataBase/NoteDataBase.java
+1
-1
PicsDao.java
...ple/mynotepad/MenuFeatures/AllNotes/DataBase/PicsDao.java
+4
-2
PicsEntity.java
.../mynotepad/MenuFeatures/AllNotes/DataBase/PicsEntity.java
+4
-2
CameraActivity.java
...le/mynotepad/MenuFeatures/Pics/Camera/CameraActivity.java
+1
-1
ChoosingPicsFragment.java
...ple/mynotepad/MenuFeatures/Pics/ChoosingPicsFragment.java
+34
-7
GalleryAdaptor.java
...e/mynotepad/MenuFeatures/Pics/Gallery/GalleryAdaptor.java
+27
-8
NotedPicsListFragment.java
...epad/MenuFeatures/Pics/Gallery/NotedPicsListFragment.java
+88
-1
OnGalleryItemClickListener.java
...MenuFeatures/Pics/Gallery/OnGalleryItemClickListener.java
+7
-0
activity_pics.xml
app/src/main/res/layout/activity_pics.xml
+2
-3
custom_gallery_item.xml
app/src/main/res/layout/custom_gallery_item.xml
+2
-2
fragment_noted_pics.xml
app/src/main/res/layout/fragment_noted_pics.xml
+1
-0
No files found.
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/AllNotesListFragment.java
View file @
4738181f
package
com
.
example
.
mynotepad
.
MenuFeatures
.
AllNotes
;
import
android.app.AlertDialog
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
androidx.annotation.NonNull
;
...
...
@@ -11,15 +9,12 @@ 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.LinearLayout
;
import
android.widget.Toast
;
import
com.example.mynotepad.Dialogs.AddTxtToPicsDialog.AddTextToPicDialog
;
import
com.example.mynotepad.Dialogs.CustomDialog
;
import
com.example.mynotepad.Dialogs.onCustomDialogClickListener
;
import
com.example.mynotepad.MenuFeatures.AllNotes.DataBase.Note
;
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/DataBase/Note.java
View file @
4738181f
...
...
@@ -3,18 +3,19 @@ package com.example.mynotepad.MenuFeatures.AllNotes.DataBase;
import
androidx.room.ColumnInfo
;
import
androidx.room.Entity
;
import
androidx.room.PrimaryKey
;
@Entity
public
class
Note
{
@Entity
public
class
Note
{
@PrimaryKey
(
autoGenerate
=
true
)
int
ID
;
@ColumnInfo
(
name
=
"title"
)
String
title
;
String
title
;
@ColumnInfo
(
name
=
"description"
)
String
txtBody
;
@ColumnInfo
(
name
=
"archived"
)
boolean
isarchived
;
public
Note
(
String
title
,
String
txtBody
,
boolean
isarchived
)
{
public
Note
(
String
title
,
String
txtBody
,
boolean
isarchived
)
{
this
.
title
=
title
;
this
.
txtBody
=
txtBody
;
this
.
isarchived
=
isarchived
;
...
...
@@ -33,7 +34,7 @@ import androidx.room.PrimaryKey;
return
txtBody
;
}
public
boolean
isarchived
()
{
public
boolean
isarchived
()
{
return
isarchived
;
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/DataBase/NoteDAO.java
View file @
4738181f
...
...
@@ -22,10 +22,6 @@ public interface NoteDAO {
@Delete
void
deleteNote
(
Note
myNote
);
@Query
(
"UPDATE Note SET title = :title , description = :description ,archived = :isarchived Where ID = :id"
)
void
updateNote
(
String
title
,
String
description
,
boolean
isarchived
,
int
id
);
}
\ No newline at end of file
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/DataBase/NoteDataBase.java
View file @
4738181f
...
...
@@ -3,7 +3,7 @@ package com.example.mynotepad.MenuFeatures.AllNotes.DataBase;
import
androidx.room.Database
;
import
androidx.room.RoomDatabase
;
@Database
(
entities
=
{
Note
.
class
,
DateEntity
.
class
},
version
=
1
)
@Database
(
entities
=
{
Note
.
class
,
DateEntity
.
class
,
PicsEntity
.
class
},
version
=
1
)
public
abstract
class
NoteDataBase
extends
RoomDatabase
{
public
abstract
NoteDAO
noteDao
();
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/DataBase/PicsDao.java
View file @
4738181f
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
PicsDao
{
// a method list type
@Query
(
"SELECT * FROM PicsEntity"
)
List
<
Date
Entity
>
getAllPicsNotes
();
List
<
Pics
Entity
>
getAllPicsNotes
();
//insert data in database
@Insert
...
...
@@ -17,7 +19,7 @@ public interface PicsDao {
//delete data in database
@Delete
void
deletePicsNote
(
DateEntity
date
Entity
);
void
deletePicsNote
(
PicsEntity
pics
Entity
);
//update data
@Query
(
"UPDATE PicsEntity SET txt = :txt , url = :url "
)
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/AllNotes/DataBase/PicsEntity.java
View file @
4738181f
...
...
@@ -2,12 +2,14 @@ package com.example.mynotepad.MenuFeatures.AllNotes.DataBase;
import
androidx.room.ColumnInfo
;
import
androidx.room.Entity
;
import
androidx.room.PrimaryKey
;
@Entity
public
class
PicsEntity
{
@PrimaryKey
(
autoGenerate
=
true
)
int
ID
;
@ColumnInfo
(
name
=
"url"
)
String
url
;
String
url
;
@ColumnInfo
(
name
=
"txt"
)
String
txt
;
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/Camera/CameraActivity.java
View file @
4738181f
...
...
@@ -146,7 +146,7 @@ public class CameraActivity extends AppCompatActivity {
}
};
p
rivate
static
File
getOutputMediaFile
()
{
p
ublic
static
File
getOutputMediaFile
()
{
//create a file to put pics in it
File
mediaStorageDir
=
new
File
(
Environment
.
getExternalStorageDirectory
(),
"MyNotePad"
);
if
(!
mediaStorageDir
.
exists
())
{
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/ChoosingPicsFragment.java
View file @
4738181f
...
...
@@ -3,10 +3,13 @@ package com.example.mynotepad.MenuFeatures.Pics;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.constraintlayout.widget.ConstraintLayout
;
import
androidx.fragment.app.Fragment
;
...
...
@@ -15,16 +18,25 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.LinearLayout
;
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.PicsEntity
;
import
com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity
;
import
com.example.mynotepad.MenuFeatures.Utils
;
import
com.example.mynotepad.R
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
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
{
...
...
@@ -82,27 +94,42 @@ public class ChoosingPicsFragment extends Fragment {
});
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
newFilePath
=
""
;
System
.
out
.
println
(
"================================================================================================"
);
if
(
data
!=
null
)
{
if
(
requestCode
==
1
)
{
// get image from gallery
newFilePath
=
data
.
getData
().
getPath
();
File
pictureFile
=
getOutputMediaFile
();
if
(
pictureFile
==
null
)
{
return
;
}
InputStream
stream
=
null
;
try
{
newFilePath
=
pictureFile
.
getPath
();
BitmapFactory
.
decodeStream
(
getActivity
().
getContentResolver
().
openInputStream
(
data
.
getData
()));
stream
=
getActivity
().
getContentResolver
().
openInputStream
(
data
.
getData
());
try
(
OutputStream
output
=
new
FileOutputStream
(
pictureFile
))
{
byte
[]
buffer
=
new
byte
[
4
*
1024
];
// or other buffer size
int
read
;
while
((
read
=
stream
.
read
(
buffer
))
!=
-
1
)
{
output
.
write
(
buffer
,
0
,
read
);
}
output
.
flush
();
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
")))))))))))))))))))))))))))))))))))))))))))))))"
+
newFilePath
);
showDialogOnResult
(
BitmapFactory
.
decode
Stream
(
stream
));
showDialogOnResult
(
BitmapFactory
.
decode
File
(
pictureFile
.
getAbsolutePath
()
));
}
else
if
(
requestCode
==
2
)
{
// get image from camera
newFilePath
=
data
.
getStringExtra
(
"filePath"
);
File
imgFile
=
new
File
(
newFilePath
);
if
(
imgFile
.
exists
())
{
System
.
out
.
println
(
"(((((((((((((((((((((((((((((((((((((((((((("
+
newFilePath
);
showDialogOnResult
(
BitmapFactory
.
decodeFile
(
imgFile
.
getAbsolutePath
()));
}
}
...
...
@@ -116,8 +143,8 @@ public class ChoosingPicsFragment extends Fragment {
addTextToPicDialog
.
setOnSavePicListenerClick
(
new
OnSavePicListenerClick
()
{
@Override
public
void
saveClicked
(
String
editTextTxt
)
{
//todo save image path and txt in data base
//todo txt should be save in database with pic path if file pah is not null and add it to my list
PicsEntity
picsEntity
=
new
PicsEntity
(
newFilePath
,
editTextTxt
);
noteDataBase
.
picsDao
().
insertPicsNote
(
picsEntity
);
}
});
}
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/Gallery/GalleryAdaptor.java
View file @
4738181f
...
...
@@ -10,18 +10,15 @@ import android.widget.TextView;
import
androidx.annotation.NonNull
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.example.mynotepad.R
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
GalleryAdaptor
extends
RecyclerView
.
Adapter
<
GalleryAdaptor
.
GalleryViewHolder
>
{
private
Array
List
<
MyGalleryPic
>
picsUrlAndTxt
;
private
Context
context
;
private
List
<
MyGalleryPic
>
picsUrlAndTxt
;
private
OnGalleryItemClickListener
onItemClickListener
;
public
GalleryAdaptor
(
ArrayList
<
MyGalleryPic
>
picsUrlAndTxt
,
Context
conte
xt
)
{
public
GalleryAdaptor
(
List
<
MyGalleryPic
>
picsUrlAndT
xt
)
{
this
.
picsUrlAndTxt
=
picsUrlAndTxt
;
this
.
context
=
context
;
}
@NonNull
...
...
@@ -43,7 +40,15 @@ public class GalleryAdaptor extends RecyclerView.Adapter<GalleryAdaptor.GalleryV
return
picsUrlAndTxt
.
size
();
}
public
class
GalleryViewHolder
extends
RecyclerView
.
ViewHolder
{
public
OnGalleryItemClickListener
getOnItemClickListener
()
{
return
onItemClickListener
;
}
public
void
setOnItemClickListener
(
OnGalleryItemClickListener
onItemClickListener
)
{
this
.
onItemClickListener
=
onItemClickListener
;
}
public
class
GalleryViewHolder
extends
RecyclerView
.
ViewHolder
implements
View
.
OnClickListener
,
View
.
OnLongClickListener
{
TextView
textView
;
ImageView
imageView
;
...
...
@@ -52,5 +57,19 @@ public class GalleryAdaptor extends RecyclerView.Adapter<GalleryAdaptor.GalleryV
textView
=
itemView
.
findViewById
(
R
.
id
.
tv_gallery
);
imageView
=
itemView
.
findViewById
(
R
.
id
.
img_gallery
);
}
@Override
public
void
onClick
(
View
view
)
{
if
(
onItemClickListener
!=
null
)
{
onItemClickListener
.
onItemClicked
(
picsUrlAndTxt
.
get
(
getAdapterPosition
()));
}
}
@Override
public
boolean
onLongClick
(
View
view
)
{
if
(
onItemClickListener
!=
null
)
onItemClickListener
.
onItemLongClicked
(
picsUrlAndTxt
.
get
(
getAdapterPosition
()));
return
true
;
}
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/Gallery/NotedPicsListFragment.java
View file @
4738181f
...
...
@@ -4,17 +4,39 @@ import android.os.Bundle;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.fragment.app.Fragment
;
import
androidx.recyclerview.widget.GridLayoutManager
;
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.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
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
com
.
example
.
mynotepad
.
MainActivity
.
noteDataBase
;
public
class
NotedPicsListFragment
extends
Fragment
{
private
List
<
MyGalleryPic
>
myGalleryPics
;
private
List
<
PicsEntity
>
picsEntityList
;
private
GalleryAdaptor
adapter
;
private
CustomToolbarOption
customToolbarOption
;
private
MyGalleryPic
myChosenPic
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
...
...
@@ -27,6 +49,71 @@ public class NotedPicsListFragment extends Fragment {
@Override
public
void
onViewCreated
(
@NonNull
View
view
,
@Nullable
Bundle
savedInstanceState
)
{
super
.
onViewCreated
(
view
,
savedInstanceState
);
RecyclerView
recyclerView
=
view
.
findViewById
(
R
.
id
.
picsRecyclerView
);
recyclerView
.
setHasFixedSize
(
true
);
RecyclerView
.
LayoutManager
layoutManager
=
new
GridLayoutManager
(
getContext
(),
2
);
recyclerView
.
setLayoutManager
(
layoutManager
);
//todo add customtoolbar
setData
();
adapter
=
new
GalleryAdaptor
(
myGalleryPics
);
recyclerView
.
setAdapter
(
adapter
);
addListeners
();
}
private
void
setData
()
{
picsEntityList
=
noteDataBase
.
picsDao
().
getAllPicsNotes
();
myGalleryPics
=
new
ArrayList
<>();
for
(
PicsEntity
picsEntity
:
picsEntityList
)
{
MyGalleryPic
myGalleryPic
=
new
MyGalleryPic
(
picsEntity
.
getUrl
(),
picsEntity
.
getTxt
());
myGalleryPics
.
add
(
myGalleryPic
);
}
}
private
void
addListeners
()
{
// add listener to recyclerView
adapter
.
setOnItemClickListener
(
new
OnGalleryItemClickListener
()
{
@Override
public
void
onItemClicked
(
MyGalleryPic
myGalleryPic
)
{
myChosenPic
=
myGalleryPic
;
//todo show big img or go to a new fragment
//set noteFragment data
final
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"url"
,
myGalleryPic
.
getUrl
());
bundle
.
putString
(
"txt"
,
myGalleryPic
.
getText
());
}
@Override
public
void
onItemLongClicked
(
MyGalleryPic
myGalleryPic
)
{
myChosenPic
=
myGalleryPic
;
}
});
}
protected
void
closeClicked
(
CustomToolbarOption
customToolbarOption
)
{
customToolbarOption
.
setVisibility
(
View
.
GONE
);
}
protected
void
deleteClicked
(
final
PicsEntity
pic
)
{
CustomDialog
customDialog
=
new
CustomDialog
();
customDialog
.
showAddTxtDialog
(
getActivity
(),
"are you sure you wanna delete it ??? "
);
customDialog
.
setOnCustomDialogClickListener
(
new
onCustomDialogClickListener
()
{
@Override
public
void
yesClicked
()
{
noteDataBase
.
picsDao
().
deletePicsNote
(
pic
);
myGalleryPics
.
remove
(
myChosenPic
);
adapter
.
notifyDataSetChanged
();
}
@Override
public
void
noClicked
()
{
}
});
// allNoteToolBar.setVisibility(View.VISIBLE);
customToolbarOption
.
setVisibility
(
View
.
GONE
);
// allNoteToolBar.setVisibility(View.VISIBLE);
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/Gallery/OnGalleryItemClickListener.java
0 → 100644
View file @
4738181f
package
com
.
example
.
mynotepad
.
MenuFeatures
.
Pics
.
Gallery
;
public
interface
OnGalleryItemClickListener
{
void
onItemClicked
(
MyGalleryPic
myGalleryPic
);
void
onItemLongClicked
(
MyGalleryPic
myGalleryPic
);
}
app/src/main/res/layout/activity_pics.xml
View file @
4738181f
...
...
@@ -23,16 +23,15 @@
android:id=
"@+id/nav_pic_fragment_place"
android:name=
"androidx.navigation.fragment.NavHostFragment"
android:layout_width=
"match_parent"
android:layout_height=
"
match_parent
"
android:layout_height=
"
0dp
"
app:defaultNavHost=
"true"
app:layout_constraintBottom_toTopOf=
"@id/nav_view"
app:layout_constraintBottom_toTopOf=
"@
+
id/nav_view"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.0"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintVertical_bias=
"1.0"
app:navGraph=
"@navigation/bottom_nav_pic"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/custom_gallery_item.xml
View file @
4738181f
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:background=
"
@color/colorPrimaryDark
"
android:background=
"
?colorButtonNormal
"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<ImageView
...
...
@@ -12,7 +12,7 @@
<TextView
android:id=
"@+id/tv_gallery"
android:layout_gravity=
"center"
android:textColor=
"
#FFFFFF
"
android:textColor=
"
?android:textColorPrimary
"
android:textStyle=
"bold"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
...
...
app/src/main/res/layout/fragment_noted_pics.xml
View file @
4738181f
...
...
@@ -6,6 +6,7 @@
tools:context=
".MenuFeatures.Pics.Gallery.NotedPicsListFragment"
>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/picsRecyclerView"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:scrollbars=
"vertical"
/>
...
...
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