In-app notifications #969

Merged
akinwale merged 13 commits from in-app-notifications into master 2020-08-18 15:19:35 +02:00
8 changed files with 68 additions and 43 deletions
Showing only changes of commit 96808d1f29 - Show all commits

View file

@ -16,8 +16,8 @@ android {
applicationId "io.lbry.browser"
minSdkVersion 21
targetSdkVersion 29
versionCode 1516
versionName "0.15.16"
versionCode 1517
versionName "0.15.17"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@ -101,8 +101,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
__32bitImplementation 'io.lbry:lbrysdk32:0.79.1'
__64bitImplementation 'io.lbry:lbrysdk64:0.79.1'
__32bitImplementation 'io.lbry:lbrysdk32:0.80.0'
__64bitImplementation 'io.lbry:lbrysdk64:0.80.0'
}
apply plugin: 'com.google.gms.google-services'

View file

@ -121,6 +121,8 @@ 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";

View file

@ -148,7 +148,7 @@ import io.lbry.browser.tasks.lbryinc.FetchRewardsTask;
import io.lbry.browser.tasks.LighthouseAutoCompleteTask;
import io.lbry.browser.tasks.MergeSubscriptionsTask;
import io.lbry.browser.tasks.claim.ResolveTask;
import io.lbry.browser.tasks.lbryinc.ListNotificationsTask;
import io.lbry.browser.tasks.lbryinc.NotificationListTask;
import io.lbry.browser.tasks.localdata.FetchRecentUrlHistoryTask;
import io.lbry.browser.tasks.wallet.DefaultSyncTaskHandler;
import io.lbry.browser.tasks.wallet.LoadSharedUserStateTask;
@ -3147,7 +3147,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void loadRemoteNotifications() {
findViewById(R.id.notification_list_empty_container).setVisibility(View.GONE);
ListNotificationsTask task = new ListNotificationsTask(this, findViewById(R.id.notifications_progress), new ListNotificationsTask.ListNotificationsHandler() {
NotificationListTask task = new NotificationListTask(this, findViewById(R.id.notifications_progress), new NotificationListTask.ListNotificationsHandler() {
@Override
public void onSuccess(List<LbryNotification> notifications) {
loadLocalNotifications();
@ -3190,9 +3190,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
LbryUri target = LbryUri.tryParse(notification.getTargetUrl());
if (target != null) {
if (target.isChannel()) {
openChannelUrl(target.toString());
openChannelUrl(notification.getTargetUrl());
} else {
openFileUrl(target.toString());
openFileUrl(notification.getTargetUrl());
}
hideNotifications();
}

View file

@ -61,6 +61,16 @@ public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.
notifyDataSetChanged();
}
public int getPositionForComment(String commentHash) {
for (int i = 0; i < items.size(); i++) {
if (commentHash.equalsIgnoreCase(items.get(i).getId())) {
return i;
}
}
return -1;
}
@Override
public int getItemCount() {
return items != null ? items.size() : 0;

View file

@ -45,10 +45,12 @@ public class CommentListTask extends AsyncTask<Void, Void, List<Comment>> {
options.put("claim_id", claim);
options.put("page", page);
options.put("page_size", pageSize);
options.put("hidden", false);
options.put("include_replies", false);
options.put("is_channel_signature_valid", true);
options.put("skip_validation", true);
options.put("visible", true);
options.put("hidden", false);
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_COMMENT_LIST, options);
JSONArray items = result.getJSONArray("items");

View file

@ -25,13 +25,13 @@ import io.lbry.browser.model.lbryinc.LbryNotification;
import io.lbry.browser.utils.Helper;
import io.lbry.browser.utils.Lbryio;
public class ListNotificationsTask extends AsyncTask<Void, Void, List<LbryNotification>> {
public class NotificationListTask extends AsyncTask<Void, Void, List<LbryNotification>> {
private Context context;
private ListNotificationsHandler handler;
private ProgressBar progressBar;
private Exception error;
public ListNotificationsTask(Context context, ProgressBar progressBar, ListNotificationsHandler handler) {
public NotificationListTask(Context context, ProgressBar progressBar, ListNotificationsHandler handler) {
this.context = context;
this.progressBar = progressBar;
this.handler = handler;
@ -59,9 +59,14 @@ public class ListNotificationsTask extends AsyncTask<Void, Void, List<LbryNotifi
}
if (notificationParams.has("dynamic")) {
JSONObject dynamic = notificationParams.getJSONObject("dynamic");
String channelUrl = Helper.getJSONString("channelURI", null, dynamic);
if (!Helper.isNullOrEmpty(channelUrl)) {
notification.setTargetUrl(channelUrl);
if (dynamic.has("channelURI")) {
String channelUrl = Helper.getJSONString("channelURI", null, dynamic);
if (!Helper.isNullOrEmpty(channelUrl)) {
notification.setTargetUrl(channelUrl);
}
}
if (dynamic.has("hash") && "comment".equalsIgnoreCase(Helper.getJSONString("notification_rule", null, item))) {
notification.setTargetUrl(String.format("%s?comment_hash=%s", notification.getTargetUrl(), dynamic.getString("hash")));
}
}

View file

@ -233,6 +233,9 @@ public class FileViewFragment extends BaseFragment implements
private View inlineChannelCreatorProgress;
private MaterialButton inlineChannelCreatorCreateButton;
// if this is set, scroll to the specific comment on load
private String commentHash;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_file_view, container, false);
@ -357,9 +360,27 @@ public class FileViewFragment extends BaseFragment implements
}
}
if (params.containsKey("url")) {
newUrl = params.get("url").toString();
if (claim == null || !newUrl.equalsIgnoreCase(currentUrl)) {
updateRequired = true;
LbryUri newLbryUri = LbryUri.tryParse(params.get("url").toString());
if (newLbryUri != null) {
newUrl = newLbryUri.toString();
String qs = newLbryUri.getQueryString();
if (!Helper.isNullOrEmpty(qs)) {
String[] qsPairs = qs.split("&");
for (String pair : qsPairs) {
String[] parts = pair.split("=");
if (parts.length < 2) {
continue;
}
if ("comment_hash".equalsIgnoreCase(parts[0])) {
commentHash = parts[1];
break;
}
}
}
if (claim == null || !newUrl.equalsIgnoreCase(currentUrl)) {
updateRequired = true;
}
}
}
} else if (currentUrl != null) {
@ -567,7 +588,6 @@ public class FileViewFragment extends BaseFragment implements
}
checkOwnClaim();
fetchChannels();
checkAndLoadComments();
}
private String getStreamingUrl() {
@ -709,7 +729,6 @@ public class FileViewFragment extends BaseFragment implements
} else {
onSdkReady();
}
checkCommentSdkInitializing();
}
public void onStop() {
@ -1513,7 +1532,6 @@ public class FileViewFragment extends BaseFragment implements
private void checkAndLoadComments() {
View root = getView();
if (root != null) {
checkCommentSdkInitializing();
RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list);
if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) {
loadComments();
@ -1521,14 +1539,6 @@ public class FileViewFragment extends BaseFragment implements
}
}
private void checkCommentSdkInitializing() {
View root = getView();
if (root != null) {
TextView commentsSDKInitializing = root.findViewById(R.id.file_view_comments_sdk_initializing);
Helper.setViewVisibility(commentsSDKInitializing, Lbry.SDK_READY ? View.GONE : View.VISIBLE);
}
}
private void showUnsupportedView() {
View root = getView();
if (root != null) {
@ -2137,9 +2147,9 @@ public class FileViewFragment extends BaseFragment implements
private void loadComments() {
View root = getView();
ProgressBar relatedLoading = root.findViewById(R.id.file_view_comments_progress);
ProgressBar commentsLoading = root.findViewById(R.id.file_view_comments_progress);
if (claim != null && root != null) {
CommentListTask task = new CommentListTask(1, 500, claim.getClaimId(), relatedLoading, new CommentListHandler() {
CommentListTask task = new CommentListTask(1, 100, claim.getClaimId(), commentsLoading, new CommentListHandler() {
@Override
public void onSuccess(List<Comment> comments, boolean hasReachedEnd) {
Context ctx = getContext();
@ -2167,6 +2177,15 @@ 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);
}
}
checkNoComments();
resolveCommentPosters();
}

View file

@ -721,19 +721,6 @@
android:textSize="14sp"
android:visibility="gone" />
<TextView
android:id="@+id/file_view_comments_sdk_initializing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/inter"
android:text="@string/sdk_initializing_comments"
android:textFontWeight="300"
android:textSize="14sp"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/file_view_comments_list"
android:layout_width="match_parent"