proper back navigation to the notifications screen #1006

Merged
akinwale merged 1 commit from notification-back into master 2020-09-09 15:05:30 +02:00
2 changed files with 37 additions and 6 deletions

View file

@ -863,12 +863,18 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
openFragment(PublishFormFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params); openFragment(PublishFormFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);
} }
public void openChannelUrl(String url) { public void openChannelUrl(String url, String source) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("url", url); params.put("url", url);
params.put("claim", getCachedClaimForUrl(url)); params.put("claim", getCachedClaimForUrl(url));
if (!Helper.isNullOrEmpty(source)) {
params.put("source", source);
}
openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params); openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
} }
public void openChannelUrl(String url) {
openChannelUrl(url, null);
}
private Claim getCachedClaimForUrl(String url) { private Claim getCachedClaimForUrl(String url) {
ClaimCacheKey key = new ClaimCacheKey(); ClaimCacheKey key = new ClaimCacheKey();
@ -889,21 +895,33 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
} }
public void openFileUrl(String url) { public void openFileUrl(String url) {
openFileUrl(url, null);
}
public void openFileUrl(String url, String source) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("url", url); params.put("url", url);
if (!Helper.isNullOrEmpty(source)) {
params.put("source", source);
}
openFragment(FileViewFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params); openFragment(FileViewFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
} }
private void openSpecialUrl(String url) { private void openSpecialUrl(String url, String source) {
String specialPath = url.substring(8).toLowerCase(); String specialPath = url.substring(8).toLowerCase();
if (specialRouteFragmentClassMap.containsKey(specialPath)) { if (specialRouteFragmentClassMap.containsKey(specialPath)) {
Class fragmentClass = specialRouteFragmentClassMap.get(specialPath); Class fragmentClass = specialRouteFragmentClassMap.get(specialPath);
if (fragmentClassNavIdMap.containsKey(fragmentClass)) { if (fragmentClassNavIdMap.containsKey(fragmentClass)) {
Map<String, Object> params = null;
if (!Helper.isNullOrEmpty(source)) {
params = new HashMap<>();
params.put("source", source);
}
openFragment( openFragment(
specialRouteFragmentClassMap.get(specialPath), specialRouteFragmentClassMap.get(specialPath),
true, true,
fragmentClassNavIdMap.get(fragmentClass), fragmentClassNavIdMap.get(fragmentClass),
null params
); );
} }
} }
@ -2241,6 +2259,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
public void navigateBackToNotifications() {
showNotifications();
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (findViewById(R.id.url_suggestions_container).getVisibility() == View.VISIBLE) { if (findViewById(R.id.url_suggestions_container).getVisibility() == View.VISIBLE) {
@ -2251,6 +2273,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
hideNotifications(); hideNotifications();
return; return;
} }
if (backPressInterceptor != null && backPressInterceptor.onBackPressed()) { if (backPressInterceptor != null && backPressInterceptor.onBackPressed()) {
return; return;
} }
@ -3321,14 +3344,14 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
String targetUrl = notification.getTargetUrl(); String targetUrl = notification.getTargetUrl();
if (targetUrl.startsWith(SPECIAL_URL_PREFIX)) { if (targetUrl.startsWith(SPECIAL_URL_PREFIX)) {
openSpecialUrl(targetUrl); openSpecialUrl(targetUrl, "notification");
} else { } else {
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(notification.getTargetUrl()); openChannelUrl(notification.getTargetUrl(), "notification");
} else { } else {
openFileUrl(notification.getTargetUrl()); openFileUrl(notification.getTargetUrl(), "notification");
} }
} }
} }

View file

@ -65,6 +65,14 @@ public class BaseFragment extends Fragment {
MainActivity.resumeGlobalPlayer(context); MainActivity.resumeGlobalPlayer(context);
} }
} }
if (params != null && params.containsKey("source") && "notification".equalsIgnoreCase(params.get("source").toString())) {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).navigateBackToNotifications();
}
}
rewardDriverClickListenerSet = false; rewardDriverClickListenerSet = false;
super.onStop(); super.onStop();
} }