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
745dc639
Commit
745dc639
authored
Oct 01, 2018
by
Sajal Narang
Committed by
GitHub
Oct 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #216 from pulsejet/patch26
Prevent multiple calls to notifications API when changing fragments
parents
54ed0f93
92783298
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
app/src/main/java/app/insti/activity/MainActivity.java
app/src/main/java/app/insti/activity/MainActivity.java
+21
-8
No files found.
app/src/main/java/app/insti/activity/MainActivity.java
View file @
745dc639
...
@@ -89,9 +89,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -89,9 +89,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
SessionManager
session
;
SessionManager
session
;
FeedFragment
feedFragment
;
FeedFragment
feedFragment
;
private
User
currentUser
;
private
User
currentUser
;
private
boolean
showNotifications
=
false
;
private
BackHandledFragment
selectedFragment
;
private
BackHandledFragment
selectedFragment
;
private
Menu
menu
;
private
Menu
menu
;
private
RetrofitInterface
retrofitInterface
;
private
List
<
Notification
>
notifications
=
null
;
/** which menu item should be checked on activity start */
/** which menu item should be checked on activity start */
private
int
initMenuChecked
=
R
.
id
.
nav_feed
;
private
int
initMenuChecked
=
R
.
id
.
nav_feed
;
...
@@ -147,22 +148,35 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -147,22 +148,35 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
checkLatestVersion
();
checkLatestVersion
();
}
}
/** Get the notifications from memory cache or network */
private
void
fetchNotifications
()
{
private
void
fetchNotifications
()
{
// Try memory cache
if
(
notifications
!=
null
)
{
showNotifications
();
return
;
}
// Get from network
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
retrofitInterface
.
getNotifications
(
Utils
.
getSessionIDHeader
()).
enqueue
(
new
EmptyCallback
<
List
<
Notification
>>()
{
retrofitInterface
.
getNotifications
(
Utils
.
getSessionIDHeader
()).
enqueue
(
new
EmptyCallback
<
List
<
Notification
>>()
{
@Override
@Override
public
void
onResponse
(
Call
<
List
<
Notification
>>
call
,
Response
<
List
<
Notification
>>
response
)
{
public
void
onResponse
(
Call
<
List
<
Notification
>>
call
,
Response
<
List
<
Notification
>>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
List
<
Notification
>
notifications
=
response
.
body
();
notifications
=
response
.
body
();
showNotifications
();
}
}
});
}
/** Show the right notification icon */
private
void
showNotifications
()
{
if
(
notifications
!=
null
&&
!
notifications
.
isEmpty
())
{
if
(
notifications
!=
null
&&
!
notifications
.
isEmpty
())
{
menu
.
findItem
(
R
.
id
.
action_notifications
).
setIcon
(
R
.
drawable
.
baseline_notifications_active_white_24
);
menu
.
findItem
(
R
.
id
.
action_notifications
).
setIcon
(
R
.
drawable
.
baseline_notifications_active_white_24
);
}
else
{
}
else
{
menu
.
findItem
(
R
.
id
.
action_notifications
).
setIcon
(
R
.
drawable
.
ic_notifications_white_24dp
);
menu
.
findItem
(
R
.
id
.
action_notifications
).
setIcon
(
R
.
drawable
.
ic_notifications_white_24dp
);
}
}
}
}
}
});
}
/** Get version code we are currently on */
/** Get version code we are currently on */
private
int
getCurrentVersion
()
{
private
int
getCurrentVersion
()
{
...
@@ -458,7 +472,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -458,7 +472,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
int
id
=
item
.
getItemId
();
int
id
=
item
.
getItemId
();
if
(
id
==
R
.
id
.
action_notifications
)
{
if
(
id
==
R
.
id
.
action_notifications
)
{
showNotifications
=
true
;
NotificationsFragment
notificationsFragment
=
new
NotificationsFragment
();
NotificationsFragment
notificationsFragment
=
new
NotificationsFragment
();
updateFragment
(
notificationsFragment
);
updateFragment
(
notificationsFragment
);
return
true
;
return
true
;
...
...
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