1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-09-28 21:57:30 +00:00

Fix ProfilePicDialogFragment instantiation. Fixes https://github.com/austinhuang0131/barinsta/issues/746

This commit is contained in:
Ammar Githam 2021-03-16 22:25:03 +09:00
parent 747745c6d5
commit 04637da854
2 changed files with 62 additions and 52 deletions

View File

@ -41,20 +41,26 @@ import static awais.instagrabber.utils.Utils.settingsHelper;
public class ProfilePicDialogFragment extends DialogFragment { public class ProfilePicDialogFragment extends DialogFragment {
private static final String TAG = "ProfilePicDlgFragment"; private static final String TAG = "ProfilePicDlgFragment";
private final long id; private long id;
private final String name; private String name;
private final String fallbackUrl; private String fallbackUrl;
private boolean isLoggedIn; private boolean isLoggedIn;
private DialogProfilepicBinding binding; private DialogProfilepicBinding binding;
private String url; private String url;
public ProfilePicDialogFragment(final long id, final String name, final String fallbackUrl) { public static ProfilePicDialogFragment getInstance(final long id, final String name, final String fallbackUrl) {
this.id = id; final Bundle args = new Bundle();
this.name = name; args.putLong("id", id);
this.fallbackUrl = fallbackUrl; args.putString("name", name);
args.putString("fallbackUrl", fallbackUrl);
final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment();
fragment.setArguments(args);
return fragment;
} }
public ProfilePicDialogFragment() {}
@Override @Override
public View onCreateView(@NonNull final LayoutInflater inflater, public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container, final ViewGroup container,
@ -94,6 +100,14 @@ public class ProfilePicDialogFragment extends DialogFragment {
} }
private void init() { private void init() {
final Bundle arguments = getArguments();
if (arguments == null) {
dismiss();
return;
}
id = arguments.getLong("id");
name = arguments.getString("name");
fallbackUrl = arguments.getString("fallbackUrl");
binding.download.setOnClickListener(v -> { binding.download.setOnClickListener(v -> {
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
@ -127,11 +141,12 @@ public class ProfilePicDialogFragment extends DialogFragment {
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
final Context context = getContext(); final Context context = getContext();
try { if (context == null) {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); dismiss();
return;
} }
catch(final Throwable e) {} Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
getDialog().dismiss(); dismiss();
} }
}); });
} else setupPhoto(fallbackUrl); } else setupPhoto(fallbackUrl);

View File

@ -375,8 +375,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (profileModel != null) { if (profileModel != null) {
restrictMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie))); restrictMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
restrictMenuItem.setTitle(profileModel.getFriendshipStatus().isRestricted() ? R.string.unrestrict : R.string.restrict); restrictMenuItem.setTitle(profileModel.getFriendshipStatus().isRestricted() ? R.string.unrestrict : R.string.restrict);
} } else {
else {
restrictMenuItem.setVisible(false); restrictMenuItem.setVisible(false);
} }
} }
@ -394,8 +393,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (profileModel != null) { if (profileModel != null) {
mutePostsMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie))); mutePostsMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.mute_posts : R.string.unmute_posts); mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.mute_posts : R.string.unmute_posts);
} } else {
else {
mutePostsMenuItem.setVisible(false); mutePostsMenuItem.setVisible(false);
} }
} }
@ -403,8 +401,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (chainingMenuItem != null) { if (chainingMenuItem != null) {
if (profileModel != null) { if (profileModel != null) {
chainingMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie))); chainingMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
} } else {
else {
chainingMenuItem.setVisible(false); chainingMenuItem.setVisible(false);
} }
} }
@ -644,8 +641,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
isLoggedIn ? R.string.error_loading_profile_loggedin : R.string.error_loading_profile, isLoggedIn ? R.string.error_loading_profile_loggedin : R.string.error_loading_profile,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
else Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); else Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} } catch (final Throwable e) {}
catch(final Throwable e) {}
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -784,8 +780,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
final String biography = profileModel.getBiography(); final String biography = profileModel.getBiography();
if (TextUtils.isEmpty(biography)) { if (TextUtils.isEmpty(biography)) {
profileDetailsBinding.mainBiography.setVisibility(View.GONE); profileDetailsBinding.mainBiography.setVisibility(View.GONE);
} } else {
else {
profileDetailsBinding.mainBiography.setVisibility(View.VISIBLE); profileDetailsBinding.mainBiography.setVisibility(View.VISIBLE);
profileDetailsBinding.mainBiography.setText(biography); profileDetailsBinding.mainBiography.setText(biography);
profileDetailsBinding.mainBiography.addOnHashtagListener(autoLinkItem -> { profileDetailsBinding.mainBiography.addOnHashtagListener(autoLinkItem -> {
@ -855,8 +850,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
String profileContext = profileModel.getProfileContext(); String profileContext = profileModel.getProfileContext();
if (TextUtils.isEmpty(profileContext)) { if (TextUtils.isEmpty(profileContext)) {
profileDetailsBinding.profileContext.setVisibility(View.GONE); profileDetailsBinding.profileContext.setVisibility(View.GONE);
} } else {
else {
profileDetailsBinding.profileContext.setVisibility(View.VISIBLE); profileDetailsBinding.profileContext.setVisibility(View.VISIBLE);
final List<UserProfileContextLink> userProfileContextLinks = profileModel.getProfileContextLinks(); final List<UserProfileContextLink> userProfileContextLinks = profileModel.getProfileContextLinks();
for (int i = 0; i < userProfileContextLinks.size(); i++) { for (int i = 0; i < userProfileContextLinks.size(); i++) {
@ -1037,8 +1031,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
})) }))
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
} } else if (profileModel.getFriendshipStatus().isFollowing() || profileModel.getFriendshipStatus().isOutgoingRequest()) {
else if (profileModel.getFriendshipStatus().isFollowing() || profileModel.getFriendshipStatus().isOutgoingRequest()) {
friendshipService.unfollow( friendshipService.unfollow(
profileModel.getPk(), profileModel.getPk(),
new ServiceCallback<FriendshipChangeResponse>() { new ServiceCallback<FriendshipChangeResponse>() {
@ -1149,7 +1142,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void showProfilePicDialog() { private void showProfilePicDialog() {
if (profileModel != null) { if (profileModel != null) {
final FragmentManager fragmentManager = getParentFragmentManager(); final FragmentManager fragmentManager = getParentFragmentManager();
final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(profileModel.getPk(), username, profileModel.getProfilePicUrl()); final ProfilePicDialogFragment fragment = ProfilePicDialogFragment.getInstance(profileModel.getPk(),
username,
profileModel.getProfilePicUrl());
final FragmentTransaction ft = fragmentManager.beginTransaction(); final FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.add(fragment, "profilePicDialog") .add(fragment, "profilePicDialog")