Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gradle/7.5/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/7.5/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/7.5/checksums/sha1-checksums.bin
Binary file not shown.
Binary file added .gradle/7.5/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.5/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.5/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/7.5/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file added .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file added .gradle/file-system.probe
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

35 changes: 33 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
}

android {
namespace 'com.example.mvvmproject'
compileSdk 33
buildFeatures {
viewBinding = true
}
dataBinding{
enabled = true
}

defaultConfig {
applicationId "com.example.mvvmproject"
Expand Down Expand Up @@ -33,12 +41,35 @@ android {
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// Retrofit and GSON
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

// Kotlin coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'

// ViewModel and livedata
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"

// new material 3 design
implementation "androidx.compose.material3:material3:1.0.1"
implementation "androidx.compose.material3:material3-window-size-class:1.0.1"

//Android room
implementation "androidx.room:room-runtime:2.5.1"
implementation "androidx.room:room-ktx:2.5.1"
kapt "androidx.room:room-compiler:2.5.1"

// Android navigation architecture
implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:theme="@style/Theme.MVVMProject"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".ui.auth.LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.mvvmproject.ui.auth

interface AuthListener {
fun onStarted()
fun onSuccess()
fun onFailure(failureMessage: String)
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/example/mvvmproject/ui/auth/AuthViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.mvvmproject.ui.auth

import android.view.View
import androidx.lifecycle.ViewModel

class AuthViewModel : ViewModel() {
var email: String? = null
var password: String? = null
var authListener: AuthListener? = null

fun onLoginButtonClick(view: View) {
authListener?.onStarted()
if (email.isNullOrEmpty() || password.isNullOrEmpty()) {
authListener?.onFailure("Invalid Email or Password")
return
}

// success
authListener?.onSuccess()
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/example/mvvmproject/ui/auth/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.mvvmproject.ui.auth

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProviders.*
import com.example.mvvmproject.R
import com.example.mvvmproject.databinding.ActivityLoginBinding
import com.example.mvvmproject.util.toast

class LoginActivity : AppCompatActivity(), AuthListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding: ActivityLoginBinding =
DataBindingUtil.setContentView(this, R.layout.activity_login)
val viewmodel = of(this).get(AuthViewModel::class.java)
binding.viewmodel = viewmodel
viewmodel.authListener = this
}

override fun onStarted() {
toast("Login started")
}

override fun onSuccess() {
toast("Login successful")
}

override fun onFailure(failureMessage: String) {
toast(failureMessage)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.example.mvvmproject
package com.example.mvvmproject.ui.auth

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.mvvmproject.R

class MainActivity : AppCompatActivity() {
class SignUpActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setContentView(R.layout.activity_sign_up)
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/example/mvvmproject/util/ViewUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.mvvmproject.util

import android.content.Context
import android.widget.Toast

// Method to show directly toast.
fun Context.toast(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}
62 changes: 62 additions & 0 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>
<variable
name="viewmodel"
type="com.example.mvvmproject.ui.auth.AuthViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.auth.LoginActivity">

<TextView
android:id="@+id/email_label"
style="@style/TextAppearance.AppCompat.Display2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginBottom="50dp"
android:gravity="center"
android:text="@string/mvvm_project"
app:layout_constraintBottom_toTopOf="@+id/email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="50dp"
android:text="@={viewmodel.email}"
android:hint="@string/type_your_email"
app:layout_constraintTop_toBottomOf="@id/email_label" />

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="30dp"
android:text="@={viewmodel.password}"
android:hint="@string/enter_password_text"
app:layout_constraintTop_toBottomOf="@id/email" />

<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:onClick="@{viewmodel::onLoginButtonClick}"
android:text="@string/login_button_Text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/password" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
tools:context=".ui.auth.SignUpActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<resources>
<string name="app_name">MVVM project</string>
<string name="type_your_email">type your email</string>
<string name="mvvm_project">MVVM Project</string>
<string name="enter_password_text">Enter password</string>
<string name="login_button_Text">login</string>
</resources>
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.databinding.enablev2=true