Skip to content

Commit

Permalink
Login Feature Implement
Browse files Browse the repository at this point in the history
  • Loading branch information
aveek committed Jun 19, 2022
1 parent a20e9d9 commit 00f1d7b
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 58 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ android {
versionCode 1
versionName "8.35.0"

buildConfigField "String", "BASE_URL", baseUrl
buildConfigField "String", "API_VERSION", apiVersion
buildConfigField "String", "APP_ID", appId
// buildConfigField "String", "BASE_URL", baseUrl
// buildConfigField "String", "API_VERSION", apiVersion
// buildConfigField "String", "APP_ID", appId
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import com.moneybox.minimb.BuildConfig
import okhttp3.Interceptor
import okhttp3.Response

class NoAuthenticationInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
return chain.proceed(
chain.request().newBuilder()
.addHeader(APP_ID_HEADER_NAME, BuildConfig.APP_ID)
.addHeader(API_VERSION_HEADER_NAME, BuildConfig.API_VERSION)
.addHeader(APP_VERSION_HEADER_NAME, BuildConfig.VERSION_NAME)
.addHeader(CONTENT_HEADER_NAME, CONTENT_HEADER_VALUE)
.build()
)
}

companion object {
private const val APP_ID_HEADER_NAME = "AppId"
private const val API_VERSION_HEADER_NAME = "ApiVersion"
private const val APP_VERSION_HEADER_NAME = "AppVersion"
private const val CONTENT_HEADER_NAME = "ContentDetail-Type"
private const val CONTENT_HEADER_VALUE = "application/json"
}
}
//class NoAuthenticationInterceptor : Interceptor {
// override fun intercept(chain: Interceptor.Chain): Response {
// return chain.proceed(
// chain.request().newBuilder()
// .addHeader(APP_ID_HEADER_NAME, BuildConfig.APP_ID)
// .addHeader(API_VERSION_HEADER_NAME, BuildConfig.API_VERSION)
// .addHeader(APP_VERSION_HEADER_NAME, BuildConfig.VERSION_NAME)
// .addHeader(CONTENT_HEADER_NAME, CONTENT_HEADER_VALUE)
// .build()
// )
// }
//
// companion object {
// private const val APP_ID_HEADER_NAME = "AppId"
// private const val API_VERSION_HEADER_NAME = "ApiVersion"
// private const val APP_VERSION_HEADER_NAME = "AppVersion"
// private const val CONTENT_HEADER_NAME = "ContentDetail-Type"
// private const val CONTENT_HEADER_VALUE = "application/json"
// }
//}
28 changes: 14 additions & 14 deletions app/src/main/java/com/moneybox/minimb/data/networking/Networking.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object Networking {
fun createClient(): OkHttpClient {
return OkHttpClient
.Builder()
.addInterceptor(NoAuthenticationInterceptor())
.build()
}

fun createRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.client(createClient())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
// fun createClient(): OkHttpClient {
// return OkHttpClient
// .Builder()
// .addInterceptor(NoAuthenticationInterceptor())
// .build()
// }
//
// fun createRetrofit(): Retrofit {
// return Retrofit.Builder()
// .baseUrl(BuildConfig.BASE_URL)
// .client(createClient())
// .addConverterFactory(GsonConverterFactory.create())
// .build()
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.moneybox.minimb.feature.login.ui

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -11,6 +12,7 @@ import com.moneybox.minimb.feature.login.LoginActivityHandler
import com.moneybox.minimb.feature.login.R
import com.moneybox.minimb.feature.login.databinding.ActivityLoginBinding
import com.moneybox.minimb.feature.login.utilities.Utils.isNetworkAvailable
import com.moneybox.minimb.network.ApiResponseResult
import com.moneybox.minimb.network.ILogger
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand Down Expand Up @@ -50,14 +52,25 @@ class LoginActivity : AppCompatActivity() {
}
}
})
loginResult.observe(this@LoginActivity, Observer{ value->
if (value){
Toast.makeText(this@LoginActivity, "Login Clicked", Toast.LENGTH_LONG).show()
loginResult.observe(this@LoginActivity, Observer{ response->

startActivity(
Intent("com.moneybox.minimb.feature.products.open")
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
.setPackage(this@LoginActivity.packageName))
Toast.makeText(this@LoginActivity, "Login Clicked", Toast.LENGTH_LONG).show()
when(response.status){
ApiResponseResult.Status.SUCCESS ->{
startActivity(
Intent("com.moneybox.minimb.feature.products.open")
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
.setPackage(this@LoginActivity.packageName))
}
ApiResponseResult.Status.ERROR ->{
binding.progressbarLogin.visibility = View.GONE
Snackbar.make(binding.root, response.message.toString(), Snackbar.LENGTH_LONG).show()
logger.error(message = "Login Response Error", throwable = null)
}
ApiResponseResult.Status.LOADING ->{
binding.progressbarLogin.visibility = View.VISIBLE
logger.debug(message = "Login Response Loading")
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ package com.moneybox.minimb.feature.login.ui

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.moneybox.minimb.feature.login.data.LoginRepository
import com.moneybox.minimb.feature.login.models.LoginResponse
import com.moneybox.minimb.network.ApiResponseResult
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject


/*Email: jaeren+androidtest@moneyboxapp.com
Password: P455word12*/
@HiltViewModel
class LoginViewModel @Inject constructor() : ViewModel() {
class LoginViewModel @Inject constructor(private val loginRepository: LoginRepository) : ViewModel() {

// private val _loginResult = MutableLiveData<ApiRe>
private val _loginResult = MutableLiveData<Boolean>()
private val _loginResult = MutableLiveData<ApiResponseResult<LoginResponse>>()
// private val _loginResult = MutableLiveData<Boolean>()
val loginResult = _loginResult

val _loginClick = MutableLiveData<Boolean>(false)
Expand All @@ -20,7 +29,17 @@ class LoginViewModel @Inject constructor() : ViewModel() {
val password = MutableLiveData<String>("")

fun login(){
_loginResult.value = true
val userMap = HashMap<String, String>()
userMap["email"] = "jaeren+androidtest@moneyboxapp.com"
userMap["password"] = "P455word12"

viewModelScope.launch(Dispatchers.IO) {
loginRepository.login(userMap).collect {
withContext(Dispatchers.Main) {
_loginResult.value = it
}
}
}
}
fun triggerLogin(){
_loginClick.value = true
Expand Down
15 changes: 12 additions & 3 deletions feature/login/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>

<import type="android.view.View" />
Expand All @@ -15,8 +16,6 @@
</data>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
Expand Down Expand Up @@ -73,6 +72,16 @@

</Button>

<ProgressBar
android:id="@+id/progressbar_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_password" />

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
baseUrl="https://api-test01.moneyboxapp.com/"
apiVersion="3.0.0"
appId="3a97b932a9d449c981b595"
#baseUrl="https://api-test01.moneyboxapp.com/"
#apiVersion="3.0.0"
#appId="3a97b932a9d449c981b595"
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.moneybox.minimb.network.core

import com.moneybox.minimb.network.core.INetworkCoreDataService.Companion.API_VERSION
import com.moneybox.minimb.network.core.INetworkCoreDataService.Companion.APP_ID
import com.moneybox.minimb.network.core.INetworkCoreDataService.Companion.VERSION_NAME
import okhttp3.Interceptor
import okhttp3.Response

class NoAuthenticationInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
return chain.proceed(
chain.request().newBuilder()
.addHeader(APP_ID_HEADER_NAME, APP_ID)
.addHeader(API_VERSION_HEADER_NAME, API_VERSION)
.addHeader(APP_VERSION_HEADER_NAME, VERSION_NAME)
.addHeader(CONTENT_HEADER_NAME, CONTENT_HEADER_VALUE)
.build()
)
}

companion object {
private const val APP_ID_HEADER_NAME = "AppId"
private const val API_VERSION_HEADER_NAME = "ApiVersion"
private const val APP_VERSION_HEADER_NAME = "AppVersion"
private const val CONTENT_HEADER_NAME = "ContentDetail-Type"
private const val CONTENT_HEADER_VALUE = "application/json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.moneybox.minimb.network.core
interface INetworkCoreDataService {

companion object {
const val BASE_URL = "https://pixabay.com"
const val NETWORK_PAGE_SIZE = 20
const val BASE_URL = "https://api-test01.moneyboxapp.com/"
const val API_VERSION="3.0.0"
const val APP_ID="3a97b932a9d449c981b595"
const val VERSION_NAME= "8.35.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.moneybox.minimb.network.core


import com.google.gson.GsonBuilder
import com.moneybox.minimb.network.BuildConfig
import com.moneybox.minimb.network.ILogger
import com.moneybox.minimb.network.LoggerNetworkModule
import com.moneybox.minimb.network.core.INetworkCoreDataService.Companion.BASE_URL
Expand Down Expand Up @@ -33,11 +34,10 @@ object NetworkCoreServiceModule {
logger.level = HttpLoggingInterceptor.Level.BASIC

val clientBuilder = OkHttpClient.Builder()
.addInterceptor(logger)
.addInterceptor(NoAuthenticationInterceptor())
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
// .addInterceptor(TokenInterceptor(sharedPreferences))
.build()
val gson = GsonBuilder()
.setLenient()
Expand Down

0 comments on commit 00f1d7b

Please sign in to comment.