|
|
@ -19,7 +19,9 @@ import android.content.Context; |
|
|
|
import android.content.SharedPreferences; |
|
|
|
import android.content.SharedPreferences; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
|
|
|
|
import android.preference.PreferenceManager; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
|
|
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
|
import android.support.design.widget.TabLayout; |
|
|
|
import android.support.design.widget.TabLayout; |
|
|
|
import android.support.v4.widget.SwipeRefreshLayout; |
|
|
|
import android.support.v4.widget.SwipeRefreshLayout; |
|
|
|
import android.support.v7.widget.DividerItemDecoration; |
|
|
|
import android.support.v7.widget.DividerItemDecoration; |
|
|
@ -40,15 +42,17 @@ import retrofit2.Response; |
|
|
|
|
|
|
|
|
|
|
|
public class NotificationsFragment extends SFragment implements |
|
|
|
public class NotificationsFragment extends SFragment implements |
|
|
|
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener, |
|
|
|
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener, |
|
|
|
NotificationsAdapter.NotificationActionListener { |
|
|
|
NotificationsAdapter.NotificationActionListener, SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
private static final String TAG = "Notifications"; // logging tag
|
|
|
|
private static final String TAG = "Notifications"; // logging tag
|
|
|
|
|
|
|
|
|
|
|
|
private SwipeRefreshLayout swipeRefreshLayout; |
|
|
|
private SwipeRefreshLayout swipeRefreshLayout; |
|
|
|
private LinearLayoutManager layoutManager; |
|
|
|
private LinearLayoutManager layoutManager; |
|
|
|
|
|
|
|
private RecyclerView recyclerView; |
|
|
|
private EndlessOnScrollListener scrollListener; |
|
|
|
private EndlessOnScrollListener scrollListener; |
|
|
|
private NotificationsAdapter adapter; |
|
|
|
private NotificationsAdapter adapter; |
|
|
|
private TabLayout.OnTabSelectedListener onTabSelectedListener; |
|
|
|
private TabLayout.OnTabSelectedListener onTabSelectedListener; |
|
|
|
private Call<List<Notification>> listCall; |
|
|
|
private Call<List<Notification>> listCall; |
|
|
|
|
|
|
|
private boolean hideFab; |
|
|
|
|
|
|
|
|
|
|
|
public static NotificationsFragment newInstance() { |
|
|
|
public static NotificationsFragment newInstance() { |
|
|
|
NotificationsFragment fragment = new NotificationsFragment(); |
|
|
|
NotificationsFragment fragment = new NotificationsFragment(); |
|
|
@ -60,7 +64,7 @@ public class NotificationsFragment extends SFragment implements |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
|
|
|
@Nullable Bundle savedInstanceState) { |
|
|
|
@Nullable Bundle savedInstanceState) { |
|
|
|
View rootView = inflater.inflate(R.layout.fragment_timeline, container, false); |
|
|
|
View rootView = inflater.inflate(R.layout.fragment_timeline, container, false); |
|
|
|
|
|
|
|
|
|
|
|
// Setup the SwipeRefreshLayout.
|
|
|
|
// Setup the SwipeRefreshLayout.
|
|
|
@ -68,7 +72,7 @@ public class NotificationsFragment extends SFragment implements |
|
|
|
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); |
|
|
|
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); |
|
|
|
swipeRefreshLayout.setOnRefreshListener(this); |
|
|
|
swipeRefreshLayout.setOnRefreshListener(this); |
|
|
|
// Setup the RecyclerView.
|
|
|
|
// Setup the RecyclerView.
|
|
|
|
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); |
|
|
|
recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); |
|
|
|
recyclerView.setHasFixedSize(true); |
|
|
|
recyclerView.setHasFixedSize(true); |
|
|
|
layoutManager = new LinearLayoutManager(context); |
|
|
|
layoutManager = new LinearLayoutManager(context); |
|
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
@ -78,19 +82,7 @@ public class NotificationsFragment extends SFragment implements |
|
|
|
R.drawable.status_divider_dark); |
|
|
|
R.drawable.status_divider_dark); |
|
|
|
divider.setDrawable(drawable); |
|
|
|
divider.setDrawable(drawable); |
|
|
|
recyclerView.addItemDecoration(divider); |
|
|
|
recyclerView.addItemDecoration(divider); |
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { |
|
|
|
|
|
|
|
NotificationsAdapter adapter = (NotificationsAdapter) view.getAdapter(); |
|
|
|
|
|
|
|
Notification notification = adapter.getItem(adapter.getItemCount() - 2); |
|
|
|
|
|
|
|
if (notification != null) { |
|
|
|
|
|
|
|
sendFetchNotificationsRequest(notification.id, null); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sendFetchNotificationsRequest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
recyclerView.addOnScrollListener(scrollListener); |
|
|
|
|
|
|
|
adapter = new NotificationsAdapter(this, this); |
|
|
|
adapter = new NotificationsAdapter(this, this); |
|
|
|
recyclerView.setAdapter(adapter); |
|
|
|
recyclerView.setAdapter(adapter); |
|
|
|
|
|
|
|
|
|
|
@ -112,6 +104,51 @@ public class NotificationsFragment extends SFragment implements |
|
|
|
return rootView; |
|
|
|
return rootView; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) { |
|
|
|
|
|
|
|
super.onActivityCreated(savedInstanceState); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't |
|
|
|
|
|
|
|
* guaranteed to be set until then. |
|
|
|
|
|
|
|
* Use a modified scroll listener that both loads more notifications as it goes, and hides |
|
|
|
|
|
|
|
* the compose button on down-scroll. */ |
|
|
|
|
|
|
|
MainActivity activity = (MainActivity) getActivity(); |
|
|
|
|
|
|
|
final FloatingActionButton composeButton = activity.composeButton; |
|
|
|
|
|
|
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( |
|
|
|
|
|
|
|
activity); |
|
|
|
|
|
|
|
preferences.registerOnSharedPreferenceChangeListener(this); |
|
|
|
|
|
|
|
hideFab = preferences.getBoolean("fabHide", false); |
|
|
|
|
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onScrolled(RecyclerView view, int dx, int dy) { |
|
|
|
|
|
|
|
super.onScrolled(view, dx, dy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hideFab) { |
|
|
|
|
|
|
|
if (dy > 0 && composeButton.isShown()) { |
|
|
|
|
|
|
|
composeButton.hide(); // hides the button if we're scrolling down
|
|
|
|
|
|
|
|
} else if (dy < 0 && !composeButton.isShown()) { |
|
|
|
|
|
|
|
composeButton.show(); // shows it if we are scrolling up
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (!composeButton.isShown()) { |
|
|
|
|
|
|
|
composeButton.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { |
|
|
|
|
|
|
|
NotificationsAdapter adapter = (NotificationsAdapter) view.getAdapter(); |
|
|
|
|
|
|
|
Notification notification = adapter.getItem(adapter.getItemCount() - 2); |
|
|
|
|
|
|
|
if (notification != null) { |
|
|
|
|
|
|
|
sendFetchNotificationsRequest(notification.id, null); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sendFetchNotificationsRequest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recyclerView.addOnScrollListener(scrollListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onDestroy() { |
|
|
|
public void onDestroy() { |
|
|
|
super.onDestroy(); |
|
|
|
super.onDestroy(); |
|
|
@ -245,4 +282,11 @@ public class NotificationsFragment extends SFragment implements |
|
|
|
public void onViewAccount(String id) { |
|
|
|
public void onViewAccount(String id) { |
|
|
|
super.viewAccount(id); |
|
|
|
super.viewAccount(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
|
|
|
|
|
|
|
if(key.equals("fabHide")) { |
|
|
|
|
|
|
|
hideFab = sharedPreferences.getBoolean("fabHide", false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|