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
9e44e059
Commit
9e44e059
authored
Aug 10, 2018
by
safwankdb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preserve scroll position in feed
parent
f4acc09d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
6 deletions
+27
-6
app/src/main/java/app/insti/fragment/FeedFragment.java
app/src/main/java/app/insti/fragment/FeedFragment.java
+27
-6
No files found.
app/src/main/java/app/insti/fragment/FeedFragment.java
View file @
9e44e059
...
@@ -45,7 +45,8 @@ public class FeedFragment extends BaseFragment {
...
@@ -45,7 +45,8 @@ public class FeedFragment extends BaseFragment {
private
AppDatabase
appDatabase
;
private
AppDatabase
appDatabase
;
private
FloatingActionButton
fab
;
private
FloatingActionButton
fab
;
private
boolean
freshEventsDisplayed
=
false
;
private
boolean
freshEventsDisplayed
=
false
;
LinearLayoutManager
mLayoutManager
;
public
static
int
index
=
-
1
,
top
=
-
1
;
public
FeedFragment
()
{
public
FeedFragment
()
{
// Required empty public constructor
// Required empty public constructor
}
}
...
@@ -60,7 +61,9 @@ public class FeedFragment extends BaseFragment {
...
@@ -60,7 +61,9 @@ public class FeedFragment extends BaseFragment {
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
toolbar
.
setTitle
(
"Feed"
);
toolbar
.
setTitle
(
"Feed"
);
feedRecyclerView
=
view
.
findViewById
(
R
.
id
.
feed_recycler_view
);
mLayoutManager
=
new
LinearLayoutManager
(
getContext
());
feedRecyclerView
.
setLayoutManager
(
mLayoutManager
);
feedSwipeRefreshLayout
=
view
.
findViewById
(
R
.
id
.
feed_swipe_refresh_layout
);
feedSwipeRefreshLayout
=
view
.
findViewById
(
R
.
id
.
feed_swipe_refresh_layout
);
feedSwipeRefreshLayout
.
setOnRefreshListener
(
new
SwipeRefreshLayout
.
OnRefreshListener
()
{
feedSwipeRefreshLayout
.
setOnRefreshListener
(
new
SwipeRefreshLayout
.
OnRefreshListener
()
{
@Override
@Override
...
@@ -77,13 +80,31 @@ public class FeedFragment extends BaseFragment {
...
@@ -77,13 +80,31 @@ public class FeedFragment extends BaseFragment {
super
.
onStart
();
super
.
onStart
();
appDatabase
=
AppDatabase
.
getAppDatabase
(
getContext
());
appDatabase
=
AppDatabase
.
getAppDatabase
(
getContext
());
new
showEventsFromDB
().
execute
();
new
showEventsFromDB
().
execute
();
fab
=
(
FloatingActionButton
)
getView
().
findViewById
(
R
.
id
.
fab
);
fab
=
(
FloatingActionButton
)
getView
().
findViewById
(
R
.
id
.
fab
);
feedRecyclerView
=
getView
().
findViewById
(
R
.
id
.
feed_recycler_view
);
updateFeed
();
updateFeed
();
}
}
@Override
public
void
onPause
()
{
super
.
onPause
();
index
=
mLayoutManager
.
findFirstVisibleItemPosition
();
View
v
=
feedRecyclerView
.
getChildAt
(
0
);
top
=
(
v
==
null
)
?
0
:
(
v
.
getTop
()
-
feedRecyclerView
.
getPaddingTop
());
}
@Override
public
void
onResume
()
{
super
.
onResume
();
if
(
index
!=
-
1
)
{
mLayoutManager
.
scrollToPositionWithOffset
(
index
,
top
);
}
}
private
void
updateFeed
()
{
private
void
updateFeed
()
{
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
retrofitInterface
.
getNewsFeed
(
"sessionid="
+
getArguments
().
getString
(
Constants
.
SESSION_ID
)).
enqueue
(
new
Callback
<
NewsFeedResponse
>()
{
retrofitInterface
.
getNewsFeed
(
"sessionid="
+
getArguments
().
getString
(
Constants
.
SESSION_ID
)).
enqueue
(
new
Callback
<
NewsFeedResponse
>()
{
...
@@ -160,7 +181,7 @@ public class FeedFragment extends BaseFragment {
...
@@ -160,7 +181,7 @@ public class FeedFragment extends BaseFragment {
public
void
run
(
Activity
pActivity
)
{
public
void
run
(
Activity
pActivity
)
{
try
{
try
{
feedRecyclerView
.
setAdapter
(
feedAdapter
);
feedRecyclerView
.
setAdapter
(
feedAdapter
);
feedRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
//
feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
catch
(
NullPointerException
e
)
{
}
catch
(
NullPointerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
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