Skip to content

Commit

Permalink
Merge pull request #122 from RamolaWeb/master
Browse files Browse the repository at this point in the history
Fix bug in quiz
  • Loading branch information
sukhbir-singh authored Oct 26, 2016
2 parents 0a0e5b7 + 13354a8 commit 17c5849
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import appteam.nith.hillffair.R;
import appteam.nith.hillffair.application.SharedPref;
import appteam.nith.hillffair.fragments.QuizFragment;
Expand All @@ -32,9 +34,6 @@
import appteam.nith.hillffair.utilities.Connection;
import appteam.nith.hillffair.utilities.ScoreCalculator;
import appteam.nith.hillffair.utilities.Utils;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand All @@ -49,6 +48,7 @@ public class QuizQuestionActivity extends AppCompatActivity {
private TextView message,time_left;
private FragmentManager manager;
private static timer t;
private ScoreCalculator scoreCalculator;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -69,6 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
progressBar=(ProgressBar)findViewById(R.id.progress);
message=(TextView)findViewById(R.id.message);
time_left=(TextView)findViewById(R.id.time_left);
scoreCalculator=ScoreCalculator.getInstance();

back2home.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -97,12 +98,16 @@ public void onResponse(Call<QuizQuestionsModel> call, Response<QuizQuestionsMode
progressBar.setVisibility(View.GONE);

QuizQuestionsModel model=response.body();

int status=response.code();

if(model!=null && response.isSuccess()){
if(model.isSuccess()){
// set viewpager

ScoreCalculator sc=ScoreCalculator.getInstance();
sc.setSpecial(1);

final List<SingleQuestionModel> questions=model.getQuestions();

pager.setVisibility(View.VISIBLE);
Expand All @@ -115,7 +120,7 @@ public void onResponse(Call<QuizQuestionsModel> call, Response<QuizQuestionsMode
t.execute();

//initialize scoreCalculator
ScoreCalculator sc=ScoreCalculator.getInstance();
//ScoreCalculator sc=ScoreCalculator.getInstance();

String answers[]=new String[questions.size()];
String selectedChoices[]=new String[questions.size()];
Expand Down Expand Up @@ -257,6 +262,7 @@ public void onResponse(Call<UpdateScoreModel> call, Response<UpdateScoreModel> r

if(model!=null && response.isSuccess()){
if(model.isSuccess()){
scoreCalculator.setSpecial(0);
Toast.makeText(QuizQuestionActivity.this,model.getMsg() ,Toast.LENGTH_SHORT);

finish();
Expand Down Expand Up @@ -379,9 +385,13 @@ protected void onProgressUpdate(Pair<String, String>... values) {

@Override
protected void onPostExecute(Void aVoid) {

if(new Connection(context).isInternet()){
Log.v("internet","available");

ScoreCalculator sc=ScoreCalculator.getInstance();

if(sc.getSpecial()==1)
((QuizQuestionActivity)context).submitScore();

}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public void onResponse(Call<Likecount> call, Response<Likecount> response) {

@Override
public void onFailure(Call<Likecount> call, Throwable t) {

Toast.makeText(mContext, "Check Your Internet Connectivity and Permissions", Toast.LENGTH_SHORT).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,26 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
finish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
progressBar.setVisibility(View.VISIBLE);

finish.setEnabled(false);

SharedPref pref=new SharedPref(getContext());
ScoreCalculator sc=ScoreCalculator.getInstance();

if(sc.getSpecial()==1){
progressBar.setVisibility(View.VISIBLE);

SharedPref pref=new SharedPref(getContext());

int score_calculated=sc.calculateScore();
Log.v("calculated_score is ",score_calculated+"");

int score_calculated=sc.calculateScore();
Log.v("calculated_score is ",score_calculated+"");
sc.resetInstance(); //Important

((QuizQuestionActivity)getActivity()).finishAndUpdateScore(pref.getUserId(),score_calculated);

}

sc.resetInstance(); //Important

((QuizQuestionActivity)getActivity()).finishAndUpdateScore(pref.getUserId(),score_calculated);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ public class ScoreCalculator {
private static ScoreCalculator obj;
private String answers[],selectedChoices[];
private int totalScore=0;
private int special;

public int getSpecial() {
return special;
}

public void setSpecial(int special) {
this.special = special;
}

private int question_type[]; // 1 => single 2 => multiple

private ScoreCalculator(){
Expand Down

0 comments on commit 17c5849

Please sign in to comment.