From 90755a1f3a41fadf0ad47e63521eb7a130ab0966 Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 3 Aug 2023 10:50:20 -0400 Subject: [PATCH] add --- app/src/main/AndroidManifest.xml | 1 + .../com/innovator/solve/CongratsPage.java | 5 +- .../com/innovator/solve/DailyChallenge.java | 34 ++++- .../innovator/solve/MainMenuController.java | 2 +- .../com/innovator/solve/MockTestManager.java | 15 +- .../solve/MultipleAnswerFragment.java | 52 ++----- .../com/innovator/solve/PastProblems.java | 29 ++-- .../com/innovator/solve/PastProblemsTwo.java | 26 ++-- .../com/innovator/solve/RetryProblem.java | 17 ++- .../java/com/innovator/solve/ReviewPage.java | 61 ++++++-- .../innovator/solve/ShortAnswerFragment.java | 21 ++- .../com/innovator/solve/TestActivity.java | 88 +++++++++++- app/src/main/res/layout/daily_challenge.xml | 37 ++++- app/src/main/res/layout/layout_two.xml | 122 ++++++++++++++-- app/src/main/res/layout/retry_problem.xml | 35 +++++ app/src/main/res/layout/review_page.xml | 134 ++++++++++-------- .../main/res/layout/single_past_problem.xml | 34 +++++ 17 files changed, 550 insertions(+), 163 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9bfb7a9..4845ee8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" + android:usesCleartextTraffic="true" android:theme="@style/AppTheme"> diff --git a/app/src/main/java/com/innovator/solve/CongratsPage.java b/app/src/main/java/com/innovator/solve/CongratsPage.java index fad9a7f..0a29e61 100644 --- a/app/src/main/java/com/innovator/solve/CongratsPage.java +++ b/app/src/main/java/com/innovator/solve/CongratsPage.java @@ -43,7 +43,10 @@ public void returnToHome(View v){ startActivity(new Intent(this, MainMenuController.class)); } public void goToReviewPage(View v){ - startActivity(new Intent(this, PastProblemsTwo.class)); + Intent i = new Intent(this, PastProblemsTwo.class); + i.putExtra("ANSWERS", getIntent().getExtras().getString("ANSWERS")); + i.putExtra("TestID", getIntent().getExtras().getString("TestID")); + startActivity(i); } } \ No newline at end of file diff --git a/app/src/main/java/com/innovator/solve/DailyChallenge.java b/app/src/main/java/com/innovator/solve/DailyChallenge.java index f0953f6..6e50d90 100644 --- a/app/src/main/java/com/innovator/solve/DailyChallenge.java +++ b/app/src/main/java/com/innovator/solve/DailyChallenge.java @@ -1,20 +1,28 @@ package com.innovator.solve; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; +import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.collection.CircularArray; import com.bumptech.glide.Glide; +import com.google.api.Distribution; import com.innovator.solve.R; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; @@ -29,6 +37,7 @@ import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; @@ -58,6 +67,8 @@ public class DailyChallenge extends AppCompatActivity{ private String currentDate; + + @Override protected void onCreate(Bundle savedInstance){ super.onCreate(savedInstance); @@ -71,8 +82,10 @@ protected void onCreate(Bundle savedInstance){ currentDate=formatter.format(date).substring(0,10).replace('/','-'); selectCategory(); + } + public void selectCategory(){ SharedPreferences pastCategories=getSharedPreferences("PastCategories", Context.MODE_PRIVATE); SharedPreferences.Editor editPastQuestions=pastCategories.edit(); @@ -153,6 +166,9 @@ public void loadChallenge(){ currentQuestionData=DailyChallengeManager.getCurrentQuestionData(); + popup = findViewById(R.id.popup); + popup.setVisibility(View.GONE); + questionDisplay.setText("Question: "+(String)currentQuestionData.get("question")); choiceA.setText("A. "+currentQuestionData.get("optA")); choiceB.setText("B. "+currentQuestionData.get("optB")); @@ -250,9 +266,7 @@ public void clickedD(View view){ } private void verifyAnswer(String choice){ - TextView explanationText = findViewById(R.id.explanation); - - explanationText.setText("Explanation: "+currentQuestionData.get("explanation")); + popup(); } private boolean retrieveDataPoints(Map databaseStorage){ @@ -305,4 +319,18 @@ public void onComplete(@NonNull Task task) { }); } + private LinearLayout popup; + + private void popup() { + popup.setVisibility(View.VISIBLE); + TextView txt = (TextView) findViewById(R.id.textView2); + txt.setText("Explanation: "+currentQuestionData.get("explanation")); + Button button = (Button) findViewById(R.id.button); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + popup.setVisibility(View.GONE); + } + }); + } } diff --git a/app/src/main/java/com/innovator/solve/MainMenuController.java b/app/src/main/java/com/innovator/solve/MainMenuController.java index 3a5c9ad..c950741 100644 --- a/app/src/main/java/com/innovator/solve/MainMenuController.java +++ b/app/src/main/java/com/innovator/solve/MainMenuController.java @@ -71,7 +71,7 @@ public void returnToHome(View view){ } public void dailyChallenge(View view){ - startActivity(new Intent(this, Review.class)); + startActivity(new Intent(this, DailyChallenge.class)); } @Override diff --git a/app/src/main/java/com/innovator/solve/MockTestManager.java b/app/src/main/java/com/innovator/solve/MockTestManager.java index c18e916..0290c74 100644 --- a/app/src/main/java/com/innovator/solve/MockTestManager.java +++ b/app/src/main/java/com/innovator/solve/MockTestManager.java @@ -114,19 +114,20 @@ private void collectTests(Mapquestions) { String category = (String) q.get("Category"); String statement = (String) q.get("Question"); String explanation = (String) q.get("Explanation"); - int picNum = Math.toIntExact((Long) q.get("MediaID")); + int picNum = Math.toIntExact((Long) q.get("QuestionPicNumber")); int exPicNum = Math.toIntExact((Long) q.get("ExMediaID")); - - TreeMap choices = new TreeMap<>(); - Map choiceMap = (Map) q.get("Choices"); - for (Object key: (choiceMap).keySet()) { - Character k = ((String) key).charAt(0); - choices.put(k, (String) choiceMap.get(key)); + if (type.charAt(0) != 'S') { + Map choiceMap = (Map) q.get("Choices"); + for (Object key: (choiceMap).keySet()) { + Character k = ((String) key).charAt(0); + choices.put(k, (String) choiceMap.get(key)); + } } + Question qObj = new Question(true, type, statement, choices, answer, explanation, category, picNum, exPicNum); questionList.add(qObj); } diff --git a/app/src/main/java/com/innovator/solve/MultipleAnswerFragment.java b/app/src/main/java/com/innovator/solve/MultipleAnswerFragment.java index dfb45f5..91801eb 100644 --- a/app/src/main/java/com/innovator/solve/MultipleAnswerFragment.java +++ b/app/src/main/java/com/innovator/solve/MultipleAnswerFragment.java @@ -152,12 +152,16 @@ public void onClick(View v) { } }); buttonD = (FButton) view.findViewById(R.id.buttonD); - buttonD.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - buttonD(true); - } - }); + if (numChoices > 3) { + buttonD.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + buttonD(true); + } + }); + } + else + view.findViewById(R.id.buttonD).setVisibility(View.GONE); buttonE = (FButton) view.findViewById(R.id.buttonE); if (numChoices > 4) { view.findViewById(R.id.buttonE).setVisibility(View.VISIBLE); @@ -246,34 +250,6 @@ public void displayQuestion() { buttonB.setText(currentQuestion.getOptB()); buttonC.setText(currentQuestion.getOptC()); buttonD.setText(currentQuestion.getOptD()); - Log.d("YAS2", ""+currentQuestion.getPicNumber()); - if (currentQuestion.getPicNumber() > -1) { - loadQuestionPic(currentQuestion.getPicNumber()); - } - } - - private void loadQuestionPic(int questionPicID){ - Log.d("YAS", ""+questionPicID); - if(questionPicID < 0)return; - StorageReference qImageRef = FirebaseStorage.getInstance().getReference() //but what if it doesn't exist? - .child(TopicManager.getPicRootFolderName()) - .child("Question_Pics") - .child(TopicManager.getPicNamePrefix()+"_q_"+questionPicID+".PNG"); - - qImageRef.getDownloadUrl().addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - if(task.isSuccessful()) - { - Glide.with(getActivity()) - .load(task.getResult()) - .into(questionPic); - } - else { - - } - } - }); } public void setAnswer(int i) { @@ -309,15 +285,15 @@ public void updateButtons(boolean notOnCreate) { updateChoices(); buttonA.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[0] == 1)?R.color.blue:R.color.white)); buttonB.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[1] == 1)?R.color.blue:R.color.white)); - buttonC.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[2] == 1)?R.color.blue:R.color.white)); - buttonD.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[3] == 1)?R.color.blue:R.color.white)); + if (numChoices > 2) buttonC.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[2] == 1)?R.color.blue:R.color.white)); + if (numChoices > 3) buttonD.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[3] == 1)?R.color.blue:R.color.white)); if (numChoices > 4) buttonE.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[4] == 1)?R.color.blue:R.color.white)); if (numChoices > 5) buttonF.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[5] == 1)?R.color.blue:R.color.white)); if (numChoices > 6) buttonG.setButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[6] == 1)?R.color.blue:R.color.white)); buttonA.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[0] == 1)?R.color.white:R.color.grey)); buttonB.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[1] == 1)?R.color.white:R.color.grey)); - buttonC.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[2] == 1)?R.color.white:R.color.grey)); - buttonD.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[3] == 1)?R.color.white:R.color.grey)); + if (numChoices > 2) buttonC.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[2] == 1)?R.color.white:R.color.grey)); + if (numChoices > 3) buttonD.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[3] == 1)?R.color.white:R.color.grey)); if (numChoices > 4) buttonE.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[4] == 1)?R.color.white:R.color.grey)); if (numChoices > 5) buttonF.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[5] == 1)?R.color.white:R.color.grey)); if (numChoices > 6) buttonG.setTextColor(ContextCompat.getColor(getActivity().getApplicationContext(), (buttonClicked[6] == 1)?R.color.white:R.color.grey)); diff --git a/app/src/main/java/com/innovator/solve/PastProblems.java b/app/src/main/java/com/innovator/solve/PastProblems.java index 800252c..c72df8c 100644 --- a/app/src/main/java/com/innovator/solve/PastProblems.java +++ b/app/src/main/java/com/innovator/solve/PastProblems.java @@ -45,10 +45,14 @@ protected void onCreate(Bundle savedInstanceState){ pastProblemsLayout = (LinearLayout)findViewById(R.id.past_problems_linear_layout); populateLayout(); + } + private LinearLayout popup; + private void getPastProblems(){ String currentUserID=InnovatorApplication.getUser().getId(); + questionLocation.collection("User_"+currentUserID).get().addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(QuerySnapshot queryDocumentSnapshots) { @@ -72,6 +76,8 @@ public void onSuccess(QuerySnapshot queryDocumentSnapshots) { @Override public void onClick(View view) { setContentView(R.layout.single_past_problem); + popup = findViewById(R.id.popup); + popup.setVisibility(View.GONE); long questionPicNumber=-1; if(questionData.get("picNumber")!=null){ @@ -90,13 +96,11 @@ public void onClick(View view) { Button choiceD=findViewById(R.id.pastAnswerD); TextView questionText=findViewById(R.id.questionDisplay); - TextView explanationText=findViewById(R.id.explanation); - Map references = new HashMap(){{ - put("Option A", choiceA); - put("Option B", choiceB); - put("Option C", choiceC); - put("Option D", choiceD); + put("Option A", choiceA); + put("Option B", choiceB); + put("Option C", choiceC); + put("Option D", choiceD); }}; choiceA.setText(questionData.get("optA").toString()); @@ -105,8 +109,17 @@ public void onClick(View view) { choiceD.setText(questionData.get("optD").toString()); questionText.setText("Question: "+questionData.get("question").toString()); - explanationText.setText("Explanation: "+questionData.get("explanation").toString()); + popup.setVisibility(View.VISIBLE); + TextView txt = (TextView) findViewById(R.id.textView2); + txt.setText("Explanation: "+questionData.get("explanation").toString()); + Button button = (Button) findViewById(R.id.button); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + popup.setVisibility(View.GONE); + } + }); references.get("Option "+correctAnswer).setBackgroundColor(Color.GREEN); references.get("Option "+correctAnswer).setTextColor(Color.WHITE); @@ -183,5 +196,5 @@ public void returnToHome(View v){ public void retryCurrentQuestion(View view){ startActivity(new Intent(this, RetryProblem.class)); } - + } diff --git a/app/src/main/java/com/innovator/solve/PastProblemsTwo.java b/app/src/main/java/com/innovator/solve/PastProblemsTwo.java index 076bb3f..8e182c1 100644 --- a/app/src/main/java/com/innovator/solve/PastProblemsTwo.java +++ b/app/src/main/java/com/innovator/solve/PastProblemsTwo.java @@ -1,31 +1,41 @@ package com.innovator.solve; -import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import java.util.ArrayList; +import java.util.Arrays; + public class PastProblemsTwo extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.review_page); - - ReviewPage information = new ReviewPage(); + String testID = getIntent().getExtras().getString("TestID"); + ArrayList answers = new ArrayList<>(Arrays.asList(getIntent().getExtras().getString("ANSWERS").split("\n"))); + Log.d("YAS", testID); + MockTestManager.MockTest m = MockTestManager.getTestByID(testID); + ArrayList qs = m.questionList; + ReviewPage information = new ReviewPage(qs, answers); TextView Question = findViewById(R.id.Question); - TextView Answer = findViewById(R.id.Answer); + TextView YourAnswer = findViewById(R.id.your_answer); + TextView Answer = findViewById(R.id.answer); Button button = findViewById(R.id.Next); Button back = findViewById(R.id.back); + information.updateButtons(button, back); information.question(Question); + information.yourAnswer(YourAnswer); information.answer(Answer); - information.Click(button, Question, Answer); - information.back(back, Question, Answer); + information.Click(button, back, Question, YourAnswer, Answer); + information.back(button, back, Question, YourAnswer, Answer); } - public void goBack(View v){ - startActivity(new Intent(this, CongratsPage.class)); + public void goBack(View v) { + finish(); } } \ No newline at end of file diff --git a/app/src/main/java/com/innovator/solve/RetryProblem.java b/app/src/main/java/com/innovator/solve/RetryProblem.java index 06d36e6..58259bf 100644 --- a/app/src/main/java/com/innovator/solve/RetryProblem.java +++ b/app/src/main/java/com/innovator/solve/RetryProblem.java @@ -7,6 +7,7 @@ import android.view.View; import android.widget.Button; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -35,6 +36,8 @@ public class RetryProblem extends AppCompatActivity { public Map buttonDict; + private LinearLayout popup; + private boolean answerSelected; protected void onCreate(Bundle savedInstance){ @@ -64,6 +67,9 @@ protected void onCreate(Bundle savedInstance){ } public void initiateValues(){ + popup = findViewById(R.id.popup); + popup.setVisibility(View.GONE); + questionText.setText("Question: "+retryQuestion.getQuestion()); choiceA.setText(retryQuestion.getOptA()); choiceB.setText(retryQuestion.getOptB()); @@ -74,7 +80,16 @@ public void initiateValues(){ } private void verifyAnswer(String choice){ - explanationText.setText("Explanation: "+retryQuestion.getExplanation()); + popup.setVisibility(View.VISIBLE); + TextView txt = (TextView) findViewById(R.id.textView2); + txt.setText("Explanation: "+retryQuestion.getExplanation()); + Button button = (Button) findViewById(R.id.button); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + popup.setVisibility(View.GONE); + } + }); buttonDict.get(choice).setBackgroundColor(Color.RED); buttonDict.get(choice).setTextColor(Color.WHITE); diff --git a/app/src/main/java/com/innovator/solve/ReviewPage.java b/app/src/main/java/com/innovator/solve/ReviewPage.java index 16ba77b..bef96f0 100644 --- a/app/src/main/java/com/innovator/solve/ReviewPage.java +++ b/app/src/main/java/com/innovator/solve/ReviewPage.java @@ -4,39 +4,70 @@ import android.widget.Button; import android.widget.TextView; +import java.util.ArrayList; + public class ReviewPage { - static int i = 0; - static int numberquestion = 1; - static String[] question = {"MATH QUESTION: WHAT IS 1+1!!!!!! OMGGGGG YAYAYAYAYAYAYYAY","What is 2+2"}; - static String[] answer = {"Well, 1+1 is equal to 2. You know why? Well, it is because if Jeff and Bob put 1 cookie each on a table, then in total, there will be 2 cookies. So, 1+1 = 2", "What the hell"}; + int page = 0; + ArrayList qs; + ArrayList yourAns; + int numQs; + + public ReviewPage(ArrayList q, ArrayList ans) { + qs = q; + numQs = qs.size(); + yourAns = ans; + } public void question(TextView x){ - String a = Integer.toString(numberquestion); - x.setText("Question" + " " + "#" + a + ":" + " " + question[i]); + String a = Integer.toString(page+1); + x.setText("Question" + " " + "#" + a + ":" + " " + qs.get(page).getQuestion()); + } + + public void yourAnswer(TextView x){ + x.setText("Your Answer: " + yourAns.get(page) + ": " + getOption(qs.get(page), yourAns.get(page))); } public void answer (TextView x){ - x.setText("Answer" + ":" + " " + answer[i]); + x.setText("Correct Answer" + ":" + " " + qs.get(page).getAnswer() + "\n" + qs.get(page).getExplanation()); } - public void Click (Button x, TextView question, TextView answer){ - x.setOnClickListener(new View.OnClickListener() { + public String getOption(Question q, String opt) { + if (opt.equalsIgnoreCase("Option A")) return q.getOptA(); + if (opt.equalsIgnoreCase("Option B")) return q.getOptB(); + if (opt.equalsIgnoreCase("Option C")) return q.getOptC(); + if (opt.equalsIgnoreCase("Option D")) return q.getOptD(); + return ""; + } + public void updateButtons(Button forward, Button back) { + if (page == 0) + back.setVisibility(View.GONE); + else + back.setVisibility(View.VISIBLE); + if (page >= numQs - 1) + forward.setVisibility(View.GONE); + else + forward.setVisibility(View.VISIBLE); + } + public void Click (Button forward, Button back, TextView question, TextView yourans, TextView answer){ + forward.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - i += 1; - numberquestion += 1; + page += 1; + updateButtons(forward, back); question(question); + yourAnswer(yourans); answer(answer); } }); } - public void back (Button x, TextView question, TextView answer){ - x.setOnClickListener(new View.OnClickListener() { + public void back (Button forward, Button back, TextView question, TextView yourans, TextView answer){ + back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - i -= 1; - numberquestion -= 1; + page -= 1; + updateButtons(forward, back); question(question); + yourAnswer(yourans); answer(answer); } }); diff --git a/app/src/main/java/com/innovator/solve/ShortAnswerFragment.java b/app/src/main/java/com/innovator/solve/ShortAnswerFragment.java index 712aacf..7a3dccd 100644 --- a/app/src/main/java/com/innovator/solve/ShortAnswerFragment.java +++ b/app/src/main/java/com/innovator/solve/ShortAnswerFragment.java @@ -2,6 +2,8 @@ import android.content.Intent; import android.net.Uri; +import android.text.Editable; +import android.text.TextWatcher; import android.text.method.ScrollingMovementMethod; import androidx.annotation.NonNull; @@ -58,6 +60,7 @@ public class ShortAnswerFragment extends Fragment { public interface OnAnswerSelected { public void onFrqAnswerSelect(String s); + public void clearChoices(); } OnAnswerSelected mCallback; Typeface tb; @@ -109,10 +112,26 @@ public void onCreate(Bundle savedInstanceState) { setQuestion(QuestionManager.decompileData(requireArguments())); displayQuestion(currentQuestion); mCallback = (OnAnswerSelected)getActivity(); + textAnswer.addTextChangedListener(new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) {} + + @Override + public void beforeTextChanged(CharSequence s, int start, + int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, + int before, int count) { + mCallback.clearChoices(); + mCallback.onFrqAnswerSelect(s.toString()); + } + }); } public void onDestroy() { - mCallback.onFrqAnswerSelect(textAnswer.getText().toString()); super.onDestroy(); } diff --git a/app/src/main/java/com/innovator/solve/TestActivity.java b/app/src/main/java/com/innovator/solve/TestActivity.java index 13fb9ec..42a99bd 100644 --- a/app/src/main/java/com/innovator/solve/TestActivity.java +++ b/app/src/main/java/com/innovator/solve/TestActivity.java @@ -3,10 +3,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Typeface; +import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -14,9 +16,24 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.signature.ObjectKey; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.security.Key; +import java.security.PrivateKey; +import java.security.Signature; import java.util.ArrayList; import java.util.Arrays; +import javax.crypto.SecretKey; + public class TestActivity extends AppCompatActivity implements DragAndDropFragment.OnAnswerSelected, MultipleAnswerFragment.OnAnswerSelected, @@ -33,9 +50,11 @@ public class TestActivity extends AppCompatActivity implements int page = 0; int[] qIds; boolean saveState = true; + ImageView questionPic; ArrayList answers = new ArrayList<>(); ArrayList qs; + String testID; @Override protected void onCreate(Bundle savedInstanceState) { @@ -45,7 +64,8 @@ protected void onCreate(Bundle savedInstanceState) { leftButton = findViewById(R.id.leftButton); rightButton = findViewById(R.id.rightButton); leftButton.setVisibility(View.GONE); - String testID = getIntent().getExtras().getString("TestID"); + questionPic = findViewById(R.id.question_picture); + testID = getIntent().getExtras().getString("TestID"); MockTestManager.MockTest m = MockTestManager.getTestByID(testID); qs = m.questionList; lastPageNo = getIntent().getExtras().getInt("NUMQUESTIONS"); @@ -104,7 +124,17 @@ protected void onCreate(Bundle savedInstanceState) { } - + public void updateImage() { + //Glide.get(findViewById(R.id.question_picture).getContext()).clearDiskCache(); + //questionPic.setImageDrawable(null); + Question q = qs.get(page); + if (q.getPicNumber() > -1) { + findViewById(R.id.viewPicButton).setVisibility(View.VISIBLE); + loadQuestionPic(q.getPicNumber()); + } + else + findViewById(R.id.viewPicButton).setVisibility(View.GONE); + } public void onDndAnswerSelect(int[][] boxAndButtons) { for (int[] pair: boxAndButtons) answers.get(page).addDndAnswer(pair[0], pair[1]); @@ -185,6 +215,7 @@ public void pageLeft(View view) { } public void buttonGen() { + updateImage(); if (page == 0) leftButton.setVisibility(View.GONE); else leftButton.setVisibility(View.VISIBLE); if (page == lastPageNo-1) { @@ -220,6 +251,10 @@ public void onDestroy() { super.onDestroy(); } + public void viewImage(View view) { + goToFormulaSheet(view); + } + public void returnToHome(View view) { prevPage = page; finish(); @@ -240,11 +275,20 @@ public void goToFormulaSheet(View view) { //findViewById(R.id.constraintLayout4).setVisibility(View.GONE); } + public void goToFormulaSheet2(View view) { + findViewById(R.id.formula_sheet2).setVisibility(View.VISIBLE); + findViewById(R.id.formula_sheet2).bringToFront(); + //findViewById(R.id.constraintLayout4).setVisibility(View.GONE); + } + public void returnToTestPage(View view) { findViewById(R.id.formula_sheet).setVisibility(View.GONE); + findViewById(R.id.formula_sheet2).setVisibility(View.GONE); findViewById(R.id.dark_screen).setVisibility(View.GONE); findViewById(R.id.leave_prompt).setVisibility(View.GONE); findViewById(R.id.submit_prompt).setVisibility(View.GONE); + findViewById(R.id.picture_layout).setVisibility(View.GONE); + findViewById(R.id.constraintLayout4).setVisibility(View.VISIBLE); } public void displayCalculator(View view) { @@ -267,11 +311,18 @@ public void goToResults(View view) { editor.clear(); editor.commit(); saveState = false; - finish(); ScoreOfMockTest.numSections = numSections; ScoreOfMockTest.section1 = gradeTest(); ScoreOfMockTest.section1total = lastPageNo; - startActivity(new Intent(this, CongratsPage.class)); + Intent i = new Intent(this, CongratsPage.class); + String ans = ""; + for (AnswerFormatManager afm: answers) { + ans += afm.toString() + "\n"; + } + i.putExtra("ANSWERS", ans.substring(0, ans.length()-1)); + i.putExtra("TestID", getIntent().getExtras().getString("TestID")); + startActivity(i); + finish(); } public int gradeTest() { @@ -281,4 +332,33 @@ public int gradeTest() { } return total; } + + private void loadQuestionPic(int questionPicID){ + if(questionPicID < 0)return; + //FirebaseAuth.getInstance().signInAnonymously(); + StorageReference qImageRef = FirebaseStorage.getInstance().getReference() //but what if it doesn't exist? + .child("Mocks") + .child(testID) + .child("Question_Pics") + .child(questionPicID+".png"); + + qImageRef.getDownloadUrl().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if(task.isSuccessful()) + { + Glide.with(questionPic.getContext()) + .load(task.getResult()) + .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) + .apply(RequestOptions.skipMemoryCacheOf(true)) + .signature(new ObjectKey(String.valueOf(System.currentTimeMillis()))) + .into(questionPic); + Log.d("idk", ""+qImageRef.getPath()); + } + else { + + } + } + }); + } } diff --git a/app/src/main/res/layout/daily_challenge.xml b/app/src/main/res/layout/daily_challenge.xml index d523db5..bbc7c98 100644 --- a/app/src/main/res/layout/daily_challenge.xml +++ b/app/src/main/res/layout/daily_challenge.xml @@ -26,6 +26,7 @@ app:layout_constraintHorizontal_bias="0.063" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + android:layout_height="match_parent" + android:id = "@+id/questioning"> + + + + + +