1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +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.webservices.ProfileService;
import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
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) {
super.onViewCreated(view, savedInstanceState);
init();
if (id.contains("_")) fetchStory();
else fetchAvatar();
fetchAvatar();
}
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);
}
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() {
if (TextUtils.isEmpty(url)) {
url = fallbackUrl;

View File

@ -75,7 +75,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
@Override
public void onPreviewClick(final NotificationModel model) {
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 {
mediaService.fetch(model.getPostId(), new ServiceCallback<FeedModel>() {
@ -151,7 +153,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
return;
}
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;
}
final AlertDialog alertDialog = new AlertDialog.Builder(context)
@ -292,15 +296,4 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
.actionGlobalProfileFragment("@" + username);
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.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.FragmentStoryViewerBinding;
import awais.instagrabber.fragments.main.FeedFragment;
import awais.instagrabber.fragments.main.ProfileFragmentDirections;
import awais.instagrabber.interfaces.SwipeEvent;
import awais.instagrabber.models.FeedStoryModel;
@ -692,33 +693,57 @@ public class StoryViewerFragment extends Fragment {
}
storiesViewModel.getList().setValue(Collections.emptyList());
if (currentStoryMediaId == null) return;
final ServiceCallback<List<StoryModel>> storyCallback = new ServiceCallback<List<StoryModel>>() {
@Override
public void onSuccess(final List<StoryModel> storyModels) {
fetching = false;
if (storyModels == null || storyModels.isEmpty()) {
storiesViewModel.getList().setValue(Collections.emptyList());
currentStory = null;
else if (currentFeedStoryIndex == -1) {
storiesService.fetch(currentStoryMediaId, new ServiceCallback<StoryModel>() {
@Override
public void onSuccess(final StoryModel storyModel) {
fetching = false;
binding.storiesList.setVisibility(View.GONE);
return;
if (storyModel == null) {
storiesViewModel.getList().setValue(Collections.emptyList());
currentStory = null;
return;
}
storiesViewModel.getList().setValue(Collections.singletonList(storyModel));
currentStory = storyModel;
refreshStory();
}
binding.storiesList.setVisibility(View.VISIBLE);
storiesViewModel.getList().setValue(storyModels);
currentStory = storyModels.get(0);
refreshStory();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
};
storiesService.getUserStory(currentStoryMediaId,
currentStoryUsername,
isLoc,
isHashtag,
isHighlight,
storyCallback);
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
});
}
else {
final ServiceCallback<List<StoryModel>> storyCallback = new ServiceCallback<List<StoryModel>>() {
@Override
public void onSuccess(final List<StoryModel> storyModels) {
fetching = false;
if (storyModels == null || storyModels.isEmpty()) {
storiesViewModel.getList().setValue(Collections.emptyList());
currentStory = null;
binding.storiesList.setVisibility(View.GONE);
return;
}
binding.storiesList.setVisibility(View.VISIBLE);
storiesViewModel.getList().setValue(storyModels);
currentStory = storyModels.get(0);
refreshStory();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
};
storiesService.getUserStory(currentStoryMediaId,
currentStoryUsername,
isLoc,
isHashtag,
isHighlight,
storyCallback);
}
}
private void refreshStory() {

View File

@ -14,6 +14,9 @@
android:name="type"
app:argType="string"
app:nullable="false" />
<action
android:id="@+id/action_notificationsViewerFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
</fragment>
<action
@ -58,4 +61,37 @@
app:argType="boolean"
app:nullable="false" />
</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>