Browse Source

1. Fix NavDirection compile issue.

2. Fix null pointer if tab order pref is null.
3. Set initial tab order in pref if empty.
renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
bde319ecd4
  1. 7
      app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java
  2. 7
      app/src/main/java/awais/instagrabber/utils/Utils.java
  3. 38
      app/src/main/res/navigation/notification_viewer_nav_graph.xml

7
app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java

@ -79,7 +79,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(Throwable e) {}
catch(Throwable ignored) {}
} }
}; };
@ -92,7 +92,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
@Override @Override
public void onPreviewClick(final Notification model) { public void onPreviewClick(final Notification model) {
final NotificationImage notificationImage = model.getArgs().getMedia().get(0); final NotificationImage notificationImage = model.getArgs().getMedia().get(0);
final long mediaId = Long.valueOf(notificationImage.getId().split("_")[0]);
final long mediaId = Long.parseLong(notificationImage.getId().split("_")[0]);
if (model.getType() == NotificationType.RESPONDED_STORY) { if (model.getType() == NotificationType.RESPONDED_STORY) {
final NavDirections action = NotificationsViewerFragmentDirections final NavDirections action = NotificationsViewerFragmentDirections
.actionNotificationsViewerFragmentToStoryViewerFragment( .actionNotificationsViewerFragmentToStoryViewerFragment(
@ -277,8 +277,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
} }
private void openProfile(final String username) { private void openProfile(final String username) {
final NavDirections action = NotificationsViewerFragmentDirections
.actionGlobalProfileFragment("@" + username);
final NavDirections action = NotificationsViewerFragmentDirections.actionGlobalProfileFragment("@" + username);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
} }
} }

7
app/src/main/java/awais/instagrabber/utils/Utils.java

@ -31,7 +31,6 @@ import android.webkit.MimeTypeMap;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
@ -474,7 +473,10 @@ public final class Utils {
final List<String> navGraphNameList = Arrays.asList(navGraphNames); final List<String> navGraphNameList = Arrays.asList(navGraphNames);
if (TextUtils.isEmpty(tabOrderString)) { if (TextUtils.isEmpty(tabOrderString)) {
// Use top 5 entries for default list // Use top 5 entries for default list
return navGraphNameList.subList(0, 5);
final List<String> top5navGraphNames = navGraphNameList.subList(0, 5);
final String newOrderString = android.text.TextUtils.join(",", top5navGraphNames);
Utils.settingsHelper.putString(PreferenceKeys.PREF_TAB_ORDER, newOrderString);
return top5navGraphNames;
} }
// Make sure that the list from preference does not contain any invalid values // Make sure that the list from preference does not contain any invalid values
final List<String> orderGraphNames = Arrays.stream(tabOrderString.split(",")) final List<String> orderGraphNames = Arrays.stream(tabOrderString.split(","))
@ -489,6 +491,7 @@ public final class Utils {
} }
public static boolean isNavRootInCurrentTabs(final String navRootString) { public static boolean isNavRootInCurrentTabs(final String navRootString) {
if (navRootString == null || tabOrderString == null) return false;
return tabOrderString.contains(navRootString); return tabOrderString.contains(navRootString);
} }
} }

38
app/src/main/res/navigation/notification_viewer_nav_graph.xml

@ -5,25 +5,6 @@
android:id="@+id/notification_viewer_nav_graph" android:id="@+id/notification_viewer_nav_graph"
app:startDestination="@id/notificationsViewer"> app:startDestination="@id/notificationsViewer">
<fragment
android:id="@+id/notificationsViewer"
android:name="awais.instagrabber.fragments.NotificationsViewerFragment"
android:label="@string/title_notifications"
tools:layout="@layout/fragment_notifications_viewer">
<argument
android:name="type"
app:argType="string"
app:nullable="false"
android:defaultValue="notif"/>
<argument
android:name="targetId"
android:defaultValue="0L"
app:argType="long" />
<action
android:id="@+id/action_notificationsViewerFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
</fragment>
<include app:graph="@navigation/profile_nav_graph" /> <include app:graph="@navigation/profile_nav_graph" />
<action <action
@ -100,4 +81,23 @@
android:name="options" android:name="options"
app:argType="awais.instagrabber.repositories.requests.StoryViewerOptions" /> app:argType="awais.instagrabber.repositories.requests.StoryViewerOptions" />
</fragment> </fragment>
<fragment
android:id="@+id/notificationsViewer"
android:name="awais.instagrabber.fragments.NotificationsViewerFragment"
android:label="@string/title_notifications"
tools:layout="@layout/fragment_notifications_viewer">
<argument
android:name="type"
app:argType="string"
app:nullable="false"
android:defaultValue="notif"/>
<argument
android:name="targetId"
android:defaultValue="0L"
app:argType="long" />
<action
android:id="@+id/action_notificationsViewerFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
</fragment>
</navigation> </navigation>
Loading…
Cancel
Save