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,8 +155,10 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
} }
}); });
scrollButton.setOnClickListener(view -> scrollToUserRank()); scrollButton.setOnClickListener(view -> scrollToUserRank());
return rootView; return rootView;
} }
@ -176,15 +179,13 @@ 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
if (currPosition > userRank) {
leaderboardListRecyclerView.smoothScrollToPosition(userRank);
}else { }else {
if (Objects.requireNonNull(leaderboardListRecyclerView.getAdapter()).getItemCount()
> userRank + 1) {
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);
@ -194,6 +195,8 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
} }
} }
}
/** /**
* Set the spinners for the leaderboard filters * Set the spinners for the leaderboard filters
*/ */