Handle special URLs from notifications. Disable auto load/play for comment notifications.

This commit is contained in:
Akinwale Ariwodola 2020-08-20 16:39:45 +01:00
parent 47cbc3624c
commit d21cfd55ab
2 changed files with 34 additions and 14 deletions

View file

@ -202,8 +202,11 @@ import lombok.Setter;
import okhttp3.OkHttpClient;
public class MainActivity extends AppCompatActivity implements SdkStatusListener {
private static final String CHANNEL_ID_PLAYBACK = "io.lbry.browser.LBRY_PLAYBACK_CHANNEL";
private static final int PLAYBACK_NOTIFICATION_ID = 3;
private static final String SPECIAL_URL_PREFIX = "lbry://?";
public static final String SKU_SKIP = "lbryskip";
static final String SKU_SKIP = "lbryskip";
private Map<String, Class> specialRouteFragmentClassMap;
@Getter
private boolean inPictureInPictureMode;
@ -888,6 +891,21 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
openFragment(FileViewFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
}
private void openSpecialUrl(String url) {
String specialPath = url.substring(8).toLowerCase();
if (specialRouteFragmentClassMap.containsKey(specialPath)) {
Class fragmentClass = specialRouteFragmentClassMap.get(specialPath);
if (fragmentClassNavIdMap.containsKey(fragmentClass)) {
openFragment(
specialRouteFragmentClassMap.get(specialPath),
true,
fragmentClassNavIdMap.get(fragmentClass),
null
);
}
}
}
public void openSendTo(String path) {
Map<String, Object> params = new HashMap<>();
params.put("directFilePath", path);
@ -1719,9 +1737,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
mediaSession.setActive(true);
}
private static final String CHANNEL_ID_PLAYBACK = "io.lbry.browser.LBRY_PLAYBACK_CHANNEL";
private static final int PLAYBACK_NOTIFICATION_ID = 3;
public void initNotificationsPage() {
findViewById(R.id.notification_list_empty_container).setVisibility(View.VISIBLE);
@ -2687,7 +2702,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
if (data != null) {
String url = data.toString();
// check special urls
if (url.startsWith("lbry://?")) {
if (url.startsWith(SPECIAL_URL_PREFIX)) {
String specialPath = url.substring(8).toLowerCase();
if (specialRouteFragmentClassMap.containsKey(specialPath)) {
Class fragmentClass = specialRouteFragmentClassMap.get(specialPath);
@ -3291,6 +3306,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
notificationListAdapter.notifyDataSetChanged();
}
String targetUrl = notification.getTargetUrl();
if (targetUrl.startsWith(SPECIAL_URL_PREFIX)) {
openSpecialUrl(targetUrl);
} else {
LbryUri target = LbryUri.tryParse(notification.getTargetUrl());
if (target != null) {
if (target.isChannel()) {
@ -3298,9 +3317,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
} else {
openFileUrl(notification.getTargetUrl());
}
hideNotifications();
}
}
hideNotifications();
}
});
((RecyclerView) findViewById(R.id.notifications_list)).setAdapter(notificationListAdapter);

View file

@ -1489,7 +1489,7 @@ public class FileViewFragment extends BaseFragment implements
}
}
if (claim.isFree()) {
if (claim.isFree() && Helper.isNullOrEmpty(commentHash)) {
if (claim.isPlayable() || (!Lbry.SDK_READY && Lbryio.isSignedIn())) {
if (MainActivity.nowPlayingClaim != null && MainActivity.nowPlayingClaim.getClaimId().equalsIgnoreCase(claim.getClaimId())) {
// claim already playing
@ -1507,7 +1507,7 @@ public class FileViewFragment extends BaseFragment implements
restoreMainActionButton();
}
if (Lbry.SDK_READY && !claim.isPlayable() && !claim.isViewable()) {
if (Lbry.SDK_READY && !claim.isPlayable() && !claim.isViewable() && Helper.isNullOrEmpty(commentHash)) {
if (claim.getFile() == null) {
loadFile();
} else {