In-app notifications #969
3 changed files with 27 additions and 12 deletions
|
@ -23,6 +23,7 @@ import com.google.firebase.messaging.RemoteMessage;
|
|||
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.model.lbryinc.LbryNotification;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -54,6 +55,7 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
|
|||
String title = payload.get("title");
|
||||
String body = payload.get("body");
|
||||
String name = payload.get("name"); // notification name
|
||||
String hash = payload.get("hash"); // comment hash
|
||||
|
||||
if (type != null && getEnabledTypes().indexOf(type) > -1 && body != null && body.trim().length() > 0) {
|
||||
// only log the receive event for valid notifications received
|
||||
|
@ -63,6 +65,10 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
|
|||
firebaseAnalytics.logEvent(LbryAnalytics.EVENT_LBRY_NOTIFICATION_RECEIVE, bundle);
|
||||
}
|
||||
|
||||
if (!Helper.isNullOrEmpty(hash)) {
|
||||
url = String.format("%s?comment_hash=%s", url, hash);
|
||||
}
|
||||
|
||||
sendNotification(title, body, type, url, name);
|
||||
}
|
||||
|
||||
|
@ -121,8 +127,6 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
|
|||
private void sendNotification(String title, String messageBody, String type, String url, String name) {
|
||||
//Intent intent = new Intent(this, MainActivity.class);
|
||||
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
android.util.Log.d("#HELP", "Title=" + title + "; Body=" + messageBody + "; Type=" + type +"; url=" + url + "; name=" + name);
|
||||
|
||||
if (url == null) {
|
||||
if (TYPE_REWARD.equals(type)) {
|
||||
url = "lbry://?rewards";
|
||||
|
|
|
@ -57,7 +57,7 @@ public class NotificationListTask extends AsyncTask<Void, Void, List<LbryNotific
|
|||
notification.setDescription(Helper.getJSONString("text", null, device));
|
||||
notification.setTargetUrl(Helper.getJSONString("target", null, device));
|
||||
}
|
||||
if (notificationParams.has("dynamic")) {
|
||||
if (notificationParams.has("dynamic") && !notificationParams.isNull("dynamic")) {
|
||||
JSONObject dynamic = notificationParams.getJSONObject("dynamic");
|
||||
if (dynamic.has("channelURI")) {
|
||||
String channelUrl = Helper.getJSONString("channelURI", null, dynamic);
|
||||
|
|
|
@ -38,6 +38,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -2133,6 +2134,10 @@ public class FileViewFragment extends BaseFragment implements
|
|||
v.findViewById(R.id.file_view_no_related_content),
|
||||
relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
// if related content loads before comment, this will affect the scroll position
|
||||
// so just ensure that we are at the correct position
|
||||
scrollToCommentHash();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2177,15 +2182,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
relatedContentList.setAdapter(commentListAdapter);
|
||||
commentListAdapter.notifyDataSetChanged();
|
||||
|
||||
// check for the position of commentHash if set
|
||||
if (!Helper.isNullOrEmpty(commentHash)) {
|
||||
int position = commentListAdapter.getPositionForComment(commentHash);
|
||||
if (position > -1) {
|
||||
android.util.Log.d("#HELP", "scrolling to position: " + position);
|
||||
relatedContentList.getLayoutManager().scrollToPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
scrollToCommentHash();
|
||||
checkNoComments();
|
||||
resolveCommentPosters();
|
||||
}
|
||||
|
@ -2200,6 +2197,20 @@ public class FileViewFragment extends BaseFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private void scrollToCommentHash() {
|
||||
View root = getView();
|
||||
// check for the position of commentHash if set
|
||||
if (root != null && !Helper.isNullOrEmpty(commentHash) && commentListAdapter != null && commentListAdapter.getItemCount() > 0) {
|
||||
RecyclerView commentList = root.findViewById(R.id.file_view_comments_list);
|
||||
int position = commentListAdapter.getPositionForComment(commentHash);
|
||||
if (position > -1) {
|
||||
NestedScrollView scrollView = root.findViewById(R.id.file_view_scroll_view);
|
||||
scrollView.requestChildFocus(commentList, commentList);
|
||||
commentList.getLayoutManager().scrollToPosition(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNoComments() {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
|
|
Loading…
Reference in a new issue