Skip to content

Commit

Permalink
Merge pull request #6 from Rifzzu/main
Browse files Browse the repository at this point in the history
change auth + fix UI
  • Loading branch information
BillyFrcs committed Jun 16, 2023
2 parents 07f2f9b + d96e5cf commit 243fa64
Show file tree
Hide file tree
Showing 62 changed files with 1,315 additions and 159 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ dependencies {

//Library Paging
implementation "androidx.paging:paging-runtime-ktx:3.1.0"

//Library Circle Image/hdodenhof
implementation 'de.hdodenhof:circleimageview:3.1.0'

// Datastore
implementation "androidx.datastore:datastore-preferences:1.0.0"
}
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
android:theme="@style/Theme.BuzzWiseApp"
tools:targetApi="31">
<activity
android:name=".ui.profiledetail.profileDetailActivity"
android:name=".ui.profile.UserInformationActivity"
android:exported="false" />
<activity
android:name=".ui.jobdetail.JobDetailActivity"
android:name=".ui.profile.EditProfileActivity"
android:exported="false" />
<activity
android:name=".ui.profiledetail.profileDetailActivity"
android:exported="false"
android:theme="@style/Theme.BuzzWiseApp" />
<activity
android:name=".ui.jobdetail.JobDetailActivity"
android:exported="false"
android:theme="@style/Theme.BuzzWiseApp" />
<activity
android:name=".ui.auth.RegisterActivity"
android:exported="false" />
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/example/buzzwiseapp/data/LoginPayload.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.buzzwiseapp.data

import com.google.gson.annotations.SerializedName

data class LoginPayload(
@field:SerializedName("email")
val email: String,

@field:SerializedName("password")
val password: String
)
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/buzzwiseapp/data/RegisterPayload.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.buzzwiseapp.data

import com.google.gson.annotations.SerializedName

data class RegisterPayload(
@field:SerializedName("name")
val name: String,

@field:SerializedName("email")
val email: String,

@field:SerializedName("password")
val password: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ package com.example.buzzwiseapp.data

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.example.buzzwiseapp.data.model.UserPreference
import com.example.buzzwiseapp.ui.SplashViewModel
import com.example.buzzwiseapp.ui.auth.LoginViewModel
import com.example.buzzwiseapp.ui.home.HomeViewModel
import com.example.buzzwiseapp.ui.profile.ProfileViewModel

class ViewModelFactory : ViewModelProvider.NewInstanceFactory(){
class ViewModelFactory(private val pref: UserPreference) : ViewModelProvider.NewInstanceFactory(){
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return when {
modelClass.isAssignableFrom(HomeViewModel::class.java) -> {
HomeViewModel() as T
}
modelClass.isAssignableFrom(LoginViewModel::class.java) -> {
LoginViewModel(pref) as T
}
modelClass.isAssignableFrom(SplashViewModel::class.java) -> {
SplashViewModel(pref) as T
}
modelClass.isAssignableFrom(ProfileViewModel::class.java) -> {
ProfileViewModel(pref) as T
}
else -> throw IllegalArgumentException("Unknown ViewModel class: " + modelClass.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class ApiConfig {

companion object {
fun getApiService(): ApiService {
val loggingInterceptor =
Expand All @@ -19,6 +20,9 @@ class ApiConfig {
.build()
return retrofit.create(ApiService::class.java)
}
private var token = ""
fun setToken(value: String) {
token = value
}
}

}
18 changes: 15 additions & 3 deletions app/src/main/java/com/example/buzzwiseapp/data/api/ApiService.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package com.example.buzzwiseapp.data.api

import com.example.buzzwiseapp.data.LoginPayload
import com.example.buzzwiseapp.data.RegisterPayload
import com.example.buzzwiseapp.data.response.DataItem
import com.example.buzzwiseapp.data.response.JobDetailResponse
import com.example.buzzwiseapp.data.response.JobResponse
import com.example.buzzwiseapp.data.response.LoginResponse
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path

interface ApiService {

@GET("jobs/alljobs")
fun getAllJobs(): Call<JobResponse>

@GET("/jobs/{userId}")
@GET("jobs/job/{userId}")
fun getDetailStory(
@Path("userId") userId: String
): Call<JobDetailResponse>
@POST("/api/users/signUp")
fun registerUser(
@Body payload: RegisterPayload
): Call<ResponseBody>
@POST("/api/users/signIn")
fun loginUser(
@Body payload: LoginPayload
): Call<LoginResponse>
}
7 changes: 0 additions & 7 deletions app/src/main/java/com/example/buzzwiseapp/data/model/Job.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.buzzwiseapp.data.model

data class UserModel(
val token: String,
val isLogin: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.example.buzzwiseapp.data.model

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import com.example.buzzwiseapp.data.api.ApiConfig
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class UserPreference private constructor(private val dataStore: DataStore<Preferences>){
//Get User
fun getUser(): Flow<UserModel> {
return dataStore.data.map { preferences ->
UserModel(
preferences[TOKEN] ?:"",
preferences[STATE_KEY] ?: false
)
}
}

//Save User Data
suspend fun saveUser(user: UserModel) {
dataStore.edit { preferences ->
preferences[TOKEN] = user.token
preferences[STATE_KEY] = user.isLogin
}
}

//Change State
suspend fun login() {
dataStore.edit { preferences ->
preferences[STATE_KEY] = true
}
}

suspend fun logout() {
dataStore.edit { preferences ->
preferences[STATE_KEY] = false
preferences[TOKEN] = ""
}
}

companion object {
@Volatile
private var INSTANCE: UserPreference? = null

private val TOKEN = stringPreferencesKey("password")
private val STATE_KEY = booleanPreferencesKey("state")

fun getInstance(dataStore: DataStore<Preferences>): UserPreference {
return INSTANCE ?: synchronized(this) {
val instance = UserPreference(dataStore)
INSTANCE = instance
instance
}
}
fun setToken(token: String) {
ApiConfig.setToken(token)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class DataItem(
@field:SerializedName("location")
val location: String? = null,

@field:SerializedName("requiredSkill")
@field:SerializedName("requiredSkills")
val requiredSkill: String? = null,

@field:SerializedName("id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.example.buzzwiseapp.data.response

import com.google.gson.annotations.SerializedName

data class LoginResponse(

@field:SerializedName("data")
val data: Data? = null,

@field:SerializedName("message")
val message: String? = null
)

data class MultiFactor(

@field:SerializedName("enrolledFactors")
val enrolledFactors: List<Any?>? = null
)

data class StsTokenManager(

@field:SerializedName("apiKey")
val apiKey: String? = null,

@field:SerializedName("expirationTime")
val expirationTime: Long? = null,

@field:SerializedName("accessToken")
val accessToken: String? = null,

@field:SerializedName("refreshToken")
val refreshToken: String? = null
)

data class User(

@field:SerializedName("apiKey")
val apiKey: String? = null,

@field:SerializedName("providerData")
val providerData: List<ProviderDataItem?>? = null,

@field:SerializedName("displayName")
val displayName: String? = null,

@field:SerializedName("appName")
val appName: String? = null,

@field:SerializedName("redirectEventId")
val redirectEventId: Any? = null,

@field:SerializedName("authDomain")
val authDomain: String? = null,

@field:SerializedName("uid")
val uid: String? = null,

@field:SerializedName("photoURL")
val photoURL: Any? = null,

@field:SerializedName("emailVerified")
val emailVerified: Boolean? = null,

@field:SerializedName("createdAt")
val createdAt: String? = null,

@field:SerializedName("isAnonymous")
val isAnonymous: Boolean? = null,

@field:SerializedName("stsTokenManager")
val stsTokenManager: StsTokenManager? = null,

@field:SerializedName("phoneNumber")
val phoneNumber: Any? = null,

@field:SerializedName("lastLoginAt")
val lastLoginAt: String? = null,

@field:SerializedName("multiFactor")
val multiFactor: MultiFactor? = null,

@field:SerializedName("tenantId")
val tenantId: Any? = null,

@field:SerializedName("email")
val email: String? = null
)

data class AdditionalUserInfo(

@field:SerializedName("providerId")
val providerId: String? = null,

@field:SerializedName("isNewUser")
val isNewUser: Boolean? = null
)

data class Data(

@field:SerializedName("credential")
val credential: Any? = null,

@field:SerializedName("additionalUserInfo")
val additionalUserInfo: AdditionalUserInfo? = null,

@field:SerializedName("operationType")
val operationType: String? = null,

@field:SerializedName("user")
val user: User? = null
)

data class ProviderDataItem(

@field:SerializedName("uid")
val uid: String? = null,

@field:SerializedName("photoURL")
val photoURL: Any? = null,

@field:SerializedName("phoneNumber")
val phoneNumber: Any? = null,

@field:SerializedName("displayName")
val displayName: String? = null,

@field:SerializedName("providerId")
val providerId: String? = null,

@field:SerializedName("email")
val email: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.buzzwiseapp.data.response

import com.google.gson.annotations.SerializedName

data class RegisterResponse(

@field:SerializedName("error")
val error: String
)
Loading

0 comments on commit 243fa64

Please sign in to comment.