-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[week7] level1 #6
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,16 @@ android { | |
} | ||
|
||
dependencies { | ||
def fragment_version = '1.2.0-rc04' | ||
def nav_version = "2.2.0-rc04" | ||
implementation "androidx.fragment:fragment-ktx:$fragment_version" | ||
implementation "androidx.fragment:fragment-testing:$fragment_version" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" | ||
implementation "androidx.navigation:navigation-ui-ktx:$nav_version" | ||
implementation "androidx.navigation:navigation-compose:1.0.0-alpha01" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compose라는 안드로이드의 새 UI 프레임워크에서만 사용할 수 있는 라이브러리에요, 굳이 의존성에 추가를 별도로 하시지 않아도됩니다. |
||
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5" | ||
implementation "androidx.navigation:navigation-ui-ktx:2.3.5" | ||
implementation "com.squareup.retrofit2:retrofit:2.9.0" | ||
implementation "com.squareup.retrofit2:converter-gson:2.9.0" | ||
implementation "com.google.code.gson:gson:2.8.6" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sopt.androidsemina_week1.ui.home | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
|
||
// cotext 확장 | ||
fun Context.shortToast(message : String){ | ||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show() | ||
// 이미 상속받아서 this를 쓸 수 있음. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상속이라기 보다는 Context의 멤버함수를 추가해준다고 생각할 수 있어요. 상속은 부모 클래스의 속성(멤버 변수와 함수)를 가지고 기능을 확장하는 "클래스"를 만든다는 개념이어서 둘이 다른 것이라고 보면 좋을 것 같습니다! |
||
|
||
// mainActivity에 가서 어떻게 쓰냐... | ||
// shortToast("텍스트") 쓰면 됨. | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragment에서는 context?.shortToast()나 requireContext().shortToast()로 사용해야해서 제가 위와 같은 확장함수를 만들때에는 Context/Fragment 둘 다 만드는 편이긴합니다. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
package org.sopt.androidsemina_week1 | ||
package org.sopt.androidsemina_week1.ui.signin | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Toast | ||
import org.sopt.androidsemina_week1.ui.home.HomeActivity | ||
import org.sopt.androidsemina_week1.ui.home.ServiceCreator | ||
import org.sopt.androidsemina_week1.data.RequestLoginData | ||
import org.sopt.androidsemina_week1.data.ResponseLoginData | ||
import org.sopt.androidsemina_week1.databinding.ActivitySigninBinding | ||
import org.sopt.androidsemina_week1.ui.home.shortToast | ||
import org.sopt.androidsemina_week1.ui.signup.SignUpActivity | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
@@ -24,6 +29,8 @@ class SignInActivity : AppCompatActivity() { | |
|
||
binding.longinBtn.setOnClickListener { | ||
initNetwork() | ||
initAutoLogin() | ||
checkAutoLogin() | ||
} | ||
|
||
binding.signupBtn.setOnClickListener { | ||
|
@@ -34,13 +41,24 @@ class SignInActivity : AppCompatActivity() { | |
setContentView(binding.root) | ||
} | ||
|
||
private fun checkAutoLogin() { | ||
shortToast("자동로그인 되었습니다.") | ||
startActivity(Intent(this, HomeActivity::class.java)) | ||
finish() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이와 같은 방식으로 구현해도 홈액티비티를 종료했을 때 당연히 이 SignInActivity도 종료될텐데 그렇다면 HomeActivity가 떠있는 동안 화면 아래에 계속 남아있겠네요. 이걸 동일하게 화면이 다섯개 정도 겹쳐있으면 핸드폰의 기종에 따라서 메모리 부족 경고가 뜨거나 앱이 강제 종료될 수 있기 때문에 좋은 패턴이 아니라고 생각할 수 있습니다. |
||
} | ||
|
||
private fun initAutoLogin() { | ||
binding.clAutoLogin.setOnClickListener { | ||
binding.ivCheck.isSelected = !binding.ivCheck.isSelected | ||
} | ||
} | ||
|
||
private fun initNetwork() { | ||
val requestLoginData = RequestLoginData( | ||
binding.idEditText.text.toString(), | ||
binding.pwEditText.text.toString() | ||
) | ||
val call : Call<ResponseLoginData> = ServiceCreator.sampleService.postLogin(requestLoginData) | ||
|
||
call.enqueue(object : Callback<ResponseLoginData>{ | ||
override fun onResponse( | ||
call: Call<ResponseLoginData>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M12,22C17.5,22 22,17.5 22,12C22,6.5 17.5,2 12,2C6.5,2 2,6.5 2,12C2,17.5 6.5,22 12,22Z" | ||
android:fillColor="#C9C9C9"/> | ||
<path | ||
android:strokeWidth="1" | ||
android:pathData="M7,13L10,16L17,9" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#ffffff" | ||
android:strokeLineCap="round"/> | ||
</vector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M12,22C17.5,22 22,17.5 22,12C22,6.5 17.5,2 12,2C6.5,2 2,6.5 2,12C2,17.5 6.5,22 12,22Z" | ||
android:fillColor="@color/teal_700"/> | ||
<path | ||
android:strokeWidth="1" | ||
android:pathData="M7,13L10,16L17,9" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#ffffff" | ||
android:strokeLineCap="round"/> | ||
</vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rc버전은 아직 출시 전에 마지막 점검차 내놓는 라이브러리여서 사용은 지양하는게 좋습니다.