mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
Fix ProfilePicDialogFragment instantiation. Fixes https://github.com/austinhuang0131/barinsta/issues/746
This commit is contained in:
parent
747745c6d5
commit
04637da854
@ -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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -641,11 +638,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
try {
|
try {
|
||||||
if (t == null) Toast.makeText(context,
|
if (t == null) Toast.makeText(context,
|
||||||
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,15 +850,14 @@ 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++) {
|
||||||
final UserProfileContextLink link = userProfileContextLinks.get(i);
|
final UserProfileContextLink link = userProfileContextLinks.get(i);
|
||||||
if (link.getUsername() != null)
|
if (link.getUsername() != null)
|
||||||
profileContext = profileContext.substring(0, link.getStart() + i)
|
profileContext = profileContext.substring(0, link.getStart() + i)
|
||||||
+ "@" + profileContext.substring(link.getStart() + i);
|
+ "@" + profileContext.substring(link.getStart() + i);
|
||||||
}
|
}
|
||||||
profileDetailsBinding.profileContext.setText(profileContext);
|
profileDetailsBinding.profileContext.setText(profileContext);
|
||||||
profileDetailsBinding.profileContext.addOnMentionClickListener(autoLinkItem -> {
|
profileDetailsBinding.profileContext.addOnMentionClickListener(autoLinkItem -> {
|
||||||
@ -921,13 +915,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
profileDetailsBinding.btnTagged.setVisibility(View.VISIBLE);
|
profileDetailsBinding.btnTagged.setVisibility(View.VISIBLE);
|
||||||
profileDetailsBinding.btnSaved.setVisibility(View.VISIBLE);
|
profileDetailsBinding.btnSaved.setVisibility(View.VISIBLE);
|
||||||
profileDetailsBinding.btnLiked.setVisibility(View.VISIBLE);
|
profileDetailsBinding.btnLiked.setVisibility(View.VISIBLE);
|
||||||
// profileDetailsBinding.btnDM.setVisibility(View.GONE);
|
// profileDetailsBinding.btnDM.setVisibility(View.GONE);
|
||||||
profileDetailsBinding.btnSaved.setText(R.string.saved);
|
profileDetailsBinding.btnSaved.setText(R.string.saved);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
profileDetailsBinding.btnSaved.setVisibility(View.GONE);
|
profileDetailsBinding.btnSaved.setVisibility(View.GONE);
|
||||||
profileDetailsBinding.btnLiked.setVisibility(View.GONE);
|
profileDetailsBinding.btnLiked.setVisibility(View.GONE);
|
||||||
// profileDetailsBinding.btnDM.setVisibility(View.VISIBLE);
|
// profileDetailsBinding.btnDM.setVisibility(View.VISIBLE);
|
||||||
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
|
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
@ -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>() {
|
||||||
@ -1086,27 +1079,27 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
PostItemType.TAGGED);
|
PostItemType.TAGGED);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
});
|
});
|
||||||
// profileDetailsBinding.btnDM.setOnClickListener(v -> {
|
// profileDetailsBinding.btnDM.setOnClickListener(v -> {
|
||||||
// profileDetailsBinding.btnDM.setEnabled(false);
|
// profileDetailsBinding.btnDM.setEnabled(false);
|
||||||
// new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
|
// new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
|
||||||
// if (thread == null) {
|
// if (thread == null) {
|
||||||
// Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
// Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||||
// profileDetailsBinding.btnDM.setEnabled(true);
|
// profileDetailsBinding.btnDM.setEnabled(true);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// if (isAdded()) {
|
// if (isAdded()) {
|
||||||
// final Bundle bundle = new Bundle();
|
// final Bundle bundle = new Bundle();
|
||||||
// bundle.putString("threadId", thread.getThreadId());
|
// bundle.putString("threadId", thread.getThreadId());
|
||||||
// bundle.putString("title", thread.getThreadTitle());
|
// bundle.putString("title", thread.getThreadTitle());
|
||||||
// if (isAdded()) {
|
// if (isAdded()) {
|
||||||
// final NavDirections action = ProfileFragmentDirections
|
// final NavDirections action = ProfileFragmentDirections
|
||||||
// .actionProfileFragmentToDMThreadFragment(thread.getThreadId(), profileModel.getUsername());
|
// .actionProfileFragmentToDMThreadFragment(thread.getThreadId(), profileModel.getUsername());
|
||||||
// NavHostFragment.findNavController(this).navigate(action);
|
// NavHostFragment.findNavController(this).navigate(action);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// profileDetailsBinding.btnDM.setEnabled(true);
|
// profileDetailsBinding.btnDM.setEnabled(true);
|
||||||
// }).execute();
|
// }).execute();
|
||||||
// });
|
// });
|
||||||
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
|
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
|
||||||
if (!hasStories) {
|
if (!hasStories) {
|
||||||
// show profile pic
|
// show profile pic
|
||||||
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user