-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавлен подсчет рейтнга пользователя
- Loading branch information
Showing
11 changed files
with
717 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
app/src/main/java/my/neomer/sixtyseconds/RatingActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package my.neomer.sixtyseconds; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
|
||
import org.w3c.dom.Text; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
import my.neomer.sixtyseconds.helpers.ApplicationResources; | ||
import my.neomer.sixtyseconds.model.UserRating; | ||
import my.neomer.sixtyseconds.transport.Callback; | ||
|
||
public class RatingActivity extends AppCompatActivity | ||
implements Callback<UserRating> | ||
{ | ||
|
||
@BindView(R.id.txtPoints) | ||
TextView txtPoints; | ||
|
||
@BindView(R.id.txtPlace) | ||
TextView txtPlace; | ||
|
||
@BindView(R.id.imvPlaceIcon) | ||
ImageView imvPlaceIcon; | ||
|
||
@BindView(R.id.loadUserRatingProgressBar) | ||
ProgressBar loadUserRatingProgressBar; | ||
|
||
@BindView(R.id.txtFirstPlace) | ||
TextView txtFirstPlace; | ||
|
||
@BindView(R.id.txtSecondPlace) | ||
TextView txtSecondPlace; | ||
|
||
@BindView(R.id.txtThirdPlace) | ||
TextView txtThirdPlace; | ||
|
||
@BindView(R.id.txtFourthPlace) | ||
TextView txtFourthPlace; | ||
|
||
@BindView(R.id.txtFifthPlace) | ||
TextView txtFifthPlace; | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_rating); | ||
|
||
ButterKnife.bind(this); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
loadUserRatingProgressBar.setVisibility(View.VISIBLE); | ||
|
||
ApplicationResources.getInstance() | ||
.getQuestionProvider() | ||
.loadUserRating(this); | ||
|
||
} | ||
|
||
@Override | ||
public void onReady(UserRating data) { | ||
loadUserRatingProgressBar.setVisibility(View.INVISIBLE); | ||
imvPlaceIcon.setVisibility(View.INVISIBLE); | ||
txtPlace.setText(String.valueOf(data.getPlace())); | ||
txtPoints.setText(String.valueOf(data.getPoints())); | ||
|
||
txtFirstPlace.setText(String.valueOf(data.getLeaderboard().get(0).getPoints())); | ||
txtSecondPlace.setText(String.valueOf(data.getLeaderboard().get(1).getPoints())); | ||
txtThirdPlace.setText(String.valueOf(data.getLeaderboard().get(2).getPoints())); | ||
txtFourthPlace.setText(String.valueOf(data.getLeaderboard().get(3).getPoints())); | ||
txtFifthPlace.setText(String.valueOf(data.getLeaderboard().get(4).getPoints())); | ||
} | ||
|
||
@Override | ||
public void onFailure(Throwable t) { | ||
|
||
ApplicationResources.getInstance() | ||
.getQuestionProvider() | ||
.loadUserRating(this); | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/my/neomer/sixtyseconds/dao/LeaderboardRecordDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package my.neomer.sixtyseconds.dao; | ||
|
||
import my.neomer.sixtyseconds.model.LeaderboardRecord; | ||
|
||
public class LeaderboardRecordDTO { | ||
|
||
private String user; | ||
private int points; | ||
|
||
public LeaderboardRecord toLeaderBoardRecord() { | ||
LeaderboardRecord record = new LeaderboardRecord(); | ||
record.setPoints(points); | ||
return record; | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/my/neomer/sixtyseconds/dao/UserRatingDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package my.neomer.sixtyseconds.dao; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import my.neomer.sixtyseconds.model.LeaderboardRecord; | ||
import my.neomer.sixtyseconds.model.UserRating; | ||
|
||
public class UserRatingDTO { | ||
|
||
private String user_id; | ||
private long points; | ||
private int place; | ||
private List<LeaderboardRecordDTO> leaderboard; | ||
|
||
public UserRating toUserRating() { | ||
UserRating userRating = new UserRating(); | ||
userRating.setPlace(place); | ||
userRating.setPoints(points); | ||
|
||
List<LeaderboardRecord> list = new ArrayList<>(); | ||
if (leaderboard != null) { | ||
for (LeaderboardRecordDTO rec : leaderboard) { | ||
list.add(rec.toLeaderBoardRecord()); | ||
} | ||
} | ||
userRating.setLeaderboard(list); | ||
return userRating; | ||
} | ||
|
||
|
||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/my/neomer/sixtyseconds/model/LeaderboardRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package my.neomer.sixtyseconds.model; | ||
|
||
public class LeaderboardRecord { | ||
|
||
private int points; | ||
|
||
public int getPoints() { | ||
return points; | ||
} | ||
|
||
public void setPoints(int points) { | ||
this.points = points; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/my/neomer/sixtyseconds/model/UserRating.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package my.neomer.sixtyseconds.model; | ||
|
||
import java.util.List; | ||
|
||
public class UserRating { | ||
|
||
private long points; | ||
private int place; | ||
private List<LeaderboardRecord> leaderboard; | ||
|
||
public long getPoints() { | ||
return points; | ||
} | ||
|
||
public void setPoints(long points) { | ||
this.points = points; | ||
} | ||
|
||
public int getPlace() { | ||
return place; | ||
} | ||
|
||
public void setPlace(int place) { | ||
this.place = place; | ||
} | ||
|
||
public List<LeaderboardRecord> getLeaderboard() { | ||
return leaderboard; | ||
} | ||
|
||
public void setLeaderboard(List<LeaderboardRecord> leaderboard) { | ||
this.leaderboard = leaderboard; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/src/main/java/my/neomer/sixtyseconds/states/RatingAnswerState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package my.neomer.sixtyseconds.states; | ||
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
import my.neomer.sixtyseconds.R; | ||
import my.neomer.sixtyseconds.gamemodes.BaseGameContext; | ||
|
||
public class RatingAnswerState extends AnswerState { | ||
|
||
//region Parcelable | ||
|
||
public static final Parcelable.Creator<RatingAnswerState> CREATOR = new Parcelable.Creator<RatingAnswerState>() { | ||
|
||
@Override | ||
public RatingAnswerState createFromParcel(Parcel source) { | ||
return new RatingAnswerState(source); | ||
} | ||
|
||
@Override | ||
public RatingAnswerState[] newArray(int size) { | ||
return new RatingAnswerState[size]; | ||
} | ||
}; | ||
|
||
private RatingAnswerState(Parcel in) { | ||
super(in); | ||
} | ||
|
||
//endregion | ||
|
||
public RatingAnswerState() { | ||
|
||
} | ||
|
||
@BindView(R.id.txtAdditionalPoints) | ||
TextView txtAdditionalPoints; | ||
|
||
@Override | ||
public void prepareState(BaseGameContext gameContext, IStateFinishListener stateFinishListener) { | ||
super.prepareState(gameContext, stateFinishListener); | ||
|
||
ButterKnife.bind(this, gameContext.getActivity()); | ||
if (getGameContext().getAnswer().getValue() != null && getGameContext().getAnswer().getValue().isCorrect()) { | ||
txtAdditionalPoints.setText(getGameContext().getActivity().getString(R.string.additional_rate_points, getGameContext().getAnswer().getValue().getPoints())); | ||
txtAdditionalPoints.setVisibility(View.VISIBLE); | ||
} else { | ||
txtAdditionalPoints.setVisibility(View.GONE); | ||
} | ||
} | ||
|
||
@Override | ||
public void finish() { | ||
txtAdditionalPoints.setVisibility(View.GONE); | ||
super.finish(); | ||
} | ||
|
||
@Override | ||
protected void showIsCorrect() { | ||
super.showIsCorrect(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
app/src/main/java/my/neomer/sixtyseconds/transport/FakeApiProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package my.neomer.sixtyseconds.transport; | ||
|
||
import my.neomer.sixtyseconds.model.Answer; | ||
import my.neomer.sixtyseconds.model.Question; | ||
import my.neomer.sixtyseconds.model.UserRating; | ||
|
||
public class FakeApiProvider implements IApiProvider { | ||
|
||
public FakeApiProvider() { | ||
} | ||
|
||
@Override | ||
public void setConfiguration(TransportConfiguration config) { | ||
|
||
} | ||
|
||
@Override | ||
public void getNextQuestion(Question.Difficulty difficulty, Callback<Question> callback) { | ||
Question question = new Question(); | ||
question.setId(0); | ||
question.setVote(0); | ||
question.setDifficulty(difficulty); | ||
question.setText("Sample question text generated by FakeApiProvider"); | ||
|
||
callback.onReady(question); | ||
} | ||
|
||
@Override | ||
public void getAnswer(Question question, String guess, Callback<Answer> callback) { | ||
Answer answer = new Answer(); | ||
answer.setAnswer("Sample answer on the question generated by FakeApiProvider"); | ||
answer.setCorrect(true); | ||
answer.setComment("Simple comment"); | ||
|
||
callback.onReady(answer); | ||
} | ||
|
||
@Override | ||
public void like(Question question) { | ||
|
||
} | ||
|
||
@Override | ||
public void dislike(Question question) { | ||
|
||
} | ||
|
||
@Override | ||
public void loadUserRating(Callback<UserRating> callback) { | ||
UserRating userRating = new UserRating(); | ||
userRating.setPoints(-1); | ||
userRating.setPlace(666); | ||
|
||
callback.onReady(userRating); | ||
} | ||
|
||
} |
Oops, something went wrong.