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
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.

13 changes: 13 additions & 0 deletions .idea/misc.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.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures{
viewBinding = true
}
}

dependencies {
Expand All @@ -40,4 +43,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.fragment:fragment-ktx:1.5.1"
}
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@
android:theme="@style/Theme.AndroidD20"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".Info"
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="false" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions app/src/main/java/com/sudo/androidd20/Info.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sudo.androidd20

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.sudo.androidd20.databinding.ActivityInfoBinding

class Info : AppCompatActivity() {
private lateinit var infoBinding: ActivityInfoBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
infoBinding = ActivityInfoBinding.inflate(layoutInflater)
setContentView(infoBinding.root)

val bundle: Bundle = intent.getBundleExtra("user")!!

infoBinding.tvUserName.text = bundle.getString("userName").toString()
infoBinding.tvPassword.text = bundle.getString("password").toString()

infoBinding.btnLogOut.setOnClickListener {
finish()
}

}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/sudo/androidd20/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.sudo.androidd20

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.sudo.androidd20.databinding.ActivityLoginBinding

class LoginActivity : AppCompatActivity() {
private val loginFragment: LoginFragment = LoginFragment()
private val signUpFragment: SignUpFragment = SignUpFragment()
private lateinit var activityMainBinding: ActivityLoginBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityMainBinding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(activityMainBinding.root)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nếu chỉ để setContentView thì k cần phải binding

if(savedInstanceState == null) {
supportFragmentManager.beginTransaction().add(R.id.fragmentState, loginFragment).commit()
}

}
}

77 changes: 77 additions & 0 deletions app/src/main/java/com/sudo/androidd20/LoginFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.sudo.androidd20

import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Paint
import android.os.Bundle
import android.text.Editable
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResultListener
import com.sudo.androidd20.databinding.FragmentLoginBinding

class LoginFragment : Fragment(){
private lateinit var fragmentLoginBinding: FragmentLoginBinding

private var user: User = User("userName", "password")

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
fragmentLoginBinding = FragmentLoginBinding.inflate(inflater, container, false)
fragmentLoginBinding.tvSignUp.paintFlags = Paint.UNDERLINE_TEXT_FLAG

arguments?.let {
user = it.getSerializable("account") as User
}

Log.e("USERNAME", "onCreateView1: ${user.userName}", )
Log.e("USERNAME", "onCreateView1: ${user.password}", )

setOnClick()





return fragmentLoginBinding.root
}

private fun setOnClick() {
fragmentLoginBinding.apply {
tvSignUp.setOnClickListener {
requireActivity().supportFragmentManager.beginTransaction().add(R.id.fragmentState, SignUpFragment()).commit()
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

có thể gọi parentFragmentmanager

btnLogin.setOnClickListener {
login()
}
}
}

private fun login() {
fragmentLoginBinding.apply {
Log.e("ngu", "userName: ${user.userName}", )
Log.e("ngu", "password: ${user.password}", )

if(user.userName == edtUserName.text.toString() && user.password == edtPassword.text.toString()) {
val intent = Intent(context, Info::class.java)
val bundle: Bundle = Bundle()
bundle.putString("userName", edtUserName.text.toString())
bundle.putString("password", edtPassword.text.toString())
intent.putExtra("user", bundle)
startActivity(intent)
} else {
Log.e("ngu", "login: ngu", )
}
}
}
}
11 changes: 0 additions & 11 deletions app/src/main/java/com/sudo/androidd20/MainActivity.kt

This file was deleted.

55 changes: 55 additions & 0 deletions app/src/main/java/com/sudo/androidd20/SignUpFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.sudo.androidd20

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResult
import com.sudo.androidd20.databinding.FragmentLoginBinding
import com.sudo.androidd20.databinding.FragmentSignUpBinding

class SignUpFragment : Fragment() {
private lateinit var fragmentSignUpBinding: FragmentSignUpBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
fragmentSignUpBinding = FragmentSignUpBinding.inflate(inflater, container, false)
fragmentSignUpBinding.apply {
tvLogin.setOnClickListener {
requireActivity().supportFragmentManager.beginTransaction().add(R.id.fragmentState, LoginFragment()).commit()
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cứ add qua add lại giũa 2 fragment v không dc
như thế backstack sẽ nhanh bị đầy gây lãng phí
tìm cách khác

btnSignUp.setOnClickListener {
// childFragmentManager.setFragmentResult("userName", bundleOf(Pair("userName", edtUserName.text.toString())))


signUp()
}
}



return fragmentSignUpBinding.root



}

private fun signUp() {
fragmentSignUpBinding.apply {
if(edtPassword.text.toString() == edtConfirmPasword.text.toString()) {
val user = User(edtUserName.text.toString(), edtPassword.text.toString())
val loginFragment = LoginFragment()
val bundle = Bundle()
bundle.putSerializable("account", user)
loginFragment.arguments = bundle
requireActivity().supportFragmentManager.beginTransaction().add(R.id.fragmentState, loginFragment).commit()
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tìm cách khác giao tiếp giữa 2 fragment

}
}


}
5 changes: 5 additions & 0 deletions app/src/main/java/com/sudo/androidd20/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sudo.androidd20

import java.io.Serializable

data class User(val userName: String, var password: String) : Serializable
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="-90"
android:startColor="#00EEFF"
android:endColor="@color/white"
android:type="linear" />
</shape>
37 changes: 37 additions & 0 deletions app/src/main/res/layout/activity_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Info"
android:orientation="vertical"
android:background="@drawable/background"
android:gravity="center_horizontal">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvUserName"
android:layout_marginTop="48dp"
android:textAlignment="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvPassword"
android:layout_marginTop="16dp"
android:textAlignment="center"/>

<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnLogOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="36dp"
android:text="Logout" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".LoginActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
<androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragmentState"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tên id nên là tên tag viết tắt + mô ta về ý nghĩa của view vd fcvAuthen

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading