1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 08:37:29 +00:00

fix story notifications

This commit is contained in:
Austin Huang 2020-12-31 12:43:56 -05:00
parent d21df4d21b
commit d2e3f6c4df
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
4 changed files with 92 additions and 60 deletions

View File

@ -43,7 +43,6 @@ import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.ProfileService; import awais.instagrabber.webservices.ProfileService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
@ -104,8 +103,7 @@ public class ProfilePicDialogFragment extends DialogFragment {
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
init(); init();
if (id.contains("_")) fetchStory(); fetchAvatar();
else fetchAvatar();
} }
private void init() { private void init() {
@ -150,26 +148,6 @@ public class ProfilePicDialogFragment extends DialogFragment {
else new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
private void fetchStory() {
final StoriesService storiesService = StoriesService.getInstance();
storiesService.fetch(id, new ServiceCallback<StoryModel>() {
@Override
public void onSuccess(final StoryModel result) {
if (result != null) {
fetchListener.onResult(result.getStoryUrl());
}
}
@Override
public void onFailure(final Throwable t) {
final Context context = getContext();
Log.d("austin_debug", "error", t);
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
getDialog().dismiss();
}
});
}
private void setupPhoto() { private void setupPhoto() {
if (TextUtils.isEmpty(url)) { if (TextUtils.isEmpty(url)) {
url = fallbackUrl; url = fallbackUrl;

View File

@ -75,7 +75,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
@Override @Override
public void onPreviewClick(final NotificationModel model) { public void onPreviewClick(final NotificationModel model) {
if (model.getType() == NotificationType.RESPONDED_STORY) { if (model.getType() == NotificationType.RESPONDED_STORY) {
showProfilePicDialog(model); final NavDirections action = NotificationsViewerFragmentDirections.actionNotificationsViewerFragmentToStoryViewerFragment(
-1, null, false, false, model.getPostId(), model.getUsername(), false);
NavHostFragment.findNavController(NotificationsViewerFragment.this).navigate(action);
} }
else { else {
mediaService.fetch(model.getPostId(), new ServiceCallback<FeedModel>() { mediaService.fetch(model.getPostId(), new ServiceCallback<FeedModel>() {
@ -151,7 +153,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
return; return;
} }
else if (model.getType() == NotificationType.RESPONDED_STORY) { else if (model.getType() == NotificationType.RESPONDED_STORY) {
showProfilePicDialog(model); final NavDirections action = NotificationsViewerFragmentDirections.actionNotificationsViewerFragmentToStoryViewerFragment(
-1, null, false, false, model.getPostId(), model.getUsername(), false);
NavHostFragment.findNavController(NotificationsViewerFragment.this).navigate(action);
return; return;
} }
final AlertDialog alertDialog = new AlertDialog.Builder(context) final AlertDialog alertDialog = new AlertDialog.Builder(context)
@ -292,15 +296,4 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
.actionGlobalProfileFragment("@" + username); .actionGlobalProfileFragment("@" + username);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
} }
private void showProfilePicDialog(final NotificationModel model) {
final FragmentManager fragmentManager = getParentFragmentManager();
final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(model.getPostId(),
model.getUsername(),
model.getPreviewPic());
final FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.add(fragment, "profilePicDialog")
.commit();
}
} }

View File

@ -74,6 +74,7 @@ import awais.instagrabber.asyncs.direct_messages.CreateThreadAction;
import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster;
import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.FragmentStoryViewerBinding; import awais.instagrabber.databinding.FragmentStoryViewerBinding;
import awais.instagrabber.fragments.main.FeedFragment;
import awais.instagrabber.fragments.main.ProfileFragmentDirections; import awais.instagrabber.fragments.main.ProfileFragmentDirections;
import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.interfaces.SwipeEvent;
import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.FeedStoryModel;
@ -692,6 +693,29 @@ public class StoryViewerFragment extends Fragment {
} }
storiesViewModel.getList().setValue(Collections.emptyList()); storiesViewModel.getList().setValue(Collections.emptyList());
if (currentStoryMediaId == null) return; if (currentStoryMediaId == null) return;
else if (currentFeedStoryIndex == -1) {
storiesService.fetch(currentStoryMediaId, new ServiceCallback<StoryModel>() {
@Override
public void onSuccess(final StoryModel storyModel) {
fetching = false;
binding.storiesList.setVisibility(View.GONE);
if (storyModel == null) {
storiesViewModel.getList().setValue(Collections.emptyList());
currentStory = null;
return;
}
storiesViewModel.getList().setValue(Collections.singletonList(storyModel));
currentStory = storyModel;
refreshStory();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
});
}
else {
final ServiceCallback<List<StoryModel>> storyCallback = new ServiceCallback<List<StoryModel>>() { final ServiceCallback<List<StoryModel>> storyCallback = new ServiceCallback<List<StoryModel>>() {
@Override @Override
public void onSuccess(final List<StoryModel> storyModels) { public void onSuccess(final List<StoryModel> storyModels) {
@ -720,6 +744,7 @@ public class StoryViewerFragment extends Fragment {
isHighlight, isHighlight,
storyCallback); storyCallback);
} }
}
private void refreshStory() { private void refreshStory() {
if (binding.storiesList.getVisibility() == View.VISIBLE) { if (binding.storiesList.getVisibility() == View.VISIBLE) {

View File

@ -14,6 +14,9 @@
android:name="type" android:name="type"
app:argType="string" app:argType="string"
app:nullable="false" /> app:nullable="false" />
<action
android:id="@+id/action_notificationsViewerFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
</fragment> </fragment>
<action <action
@ -58,4 +61,37 @@
app:argType="boolean" app:argType="boolean"
app:nullable="false" /> app:nullable="false" />
</action> </action>
<fragment
android:id="@+id/storyViewerFragment"
android:name="awais.instagrabber.fragments.StoryViewerFragment"
android:label="StoryViewerFragment"
tools:layout="@layout/fragment_story_viewer">
<argument
android:name="feedStoryIndex"
app:argType="integer"
app:nullable="false" />
<argument
android:name="highlight"
app:argType="string"
app:nullable="true" />
<argument
android:name="isHashtag"
app:argType="boolean" />
<argument
android:name="isLoc"
app:argType="boolean" />
<argument
android:name="profileId"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
<argument
android:name="isArchive"
app:argType="boolean"
app:nullable="false" />
</fragment>
</navigation> </navigation>