|
|
@ -307,6 +307,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
private AccountRepository accountRepository; |
|
|
|
private FavoriteRepository favoriteRepository; |
|
|
|
private AppStateViewModel appStateViewModel; |
|
|
|
private boolean disableDm = false; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onCreate(@Nullable final Bundle savedInstanceState) { |
|
|
@ -322,8 +323,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
mediaService = isLoggedIn ? MediaService.getInstance(null, null, 0) : null; |
|
|
|
userService = isLoggedIn ? UserService.getInstance() : null; |
|
|
|
graphQLService = isLoggedIn ? null : GraphQLService.getInstance(); |
|
|
|
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext())); |
|
|
|
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(getContext())); |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context)); |
|
|
|
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context)); |
|
|
|
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class); |
|
|
|
setHasOptionsMenu(true); |
|
|
|
} |
|
|
@ -578,6 +581,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
} |
|
|
|
|
|
|
|
private void init() { |
|
|
|
disableDm = fragmentActivity.getCurrentTabs() |
|
|
|
.stream() |
|
|
|
.noneMatch(tab -> tab.getNavigationRootId() == R.id.direct_messages_nav_graph); |
|
|
|
if (getArguments() != null) { |
|
|
|
final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments()); |
|
|
|
username = fragmentArgs.getUsername(); |
|
|
@ -612,8 +618,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
username = profileModel.getUsername(); |
|
|
|
setUsernameDelayed(); |
|
|
|
setProfileDetails(); |
|
|
|
} |
|
|
|
else if (isLoggedIn) { |
|
|
|
} else if (isLoggedIn) { |
|
|
|
userService.getUsernameInfo(usernameTemp, new ServiceCallback<User>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(final User user) { |
|
|
@ -647,8 +652,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
} catch (final Throwable ignored) {} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
graphQLService.fetchUser(usernameTemp, new ServiceCallback<User>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(final User user) { |
|
|
@ -939,7 +943,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
} |
|
|
|
profileDetailsBinding.btnSaved.setVisibility(View.GONE); |
|
|
|
profileDetailsBinding.btnLiked.setVisibility(View.GONE); |
|
|
|
profileDetailsBinding.btnDM.setVisibility(View.VISIBLE); |
|
|
|
profileDetailsBinding.btnDM.setVisibility(disableDm ? View.GONE : View.VISIBLE); |
|
|
|
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE); |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
@ -1116,23 +1120,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
PostItemType.TAGGED); |
|
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
|
}); |
|
|
|
profileDetailsBinding.btnDM.setOnClickListener(v -> { |
|
|
|
profileDetailsBinding.btnDM.setEnabled(false); |
|
|
|
new CreateThreadAction(cookie, profileModel.getPk(), thread -> { |
|
|
|
if (thread == null) { |
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
if (!disableDm) { |
|
|
|
profileDetailsBinding.btnDM.setOnClickListener(v -> { |
|
|
|
profileDetailsBinding.btnDM.setEnabled(false); |
|
|
|
new CreateThreadAction(cookie, profileModel.getPk(), thread -> { |
|
|
|
if (thread == null) { |
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
profileDetailsBinding.btnDM.setEnabled(true); |
|
|
|
return; |
|
|
|
} |
|
|
|
final InboxManager inboxManager = DirectMessagesManager.getInstance().getInboxManager(); |
|
|
|
if (!inboxManager.containsThread(thread.getThreadId())) { |
|
|
|
thread.setTemp(true); |
|
|
|
inboxManager.addThread(thread, 0); |
|
|
|
} |
|
|
|
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername()); |
|
|
|
profileDetailsBinding.btnDM.setEnabled(true); |
|
|
|
return; |
|
|
|
} |
|
|
|
final InboxManager inboxManager = DirectMessagesManager.getInstance().getInboxManager(); |
|
|
|
if (!inboxManager.containsThread(thread.getThreadId())) { |
|
|
|
thread.setTemp(true); |
|
|
|
inboxManager.addThread(thread, 0); |
|
|
|
} |
|
|
|
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername()); |
|
|
|
profileDetailsBinding.btnDM.setEnabled(true); |
|
|
|
}).execute(); |
|
|
|
}); |
|
|
|
}).execute(); |
|
|
|
}); |
|
|
|
} |
|
|
|
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> { |
|
|
|
if (!hasStories) { |
|
|
|
// show profile pic |
|
|
|