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
f05bad14
Commit
f05bad14
authored
Jul 11, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add clickable notifications
parent
7cd72b00
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
152 additions
and
18 deletions
+152
-18
app/src/main/java/app/insti/MainActivity.java
app/src/main/java/app/insti/MainActivity.java
+2
-5
app/src/main/java/app/insti/adapter/NotificationsAdapter.java
...src/main/java/app/insti/adapter/NotificationsAdapter.java
+22
-6
app/src/main/java/app/insti/api/RetrofitInterface.java
app/src/main/java/app/insti/api/RetrofitInterface.java
+4
-0
app/src/main/java/app/insti/data/Notification.java
app/src/main/java/app/insti/data/Notification.java
+79
-0
app/src/main/java/app/insti/fragment/NotificationsFragment.java
...c/main/java/app/insti/fragment/NotificationsFragment.java
+45
-7
No files found.
app/src/main/java/app/insti/MainActivity.java
View file @
f05bad14
...
@@ -180,15 +180,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -180,15 +180,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int
id
=
item
.
getItemId
();
int
id
=
item
.
getItemId
();
//noinspection SimplifiableIfStatement
if
(
id
==
R
.
id
.
action_notifications
)
{
if
(
id
==
R
.
id
.
action_notifications
)
{
showNotifications
=
true
;
showNotifications
=
true
;
// fetchNotifications();
NotificationsFragment
notificationsFragment
=
new
NotificationsFragment
();
updateFragment
(
notificationsFragment
);
return
true
;
return
true
;
}
}
return
super
.
onOptionsItemSelected
(
item
);
return
super
.
onOptionsItemSelected
(
item
);
...
...
app/src/main/java/app/insti/adapter/NotificationsAdapter.java
View file @
f05bad14
...
@@ -5,20 +5,26 @@ import android.support.v7.widget.RecyclerView;
...
@@ -5,20 +5,26 @@ import android.support.v7.widget.RecyclerView;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.google.gson.Gson
;
import
com.squareup.picasso.Picasso
;
import
java.util.List
;
import
java.util.List
;
import
app.insti.ItemClickListener
;
import
app.insti.ItemClickListener
;
import
app.insti.R
;
import
app.insti.R
;
import
app.insti.api.model.AppNotification
;
import
app.insti.api.model.AppNotification
;
import
app.insti.data.Event
;
import
app.insti.data.Notification
;
public
class
NotificationsAdapter
extends
RecyclerView
.
Adapter
<
NotificationsAdapter
.
Viewholder
>
{
public
class
NotificationsAdapter
extends
RecyclerView
.
Adapter
<
NotificationsAdapter
.
Viewholder
>
{
private
List
<
App
Notification
>
notifications
;
private
List
<
Notification
>
notifications
;
private
Context
context
;
private
Context
context
;
private
ItemClickListener
itemClickListener
;
private
ItemClickListener
itemClickListener
;
public
NotificationsAdapter
(
List
<
App
Notification
>
notifications
,
ItemClickListener
itemClickListener
)
{
public
NotificationsAdapter
(
List
<
Notification
>
notifications
,
ItemClickListener
itemClickListener
)
{
this
.
notifications
=
notifications
;
this
.
notifications
=
notifications
;
this
.
itemClickListener
=
itemClickListener
;
this
.
itemClickListener
=
itemClickListener
;
}
}
...
@@ -27,7 +33,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
...
@@ -27,7 +33,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
public
Viewholder
onCreateViewHolder
(
ViewGroup
viewGroup
,
int
i
)
{
public
Viewholder
onCreateViewHolder
(
ViewGroup
viewGroup
,
int
i
)
{
context
=
viewGroup
.
getContext
();
context
=
viewGroup
.
getContext
();
LayoutInflater
inflater
=
LayoutInflater
.
from
(
context
);
LayoutInflater
inflater
=
LayoutInflater
.
from
(
context
);
View
notificationView
=
inflater
.
inflate
(
R
.
layout
.
notification
,
viewGroup
,
false
);
View
notificationView
=
inflater
.
inflate
(
R
.
layout
.
body_card_view
,
viewGroup
,
false
);
final
Viewholder
notificationsViewHolder
=
new
Viewholder
(
notificationView
);
final
Viewholder
notificationsViewHolder
=
new
Viewholder
(
notificationView
);
notificationView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
notificationView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
...
@@ -41,8 +47,14 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
...
@@ -41,8 +47,14 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
@Override
@Override
public
void
onBindViewHolder
(
Viewholder
viewholder
,
int
i
)
{
public
void
onBindViewHolder
(
Viewholder
viewholder
,
int
i
)
{
AppNotification
appNotification
=
notifications
.
get
(
i
);
Gson
gson
=
new
Gson
();
viewholder
.
notificationTitle
.
setText
(
appNotification
.
getNotificationName
());
Notification
appNotification
=
notifications
.
get
(
i
);
viewholder
.
notificationVerb
.
setText
(
appNotification
.
getNotificationVerb
());
if
(
appNotification
.
getNotificationActorType
().
contains
(
"event"
))
{
Event
event
=
gson
.
fromJson
(
gson
.
toJson
(
appNotification
.
getNotificationActor
()),
Event
.
class
);
Picasso
.
get
().
load
(
event
.
getEventImageURL
()).
into
(
viewholder
.
notificationPicture
);
viewholder
.
notificationTitle
.
setText
(
event
.
getEventName
());
}
}
}
@Override
@Override
...
@@ -52,11 +64,15 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
...
@@ -52,11 +64,15 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
public
class
Viewholder
extends
RecyclerView
.
ViewHolder
{
public
class
Viewholder
extends
RecyclerView
.
ViewHolder
{
private
TextView
notificationTitle
;
private
TextView
notificationTitle
;
private
ImageView
notificationPicture
;
private
TextView
notificationVerb
;
public
Viewholder
(
View
itemView
)
{
public
Viewholder
(
View
itemView
)
{
super
(
itemView
);
super
(
itemView
);
notificationTitle
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
notification_title
);
notificationPicture
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
body_card_avatar
);
notificationTitle
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
body_card_name
);
notificationVerb
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
body_card_description
);
}
}
}
}
}
}
app/src/main/java/app/insti/api/RetrofitInterface.java
View file @
f05bad14
...
@@ -10,6 +10,7 @@ import app.insti.api.model.LoginResponse;
...
@@ -10,6 +10,7 @@ import app.insti.api.model.LoginResponse;
import
app.insti.api.model.NewsFeedResponse
;
import
app.insti.api.model.NewsFeedResponse
;
import
app.insti.data.HostelMessMenu
;
import
app.insti.data.HostelMessMenu
;
import
app.insti.data.NewsArticle
;
import
app.insti.data.NewsArticle
;
import
app.insti.data.Notification
;
import
app.insti.data.PlacementBlogPost
;
import
app.insti.data.PlacementBlogPost
;
import
app.insti.data.TrainingBlogPost
;
import
app.insti.data.TrainingBlogPost
;
import
app.insti.data.User
;
import
app.insti.data.User
;
...
@@ -64,6 +65,9 @@ public interface RetrofitInterface {
...
@@ -64,6 +65,9 @@ public interface RetrofitInterface {
@GET
(
"news"
)
@GET
(
"news"
)
Call
<
List
<
NewsArticle
>>
getNews
(
@Header
(
"Cookie"
)
String
sessionID
);
Call
<
List
<
NewsArticle
>>
getNews
(
@Header
(
"Cookie"
)
String
sessionID
);
@GET
(
"notifications"
)
Call
<
List
<
Notification
>>
getNotifications
(
@Header
(
"Cookie"
)
String
sessionID
);
@GET
(
"logout"
)
@GET
(
"logout"
)
Call
<
Void
>
logout
(
@Header
(
"Cookie"
)
String
sessionID
);
Call
<
Void
>
logout
(
@Header
(
"Cookie"
)
String
sessionID
);
...
...
app/src/main/java/app/insti/data/Notification.java
View file @
f05bad14
package
app.insti.data
;
package
app.insti.data
;
import
android.arch.persistence.room.ColumnInfo
;
import
android.arch.persistence.room.Entity
;
import
android.arch.persistence.room.PrimaryKey
;
import
android.support.annotation.NonNull
;
import
com.google.gson.annotations.SerializedName
;
@Entity
(
tableName
=
"news"
)
public
class
Notification
{
public
class
Notification
{
@NonNull
()
@PrimaryKey
()
@ColumnInfo
(
name
=
"id"
)
@SerializedName
(
"id"
)
private
Integer
notificationId
;
@ColumnInfo
(
name
=
"verb"
)
@SerializedName
(
"verb"
)
private
String
notificationVerb
;
@ColumnInfo
(
name
=
"unread"
)
@SerializedName
(
"unread"
)
private
boolean
notificationUnread
;
@ColumnInfo
(
name
=
"actor_type"
)
@SerializedName
(
"actor_type"
)
private
String
notificationActorType
;
@ColumnInfo
(
name
=
"actor"
)
@SerializedName
(
"actor"
)
private
Object
notificationActor
;
public
Notification
(
@NonNull
Integer
notificationId
,
String
notificationVerb
,
boolean
notificationUnread
,
String
notificationActorType
,
Object
notificationActor
)
{
this
.
notificationId
=
notificationId
;
this
.
notificationVerb
=
notificationVerb
;
this
.
notificationUnread
=
notificationUnread
;
this
.
notificationActorType
=
notificationActorType
;
this
.
notificationActor
=
notificationActor
;
}
@NonNull
public
Integer
getNotificationId
()
{
return
notificationId
;
}
public
void
setNotificationId
(
@NonNull
Integer
notificationId
)
{
this
.
notificationId
=
notificationId
;
}
public
String
getNotificationVerb
()
{
return
notificationVerb
;
}
public
void
setNotificationVerb
(
String
notificationVerb
)
{
this
.
notificationVerb
=
notificationVerb
;
}
public
boolean
isNotificationUnread
()
{
return
notificationUnread
;
}
public
void
setNotificationUnread
(
boolean
notificationUnread
)
{
this
.
notificationUnread
=
notificationUnread
;
}
public
String
getNotificationActorType
()
{
return
notificationActorType
;
}
public
void
setNotificationActorType
(
String
notificationActorType
)
{
this
.
notificationActorType
=
notificationActorType
;
}
public
Object
getNotificationActor
()
{
return
notificationActor
;
}
public
void
setNotificationActor
(
Object
notificationActor
)
{
this
.
notificationActor
=
notificationActor
;
}
}
}
app/src/main/java/app/insti/fragment/NotificationsFragment.java
View file @
f05bad14
...
@@ -3,12 +3,15 @@ package app.insti.fragment;
...
@@ -3,12 +3,15 @@ package app.insti.fragment;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.Toolbar
;
import
android.support.v7.widget.Toolbar
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.Toast
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
...
@@ -16,10 +19,17 @@ import java.util.List;
...
@@ -16,10 +19,17 @@ import java.util.List;
import
app.insti.Constants
;
import
app.insti.Constants
;
import
app.insti.ItemClickListener
;
import
app.insti.ItemClickListener
;
import
app.insti.MainActivity
;
import
app.insti.R
;
import
app.insti.R
;
import
app.insti.adapter.NotificationsAdapter
;
import
app.insti.adapter.NotificationsAdapter
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.ServiceGenerator
;
import
app.insti.api.model.AppNotification
;
import
app.insti.api.model.AppNotification
;
import
app.insti.api.model.NotificationsResponse
;
import
app.insti.api.model.NotificationsResponse
;
import
app.insti.data.Notification
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
/**
/**
* A simple {@link Fragment} subclass.
* A simple {@link Fragment} subclass.
...
@@ -28,6 +38,8 @@ public class NotificationsFragment extends BaseFragment {
...
@@ -28,6 +38,8 @@ public class NotificationsFragment extends BaseFragment {
RecyclerView
notificationsRecyclerView
;
RecyclerView
notificationsRecyclerView
;
List
<
Notification
>
notifications
;
public
NotificationsFragment
()
{
public
NotificationsFragment
()
{
// Required empty public constructor
// Required empty public constructor
}
}
...
@@ -47,18 +59,44 @@ public class NotificationsFragment extends BaseFragment {
...
@@ -47,18 +59,44 @@ public class NotificationsFragment extends BaseFragment {
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
toolbar
.
setTitle
(
"Notifications"
);
toolbar
.
setTitle
(
"Notifications"
);
Bundle
bundle
=
getArguments
();
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
String
notificationsResponseJson
=
bundle
.
getString
(
Constants
.
NOTIFICATIONS_RESPONSE_JSON
);
retrofitInterface
.
getNotifications
(((
MainActivity
)
getActivity
()).
getSessionIDHeader
()).
enqueue
(
new
Callback
<
List
<
Notification
>>()
{
NotificationsResponse
notificationsResponse
=
new
Gson
().
fromJson
(
notificationsResponseJson
,
NotificationsResponse
.
class
);
@Override
showNotifications
(
notificationsResponse
);
public
void
onResponse
(
Call
<
List
<
Notification
>>
call
,
Response
<
List
<
Notification
>>
response
)
{
if
(
response
.
isSuccessful
())
{
notifications
=
response
.
body
();
showNotifications
(
notifications
);
}
}
}
private
void
showNotifications
(
NotificationsResponse
notificationsResponse
)
{
@Override
List
<
AppNotification
>
notifications
=
notificationsResponse
.
getNotifications
();
public
void
onFailure
(
Call
<
List
<
Notification
>>
call
,
Throwable
t
)
{
}
});
}
private
void
showNotifications
(
final
List
<
Notification
>
notifications
)
{
NotificationsAdapter
notificationsAdapter
=
new
NotificationsAdapter
(
notifications
,
new
ItemClickListener
()
{
NotificationsAdapter
notificationsAdapter
=
new
NotificationsAdapter
(
notifications
,
new
ItemClickListener
()
{
@Override
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
public
void
onItemClick
(
View
v
,
int
position
)
{
//TODO: What to do?
/* Get the notification */
Notification
notification
=
notifications
.
get
(
position
);
/* Open event */
if
(
notification
.
getNotificationActorType
().
contains
(
"event"
))
{
String
eventJson
=
new
Gson
().
toJson
(
notification
.
getNotificationActor
());
Bundle
bundle
=
getArguments
();
if
(
bundle
==
null
)
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
EVENT_JSON
,
eventJson
);
EventFragment
eventFragment
=
new
EventFragment
();
eventFragment
.
setArguments
(
bundle
);
FragmentManager
manager
=
getActivity
().
getSupportFragmentManager
();
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
transaction
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
transaction
.
replace
(
R
.
id
.
framelayout_for_fragment
,
eventFragment
,
eventFragment
.
getTag
());
transaction
.
addToBackStack
(
eventFragment
.
getTag
()).
commit
();
}
}
}
});
});
notificationsRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
notifications_recycler_view
);
notificationsRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
notifications_recycler_view
);
...
...
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