Skip to content

Commit

Permalink
Re-deign And Optimise code
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitjakhar committed Jun 30, 2021
1 parent 9fa2c75 commit 48ea3ab
Show file tree
Hide file tree
Showing 72 changed files with 42,533 additions and 443 deletions.
117 changes: 117 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ android {
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0-rc01'
Expand Down Expand Up @@ -110,5 +108,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-auth:19.0.0'

implementation('com.github.hellosagar:ProgressButton:0.31')
implementation "com.airbnb.android:lottie:3.7.0"


}
Binary file added app/release/app-release.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/java/com/rohit/quizzon/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity() {
R.id.quizListFragment -> hideBottomBar()
R.id.quizFragment -> hideBottomBar()
R.id.nav_create_quiz -> hideBottomBar()
R.id.resultFragment -> hideBottomBar()
else -> showBottomBar()
}
}
Expand Down
19 changes: 0 additions & 19 deletions app/src/main/java/com/rohit/quizzon/ResultFragment.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.datastore.preferences.core.edit
import com.rohit.quizzon.data.model.body.UserProfileBody
import com.rohit.quizzon.utils.PreferenceDataStore
import com.rohit.quizzon.utils.PreferenceDataStore.PreferenceKey.PREF_LOGGED_IN
import com.rohit.quizzon.utils.PreferenceDataStore.PreferenceKey.PREF_USER_GENDER
import com.rohit.quizzon.utils.PreferenceDataStore.PreferenceKey.PREF_USER_ID
import com.rohit.quizzon.utils.PreferenceDataStore.PreferenceKey.PREF_USER_NAME
import com.rohit.quizzon.utils.PreferenceDataStore.PreferenceKey.PREF_USE_EMAIL
Expand All @@ -32,8 +31,7 @@ class DataStorePreferenceStorage @Inject constructor(
UserProfileBody(
username = it[PREF_USER_NAME] ?: "",
user_id = it[PREF_USER_ID] ?: "",
userEmail = it[PREF_USE_EMAIL] ?: "",
gender = it[PREF_USER_GENDER] ?: "male"
userEmail = it[PREF_USE_EMAIL] ?: ""
)
}

Expand All @@ -42,7 +40,6 @@ class DataStorePreferenceStorage @Inject constructor(
mutablePreferences[PREF_USER_NAME] = user.username
mutablePreferences[PREF_USE_EMAIL] = user.userEmail
mutablePreferences[PREF_USER_ID] = user.user_id
mutablePreferences[PREF_USER_GENDER] = user.gender
}
}

Expand Down
21 changes: 10 additions & 11 deletions app/src/main/java/com/rohit/quizzon/data/QuizService.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.rohit.quizzon.data

import com.rohit.quizzon.data.model.body.*
import com.rohit.quizzon.data.model.body.DataGetBody
import com.rohit.quizzon.data.model.body.InsertDataBody
import com.rohit.quizzon.data.model.response.CategoryResponseItem
import com.rohit.quizzon.data.model.response.DataInsertResponse
import com.rohit.quizzon.data.model.response.DeleteResponseBody
import com.rohit.quizzon.data.model.response.QuizResponse
import com.rohit.quizzon.data.model.response.UserProfileResponse
import retrofit2.Response
Expand All @@ -13,22 +15,22 @@ import retrofit2.http.POST
interface QuizService {

@POST("/")
suspend fun fetechQuizes(
suspend fun getQuizzes(
@Header("Authorization") token: String,
@Body getQuizBody: DataGetBody
): Response<List<QuizResponse>>

@POST("/")
suspend fun saveUserData(
suspend fun deleteQuiz(
@Header("Authorization") token: String,
@Body user: InsertDataBody
): Response<DataInsertResponse>
@Body getQuizBody: DataGetBody
): Response<DeleteResponseBody>

@POST("/")
suspend fun fetchCategory(
suspend fun saveUserData(
@Header("Authorization") token: String,
@Body categoryBody: DataGetBody
): List<CategoryResponseItem>
@Body user: InsertDataBody
): Response<DataInsertResponse>

@POST("/")
suspend fun getCategory(
Expand All @@ -47,7 +49,4 @@ interface QuizService {
@Header("Authorization") token: String,
@Body quizBody: InsertDataBody
): Response<DataInsertResponse>

@POST("/")
suspend fun fetchProfile()
}
57 changes: 50 additions & 7 deletions app/src/main/java/com/rohit/quizzon/data/RemoteRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ package com.rohit.quizzon.data
import android.util.Log
import com.google.firebase.auth.FirebaseAuth
import com.rohit.quizzon.BuildConfig
import com.rohit.quizzon.data.model.body.*
import com.rohit.quizzon.data.model.body.DataGetBody
import com.rohit.quizzon.data.model.body.InsertDataBody
import com.rohit.quizzon.data.model.body.QuestionBody
import com.rohit.quizzon.data.model.body.UserProfileBody
import com.rohit.quizzon.data.model.response.CategoryResponseItem
import com.rohit.quizzon.data.model.response.DataInsertResponse
import com.rohit.quizzon.data.model.response.DeleteResponseBody
import com.rohit.quizzon.data.model.response.QuizResponse
import com.rohit.quizzon.data.model.response.UserProfileResponse
import com.rohit.quizzon.utils.NetworkResponse
import com.rohit.quizzon.utils.mapToErrorResponse
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
import okhttp3.Credentials
Expand Down Expand Up @@ -40,8 +46,7 @@ class RemoteRepository @Inject constructor(
UserProfileBody(
user_id = it.userId,
username = it.username,
userEmail = it.userEmail,
gender = "Male"
userEmail = it.userEmail
)
)
}
Expand Down Expand Up @@ -85,8 +90,7 @@ class RemoteRepository @Inject constructor(
val userProfileBody = UserProfileBody(
user_id = it.uid,
username = username,
userEmail = email,
gender = gender
userEmail = email
)
val userInsertBody = InsertDataBody(
operation = INSERT_OPERATION,
Expand Down Expand Up @@ -151,7 +155,7 @@ class RemoteRepository @Inject constructor(
else -> "$GET_QUIZ_QUERY WHERE category_id = '$category_id'"
}
val response =
apiCall.fetechQuizes(cred, DataGetBody(operation = SQL_OPERATION, sql = SQL_QUERY))
apiCall.getQuizzes(cred, DataGetBody(operation = SQL_OPERATION, sql = SQL_QUERY))
return if (response.isSuccessful) {
NetworkResponse.Success(data = response.body(), message = response.message())
} else {
Expand Down Expand Up @@ -189,10 +193,49 @@ class RemoteRepository @Inject constructor(
} else NetworkResponse.Failure(mapToErrorResponse(response.errorBody()).error)
}

suspend fun loadQuizData(quizId: String): NetworkResponse<QuizResponse> {
val SQL_QUERY = "$GET_QUIZ_QUERY WHERE quiz_id = '$quizId'"
val response =
apiCall.getQuizzes(cred, DataGetBody(operation = SQL_OPERATION, sql = SQL_QUERY))
return if (response.isSuccessful) {
val quizData = response.body()
return if (!quizData.isNullOrEmpty()) {
NetworkResponse.Success(data = quizData[0], message = "Added")
} else NetworkResponse.Failure("Quiz Not Found!. Please Check Quiz Id")
} else {
NetworkResponse.Failure(message = mapToErrorResponse(response.errorBody()).error)
}
}

suspend fun userQuizList(
user_id: String
): NetworkResponse<List<QuizResponse>> {
val SQL_QUERY = "$GET_QUIZ_QUERY WHERE create_id = '$user_id'"
val response =
apiCall.getQuizzes(cred, DataGetBody(operation = SQL_OPERATION, sql = SQL_QUERY))
return if (response.isSuccessful) {
NetworkResponse.Success(data = response.body(), message = response.message())
} else {
NetworkResponse.Failure(mapToErrorResponse(response.errorBody()).error)
}
}

suspend fun deleteQuiz(quizId: String): NetworkResponse<DeleteResponseBody> {
val SQL_QUERY = "$DELETE_QUIZ_QUERY WHERE quiz_id = '$quizId'"
val response =
apiCall.deleteQuiz(cred, DataGetBody(operation = SQL_OPERATION, sql = SQL_QUERY))
return if (response.isSuccessful) {
NetworkResponse.Success(data = null, message = response.message())
} else {
NetworkResponse.Failure(mapToErrorResponse(response.errorBody()).error)
}
}

companion object {
const val SQL_OPERATION = "sql"
const val GET_CATEGORY_QUERY = "SELECT * FROM dev.category"
const val GET_QUIZ_QUERY = "SELECT * FROM dev.quizzes"
const val DELETE_QUIZ_QUERY = "DELETE FROM dev.quizzes"
const val GET_USER_PROFILE_QUERY = "SELECT * FROM dev.user_profile"
const val INSERT_OPERATION = "insert"
const val APP_SCHEMA = "dev"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/rohit/quizzon/data/model/QuizResult.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.rohit.quizzon.data.model

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
data class QuizResult(
val totalQuestion: Int,
val rightAnswer: Int,
val wrongAnswer: Int
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ data class UserProfileBody(
val user_id: String,
val username: String,
val userEmail: String,
val gender: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.rohit.quizzon.data.model.response

import com.google.gson.annotations.SerializedName

data class DeleteResponseBody(
@SerializedName("deleted_hashes")
val deletedHashes: List<String>,
@SerializedName("message")
val message: String,
@SerializedName("skipped_hashes")
val skippedHashes: List<Any>
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.rohit.quizzon.data.model.CreateQuestionData
import com.rohit.quizzon.ui.viewholder.CreateQuestionViewHolder
import com.rohit.quizzon.utils.listener.CreateQuizListener

class CreateQuestionAdapter(
class QuestionAdapter(
private val createQuizListener: CreateQuizListener
) :
ListAdapter<CreateQuestionData, CreateQuestionViewHolder>(diffUtil) {
Expand Down
Loading

0 comments on commit 48ea3ab

Please sign in to comment.