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 {
private static final String TAG = "ProfilePicDlgFragment";
private final long id;
private final String name;
private final String fallbackUrl;
private long id;
private String name;
private String fallbackUrl;
private boolean isLoggedIn;
private DialogProfilepicBinding binding;
private String url;
public ProfilePicDialogFragment(final long id, final String name, final String fallbackUrl) {
this.id = id;
this.name = name;
this.fallbackUrl = fallbackUrl;
public static ProfilePicDialogFragment getInstance(final long id, final String name, final String fallbackUrl) {
final Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", name);
args.putString("fallbackUrl", fallbackUrl);
final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment();
fragment.setArguments(args);
return fragment;
}
public ProfilePicDialogFragment() {}
@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container,
@ -94,6 +100,14 @@ public class ProfilePicDialogFragment extends DialogFragment {
}
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 -> {
final Context context = getContext();
if (context == null) return;
@ -127,11 +141,12 @@ public class ProfilePicDialogFragment extends DialogFragment {
@Override
public void onFailure(final Throwable t) {
final Context context = getContext();
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
if (context == null) {
dismiss();
return;
}
catch(final Throwable e) {}
getDialog().dismiss();
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
dismiss();
}
});
} else setupPhoto(fallbackUrl);

View File

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