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" applicationId "io.lbry.browser"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 1516 versionCode 1517
versionName "0.15.16" versionName "0.15.17"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -101,8 +101,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
__32bitImplementation 'io.lbry:lbrysdk32:0.79.1' __32bitImplementation 'io.lbry:lbrysdk32:0.80.0'
__64bitImplementation 'io.lbry:lbrysdk64:0.79.1' __64bitImplementation 'io.lbry:lbrysdk64:0.80.0'
} }
apply plugin: 'com.google.gms.google-services' 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) { private void sendNotification(String title, String messageBody, String type, String url, String name) {
//Intent intent = new Intent(this, MainActivity.class); //Intent intent = new Intent(this, MainActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //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 (url == null) {
if (TYPE_REWARD.equals(type)) { if (TYPE_REWARD.equals(type)) {
url = "lbry://?rewards"; 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.LighthouseAutoCompleteTask;
import io.lbry.browser.tasks.MergeSubscriptionsTask; import io.lbry.browser.tasks.MergeSubscriptionsTask;
import io.lbry.browser.tasks.claim.ResolveTask; 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.localdata.FetchRecentUrlHistoryTask;
import io.lbry.browser.tasks.wallet.DefaultSyncTaskHandler; import io.lbry.browser.tasks.wallet.DefaultSyncTaskHandler;
import io.lbry.browser.tasks.wallet.LoadSharedUserStateTask; import io.lbry.browser.tasks.wallet.LoadSharedUserStateTask;
@ -3147,7 +3147,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void loadRemoteNotifications() { private void loadRemoteNotifications() {
findViewById(R.id.notification_list_empty_container).setVisibility(View.GONE); 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 @Override
public void onSuccess(List<LbryNotification> notifications) { public void onSuccess(List<LbryNotification> notifications) {
loadLocalNotifications(); loadLocalNotifications();
@ -3190,9 +3190,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
LbryUri target = LbryUri.tryParse(notification.getTargetUrl()); LbryUri target = LbryUri.tryParse(notification.getTargetUrl());
if (target != null) { if (target != null) {
if (target.isChannel()) { if (target.isChannel()) {
openChannelUrl(target.toString()); openChannelUrl(notification.getTargetUrl());
} else { } else {
openFileUrl(target.toString()); openFileUrl(notification.getTargetUrl());
} }
hideNotifications(); hideNotifications();
} }

View file

@ -61,6 +61,16 @@ public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.
notifyDataSetChanged(); 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 @Override
public int getItemCount() { public int getItemCount() {
return items != null ? items.size() : 0; 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("claim_id", claim);
options.put("page", page); options.put("page", page);
options.put("page_size", pageSize); options.put("page_size", pageSize);
options.put("hidden", false);
options.put("include_replies", false); options.put("include_replies", false);
options.put("is_channel_signature_valid", true); options.put("is_channel_signature_valid", true);
options.put("skip_validation", true);
options.put("visible", true); options.put("visible", true);
options.put("hidden", false);
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_COMMENT_LIST, options); JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_COMMENT_LIST, options);
JSONArray items = result.getJSONArray("items"); 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.Helper;
import io.lbry.browser.utils.Lbryio; 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 Context context;
private ListNotificationsHandler handler; private ListNotificationsHandler handler;
private ProgressBar progressBar; private ProgressBar progressBar;
private Exception error; private Exception error;
public ListNotificationsTask(Context context, ProgressBar progressBar, ListNotificationsHandler handler) { public NotificationListTask(Context context, ProgressBar progressBar, ListNotificationsHandler handler) {
this.context = context; this.context = context;
this.progressBar = progressBar; this.progressBar = progressBar;
this.handler = handler; this.handler = handler;
@ -59,9 +59,14 @@ public class ListNotificationsTask extends AsyncTask<Void, Void, List<LbryNotifi
} }
if (notificationParams.has("dynamic")) { if (notificationParams.has("dynamic")) {
JSONObject dynamic = notificationParams.getJSONObject("dynamic"); JSONObject dynamic = notificationParams.getJSONObject("dynamic");
String channelUrl = Helper.getJSONString("channelURI", null, dynamic); if (dynamic.has("channelURI")) {
if (!Helper.isNullOrEmpty(channelUrl)) { String channelUrl = Helper.getJSONString("channelURI", null, dynamic);
notification.setTargetUrl(channelUrl); 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 View inlineChannelCreatorProgress;
private MaterialButton inlineChannelCreatorCreateButton; private MaterialButton inlineChannelCreatorCreateButton;
// if this is set, scroll to the specific comment on load
private String commentHash;
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_file_view, container, false); 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")) { if (params.containsKey("url")) {
newUrl = params.get("url").toString(); LbryUri newLbryUri = LbryUri.tryParse(params.get("url").toString());
if (claim == null || !newUrl.equalsIgnoreCase(currentUrl)) { if (newLbryUri != null) {
updateRequired = true; 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) { } else if (currentUrl != null) {
@ -567,7 +588,6 @@ public class FileViewFragment extends BaseFragment implements
} }
checkOwnClaim(); checkOwnClaim();
fetchChannels(); fetchChannels();
checkAndLoadComments();
} }
private String getStreamingUrl() { private String getStreamingUrl() {
@ -709,7 +729,6 @@ public class FileViewFragment extends BaseFragment implements
} else { } else {
onSdkReady(); onSdkReady();
} }
checkCommentSdkInitializing();
} }
public void onStop() { public void onStop() {
@ -1513,7 +1532,6 @@ public class FileViewFragment extends BaseFragment implements
private void checkAndLoadComments() { private void checkAndLoadComments() {
View root = getView(); View root = getView();
if (root != null) { if (root != null) {
checkCommentSdkInitializing();
RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list); RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list);
if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) { if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) {
loadComments(); 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() { private void showUnsupportedView() {
View root = getView(); View root = getView();
if (root != null) { if (root != null) {
@ -2137,9 +2147,9 @@ public class FileViewFragment extends BaseFragment implements
private void loadComments() { private void loadComments() {
View root = getView(); 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) { 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 @Override
public void onSuccess(List<Comment> comments, boolean hasReachedEnd) { public void onSuccess(List<Comment> comments, boolean hasReachedEnd) {
Context ctx = getContext(); Context ctx = getContext();
@ -2167,6 +2177,15 @@ public class FileViewFragment extends BaseFragment implements
relatedContentList.setAdapter(commentListAdapter); relatedContentList.setAdapter(commentListAdapter);
commentListAdapter.notifyDataSetChanged(); 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(); checkNoComments();
resolveCommentPosters(); resolveCommentPosters();
} }

View file

@ -721,19 +721,6 @@
android:textSize="14sp" android:textSize="14sp"
android:visibility="gone" /> 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 <androidx.recyclerview.widget.RecyclerView
android:id="@+id/file_view_comments_list" android:id="@+id/file_view_comments_list"
android:layout_width="match_parent" android:layout_width="match_parent"