├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cheezycode │ │ └── quizzed │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cheezycode │ │ │ └── quizzed │ │ │ ├── activities │ │ │ ├── LoginActivity.kt │ │ │ ├── LoginIntro.kt │ │ │ ├── MainActivity.kt │ │ │ ├── ProfileActivity.kt │ │ │ ├── QuestionActivity.kt │ │ │ ├── ResultActivity.kt │ │ │ └── SignupActivity.kt │ │ │ ├── adapters │ │ │ ├── OptionAdapter.kt │ │ │ └── QuizAdapter.kt │ │ │ ├── models │ │ │ ├── Question.kt │ │ │ └── Quiz.kt │ │ │ └── utils │ │ │ ├── ColorPicker.kt │ │ │ └── IconPicker.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── btn_primary.xml │ │ ├── edit_text_background.xml │ │ ├── ic_date.xml │ │ ├── ic_hamburger.xml │ │ ├── ic_icon.png │ │ ├── ic_icon_1.xml │ │ ├── ic_icon_2.xml │ │ ├── ic_icon_3.xml │ │ ├── ic_icon_4.xml │ │ ├── ic_icon_5.xml │ │ ├── ic_icon_6.xml │ │ ├── ic_icon_7.xml │ │ ├── ic_icon_8.xml │ │ ├── ic_icon_trophy.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_quiz_login_hero_image.xml │ │ ├── ic_wave.xml │ │ ├── option_item_bg.xml │ │ └── option_item_selected_bg.xml │ │ ├── layout │ │ ├── activity_login.xml │ │ ├── activity_login_intro.xml │ │ ├── activity_main.xml │ │ ├── activity_profile.xml │ │ ├── activity_question.xml │ │ ├── activity_result.xml │ │ ├── activity_signup.xml │ │ ├── drawer_header.xml │ │ ├── option_item.xml │ │ └── quiz_item.xml │ │ ├── menu │ │ └── drawer_menu.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── cheezycode │ └── quizzed │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 20 | 22 | 23 | 24 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | xmlns:android 33 | 34 | ^$ 35 | 36 | 37 | 38 |
39 |
40 | 41 | 42 | 43 | xmlns:.* 44 | 45 | ^$ 46 | 47 | 48 | BY_NAME 49 | 50 |
51 |
52 | 53 | 54 | 55 | .*:id 56 | 57 | http://schemas.android.com/apk/res/android 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | .*:name 67 | 68 | http://schemas.android.com/apk/res/android 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | name 78 | 79 | ^$ 80 | 81 | 82 | 83 |
84 |
85 | 86 | 87 | 88 | style 89 | 90 | ^$ 91 | 92 | 93 | 94 |
95 |
96 | 97 | 98 | 99 | .* 100 | 101 | ^$ 102 | 103 | 104 | BY_NAME 105 | 106 |
107 |
108 | 109 | 110 | 111 | .* 112 | 113 | http://schemas.android.com/apk/res/android 114 | 115 | 116 | ANDROID_ATTRIBUTE_ORDER 117 | 118 |
119 |
120 | 121 | 122 | 123 | .* 124 | 125 | .* 126 | 127 | 128 | BY_NAME 129 | 130 |
131 |
132 |
133 |
134 | 135 | 137 |
138 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.google.gms.google-services' 5 | 6 | android { 7 | compileSdkVersion 29 8 | 9 | defaultConfig { 10 | applicationId "com.cheezycode.quizzed" 11 | minSdkVersion 21 12 | targetSdkVersion 29 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: "libs", include: ["*.jar"]) 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 30 | implementation 'androidx.core:core-ktx:1.3.2' 31 | implementation 'androidx.appcompat:appcompat:1.2.0' 32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 33 | implementation 'com.google.firebase:firebase-auth:19.3.2' 34 | implementation 'com.google.firebase:firebase-firestore:22.0.0' 35 | testImplementation 'junit:junit:4.12' 36 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 38 | implementation 'com.google.android.material:material:1.1.0' 39 | implementation 'com.google.code.gson:gson:2.8.6' 40 | } 41 | -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "1094127200925", 4 | "firebase_url": "https://quizzed-7ef7e.firebaseio.com", 5 | "project_id": "quizzed-7ef7e", 6 | "storage_bucket": "quizzed-7ef7e.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:1094127200925:android:0b60d33b1955db55904274", 12 | "android_client_info": { 13 | "package_name": "com.cheezycode.quizzed" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "1094127200925-6qaal2hf85mk1a3jbaf5v6geb1feept3.apps.googleusercontent.com", 19 | "client_type": 3 20 | } 21 | ], 22 | "api_key": [ 23 | { 24 | "current_key": "AIzaSyDECeQy5p3BX8WiQVBVWgyPzHVynIwiWWM" 25 | } 26 | ], 27 | "services": { 28 | "appinvite_service": { 29 | "other_platform_oauth_client": [ 30 | { 31 | "client_id": "1094127200925-6qaal2hf85mk1a3jbaf5v6geb1feept3.apps.googleusercontent.com", 32 | "client_type": 3 33 | } 34 | ] 35 | } 36 | } 37 | } 38 | ], 39 | "configuration_version": "1" 40 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/cheezycode/quizzed/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.cheezycode.quizzed", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/LoginActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.widget.Toast 7 | import com.cheezycode.quizzed.R 8 | import com.google.firebase.auth.FirebaseAuth 9 | import kotlinx.android.synthetic.main.activity_login.* 10 | 11 | class LoginActivity : AppCompatActivity() { 12 | 13 | lateinit var firebaseAuth: FirebaseAuth 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | setContentView(R.layout.activity_login) 18 | firebaseAuth = FirebaseAuth.getInstance() 19 | 20 | btnLogin.setOnClickListener { 21 | login() 22 | } 23 | 24 | btnSignUp.setOnClickListener { 25 | val intent = Intent(this, SignupActivity::class.java) 26 | startActivity(intent) 27 | finish() 28 | } 29 | 30 | } 31 | 32 | private fun login(){ 33 | val email = etEmailAddress.text.toString() 34 | val password = etPassword.text.toString() 35 | 36 | 37 | if (email.isBlank() || password.isBlank()) { 38 | Toast.makeText(this, "Email/password cannot be empty", Toast.LENGTH_SHORT).show() 39 | return 40 | } 41 | 42 | firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this){ 43 | if(it.isSuccessful){ 44 | Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show() 45 | val intent = Intent(this, MainActivity::class.java) 46 | startActivity(intent) 47 | finish() 48 | } 49 | else{ 50 | Toast.makeText(this, "Authentication Failed", Toast.LENGTH_SHORT).show() 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/LoginIntro.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.widget.Toast 7 | import com.cheezycode.quizzed.R 8 | import com.google.firebase.auth.FirebaseAuth 9 | import kotlinx.android.synthetic.main.activity_login_intro.* 10 | import java.lang.Exception 11 | 12 | class LoginIntro : AppCompatActivity() { 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_login_intro) 16 | val auth = FirebaseAuth.getInstance() 17 | if(auth.currentUser != null){ 18 | Toast.makeText(this, "User is already logged in!", Toast.LENGTH_SHORT).show() 19 | redirect("MAIN") 20 | } 21 | 22 | btnGetStarted.setOnClickListener { 23 | redirect("LOGIN") 24 | } 25 | } 26 | 27 | private fun redirect(name:String){ 28 | val intent = when(name){ 29 | "LOGIN" -> Intent(this, LoginActivity::class.java) 30 | "MAIN" -> Intent(this, MainActivity::class.java) 31 | else -> throw Exception("no path exists") 32 | } 33 | startActivity(intent) 34 | finish() 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.util.Log 7 | import android.view.MenuItem 8 | import android.widget.Toast 9 | import androidx.appcompat.app.ActionBarDrawerToggle 10 | import androidx.recyclerview.widget.GridLayoutManager 11 | import com.cheezycode.quizzed.R 12 | import com.cheezycode.quizzed.adapters.QuizAdapter 13 | import com.cheezycode.quizzed.models.Quiz 14 | import com.google.android.material.datepicker.MaterialDatePicker 15 | import com.google.firebase.firestore.FirebaseFirestore 16 | import kotlinx.android.synthetic.main.activity_main.* 17 | import java.text.SimpleDateFormat 18 | import java.util.* 19 | 20 | class MainActivity : AppCompatActivity() { 21 | 22 | lateinit var actionBarDrawerToggle: ActionBarDrawerToggle 23 | lateinit var adapter: QuizAdapter 24 | private var quizList = mutableListOf() 25 | lateinit var firestore: FirebaseFirestore 26 | 27 | override fun onCreate(savedInstanceState: Bundle?) { 28 | super.onCreate(savedInstanceState) 29 | setContentView(R.layout.activity_main) 30 | setUpViews() 31 | } 32 | 33 | fun setUpViews() { 34 | setUpFireStore() 35 | setUpDrawerLayout() 36 | setUpRecyclerView() 37 | setUpDatePicker() 38 | } 39 | 40 | private fun setUpDatePicker() { 41 | btnDatePicker.setOnClickListener { 42 | val datePicker = MaterialDatePicker.Builder.datePicker().build() 43 | datePicker.show(supportFragmentManager, "DatePicker") 44 | datePicker.addOnPositiveButtonClickListener { 45 | Log.d("DATEPICKER", datePicker.headerText) 46 | val dateFormatter = SimpleDateFormat("dd-mm-yyyy") 47 | val date = dateFormatter.format(Date(it)) 48 | val intent = Intent(this, QuestionActivity::class.java) 49 | intent.putExtra("DATE", date) 50 | startActivity(intent) 51 | } 52 | datePicker.addOnNegativeButtonClickListener { 53 | Log.d("DATEPICKER", datePicker.headerText) 54 | 55 | } 56 | datePicker.addOnCancelListener { 57 | Log.d("DATEPICKER", "Date Picker Cancelled") 58 | } 59 | } 60 | } 61 | 62 | private fun setUpFireStore() { 63 | firestore = FirebaseFirestore.getInstance() 64 | val collectionReference = firestore.collection("quizzes") 65 | collectionReference.addSnapshotListener { value, error -> 66 | if(value == null || error != null){ 67 | Toast.makeText(this, "Error fetching data", Toast.LENGTH_SHORT).show() 68 | return@addSnapshotListener 69 | } 70 | Log.d("DATA", value.toObjects(Quiz::class.java).toString()) 71 | quizList.clear() 72 | quizList.addAll(value.toObjects(Quiz::class.java)) 73 | adapter.notifyDataSetChanged() 74 | } 75 | } 76 | 77 | private fun setUpRecyclerView() { 78 | adapter = QuizAdapter(this, quizList) 79 | quizRecyclerView.layoutManager = GridLayoutManager(this, 2) 80 | quizRecyclerView.adapter = adapter 81 | } 82 | 83 | fun setUpDrawerLayout() { 84 | setSupportActionBar(appBar) 85 | actionBarDrawerToggle = 86 | ActionBarDrawerToggle(this, mainDrawer, R.string.app_name, R.string.app_name) 87 | actionBarDrawerToggle.syncState() 88 | navigationView.setNavigationItemSelectedListener { 89 | val intent = Intent(this, ProfileActivity::class.java) 90 | startActivity(intent) 91 | mainDrawer.closeDrawers() 92 | true 93 | } 94 | } 95 | 96 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 97 | if (actionBarDrawerToggle.onOptionsItemSelected(item)) { 98 | return true 99 | } 100 | return super.onOptionsItemSelected(item) 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/ProfileActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import com.cheezycode.quizzed.R 7 | import com.google.firebase.auth.FirebaseAuth 8 | import kotlinx.android.synthetic.main.activity_profile.* 9 | 10 | class ProfileActivity : AppCompatActivity() { 11 | lateinit var firebaseAuth: FirebaseAuth 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_profile) 16 | firebaseAuth = FirebaseAuth.getInstance() 17 | txtEmail.text = firebaseAuth.currentUser?.email 18 | 19 | btnLogout.setOnClickListener { 20 | FirebaseAuth.getInstance().signOut() 21 | val intent = Intent(this, LoginActivity::class.java) 22 | startActivity(intent) 23 | 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/QuestionActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.util.Log 7 | import android.view.View 8 | import androidx.recyclerview.widget.LinearLayoutManager 9 | import com.cheezycode.quizzed.R 10 | import com.cheezycode.quizzed.adapters.OptionAdapter 11 | import com.cheezycode.quizzed.models.Question 12 | import com.cheezycode.quizzed.models.Quiz 13 | import com.google.firebase.firestore.FirebaseFirestore 14 | import com.google.gson.Gson 15 | import kotlinx.android.synthetic.main.activity_question.* 16 | 17 | class QuestionActivity : AppCompatActivity() { 18 | 19 | var quizzes : MutableList? = null 20 | var questions: MutableMap? = null 21 | var index = 1 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setContentView(R.layout.activity_question) 26 | setUpFirestore() 27 | setUpEventListener() 28 | } 29 | 30 | private fun setUpEventListener() { 31 | btnPrevious.setOnClickListener { 32 | index-- 33 | bindViews() 34 | } 35 | 36 | btnNext.setOnClickListener { 37 | index++ 38 | bindViews() 39 | } 40 | 41 | btnSubmit.setOnClickListener { 42 | Log.d("FINALQUIZ", questions.toString()) 43 | 44 | val intent = Intent(this, ResultActivity::class.java) 45 | val json = Gson().toJson(quizzes!![0]) 46 | intent.putExtra("QUIZ", json) 47 | startActivity(intent) 48 | } 49 | } 50 | 51 | private fun setUpFirestore() { 52 | val firestore = FirebaseFirestore.getInstance() 53 | var date = intent.getStringExtra("DATE") 54 | if (date != null) { 55 | firestore.collection("quizzes").whereEqualTo("title", date) 56 | .get() 57 | .addOnSuccessListener { 58 | if(it != null && !it.isEmpty){ 59 | quizzes = it.toObjects(Quiz::class.java) 60 | questions = quizzes!![0].questions 61 | bindViews() 62 | } 63 | } 64 | } 65 | } 66 | 67 | private fun bindViews() { 68 | btnPrevious.visibility = View.GONE 69 | btnSubmit.visibility = View.GONE 70 | btnNext.visibility = View.GONE 71 | 72 | if(index == 1){ //first question 73 | btnNext.visibility = View.VISIBLE 74 | } 75 | else if(index == questions!!.size) { // last question 76 | btnSubmit.visibility = View.VISIBLE 77 | btnPrevious.visibility = View.VISIBLE 78 | } 79 | else{ // Middle 80 | btnPrevious.visibility = View.VISIBLE 81 | btnNext.visibility = View.VISIBLE 82 | } 83 | 84 | val question = questions!!["question$index"] 85 | question?.let { 86 | description.text = it.description 87 | val optionAdapter = OptionAdapter(this, it) 88 | optionList.layoutManager = LinearLayoutManager(this) 89 | optionList.adapter = optionAdapter 90 | optionList.setHasFixedSize(true) 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/ResultActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.os.Build 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.text.Html 7 | import com.cheezycode.quizzed.R 8 | import com.cheezycode.quizzed.models.Quiz 9 | import com.google.gson.Gson 10 | import kotlinx.android.synthetic.main.activity_result.* 11 | 12 | class ResultActivity : AppCompatActivity() { 13 | lateinit var quiz: Quiz 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_result) 17 | setUpViews() 18 | } 19 | 20 | private fun setUpViews() { 21 | val quizData = intent.getStringExtra("QUIZ") 22 | quiz = Gson().fromJson(quizData, Quiz::class.java) 23 | calculateScore() 24 | setAnswerView() 25 | } 26 | 27 | private fun setAnswerView() { 28 | val builder = StringBuilder("") 29 | for (entry in quiz.questions.entries) { 30 | val question = entry.value 31 | builder.append("Question: ${question.description}

") 32 | builder.append("Answer: ${question.answer}

") 33 | } 34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 35 | txtAnswer.text = Html.fromHtml(builder.toString(), Html.FROM_HTML_MODE_COMPACT); 36 | } else { 37 | txtAnswer.text = Html.fromHtml(builder.toString()); 38 | } 39 | } 40 | 41 | private fun calculateScore() { 42 | var score = 0 43 | for (entry in quiz.questions.entries) { 44 | val question = entry.value 45 | if (question.answer == question.userAnswer) { 46 | score += 10 47 | } 48 | } 49 | txtScore.text = "Your Score : $score" 50 | } 51 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/activities/SignupActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.activities 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.widget.Toast 7 | import com.cheezycode.quizzed.R 8 | import com.google.firebase.auth.FirebaseAuth 9 | import kotlinx.android.synthetic.main.activity_signup.* 10 | import kotlinx.android.synthetic.main.activity_signup.btnSignUp 11 | import kotlinx.android.synthetic.main.activity_signup.etEmailAddress 12 | import kotlinx.android.synthetic.main.activity_signup.etPassword 13 | 14 | class SignupActivity : AppCompatActivity() { 15 | 16 | lateinit var firebaseAuth: FirebaseAuth 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | setContentView(R.layout.activity_signup) 21 | firebaseAuth = FirebaseAuth.getInstance() 22 | 23 | btnSignUp.setOnClickListener { 24 | signUpUser() 25 | } 26 | 27 | btnLogin.setOnClickListener { 28 | val intent = Intent(this, LoginActivity::class.java) 29 | startActivity(intent) 30 | finish() 31 | } 32 | } 33 | 34 | private fun signUpUser(){ 35 | val email = etEmailAddress.text.toString() 36 | val password = etPassword.text.toString() 37 | val confirmPassword = etConfirmPassword.text.toString() 38 | 39 | if (email.isBlank() || password.isBlank() || confirmPassword.isBlank()) { 40 | Toast.makeText(this, "Email and Password can't be blank", Toast.LENGTH_SHORT).show() 41 | return 42 | } 43 | 44 | if (password != confirmPassword) { 45 | Toast.makeText(this, "Password and Confirm Password do not match", Toast.LENGTH_SHORT) 46 | .show() 47 | return 48 | } 49 | 50 | firebaseAuth.createUserWithEmailAndPassword(email, password) 51 | .addOnCompleteListener(this) { 52 | if(it.isSuccessful){ 53 | Toast.makeText(this,"Login Successful", Toast.LENGTH_SHORT).show() 54 | val intent = Intent(this, MainActivity::class.java) 55 | startActivity(intent) 56 | finish() 57 | } 58 | else{ 59 | Toast.makeText(this, "Error creating user.", Toast.LENGTH_SHORT).show() 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/adapters/OptionAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.adapters 2 | 3 | import android.content.Context 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.TextView 8 | import android.widget.Toast 9 | import androidx.recyclerview.widget.RecyclerView 10 | import com.cheezycode.quizzed.R 11 | import com.cheezycode.quizzed.models.Question 12 | 13 | class OptionAdapter(val context: Context, val question: Question) : 14 | RecyclerView.Adapter() { 15 | 16 | private var options: List = listOf(question.option1, question.option2, question.option3, question.option4) 17 | 18 | inner class OptionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){ 19 | var optionView = itemView.findViewById(R.id.quiz_option) 20 | } 21 | 22 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OptionViewHolder { 23 | val view = LayoutInflater.from(context).inflate(R.layout.option_item, parent, false) 24 | return OptionViewHolder(view) 25 | } 26 | 27 | override fun onBindViewHolder(holder: OptionViewHolder, position: Int) { 28 | holder.optionView.text = options[position] 29 | holder.itemView.setOnClickListener { 30 | question.userAnswer = options[position] 31 | notifyDataSetChanged() 32 | } 33 | if(question.userAnswer == options[position]){ 34 | holder.itemView.setBackgroundResource(R.drawable.option_item_selected_bg) 35 | } 36 | else{ 37 | holder.itemView.setBackgroundResource(R.drawable.option_item_bg) 38 | } 39 | 40 | } 41 | 42 | override fun getItemCount(): Int { 43 | return options.size 44 | } 45 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/adapters/QuizAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.adapters 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.graphics.Color 6 | import android.text.Layout 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import android.widget.ImageView 11 | import android.widget.TextView 12 | import android.widget.Toast 13 | import androidx.cardview.widget.CardView 14 | import androidx.recyclerview.widget.RecyclerView 15 | import com.cheezycode.quizzed.R 16 | import com.cheezycode.quizzed.activities.QuestionActivity 17 | import com.cheezycode.quizzed.models.Quiz 18 | import com.cheezycode.quizzed.utils.ColorPicker 19 | import com.cheezycode.quizzed.utils.IconPicker 20 | 21 | class QuizAdapter(val context: Context, val quizzes: List) : 22 | RecyclerView.Adapter() { 23 | 24 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QuizViewHolder { 25 | val view = LayoutInflater.from(context).inflate(R.layout.quiz_item, parent, false) 26 | return QuizViewHolder(view) 27 | } 28 | 29 | override fun onBindViewHolder(holder: QuizViewHolder, position: Int) { 30 | holder.textViewTitle.text = quizzes[position].title 31 | holder.cardContainer.setCardBackgroundColor(Color.parseColor(ColorPicker.getColor())) 32 | holder.iconView.setImageResource(IconPicker.getIcon()) 33 | holder.itemView.setOnClickListener { 34 | Toast.makeText(context, quizzes[position].title, Toast.LENGTH_SHORT).show() 35 | val intent = Intent(context, QuestionActivity::class.java) 36 | intent.putExtra("DATE", quizzes[position].title) 37 | context.startActivity(intent) 38 | } 39 | } 40 | 41 | override fun getItemCount(): Int { 42 | return quizzes.size 43 | } 44 | 45 | inner class QuizViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 46 | var textViewTitle: TextView = itemView.findViewById(R.id.quizTitle) 47 | var iconView: ImageView = itemView.findViewById(R.id.quizIcon) 48 | var cardContainer: CardView = itemView.findViewById(R.id.cardContainer) 49 | } 50 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/models/Question.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.models 2 | 3 | data class Question( 4 | var description: String = "", 5 | var option1: String = "", 6 | var option2: String = "", 7 | var option3: String = "", 8 | var option4: String = "", 9 | var answer: String = "", 10 | var userAnswer: String = "" 11 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/models/Quiz.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.models 2 | 3 | data class Quiz ( 4 | var id : String = "", 5 | var title: String = "", 6 | var questions: MutableMap = mutableMapOf() 7 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/utils/ColorPicker.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.utils 2 | 3 | object ColorPicker { 4 | val colors = arrayOf( 5 | "#3EB9DF", 6 | "#3685BC", 7 | "#D36280", 8 | "#E44F55", 9 | "#FA8056", 10 | "#818BCA", 11 | "#7D659F", 12 | "#51BAB3", 13 | "#4FB66C", 14 | "#E3AD17", 15 | "#627991", 16 | "#EF8EAD", 17 | "#B5BFC6" 18 | ) 19 | var currentColorIndex = 0 20 | 21 | fun getColor(): String { 22 | currentColorIndex = (currentColorIndex + 1) % colors.size 23 | return colors[currentColorIndex] 24 | } 25 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cheezycode/quizzed/utils/IconPicker.kt: -------------------------------------------------------------------------------- 1 | package com.cheezycode.quizzed.utils 2 | 3 | import com.cheezycode.quizzed.R 4 | 5 | object IconPicker { 6 | val icons = arrayOf( 7 | R.drawable.ic_icon_1, 8 | R.drawable.ic_icon_2, 9 | R.drawable.ic_icon_3, 10 | R.drawable.ic_icon_4, 11 | R.drawable.ic_icon_5, 12 | R.drawable.ic_icon_6, 13 | R.drawable.ic_icon_7, 14 | R.drawable.ic_icon_8 15 | ) 16 | var currentIcon = 0 17 | 18 | fun getIcon(): Int { 19 | currentIcon = (currentIcon + 1) % icons.size 20 | return icons[currentIcon] 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_primary.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/edit_text_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_date.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_hamburger.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheezyCode/Quizzed/cef1d1beccffd038e598f24656479228cf102830/app/src/main/res/drawable/ic_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_1.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 97 | 104 | 111 | 118 | 121 | 124 | 131 | 138 | 139 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_2.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 95 | 100 | 105 | 110 | 111 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_3.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 97 | 104 | 111 | 118 | 125 | 132 | 133 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_4.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 97 | 104 | 111 | 118 | 119 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_5.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 97 | 104 | 111 | 118 | 125 | 132 | 139 | 146 | 153 | 160 | 167 | 168 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_6.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 77 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_7.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 97 | 104 | 111 | 118 | 125 | 132 | 139 | 146 | 153 | 160 | 167 | 174 | 175 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_8.xml: -------------------------------------------------------------------------------- 1 | 6 | 13 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 79 | 80 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_icon_trophy.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 45 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_quiz_login_hero_image.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 45 | 48 | 51 | 54 | 57 | 60 | 63 | 66 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 98 | 101 | 104 | 107 | 110 | 113 | 116 | 119 | 122 | 125 | 128 | 131 | 134 | 137 | 140 | 143 | 146 | 149 | 152 | 155 | 156 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_wave.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/option_item_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/option_item_selected_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 27 | 28 | 35 | 36 | 46 | 47 | 57 | 58 |