|
@ -12,69 +12,129 @@ import android.text.TextWatcher; |
|
|
import android.text.style.RelativeSizeSpan; |
|
|
import android.text.style.RelativeSizeSpan; |
|
|
import android.util.Log; |
|
|
import android.util.Log; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.Menu; |
|
|
|
|
|
import android.view.MenuInflater; |
|
|
|
|
|
import android.view.MenuItem; |
|
|
|
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.view.ViewGroup; |
|
|
import android.view.ViewGroup; |
|
|
import android.view.inputmethod.InputMethodManager; |
|
|
import android.view.inputmethod.InputMethodManager; |
|
|
import android.widget.LinearLayout; |
|
|
|
|
|
import android.widget.Toast; |
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
import androidx.annotation.NonNull; |
|
|
import androidx.annotation.Nullable; |
|
|
import androidx.annotation.Nullable; |
|
|
import androidx.appcompat.app.ActionBar; |
|
|
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import androidx.appcompat.widget.SearchView; |
|
|
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
|
|
|
|
import androidx.appcompat.widget.LinearLayoutCompat; |
|
|
import androidx.fragment.app.FragmentManager; |
|
|
import androidx.fragment.app.FragmentManager; |
|
|
import androidx.fragment.app.FragmentTransaction; |
|
|
import androidx.fragment.app.FragmentTransaction; |
|
|
|
|
|
import androidx.lifecycle.ViewModelProvider; |
|
|
import androidx.navigation.NavDirections; |
|
|
import androidx.navigation.NavDirections; |
|
|
import androidx.navigation.fragment.NavHostFragment; |
|
|
import androidx.navigation.fragment.NavHostFragment; |
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; |
|
|
|
|
|
|
|
|
import awais.instagrabber.R; |
|
|
import awais.instagrabber.R; |
|
|
import awais.instagrabber.adapters.CommentsAdapter; |
|
|
import awais.instagrabber.adapters.CommentsAdapter; |
|
|
import awais.instagrabber.asyncs.CommentsFetcher; |
|
|
import awais.instagrabber.asyncs.CommentsFetcher; |
|
|
import awais.instagrabber.databinding.FragmentCommentsBinding; |
|
|
import awais.instagrabber.databinding.FragmentCommentsBinding; |
|
|
import awais.instagrabber.dialogs.ProfilePicDialogFragment; |
|
|
import awais.instagrabber.dialogs.ProfilePicDialogFragment; |
|
|
import awais.instagrabber.interfaces.MentionClickListener; |
|
|
|
|
|
import awais.instagrabber.models.CommentModel; |
|
|
import awais.instagrabber.models.CommentModel; |
|
|
import awais.instagrabber.models.ProfileModel; |
|
|
import awais.instagrabber.models.ProfileModel; |
|
|
import awais.instagrabber.utils.Constants; |
|
|
import awais.instagrabber.utils.Constants; |
|
|
import awais.instagrabber.utils.CookieUtils; |
|
|
import awais.instagrabber.utils.CookieUtils; |
|
|
import awais.instagrabber.utils.TextUtils; |
|
|
import awais.instagrabber.utils.TextUtils; |
|
|
import awais.instagrabber.utils.Utils; |
|
|
import awais.instagrabber.utils.Utils; |
|
|
|
|
|
import awais.instagrabber.viewmodels.CommentsViewModel; |
|
|
import awais.instagrabber.webservices.MediaService; |
|
|
import awais.instagrabber.webservices.MediaService; |
|
|
import awais.instagrabber.webservices.ServiceCallback; |
|
|
import awais.instagrabber.webservices.ServiceCallback; |
|
|
|
|
|
|
|
|
import static android.content.Context.INPUT_METHOD_SERVICE; |
|
|
import static android.content.Context.INPUT_METHOD_SERVICE; |
|
|
|
|
|
|
|
|
public final class CommentsViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { |
|
|
|
|
|
|
|
|
public final class CommentsViewerFragment extends BottomSheetDialogFragment implements SwipeRefreshLayout.OnRefreshListener { |
|
|
private static final String TAG = "CommentsViewerFragment"; |
|
|
private static final String TAG = "CommentsViewerFragment"; |
|
|
|
|
|
|
|
|
private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); |
|
|
private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); |
|
|
|
|
|
|
|
|
private CommentsAdapter commentsAdapter; |
|
|
private CommentsAdapter commentsAdapter; |
|
|
private CommentModel commentModel; |
|
|
|
|
|
private FragmentCommentsBinding binding; |
|
|
private FragmentCommentsBinding binding; |
|
|
private String shortCode; |
|
|
private String shortCode; |
|
|
private String userId; |
|
|
private String userId; |
|
|
private Resources resources; |
|
|
private Resources resources; |
|
|
private InputMethodManager imm; |
|
|
private InputMethodManager imm; |
|
|
private AppCompatActivity fragmentActivity; |
|
|
private AppCompatActivity fragmentActivity; |
|
|
private LinearLayout root; |
|
|
|
|
|
|
|
|
private LinearLayoutCompat root; |
|
|
private boolean shouldRefresh = true; |
|
|
private boolean shouldRefresh = true; |
|
|
private MediaService mediaService; |
|
|
private MediaService mediaService; |
|
|
private String postId; |
|
|
private String postId; |
|
|
|
|
|
private CommentsViewModel commentsViewModel; |
|
|
|
|
|
|
|
|
|
|
|
private final CommentsAdapter.CommentCallback commentCallback = new CommentsAdapter.CommentCallback() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(final CommentModel comment) { |
|
|
|
|
|
onCommentClick(comment); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onHashtagClick(final String hashtag) { |
|
|
|
|
|
final NavDirections action = CommentsViewerFragmentDirections.actionGlobalHashTagFragment(hashtag); |
|
|
|
|
|
NavHostFragment.findNavController(CommentsViewerFragment.this).navigate(action); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onMentionClick(final String mention) { |
|
|
|
|
|
openProfile(mention); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onURLClick(final String url) { |
|
|
|
|
|
Utils.openURL(getContext(), url); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onEmailClick(final String emailAddress) { |
|
|
|
|
|
Utils.openEmailAddress(getContext(), emailAddress); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
private final View.OnClickListener newCommentListener = v -> { |
|
|
|
|
|
final Editable text = binding.commentText.getText(); |
|
|
|
|
|
final Context context = getContext(); |
|
|
|
|
|
if (context == null) return; |
|
|
|
|
|
if (text == null || TextUtils.isEmpty(text.toString())) { |
|
|
|
|
|
Toast.makeText(context, R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
final String userId = CookieUtils.getUserIdFromCookie(cookie); |
|
|
|
|
|
if (userId == null) return; |
|
|
|
|
|
String replyToId = null; |
|
|
|
|
|
final CommentModel commentModel = commentsAdapter.getSelected(); |
|
|
|
|
|
if (commentModel != null) { |
|
|
|
|
|
replyToId = commentModel.getId(); |
|
|
|
|
|
} |
|
|
|
|
|
mediaService.comment(postId, text.toString(), userId, replyToId, CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<Boolean>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onSuccess(final Boolean result) { |
|
|
|
|
|
commentsAdapter.clearSelection(); |
|
|
|
|
|
binding.commentText.setText(""); |
|
|
|
|
|
if (!result) { |
|
|
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
onRefresh(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(final Throwable t) { |
|
|
|
|
|
Log.e(TAG, "Error during comment", t); |
|
|
|
|
|
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onCreate(@Nullable final Bundle savedInstanceState) { |
|
|
public void onCreate(@Nullable final Bundle savedInstanceState) { |
|
|
super.onCreate(savedInstanceState); |
|
|
super.onCreate(savedInstanceState); |
|
|
fragmentActivity = (AppCompatActivity) getActivity(); |
|
|
fragmentActivity = (AppCompatActivity) getActivity(); |
|
|
mediaService = MediaService.getInstance(); |
|
|
mediaService = MediaService.getInstance(); |
|
|
setHasOptionsMenu(true); |
|
|
|
|
|
|
|
|
// setHasOptionsMenu(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@NonNull |
|
|
@NonNull |
|
@ -85,6 +145,8 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
return root; |
|
|
return root; |
|
|
} |
|
|
} |
|
|
binding = FragmentCommentsBinding.inflate(getLayoutInflater()); |
|
|
binding = FragmentCommentsBinding.inflate(getLayoutInflater()); |
|
|
|
|
|
binding.swipeRefreshLayout.setEnabled(false); |
|
|
|
|
|
binding.swipeRefreshLayout.setNestedScrollingEnabled(false); |
|
|
root = binding.getRoot(); |
|
|
root = binding.getRoot(); |
|
|
return root; |
|
|
return root; |
|
|
} |
|
|
} |
|
@ -96,34 +158,33 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
shouldRefresh = false; |
|
|
shouldRefresh = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { |
|
|
|
|
|
inflater.inflate(R.menu.follow, menu); |
|
|
|
|
|
menu.findItem(R.id.action_compare).setVisible(false); |
|
|
|
|
|
final MenuItem menuSearch = menu.findItem(R.id.action_search); |
|
|
|
|
|
final SearchView searchView = (SearchView) menuSearch.getActionView(); |
|
|
|
|
|
searchView.setQueryHint(getResources().getString(R.string.action_search)); |
|
|
|
|
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onQueryTextSubmit(final String query) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onQueryTextChange(final String query) { |
|
|
|
|
|
if (commentsAdapter != null) commentsAdapter.getFilter().filter(query); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// @Override |
|
|
|
|
|
// public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { |
|
|
|
|
|
// inflater.inflate(R.menu.follow, menu); |
|
|
|
|
|
// menu.findItem(R.id.action_compare).setVisible(false); |
|
|
|
|
|
// final MenuItem menuSearch = menu.findItem(R.id.action_search); |
|
|
|
|
|
// final SearchView searchView = (SearchView) menuSearch.getActionView(); |
|
|
|
|
|
// searchView.setQueryHint(getResources().getString(R.string.action_search)); |
|
|
|
|
|
// searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { |
|
|
|
|
|
// @Override |
|
|
|
|
|
// public boolean onQueryTextSubmit(final String query) { |
|
|
|
|
|
// return false; |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// @Override |
|
|
|
|
|
// public boolean onQueryTextChange(final String query) { |
|
|
|
|
|
// // if (commentsAdapter != null) commentsAdapter.getFilter().filter(query); |
|
|
|
|
|
// return true; |
|
|
|
|
|
// } |
|
|
|
|
|
// }); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onRefresh() { |
|
|
public void onRefresh() { |
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
new CommentsFetcher(shortCode, commentModels -> { |
|
|
new CommentsFetcher(shortCode, commentModels -> { |
|
|
|
|
|
commentsViewModel.getList().postValue(commentModels); |
|
|
binding.swipeRefreshLayout.setRefreshing(false); |
|
|
binding.swipeRefreshLayout.setRefreshing(false); |
|
|
commentsAdapter = new CommentsAdapter(commentModels, true, clickListener, mentionClickListener); |
|
|
|
|
|
binding.rvComments.setAdapter(commentsAdapter); |
|
|
|
|
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -133,9 +194,14 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
shortCode = fragmentArgs.getShortCode(); |
|
|
shortCode = fragmentArgs.getShortCode(); |
|
|
postId = fragmentArgs.getPostId(); |
|
|
postId = fragmentArgs.getPostId(); |
|
|
userId = fragmentArgs.getPostUserId(); |
|
|
userId = fragmentArgs.getPostUserId(); |
|
|
setTitle(); |
|
|
|
|
|
|
|
|
// setTitle(); |
|
|
binding.swipeRefreshLayout.setOnRefreshListener(this); |
|
|
binding.swipeRefreshLayout.setOnRefreshListener(this); |
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
|
|
|
commentsViewModel = new ViewModelProvider(this).get(CommentsViewModel.class); |
|
|
|
|
|
binding.rvComments.setLayoutManager(new LinearLayoutManager(getContext())); |
|
|
|
|
|
commentsAdapter = new CommentsAdapter(commentCallback); |
|
|
|
|
|
binding.rvComments.setAdapter(commentsAdapter); |
|
|
|
|
|
commentsViewModel.getList().observe(getViewLifecycleOwner(), commentsAdapter::submitList); |
|
|
resources = getResources(); |
|
|
resources = getResources(); |
|
|
if (!TextUtils.isEmpty(cookie)) { |
|
|
if (!TextUtils.isEmpty(cookie)) { |
|
|
binding.commentField.setStartIconVisible(false); |
|
|
binding.commentField.setStartIconVisible(false); |
|
@ -155,40 +221,68 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
public void afterTextChanged(final Editable s) {} |
|
|
public void afterTextChanged(final Editable s) {} |
|
|
}); |
|
|
}); |
|
|
binding.commentField.setStartIconOnClickListener(v -> { |
|
|
binding.commentField.setStartIconOnClickListener(v -> { |
|
|
if (commentModel != null) { |
|
|
|
|
|
final View focus = binding.rvComments.findViewWithTag(commentModel); |
|
|
|
|
|
focus.setBackgroundColor(0x00000000); |
|
|
|
|
|
commentModel = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
commentsAdapter.clearSelection(); |
|
|
binding.commentText.setText(""); |
|
|
binding.commentText.setText(""); |
|
|
}); |
|
|
}); |
|
|
binding.commentField.setEndIconOnClickListener(newCommentListener); |
|
|
binding.commentField.setEndIconOnClickListener(newCommentListener); |
|
|
} |
|
|
} |
|
|
new CommentsFetcher(this.shortCode, commentModels -> { |
|
|
|
|
|
commentsAdapter = new CommentsAdapter(commentModels, true, clickListener, mentionClickListener); |
|
|
|
|
|
binding.rvComments.setAdapter(commentsAdapter); |
|
|
|
|
|
binding.swipeRefreshLayout.setRefreshing(false); |
|
|
|
|
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
|
|
|
|
|
|
onRefresh(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void setTitle() { |
|
|
|
|
|
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); |
|
|
|
|
|
if (actionBar == null) return; |
|
|
|
|
|
actionBar.setTitle(R.string.title_comments); |
|
|
|
|
|
|
|
|
// private void setTitle() { |
|
|
|
|
|
// final ActionBar actionBar = fragmentActivity.getSupportActionBar(); |
|
|
|
|
|
// if (actionBar == null) return; |
|
|
|
|
|
// actionBar.setTitle(R.string.title_comments); |
|
|
// actionBar.setSubtitle(shortCode); |
|
|
// actionBar.setSubtitle(shortCode); |
|
|
} |
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { |
|
|
|
|
|
|
|
|
private void onCommentClick(final CommentModel commentModel) { |
|
|
|
|
|
final String username = commentModel.getProfileModel().getUsername(); |
|
|
|
|
|
final SpannableString title = new SpannableString(username + ":\n" + commentModel.getText()); |
|
|
|
|
|
title.setSpan(new RelativeSizeSpan(1.23f), 0, username.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); |
|
|
|
|
|
|
|
|
|
|
|
String[] commentDialogList; |
|
|
|
|
|
|
|
|
|
|
|
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie); |
|
|
|
|
|
if (!TextUtils.isEmpty(cookie) |
|
|
|
|
|
&& userIdFromCookie != null |
|
|
|
|
|
&& (userIdFromCookie.equals(commentModel.getProfileModel().getId()) || userIdFromCookie.equals(userId))) { |
|
|
|
|
|
commentDialogList = new String[]{ |
|
|
|
|
|
resources.getString(R.string.open_profile), |
|
|
|
|
|
resources.getString(R.string.view_pfp), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_user), |
|
|
|
|
|
// resources.getString(R.string.comment_viewer_copy_comment), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_reply_comment), |
|
|
|
|
|
commentModel.getLiked() ? resources.getString(R.string.comment_viewer_unlike_comment) |
|
|
|
|
|
: resources.getString(R.string.comment_viewer_like_comment), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_delete_comment) |
|
|
|
|
|
}; |
|
|
|
|
|
} else if (!TextUtils.isEmpty(cookie)) { |
|
|
|
|
|
commentDialogList = new String[]{ |
|
|
|
|
|
resources.getString(R.string.open_profile), |
|
|
|
|
|
resources.getString(R.string.view_pfp), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_user), |
|
|
|
|
|
// resources.getString(R.string.comment_viewer_copy_comment), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_reply_comment), |
|
|
|
|
|
commentModel.getLiked() ? resources.getString(R.string.comment_viewer_unlike_comment) |
|
|
|
|
|
: resources.getString(R.string.comment_viewer_like_comment), |
|
|
|
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
commentDialogList = new String[]{ |
|
|
|
|
|
resources.getString(R.string.open_profile), |
|
|
|
|
|
resources.getString(R.string.view_pfp), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_user), |
|
|
|
|
|
// resources.getString(R.string.comment_viewer_copy_comment) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
final Context context = getContext(); |
|
|
final Context context = getContext(); |
|
|
if (context == null) return; |
|
|
if (context == null) return; |
|
|
if (commentModel == null) { |
|
|
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { |
|
|
final ProfileModel profileModel = commentModel.getProfileModel(); |
|
|
final ProfileModel profileModel = commentModel.getProfileModel(); |
|
|
|
|
|
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); |
|
|
switch (which) { |
|
|
switch (which) { |
|
|
case 0: // open profile |
|
|
case 0: // open profile |
|
|
openProfile(profileModel.getUsername()); |
|
|
|
|
|
|
|
|
openProfile("@" + profileModel.getUsername()); |
|
|
break; |
|
|
break; |
|
|
case 1: // view profile pic |
|
|
case 1: // view profile pic |
|
|
final FragmentManager fragmentManager = getParentFragmentManager(); |
|
|
final FragmentManager fragmentManager = getParentFragmentManager(); |
|
@ -203,31 +297,31 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
case 2: // copy username |
|
|
case 2: // copy username |
|
|
Utils.copyText(context, profileModel.getUsername()); |
|
|
Utils.copyText(context, profileModel.getUsername()); |
|
|
break; |
|
|
break; |
|
|
case 3: // copy comment |
|
|
|
|
|
Utils.copyText(context, commentModel.getText().toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case 4: // reply to comment |
|
|
|
|
|
final View focus = binding.rvComments.findViewWithTag(commentModel); |
|
|
|
|
|
focus.setBackgroundColor(0x80888888); |
|
|
|
|
|
|
|
|
// case 3: // copy comment |
|
|
|
|
|
// Utils.copyText(context, commentModel.getText().toString()); |
|
|
|
|
|
// break; |
|
|
|
|
|
case 3: // reply to comment |
|
|
|
|
|
// final View focus = binding.rvComments.findViewWithTag(commentModel); |
|
|
|
|
|
// focus.setBackgroundColor(0x80888888); |
|
|
|
|
|
commentsAdapter.setSelected(commentModel); |
|
|
String mention = "@" + profileModel.getUsername() + " "; |
|
|
String mention = "@" + profileModel.getUsername() + " "; |
|
|
binding.commentText.setText(mention); |
|
|
binding.commentText.setText(mention); |
|
|
binding.commentText.requestFocus(); |
|
|
binding.commentText.requestFocus(); |
|
|
binding.commentText.setSelection(mention.length()); |
|
|
binding.commentText.setSelection(mention.length()); |
|
|
binding.commentText.postDelayed(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
|
binding.commentText.postDelayed(() -> { |
|
|
imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE); |
|
|
imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE); |
|
|
if (imm == null) return; |
|
|
if (imm == null) return; |
|
|
imm.showSoftInput(binding.commentText, 0); |
|
|
imm.showSoftInput(binding.commentText, 0); |
|
|
} |
|
|
|
|
|
}, 200); |
|
|
}, 200); |
|
|
break; |
|
|
break; |
|
|
case 5: // like/unlike comment |
|
|
|
|
|
|
|
|
case 4: // like/unlike comment |
|
|
|
|
|
if (csrfToken == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
if (!commentModel.getLiked()) { |
|
|
if (!commentModel.getLiked()) { |
|
|
mediaService.commentLike(commentModel.getId(), CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<Boolean>() { |
|
|
|
|
|
|
|
|
mediaService.commentLike(commentModel.getId(), csrfToken, new ServiceCallback<Boolean>() { |
|
|
@Override |
|
|
@Override |
|
|
public void onSuccess(final Boolean result) { |
|
|
public void onSuccess(final Boolean result) { |
|
|
commentModel = null; |
|
|
|
|
|
if (!result) { |
|
|
if (!result) { |
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
return; |
|
|
return; |
|
@ -243,10 +337,9 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
}); |
|
|
}); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
mediaService.commentUnlike(commentModel.getId(), CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<Boolean>() { |
|
|
|
|
|
|
|
|
mediaService.commentUnlike(commentModel.getId(), csrfToken, new ServiceCallback<Boolean>() { |
|
|
@Override |
|
|
@Override |
|
|
public void onSuccess(final Boolean result) { |
|
|
public void onSuccess(final Boolean result) { |
|
|
commentModel = null; |
|
|
|
|
|
if (!result) { |
|
|
if (!result) { |
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
return; |
|
|
return; |
|
@ -261,15 +354,14 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
break; |
|
|
break; |
|
|
case 6: // delete comment |
|
|
|
|
|
|
|
|
case 5: // delete comment |
|
|
final String userId = CookieUtils.getUserIdFromCookie(cookie); |
|
|
final String userId = CookieUtils.getUserIdFromCookie(cookie); |
|
|
if (userId == null) return; |
|
|
if (userId == null) return; |
|
|
mediaService.deleteComment( |
|
|
mediaService.deleteComment( |
|
|
postId, userId, commentModel.getId(), CookieUtils.getCsrfTokenFromCookie(cookie), |
|
|
|
|
|
|
|
|
postId, userId, commentModel.getId(), csrfToken, |
|
|
new ServiceCallback<Boolean>() { |
|
|
new ServiceCallback<Boolean>() { |
|
|
@Override |
|
|
@Override |
|
|
public void onSuccess(final Boolean result) { |
|
|
public void onSuccess(final Boolean result) { |
|
|
commentModel = null; |
|
|
|
|
|
if (!result) { |
|
|
if (!result) { |
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
return; |
|
|
return; |
|
@ -286,105 +378,15 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
private final View.OnClickListener clickListener = v -> { |
|
|
|
|
|
final Object tag = v.getTag(); |
|
|
|
|
|
if (tag instanceof CommentModel) { |
|
|
|
|
|
commentModel = (CommentModel) tag; |
|
|
|
|
|
|
|
|
|
|
|
final String username = commentModel.getProfileModel().getUsername(); |
|
|
|
|
|
final SpannableString title = new SpannableString(username + ":\n" + commentModel.getText()); |
|
|
|
|
|
title.setSpan(new RelativeSizeSpan(1.23f), 0, username.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); |
|
|
|
|
|
|
|
|
|
|
|
String[] commentDialogList; |
|
|
|
|
|
|
|
|
|
|
|
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie); |
|
|
|
|
|
if (!TextUtils.isEmpty(cookie) |
|
|
|
|
|
&& userIdFromCookie != null |
|
|
|
|
|
&& (userIdFromCookie.equals(commentModel.getProfileModel().getId()) || userIdFromCookie.equals(userId))) { |
|
|
|
|
|
commentDialogList = new String[]{ |
|
|
|
|
|
resources.getString(R.string.open_profile), |
|
|
|
|
|
resources.getString(R.string.view_pfp), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_user), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_comment), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_reply_comment), |
|
|
|
|
|
commentModel.getLiked() ? resources.getString(R.string.comment_viewer_unlike_comment) |
|
|
|
|
|
: resources.getString(R.string.comment_viewer_like_comment), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_delete_comment) |
|
|
|
|
|
}; |
|
|
|
|
|
} else if (!TextUtils.isEmpty(cookie)) { |
|
|
|
|
|
commentDialogList = new String[]{ |
|
|
|
|
|
resources.getString(R.string.open_profile), |
|
|
|
|
|
resources.getString(R.string.view_pfp), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_user), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_comment), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_reply_comment), |
|
|
|
|
|
commentModel.getLiked() ? resources.getString(R.string.comment_viewer_unlike_comment) |
|
|
|
|
|
: resources.getString(R.string.comment_viewer_like_comment), |
|
|
|
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
commentDialogList = new String[]{ |
|
|
|
|
|
resources.getString(R.string.open_profile), |
|
|
|
|
|
resources.getString(R.string.view_pfp), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_user), |
|
|
|
|
|
resources.getString(R.string.comment_viewer_copy_comment) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
final Context context = getContext(); |
|
|
|
|
|
if (context == null) return; |
|
|
|
|
|
new AlertDialog.Builder(context) |
|
|
new AlertDialog.Builder(context) |
|
|
.setTitle(title) |
|
|
.setTitle(title) |
|
|
.setItems(commentDialogList, profileDialogListener) |
|
|
.setItems(commentDialogList, profileDialogListener) |
|
|
.setNegativeButton(R.string.cancel, null) |
|
|
.setNegativeButton(R.string.cancel, null) |
|
|
.show(); |
|
|
.show(); |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private final MentionClickListener mentionClickListener = (view, text, isHashtag, isLocation) -> { |
|
|
|
|
|
if (isHashtag) { |
|
|
|
|
|
final NavDirections action = CommentsViewerFragmentDirections.actionGlobalHashTagFragment(text); |
|
|
|
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
openProfile(text); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private final View.OnClickListener newCommentListener = v -> { |
|
|
|
|
|
final Editable text = binding.commentText.getText(); |
|
|
|
|
|
final Context context = getContext(); |
|
|
|
|
|
if (context == null) return; |
|
|
|
|
|
if (text == null || TextUtils.isEmpty(text.toString())) { |
|
|
|
|
|
Toast.makeText(context, R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
final String userId = CookieUtils.getUserIdFromCookie(cookie); |
|
|
|
|
|
if (userId == null) return; |
|
|
|
|
|
String replyToId = null; |
|
|
|
|
|
if (commentModel != null) { |
|
|
|
|
|
replyToId = commentModel.getId(); |
|
|
|
|
|
} |
|
|
|
|
|
mediaService.comment(postId, text.toString(), userId, replyToId, CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<Boolean>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onSuccess(final Boolean result) { |
|
|
|
|
|
commentModel = null; |
|
|
|
|
|
binding.commentText.setText(""); |
|
|
|
|
|
if (!result) { |
|
|
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
onRefresh(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(final Throwable t) { |
|
|
|
|
|
Log.e(TAG, "Error during comment", t); |
|
|
|
|
|
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private void openProfile(final String username) { |
|
|
private void openProfile(final String username) { |
|
|
final NavDirections action = CommentsViewerFragmentDirections.actionGlobalProfileFragment("@" + username); |
|
|
|
|
|
|
|
|
final NavDirections action = CommentsViewerFragmentDirections.actionGlobalProfileFragment(username); |
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |