Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
8b816b0d
Commit
8b816b0d
authored
Oct 27, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use CardAdapter for NotificationsAdapter
parent
98b30cf8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
97 deletions
+93
-97
app/src/main/java/app/insti/adapter/CardAdapter.java
app/src/main/java/app/insti/adapter/CardAdapter.java
+8
-1
app/src/main/java/app/insti/adapter/NotificationsAdapter.java
...src/main/java/app/insti/adapter/NotificationsAdapter.java
+84
-60
app/src/main/java/app/insti/fragment/NotificationsFragment.java
...c/main/java/app/insti/fragment/NotificationsFragment.java
+1
-36
No files found.
app/src/main/java/app/insti/adapter/CardAdapter.java
View file @
8b816b0d
...
@@ -76,7 +76,14 @@ public abstract class CardAdapter<T> extends RecyclerView.Adapter<CardAdapter<T>
...
@@ -76,7 +76,14 @@ public abstract class CardAdapter<T> extends RecyclerView.Adapter<CardAdapter<T>
Utils
.
loadImageWithPlaceholder
(
viewHolder
.
bigPicture
,
getBigImageUrl
(
t
));
Utils
.
loadImageWithPlaceholder
(
viewHolder
.
bigPicture
,
getBigImageUrl
(
t
));
}
else
{
}
else
{
// Build basic request
// Build basic request
RequestCreator
requestCreator
=
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
getAvatarUrl
(
t
)));
RequestCreator
requestCreator
;
if
(
getAvatarUrl
(
t
)
!=
null
)
requestCreator
=
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
getAvatarUrl
(
t
)));
else
if
(
getAvatarPlaceholder
()
!=
0
)
{
requestCreator
=
Picasso
.
get
().
load
(
getAvatarPlaceholder
());
}
else
{
return
;
}
// Check if we have a placeholder
// Check if we have a placeholder
if
(
getAvatarPlaceholder
()
!=
0
)
{
if
(
getAvatarPlaceholder
()
!=
0
)
{
...
...
app/src/main/java/app/insti/adapter/NotificationsAdapter.java
View file @
8b816b0d
package
app.insti.adapter
;
package
app.insti.adapter
;
import
android.content.Context
;
import
android.support.v4.app.Fragment
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v4.app.FragmentActivity
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.squareup.picasso.Picasso
;
import
java.util.List
;
import
java.util.List
;
import
app.insti.R
;
import
app.insti.R
;
import
app.insti.Utils
;
import
app.insti.Utils
;
import
app.insti.api.EmptyCallback
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.model.Event
;
import
app.insti.api.model.Event
;
import
app.insti.api.model.NewsArticle
;
import
app.insti.api.model.NewsArticle
;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.PlacementBlogPost
;
import
app.insti.api.model.PlacementBlogPost
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.fragment.NewsFragment
;
import
app.insti.fragment.PlacementBlogFragment
;
import
app.insti.fragment.TrainingBlogFragment
;
public
class
NotificationsAdapter
extends
RecyclerView
.
Adapter
<
NotificationsAdapter
.
Viewholder
>
{
public
class
NotificationsAdapter
extends
CardAdapter
<
Notification
>
{
private
List
<
Notification
>
notifications
;
private
Context
context
;
private
ItemClickListener
itemClickListener
;
public
NotificationsAdapter
(
List
<
Notification
>
notifications
,
ItemClickListener
itemClickListener
)
{
private
final
String
TYPE_EVENT
=
"event"
;
this
.
notifications
=
notifications
;
private
final
String
TYPE_NEWSENTRY
=
"newsentry"
;
this
.
itemClickListener
=
itemClickListener
;
private
final
String
TYPE_BLOG
=
"blogentry"
;
private
Gson
gson
;
public
NotificationsAdapter
(
List
<
Notification
>
notifications
,
Fragment
fragment
)
{
super
(
notifications
,
fragment
);
gson
=
new
Gson
();
}
}
@Override
@Override
public
Viewholder
onCreateViewHolder
(
ViewGroup
viewGroup
,
int
i
)
{
public
void
onClick
(
Notification
notification
,
FragmentActivity
fragmentActivity
)
{
context
=
viewGroup
.
getContext
();
/* Mark notification read */
LayoutInflater
inflater
=
LayoutInflater
.
from
(
context
);
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
View
notificationView
=
inflater
.
inflate
(
R
.
layout
.
feed_card
,
viewGroup
,
false
);
String
sessId
=
Utils
.
getSessionIDHeader
();
retrofitInterface
.
markNotificationRead
(
sessId
,
notification
.
getNotificationId
().
toString
()).
enqueue
(
new
EmptyCallback
<
Void
>());
final
Viewholder
notificationsViewHolder
=
new
Viewholder
(
notificationView
);
notificationView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
/* Open event */
@Override
if
(
isEvent
(
notification
))
{
public
void
onClick
(
View
v
)
{
Gson
gson
=
new
Gson
();
itemClickListener
.
onItemClick
(
v
,
notificationsViewHolder
.
getAdapterPosition
());
Event
event
=
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
Event
.
class
)
;
Utils
.
openEventFragment
(
event
,
fragmentActivity
);
}
else
if
(
isNews
(
notification
))
{
NewsFragment
newsFragment
=
new
NewsFragment
();
Utils
.
updateFragment
(
newsFragment
,
fragmentActivity
);
}
else
if
(
isBlogPost
(
notification
))
{
Gson
gson
=
new
Gson
();
PlacementBlogPost
post
=
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
PlacementBlogPost
.
class
);
if
(
post
.
getLink
().
contains
(
"training"
))
{
Utils
.
updateFragment
(
new
TrainingBlogFragment
(),
fragmentActivity
);
}
else
{
Utils
.
updateFragment
(
new
PlacementBlogFragment
(),
fragmentActivity
);
}
}
});
}
return
notificationsViewHolder
;
}
}
@Override
@Override
public
void
onBindViewHolder
(
Viewholder
viewholder
,
int
i
)
{
public
String
getTitle
(
Notification
notification
)
{
Gson
gson
=
new
Gson
();
if
(
isEvent
(
notification
))
{
Notification
appNotification
=
notifications
.
get
(
i
);
return
getEvent
(
notification
).
getEventName
();
viewholder
.
notificationVerb
.
setText
(
appNotification
.
getNotificationVerb
());
}
else
if
(
isNews
(
notification
))
{
if
(
appNotification
.
getNotificationActorType
().
contains
(
"event"
))
{
return
getNews
(
notification
).
getTitle
();
Event
event
=
gson
.
fromJson
(
gson
.
toJson
(
appNotification
.
getNotificationActor
()),
Event
.
class
);
}
else
if
(
isBlogPost
(
notification
))
{
Picasso
.
get
().
load
(
return
getBlogPost
(
notification
).
getTitle
();
Utils
.
resizeImageUrl
(
event
.
getEventImageURL
())
).
into
(
viewholder
.
notificationPicture
);
viewholder
.
notificationTitle
.
setText
(
event
.
getEventName
());
}
else
if
(
appNotification
.
getNotificationActorType
().
contains
(
"newsentry"
))
{
NewsArticle
article
=
gson
.
fromJson
(
gson
.
toJson
(
appNotification
.
getNotificationActor
()),
NewsArticle
.
class
);
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
article
.
getBody
().
getBodyImageURL
())
).
into
(
viewholder
.
notificationPicture
);
viewholder
.
notificationTitle
.
setText
(
article
.
getTitle
());
}
else
if
(
appNotification
.
getNotificationActorType
().
contains
(
"blogentry"
))
{
PlacementBlogPost
post
=
gson
.
fromJson
(
gson
.
toJson
(
appNotification
.
getNotificationActor
()),
PlacementBlogPost
.
class
);
Picasso
.
get
().
load
(
R
.
drawable
.
lotus_sq
).
into
(
viewholder
.
notificationPicture
);
viewholder
.
notificationTitle
.
setText
(
post
.
getTitle
());
}
}
return
"Notification"
;
}
}
@Override
@Override
public
int
getItemCount
(
)
{
public
String
getSubtitle
(
Notification
notification
)
{
return
notification
s
.
size
();
return
notification
.
getNotificationVerb
();
}
}
public
class
Viewholder
extends
RecyclerView
.
ViewHolder
{
@Override
private
TextView
notificationTitle
;
public
String
getAvatarUrl
(
Notification
notification
)
{
private
ImageView
notificationPicture
;
if
(
isEvent
(
notification
))
{
private
TextView
notificationVerb
;
return
getEvent
(
notification
).
getEventImageURL
();
}
else
if
(
isNews
(
notification
))
{
return
getNews
(
notification
).
getBody
().
getBodyImageURL
();
}
return
null
;
}
public
Viewholder
(
View
itemView
)
{
@Override
super
(
itemView
);
public
int
getAvatarPlaceholder
()
{
return
R
.
drawable
.
lotus_sq
;
}
notificationPicture
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
object_picture
);
private
boolean
isEvent
(
Notification
notification
)
{
notificationTitle
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
object_title
);
return
notification
.
getNotificationActorType
().
contains
(
TYPE_EVENT
);
notificationVerb
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
object_subtitle
);
}
}
private
boolean
isNews
(
Notification
notification
)
{
return
notification
.
getNotificationActorType
().
contains
(
TYPE_NEWSENTRY
);
}
private
boolean
isBlogPost
(
Notification
notification
)
{
return
notification
.
getNotificationActorType
().
contains
(
TYPE_BLOG
);
}
private
Event
getEvent
(
Notification
notification
)
{
return
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
Event
.
class
);
}
private
NewsArticle
getNews
(
Notification
notification
)
{
return
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
NewsArticle
.
class
);
}
private
PlacementBlogPost
getBlogPost
(
Notification
notification
)
{
return
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
PlacementBlogPost
.
class
);
}
}
}
}
app/src/main/java/app/insti/fragment/NotificationsFragment.java
View file @
8b816b0d
...
@@ -10,19 +10,13 @@ import android.view.LayoutInflater;
...
@@ -10,19 +10,13 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
com.google.gson.Gson
;
import
java.util.List
;
import
java.util.List
;
import
app.insti.R
;
import
app.insti.R
;
import
app.insti.Utils
;
import
app.insti.Utils
;
import
app.insti.adapter.NotificationsAdapter
;
import
app.insti.adapter.NotificationsAdapter
;
import
app.insti.api.EmptyCallback
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.model.Event
;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.PlacementBlogPost
;
import
app.insti.interfaces.ItemClickListener
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Response
;
...
@@ -78,36 +72,7 @@ public class NotificationsFragment extends BaseFragment {
...
@@ -78,36 +72,7 @@ public class NotificationsFragment extends BaseFragment {
/* Hide loader */
/* Hide loader */
getActivity
().
findViewById
(
R
.
id
.
loadingPanel
).
setVisibility
(
View
.
GONE
);
getActivity
().
findViewById
(
R
.
id
.
loadingPanel
).
setVisibility
(
View
.
GONE
);
NotificationsAdapter
notificationsAdapter
=
new
NotificationsAdapter
(
notifications
,
new
ItemClickListener
()
{
NotificationsAdapter
notificationsAdapter
=
new
NotificationsAdapter
(
notifications
,
this
);
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
/* Get the notification */
Notification
notification
=
notifications
.
get
(
position
);
/* Mark notification read */
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
String
sessId
=
Utils
.
getSessionIDHeader
();
retrofitInterface
.
markNotificationRead
(
sessId
,
notification
.
getNotificationId
().
toString
()).
enqueue
(
new
EmptyCallback
<
Void
>());
/* Open event */
if
(
notification
.
getNotificationActorType
().
contains
(
"event"
))
{
Gson
gson
=
new
Gson
();
Event
event
=
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
Event
.
class
)
;
Utils
.
openEventFragment
(
event
,
getActivity
());
}
else
if
(
notification
.
getNotificationActorType
().
contains
(
"newsentry"
))
{
NewsFragment
newsFragment
=
new
NewsFragment
();
Utils
.
updateFragment
(
newsFragment
,
getActivity
());
}
else
if
(
notification
.
getNotificationActorType
().
contains
(
"blogentry"
))
{
Gson
gson
=
new
Gson
();
PlacementBlogPost
post
=
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
PlacementBlogPost
.
class
);
if
(
post
.
getLink
().
contains
(
"training"
))
{
Utils
.
updateFragment
(
new
TrainingBlogFragment
(),
getActivity
());
}
else
{
Utils
.
updateFragment
(
new
PlacementBlogFragment
(),
getActivity
());
}
}
}
});
notificationsRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
notifications_recycler_view
);
notificationsRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
notifications_recycler_view
);
notificationsRecyclerView
.
setAdapter
(
notificationsAdapter
);
notificationsRecyclerView
.
setAdapter
(
notificationsAdapter
);
notificationsRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
notificationsRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
...
...
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