Frontend notifications
This commit is contained in:
parent
aa7d0236f9
commit
88f8637e23
|
@ -1483,7 +1483,7 @@ public class PeertubeAPI {
|
||||||
* @param resobj JSONObject
|
* @param resobj JSONObject
|
||||||
* @return Peertube
|
* @return Peertube
|
||||||
*/
|
*/
|
||||||
public static PeertubeNotification parsePeertubeNotifications(Context context,JSONObject resobj){
|
private static PeertubeNotification parsePeertubeNotifications(Context context,JSONObject resobj){
|
||||||
PeertubeNotification peertubeNotification = new PeertubeNotification();
|
PeertubeNotification peertubeNotification = new PeertubeNotification();
|
||||||
try {
|
try {
|
||||||
peertubeNotification.setId(resobj.get("id").toString());
|
peertubeNotification.setId(resobj.get("id").toString());
|
||||||
|
@ -1495,19 +1495,25 @@ public class PeertubeAPI {
|
||||||
if( resobj.has("comment")){
|
if( resobj.has("comment")){
|
||||||
PeertubeComment peertubeComment = new PeertubeComment();
|
PeertubeComment peertubeComment = new PeertubeComment();
|
||||||
JSONObject comment = resobj.getJSONObject("comment");
|
JSONObject comment = resobj.getJSONObject("comment");
|
||||||
|
if( comment.has("account")){
|
||||||
|
JSONObject account = comment.getJSONObject("account");
|
||||||
PeertubeAccountNotification peertubeAccountNotification = new PeertubeAccountNotification();
|
PeertubeAccountNotification peertubeAccountNotification = new PeertubeAccountNotification();
|
||||||
peertubeAccountNotification.setDisplayName(comment.get("displayName").toString());
|
peertubeAccountNotification.setDisplayName(account.get("displayName").toString());
|
||||||
peertubeAccountNotification.setName(comment.get("name").toString());
|
peertubeAccountNotification.setName(account.get("name").toString());
|
||||||
peertubeAccountNotification.setId(comment.get("id").toString());
|
peertubeAccountNotification.setId(account.get("id").toString());
|
||||||
if( comment.has("avatar")){
|
peertubeAccountNotification.setAvatar(account.getJSONObject("avatar").get("path").toString());
|
||||||
peertubeAccountNotification.setAvatar(comment.getJSONObject("avatar").get("path").toString());
|
|
||||||
}
|
|
||||||
peertubeComment.setPeertubeAccountNotification(peertubeAccountNotification);
|
peertubeComment.setPeertubeAccountNotification(peertubeAccountNotification);
|
||||||
|
}
|
||||||
|
if( comment.has("video")){
|
||||||
|
JSONObject video = comment.getJSONObject("video");
|
||||||
PeertubeVideoNotification peertubeVideoNotification = new PeertubeVideoNotification();
|
PeertubeVideoNotification peertubeVideoNotification = new PeertubeVideoNotification();
|
||||||
peertubeVideoNotification.setUuid(comment.get("uuid").toString());
|
peertubeVideoNotification.setUuid(video.get("uuid").toString());
|
||||||
peertubeVideoNotification.setName(comment.get("name").toString());
|
peertubeVideoNotification.setName(video.get("name").toString());
|
||||||
peertubeVideoNotification.setId(comment.get("id").toString());
|
peertubeVideoNotification.setId(video.get("id").toString());
|
||||||
peertubeComment.setPeertubeVideoNotification(peertubeVideoNotification);
|
peertubeComment.setPeertubeVideoNotification(peertubeVideoNotification);
|
||||||
|
}
|
||||||
|
peertubeComment.setId(comment.get("id").toString());
|
||||||
|
peertubeComment.setThreadId(comment.get("threadId").toString());
|
||||||
peertubeNotification.setPeertubeComment(peertubeComment);
|
peertubeNotification.setPeertubeComment(peertubeComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1519,7 +1525,7 @@ public class PeertubeAPI {
|
||||||
peertubeVideoNotification.setId(video.get("id").toString());
|
peertubeVideoNotification.setId(video.get("id").toString());
|
||||||
if( video.has("channel")){
|
if( video.has("channel")){
|
||||||
PeertubeAccountNotification peertubeAccountNotification = new PeertubeAccountNotification();
|
PeertubeAccountNotification peertubeAccountNotification = new PeertubeAccountNotification();
|
||||||
JSONObject channel = resobj.getJSONObject("video");
|
JSONObject channel = video.getJSONObject("channel");
|
||||||
peertubeAccountNotification.setDisplayName(channel.get("displayName").toString());
|
peertubeAccountNotification.setDisplayName(channel.get("displayName").toString());
|
||||||
peertubeAccountNotification.setName(channel.get("name").toString());
|
peertubeAccountNotification.setName(channel.get("name").toString());
|
||||||
peertubeAccountNotification.setId(channel.get("id").toString());
|
peertubeAccountNotification.setId(channel.get("id").toString());
|
||||||
|
@ -1550,7 +1556,9 @@ public class PeertubeAPI {
|
||||||
PeertubeAccountNotification peertubeAccounFollowingNotification = new PeertubeAccountNotification();
|
PeertubeAccountNotification peertubeAccounFollowingNotification = new PeertubeAccountNotification();
|
||||||
peertubeAccounFollowingNotification.setDisplayName(following.get("displayName").toString());
|
peertubeAccounFollowingNotification.setDisplayName(following.get("displayName").toString());
|
||||||
peertubeAccounFollowingNotification.setName(following.get("name").toString());
|
peertubeAccounFollowingNotification.setName(following.get("name").toString());
|
||||||
|
try {
|
||||||
peertubeAccounFollowingNotification.setId(following.get("id").toString());
|
peertubeAccounFollowingNotification.setId(following.get("id").toString());
|
||||||
|
}catch (Exception ignored){}
|
||||||
if( following.has("avatar")){
|
if( following.has("avatar")){
|
||||||
peertubeAccounFollowingNotification.setAvatar(following.getJSONObject("avatar").get("path").toString());
|
peertubeAccounFollowingNotification.setAvatar(following.getJSONObject("avatar").get("path").toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,12 @@ package fr.gouv.etalab.mastodon.drawers;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.Html;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -56,7 +58,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter {
|
||||||
private List<PeertubeNotification> notifications;
|
private List<PeertubeNotification> notifications;
|
||||||
private LayoutInflater layoutInflater;
|
private LayoutInflater layoutInflater;
|
||||||
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
|
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
|
||||||
private PeertubeNotificationsListAdapter.ViewHolder holder;
|
|
||||||
private int style;
|
private int style;
|
||||||
|
|
||||||
public PeertubeNotificationsListAdapter(Context context, List<PeertubeNotification> notifications){
|
public PeertubeNotificationsListAdapter(Context context, List<PeertubeNotification> notifications){
|
||||||
|
@ -71,13 +73,13 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_notification, parent, false));
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_peertube_notification, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
|
||||||
holder = (PeertubeNotificationsListAdapter.ViewHolder) viewHolder;
|
ViewHolder holder = (ViewHolder) viewHolder;
|
||||||
PeertubeNotification notification = notifications.get(position);
|
PeertubeNotification notification = notifications.get(position);
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
@ -102,17 +104,21 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter {
|
||||||
PeertubeAccountNotification accountAction = null;
|
PeertubeAccountNotification accountAction = null;
|
||||||
PeertubeVideoNotification videoAction = null;
|
PeertubeVideoNotification videoAction = null;
|
||||||
if( notification.getPeertubeActorFollow() != null){
|
if( notification.getPeertubeActorFollow() != null){
|
||||||
|
String profileUrl = Helper.getLiveInstanceWithProtocol(context) + notification.getPeertubeActorFollow().getFollower().getAvatar();
|
||||||
Helper.loadGiF(context, notification.getPeertubeActorFollow().getFollower().getAvatar(), holder.peertube_notif_pp);
|
Helper.loadGiF(context,profileUrl, holder.peertube_notif_pp);
|
||||||
accountAction =notification.getPeertubeActorFollow().getFollower();
|
accountAction =notification.getPeertubeActorFollow().getFollower();
|
||||||
String type = notification.getPeertubeActorFollow().getFollowing().getType();
|
String type = notification.getPeertubeActorFollow().getFollowing().getType();
|
||||||
String message;
|
String message;
|
||||||
if( type.equals("account")){
|
if( type != null && type.equals("account")){
|
||||||
message = context.getString(R.string.peertube_follow_channel, accountAction.getDisplayName(), notification.getPeertubeActorFollow().getFollowing().getDisplayName());
|
message = context.getString(R.string.peertube_follow_channel, notification.getPeertubeActorFollow().getFollower().getDisplayName(), notification.getPeertubeActorFollow().getFollowing().getDisplayName());
|
||||||
}else{
|
}else{
|
||||||
message = context.getString(R.string.peertube_follow_account, accountAction.getDisplayName());
|
message = context.getString(R.string.peertube_follow_account, accountAction.getDisplayName());
|
||||||
}
|
}
|
||||||
holder.peertube_notif_message.setText(message);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY));
|
||||||
|
else
|
||||||
|
//noinspection deprecation
|
||||||
|
holder.peertube_notif_message.setText(Html.fromHtml(message));
|
||||||
PeertubeAccountNotification finalAccountAction1 = accountAction;
|
PeertubeAccountNotification finalAccountAction1 = accountAction;
|
||||||
holder.peertube_notif_pp.setOnClickListener(v -> {
|
holder.peertube_notif_pp.setOnClickListener(v -> {
|
||||||
Intent intent = new Intent(context, ShowAccountActivity.class);
|
Intent intent = new Intent(context, ShowAccountActivity.class);
|
||||||
|
@ -123,21 +129,30 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
});
|
});
|
||||||
}else if( notification.getPeertubeComment() != null){ //Comment Notification
|
}else if( notification.getPeertubeComment() != null){ //Comment Notification
|
||||||
Helper.loadGiF(context, notification.getPeertubeComment().getPeertubeAccountNotification().getAvatar(), holder.peertube_notif_pp);
|
String profileUrl = Helper.getLiveInstanceWithProtocol(context) + notification.getPeertubeComment().getPeertubeAccountNotification().getAvatar();
|
||||||
|
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
|
||||||
accountAction = notification.getPeertubeComment().getPeertubeAccountNotification();
|
accountAction = notification.getPeertubeComment().getPeertubeAccountNotification();
|
||||||
videoAction = notification.getPeertubeComment().getPeertubeVideoNotification();
|
videoAction = notification.getPeertubeComment().getPeertubeVideoNotification();
|
||||||
holder.peertube_notif_message.setText(context.getString(R.string.peertube_comment_on_video,accountAction.getDisplayName(), videoAction.getName()));
|
String message = context.getString(R.string.peertube_comment_on_video,accountAction.getDisplayName(), videoAction.getName());
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY));
|
||||||
|
else
|
||||||
|
//noinspection deprecation
|
||||||
|
holder.peertube_notif_message.setText(Html.fromHtml(message));
|
||||||
PeertubeVideoNotification finalVideoAction1 = videoAction;
|
PeertubeVideoNotification finalVideoAction1 = videoAction;
|
||||||
holder.peertube_notif_message.setOnClickListener(v -> {
|
holder.peertube_notif_message.setOnClickListener(v -> {
|
||||||
Intent intent = new Intent(context, PeertubeActivity.class);
|
Intent intent = new Intent(context, PeertubeActivity.class);
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
|
b.putString("peertube_instance", Helper.getLiveInstance(context));
|
||||||
b.putString("video_id", finalVideoAction1.getUuid());
|
b.putString("video_id", finalVideoAction1.getUuid());
|
||||||
intent.putExtras(b);
|
intent.putExtras(b);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
});
|
});
|
||||||
}else {//Other Notifications
|
}else {//Other Notifications
|
||||||
if (notification.getPeertubeVideoNotification() != null && notification.getPeertubeVideoNotification().getPeertubeAccountNotification() != null){
|
if (notification.getPeertubeVideoNotification() != null && notification.getPeertubeVideoNotification().getPeertubeAccountNotification() != null){
|
||||||
Helper.loadGiF(context, notification.getPeertubeVideoNotification().getPeertubeAccountNotification().getAvatar(), holder.peertube_notif_pp);
|
String profileUrl = Helper.getLiveInstanceWithProtocol(context) + notification.getPeertubeVideoNotification().getPeertubeAccountNotification().getAvatar();
|
||||||
|
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
|
||||||
accountAction = notification.getPeertubeVideoNotification().getPeertubeAccountNotification();
|
accountAction = notification.getPeertubeVideoNotification().getPeertubeAccountNotification();
|
||||||
videoAction = notification.getPeertubeVideoNotification();
|
videoAction = notification.getPeertubeVideoNotification();
|
||||||
String message = "";
|
String message = "";
|
||||||
|
@ -154,18 +169,23 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter {
|
||||||
}else if(notification.getType() == DisplayPeertubeNotificationsFragment.UNBLACKLIST_ON_MY_VIDEO){
|
}else if(notification.getType() == DisplayPeertubeNotificationsFragment.UNBLACKLIST_ON_MY_VIDEO){
|
||||||
message = context.getString(R.string.peertube_video_unblacklist, videoAction.getName());
|
message = context.getString(R.string.peertube_video_unblacklist, videoAction.getName());
|
||||||
}
|
}
|
||||||
holder.peertube_notif_message.setText(message);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY));
|
||||||
|
else
|
||||||
|
//noinspection deprecation
|
||||||
|
holder.peertube_notif_message.setText(Html.fromHtml(message));
|
||||||
PeertubeVideoNotification finalVideoAction = videoAction;
|
PeertubeVideoNotification finalVideoAction = videoAction;
|
||||||
holder.peertube_notif_message.setOnClickListener(v -> {
|
holder.peertube_notif_message.setOnClickListener(v -> {
|
||||||
Intent intent = new Intent(context, PeertubeActivity.class);
|
Intent intent = new Intent(context, PeertubeActivity.class);
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
|
b.putString("peertube_instance", Helper.getLiveInstance(context));
|
||||||
b.putString("video_id", finalVideoAction.getUuid());
|
b.putString("video_id", finalVideoAction.getUuid());
|
||||||
intent.putExtras(b);
|
intent.putExtras(b);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
holder.peertube_notif_date.setText(Helper.dateDiff(context, notification.getCreatedAt()));
|
||||||
PeertubeAccountNotification finalAccountAction = accountAction;
|
PeertubeAccountNotification finalAccountAction = accountAction;
|
||||||
holder.peertube_notif_pp.setOnClickListener(v -> {
|
holder.peertube_notif_pp.setOnClickListener(v -> {
|
||||||
if( finalAccountAction != null){
|
if( finalAccountAction != null){
|
||||||
|
|
|
@ -38,14 +38,12 @@ import java.util.List;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingNotificationsAsyncTask;
|
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeNotificationsAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeNotificationsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
import fr.gouv.etalab.mastodon.client.Entities.PeertubeNotification;
|
||||||
import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter;
|
import fr.gouv.etalab.mastodon.drawers.PeertubeNotificationsListAdapter;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingNotificationsInterface;
|
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeNotificationsInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeNotificationsInterface;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,16 +51,16 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeNotificationsInterfa
|
||||||
* Created by Thomas on 24/01/2019.
|
* Created by Thomas on 24/01/2019.
|
||||||
* Fragment to display peertube notifications
|
* Fragment to display peertube notifications
|
||||||
*/
|
*/
|
||||||
public class DisplayPeertubeNotificationsFragment extends Fragment implements OnRetrieveMissingNotificationsInterface, OnRetrievePeertubeNotificationsInterface {
|
public class DisplayPeertubeNotificationsFragment extends Fragment implements OnRetrievePeertubeNotificationsInterface {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean flag_loading;
|
private boolean flag_loading;
|
||||||
private Context context;
|
private Context context;
|
||||||
private AsyncTask<Void, Void, Void> asyncTask;
|
private AsyncTask<Void, Void, Void> asyncTask;
|
||||||
private NotificationsListAdapter notificationsListAdapter;
|
private PeertubeNotificationsListAdapter notificationsListAdapter;
|
||||||
private String max_id;
|
private String max_id;
|
||||||
private List<Notification> notifications;
|
private List<PeertubeNotification> notifications;
|
||||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||||
private boolean firstLoad;
|
private boolean firstLoad;
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
@ -113,7 +111,7 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
|
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
|
||||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
|
notificationsListAdapter = new PeertubeNotificationsListAdapter(context,this.notifications);
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
mLayoutManager = new LinearLayoutManager(context);
|
mLayoutManager = new LinearLayoutManager(context);
|
||||||
lv_notifications.setLayoutManager(mLayoutManager);
|
lv_notifications.setLayoutManager(mLayoutManager);
|
||||||
|
@ -145,15 +143,12 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
MainActivity.countNewNotifications = 0;
|
|
||||||
try {
|
try {
|
||||||
((MainActivity) context).updateNotifCounter();
|
((MainActivity) context).updateNotifCounter();
|
||||||
}catch (Exception ignored){}
|
}catch (Exception ignored){}
|
||||||
String sinceId = null;
|
if( context != null) {
|
||||||
if( notifications != null && notifications.size() > 0 )
|
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, max_id, DisplayPeertubeNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
sinceId = notifications.get(0).getId();
|
}
|
||||||
if( context != null)
|
|
||||||
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, sinceId, DisplayPeertubeNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
@ -216,26 +211,6 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called from main activity in onResume to retrieve missing notifications
|
|
||||||
* @param sinceId String
|
|
||||||
*/
|
|
||||||
public void retrieveMissingNotifications(String sinceId){
|
|
||||||
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, sinceId, DisplayPeertubeNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMenuVisibility(final boolean visible) {
|
|
||||||
super.setMenuVisibility(visible);
|
|
||||||
if( context == null)
|
|
||||||
return;
|
|
||||||
//Store last notification id to avoid to notify for those that have been already seen
|
|
||||||
if (visible && notifications != null && notifications.size() > 0) {
|
|
||||||
retrieveMissingNotifications(notifications.get(0).getId());
|
|
||||||
updateNotificationLastId(notifications.get(0).getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void scrollToTop(){
|
public void scrollToTop(){
|
||||||
if( lv_notifications != null)
|
if( lv_notifications != null)
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
|
@ -252,60 +227,13 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
MainActivity.countNewNotifications = 0;
|
|
||||||
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, null, DisplayPeertubeNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, null, DisplayPeertubeNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void refresh(Notification notification){
|
|
||||||
if( context == null)
|
|
||||||
return;
|
|
||||||
if( notification != null){
|
|
||||||
//Makes sure the notifications is not already displayed
|
|
||||||
if( !this.notifications.contains(notification)) {
|
|
||||||
//Update the id of the last notification retrieved
|
|
||||||
MainActivity.lastNotificationId = notification.getId();
|
|
||||||
notifications.add(0, notification);
|
|
||||||
MainActivity.countNewNotifications++;
|
|
||||||
try {
|
|
||||||
((MainActivity) context).updateNotifCounter();
|
|
||||||
}catch (Exception ignored){}
|
|
||||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
|
||||||
if (firstVisibleItem > 0)
|
|
||||||
notificationsListAdapter.notifyItemInserted(0);
|
|
||||||
else
|
|
||||||
notificationsListAdapter.notifyDataSetChanged();
|
|
||||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRetrieveMissingNotifications(List<Notification> notifications) {
|
|
||||||
flag_loading = false;
|
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
|
||||||
if( this.notifications != null && this.notifications.size() > 0){
|
|
||||||
notificationsListAdapter.notifyItemRangeChanged(0,this.notifications.size());
|
|
||||||
}
|
|
||||||
if( notifications != null && notifications.size() > 0) {
|
|
||||||
int inserted = 0;
|
|
||||||
for (int i = notifications.size()-1 ; i >= 0 ; i--) {
|
|
||||||
if (this.notifications != null && this.notifications.size() == 0 ||
|
|
||||||
Long.parseLong(notifications.get(i).getId()) > Long.parseLong(this.notifications.get(0).getId())) {
|
|
||||||
MainActivity.countNewNotifications++;
|
|
||||||
this.notifications.add(0, notifications.get(i));
|
|
||||||
inserted++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notificationsListAdapter.notifyItemRangeInserted(0,inserted);
|
|
||||||
try {
|
|
||||||
((MainActivity) context).updateNotifCounter();
|
|
||||||
}catch (Exception ignored){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,7 +245,6 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
|
|
||||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||||
if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
|
if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
|
||||||
MainActivity.countNewNotifications = 0;
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
@ -339,7 +266,7 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
|
|
||||||
int previousPosition = notifications.size();
|
int previousPosition = notifications.size();
|
||||||
max_id = apiResponse.getMax_id();
|
max_id = apiResponse.getMax_id();
|
||||||
List<Notification> notifications = apiResponse.getNotifications();
|
List<PeertubeNotification> notifications = apiResponse.getPeertubeNotifications();
|
||||||
|
|
||||||
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
@ -356,11 +283,8 @@ public class DisplayPeertubeNotificationsFragment extends Fragment implements O
|
||||||
}
|
}
|
||||||
|
|
||||||
if( notifications != null && notifications.size() > 0) {
|
if( notifications != null && notifications.size() > 0) {
|
||||||
for(Notification tmpNotification: notifications){
|
for(PeertubeNotification tmpNotification: notifications){
|
||||||
|
|
||||||
if( lastReadNotifications != null && Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications)) {
|
|
||||||
MainActivity.countNewNotifications++;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
((MainActivity) context).updateNotifCounter();
|
((MainActivity) context).updateNotifCounter();
|
||||||
}catch (Exception ignored){}
|
}catch (Exception ignored){}
|
||||||
|
|
|
@ -23,17 +23,27 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:paddingBottom="5dp"
|
android:paddingTop="10dp"
|
||||||
android:paddingTop="5dp"
|
android:layout_marginStart="5dp"
|
||||||
android:orientation="horizontal">
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:divider="?android:dividerHorizontal"
|
||||||
|
android:showDividers="end"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/peertube_notif_pp"
|
android:id="@+id/peertube_notif_pp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="top"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp" />
|
android:layout_height="50dp" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
android:layout_height="wrap_content" android:orientation="vertical">
|
android:layout_height="wrap_content" android:orientation="vertical">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/peertube_notif_date"
|
android:id="@+id/peertube_notif_date"
|
||||||
|
@ -46,10 +56,13 @@
|
||||||
android:id="@+id/peertube_notif_message"
|
android:id="@+id/peertube_notif_message"
|
||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
android:autoLink="web"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
|
|
@ -842,16 +842,16 @@
|
||||||
<string name="settings_category_label_hiddencontent">Hidden content</string>
|
<string name="settings_category_label_hiddencontent">Hidden content</string>
|
||||||
<string name="settings_category_label_composing">Composing</string>
|
<string name="settings_category_label_composing">Composing</string>
|
||||||
<string name="contact">Contacts</string>
|
<string name="contact">Contacts</string>
|
||||||
<string name="peertube_comment_on_video">%1$s commented your video %2$s</string>
|
<string name="peertube_comment_on_video"><![CDATA[<b>%1$s</b> commented your video <b>%2$s</b>]]></string>
|
||||||
<string name="peertube_follow_channel">%1$s is following your channel %2$s</string>
|
<string name="peertube_follow_channel"><![CDATA[<b>%1$s</b> is following your channel <b>%2$s</b>]]></string>
|
||||||
<string name="peertube_follow_account">%1$s is following your account</string>
|
<string name="peertube_follow_account"><![CDATA[<b>%1$s</b> is following your account]]></string>
|
||||||
|
|
||||||
<string name="peertube_video_published">Your video %1$s has been published</string>
|
<string name="peertube_video_published"><![CDATA[Your video <b>%1$s</b> has been published]]></string>
|
||||||
<string name="peertube_video_import_success">Your video import %1$s succeeded</string>
|
<string name="peertube_video_import_success"><![CDATA[Your video import <b>%1$s</b> succeeded]]></string>
|
||||||
<string name="peertube_video_import_error">Your video import %1$s failed</string>
|
<string name="peertube_video_import_error"><![CDATA[Your video import <b>%1$s</b> failed]]></string>
|
||||||
<string name="peertube_video_from_subscription">%1$s published a new video: %2$s</string>
|
<string name="peertube_video_from_subscription"><![CDATA[<b>%1$s</b> published a new video: <b>%2$s</b>]]></string>
|
||||||
<string name="peertube_video_blacklist">Your video %1$s has been blacklisted</string>
|
<string name="peertube_video_blacklist"><![CDATA[Your video <b>%1$s</b> has been blacklisted]]></string>
|
||||||
<string name="peertube_video_unblacklist">Your video %1$s has been unblacklisted</string>
|
<string name="peertube_video_unblacklist"><![CDATA[Your video <b>%1$s</b> has been unblacklisted]]></string>
|
||||||
<!-- end languages -->
|
<!-- end languages -->
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue