issue #3996 solved (#3999)

This commit is contained in:
Harsh Maheshwari 2020-12-22 23:52:40 +05:30 committed by GitHub
parent b2823514ed
commit 1ccb3578e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.MergeAdapter; import androidx.recyclerview.widget.MergeAdapter;
@ -154,7 +155,9 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
} }
}); });
scrollButton.setOnClickListener(view -> scrollToUserRank());
scrollButton.setOnClickListener(view -> scrollToUserRank());
return rootView; return rootView;
} }
@ -176,22 +179,22 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
* If you are viewing the leaderboard below userRank, it scrolls to the user rank at the top * If you are viewing the leaderboard below userRank, it scrolls to the user rank at the top
*/ */
private void scrollToUserRank() { private void scrollToUserRank() {
if (Objects.requireNonNull(leaderboardListRecyclerView.getAdapter()).getItemCount() > userRank + 1) {
int currPosition = ((LinearLayoutManager) leaderboardListRecyclerView.getLayoutManager()) if(userRank==0){
.findFirstCompletelyVisibleItemPosition(); Toast.makeText(getContext(),R.string.no_achievements_yet,Toast.LENGTH_SHORT).show();
// if you are below your rank, scroll to userRank }else {
if (currPosition > userRank) { if (Objects.requireNonNull(leaderboardListRecyclerView.getAdapter()).getItemCount()
leaderboardListRecyclerView.smoothScrollToPosition(userRank); > userRank + 1) {
} else {
leaderboardListRecyclerView.smoothScrollToPosition(userRank + 1); leaderboardListRecyclerView.smoothScrollToPosition(userRank + 1);
} } else {
} else { if (viewModel != null) {
if (viewModel != null) { viewModel.refresh(duration, category, userRank + 1, 0);
viewModel.refresh(duration, category, userRank + 1, 0); setLeaderboard(duration, category, userRank + 1, 0);
setLeaderboard(duration, category, userRank + 1, 0); scrollToRank = true;
scrollToRank = true; }
} }
} }
} }
/** /**