mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Added Auto Scroll (#3912)
* Fixed #3910 Truncated Spinners * Added AutoScroll for Leaderboard Rank * Revert Irrelevant Change * Fixed Bounce Back Issue * Fixed Incorrect UserRank Issue on Rotation * Fixed Overlapping issue * As per java convention
This commit is contained in:
parent
01531de156
commit
df209e752d
4 changed files with 51 additions and 1 deletions
|
|
@ -138,6 +138,7 @@
|
|||
|
||||
<activity
|
||||
android:name=".profile.ProfileActivity"
|
||||
android:configChanges="orientation|screenSize|keyboard"
|
||||
android:label="@string/Profile" />
|
||||
|
||||
<activity
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Spinner;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
|
@ -50,6 +51,9 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
@BindView(R.id.duration_spinner)
|
||||
Spinner durationSpinner;
|
||||
|
||||
@BindView(R.id.scroll)
|
||||
Button scrollButton;
|
||||
|
||||
@Inject
|
||||
SessionManager sessionManager;
|
||||
|
||||
|
|
@ -89,6 +93,16 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
*/
|
||||
private int offset = START_OFFSET;
|
||||
|
||||
/**
|
||||
* Set initial User Rank to 0
|
||||
*/
|
||||
private int userRank;
|
||||
|
||||
/**
|
||||
* This variable represents if user wants to scroll to his rank or not
|
||||
*/
|
||||
private boolean scrollToRank;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_leaderboard, container, false);
|
||||
|
|
@ -140,6 +154,8 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
}
|
||||
});
|
||||
|
||||
scrollButton.setOnClickListener(view -> scrollToUserRank());
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
|
@ -147,12 +163,29 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
* Refreshes the leaderboard list
|
||||
*/
|
||||
private void refreshLeaderboard() {
|
||||
scrollToRank = false;
|
||||
if (viewModel != null) {
|
||||
viewModel.refresh(duration, category, limit, offset);
|
||||
setLeaderboard(duration, category, limit, offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs Auto Scroll to the User's Rank
|
||||
* We use userRank+1 to load one extra user and prevent overlapping of my rank button
|
||||
*/
|
||||
private void scrollToUserRank() {
|
||||
if (Objects.requireNonNull(leaderboardListRecyclerView.getAdapter()).getItemCount() > userRank + 1) {
|
||||
leaderboardListRecyclerView.smoothScrollToPosition(userRank + 1);
|
||||
} else {
|
||||
if (viewModel != null) {
|
||||
viewModel.refresh(duration, category, userRank + 1, 0);
|
||||
setLeaderboard(duration, category, userRank + 1, 0);
|
||||
scrollToRank = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the spinners for the leaderboard filters
|
||||
*/
|
||||
|
|
@ -183,6 +216,7 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
.subscribe(
|
||||
response -> {
|
||||
if (response != null && response.getStatus() == 200) {
|
||||
userRank = response.getRank();
|
||||
setViews(response, duration, category, limit, offset);
|
||||
}
|
||||
},
|
||||
|
|
@ -217,6 +251,9 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
showProgressBar();
|
||||
} else if (status.equalsIgnoreCase(LOADED)) {
|
||||
hideProgressBar();
|
||||
if (scrollToRank) {
|
||||
leaderboardListRecyclerView.smoothScrollToPosition(userRank + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -229,6 +266,7 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
progressBar.setVisibility(View.GONE);
|
||||
categorySpinner.setVisibility(View.VISIBLE);
|
||||
durationSpinner.setVisibility(View.VISIBLE);
|
||||
scrollButton.setVisibility(View.VISIBLE);
|
||||
leaderboardListRecyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
@ -240,6 +278,7 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment {
|
|||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
scrollButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/filters" />
|
||||
|
||||
<Button
|
||||
android:text="@string/leaderboard_my_rank_button_text"
|
||||
android:id="@+id/scroll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/leaderboard_list"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -53,4 +62,4 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/leaderboard_list" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
|
|
@ -688,4 +688,5 @@ Upload your first media by tapping on the add button.</string>
|
|||
<string name="leaderboard_upload">Upload</string>
|
||||
<string name="leaderboard_nearby">Nearby</string>
|
||||
<string name="leaderboard_used">Used</string>
|
||||
<string name="leaderboard_my_rank_button_text">My Rank</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue