Skip to content
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

Add timber #6

Open
wants to merge 3 commits into
base: develop/view
Choose a base branch
from
Open
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 app/build.gradle
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ android {
}

dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
// ViewModel 생성함수를 편하게 사용하고 싶다면?
implementation "androidx.fragment:fragment-ktx:1.5.3"
21 changes: 11 additions & 10 deletions app/src/main/java/org/sopt/sample/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
package org.sopt.sample

import org.sopt.sample.adapter.rvAdapter
import org.sopt.sample.databinding.FragmentHomeBinding
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import org.sopt.sample.adapter.rvAdapter
import org.sopt.sample.base.BindingFragment
import org.sopt.sample.databinding.FragmentSearchBinding
import org.sopt.sample.remote.*
import org.sopt.sample.databinding.FragmentHomeBinding
import org.sopt.sample.remote.ResponseUserDTO
import org.sopt.sample.remote.UserServicePool
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import timber.log.Timber

class HomeFragment: BindingFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private var _binding : FragmentHomeBinding? = null
class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private var _binding: FragmentHomeBinding? = null
get() = requireNotNull(_binding)
private val userService = UserServicePool.userService

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if(BuildConfig.DEBUG){
Timber.plant(Timber.DebugTree())
}
Comment on lines +24 to +26
Copy link
Member

Choose a reason for hiding this comment

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

애플리케이션 클래스 생성해서 onCreate()에 넣어주세요! 애플리케이션이 실행될 때 딱 한번 실행됩니다! 현재 코드 상에서는 홈프래그먼트가 실행될 때 마다 해당 코드가 실행될 것입니다!

val adapter = rvAdapter(requireContext())
binding.rvRepos.adapter = adapter
userService.user().enqueue(object : Callback<ResponseUserDTO> {
override fun onResponse(
call: Call<ResponseUserDTO>,
response: Response<ResponseUserDTO>
) {
Log.d("유저 정보", "${response.body()}")
if (response.isSuccessful) {
response.body()?.let {
Timber.d("${response.body()}")
adapter.setRepoList(it.data)
}
}
1 change: 1 addition & 0 deletions app/src/main/java/org/sopt/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import androidx.fragment.app.FragmentContainerView
import com.google.android.material.bottomnavigation.BottomNavigationView
import org.sopt.sample.base.BindingActivity
import org.sopt.sample.databinding.ActivityMainBinding
import timber.log.Timber

class MainActivity :BindingActivity<ActivityMainBinding>(R.layout.activity_main){
private val frame: FragmentContainerView by lazy { // activity_main의 화면 부분
2 changes: 2 additions & 0 deletions app/src/main/java/org/sopt/sample/SignInActivity.kt
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package org.sopt.sample

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.viewModels
import org.sopt.sample.base.BindingActivity
import org.sopt.sample.databinding.ActivitySignInBinding
@@ -22,6 +23,7 @@ class SignInActivity: BindingActivity<ActivitySignInBinding>(R.layout.activity_s
}

viewModel.loginResult.observe(this) {
Toast.makeText(this, getString(R.string.sign_in_success_toast_msg), Toast.LENGTH_LONG).show()
startActivity(Intent(this, MainActivity::class.java))
}
binding.registerBtn.setOnClickListener(){
2 changes: 2 additions & 0 deletions app/src/main/java/org/sopt/sample/SignUpActivity.kt
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import org.sopt.sample.base.BindingActivity
@@ -100,6 +101,7 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_

viewModel.signupResult.observe(this) {
startActivity(Intent(this,SignInActivity::class.java))
Toast.makeText(this,getString(R.string.sign_up_success_toast_msg), Toast.LENGTH_LONG).show()
Copy link
Member

Choose a reason for hiding this comment

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

control + alt + L 을 눌러서 코드 정렬을 시켜봅시당!

}
}
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ class RepoViewHolder(
): RecyclerView.ViewHolder(binding.root){
fun onBind(data: ResponseUserDTO.Data){
binding.imgGithub.load(data.avatar)
binding.txtGithubName.setText(data.first_name)
binding.txtGithubName.setText(data.firstName)
binding.txtGithubAuthor.setText(data.email)
}

4 changes: 2 additions & 2 deletions app/src/main/java/org/sopt/sample/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.sample.login

import android.util.Log
import android.widget.Toast
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
@@ -9,7 +10,7 @@ import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class LoginViewModel: ViewModel() {
class LoginViewModel : ViewModel() {
private val _loginResult: MutableLiveData<ResponseLoginDTO> = MutableLiveData()
val loginResult: LiveData<ResponseLoginDTO>
get() = _loginResult
@@ -22,7 +23,6 @@ class LoginViewModel: ViewModel() {
call: Call<ResponseLoginDTO>,
response: Response<ResponseLoginDTO>
) {
Log.d("로그인 성공", "${response.body()}")
_loginResult.value = response.body()
}

10 changes: 7 additions & 3 deletions app/src/main/java/org/sopt/sample/remote/ResponseUserDTO.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.sopt.sample.remote

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseUserDTO(
val page: Int,
val per_page: Int,
val total: Int,
val total_pages: Int,
@SerialName("total_pages")
val totalPages: Int,
val data: List<Data>,
val support: Support,

@@ -16,8 +18,10 @@ data class ResponseUserDTO(
data class Data(
val id: Int,
val email: String,
val first_name: String,
val last_name: String,
@SerialName("first_name")
val firstName: String,
Copy link
Member

Choose a reason for hiding this comment

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

카멜케이스 좋습니다~~

@SerialName("last_name")
val lastName: String,
val avatar: String,
)

3 changes: 1 addition & 2 deletions app/src/main/java/org/sopt/sample/signup/SignupViewModel.kt
Original file line number Diff line number Diff line change
@@ -33,11 +33,10 @@ class SignupViewModel: ViewModel() {
response: Response<ResponseSignupDTO>
) {
_signupResult.value = response.body()
Log.d("회원가입 성공", "${response.body()}")
Copy link
Member

Choose a reason for hiding this comment

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

이곳에서 Timber를 찍을 수 있겠네용!

}

override fun onFailure(call: Call<ResponseSignupDTO>, t: Throwable) {
TODO("Not yet implemented")

}
})

14 changes: 7 additions & 7 deletions app/src/main/res/layout/activity_sign_in.xml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="Welcome to SOPT"
android:text="@string/sign_in_title"
Copy link
Member

Choose a reason for hiding this comment

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

👍

android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
@@ -35,7 +35,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="ID"
android:text="@string/sign_id_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_title" />
@@ -46,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="아이디를 입력하세요"
android:hint="@string/sign_id_hint"
app:layout_constraintTop_toBottomOf="@+id/txt_id_title"
tools:layout_editor_absoluteX="40dp" />

@@ -56,7 +56,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="비밀번호"
android:text="@string/sign_pw_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_id" />
@@ -67,7 +67,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="비밀번호를 입력하세요"
android:hint="@string/sign_pw_hint"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@+id/txt_password_title" />

@@ -77,7 +77,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="30dp"
android:text="LOGIN"
android:text="@string/sign_in"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_pw" />
@@ -87,7 +87,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:text="SIGNUP"
android:text="@string/sign_up"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginBtn" />
24 changes: 12 additions & 12 deletions app/src/main/res/layout/activity_sign_up.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="SIGNUP"
android:text="@string/sign_up_title"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
@@ -34,7 +34,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="이메일"
android:text="@string/sign_up_email_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_title" />
@@ -45,7 +45,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="이메일을 입력하세요"
android:hint="@string/sign_up_email_hint"
app:layout_constraintTop_toBottomOf="@+id/txt_email_title"
tools:layout_editor_absoluteX="40dp" />

@@ -54,8 +54,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:text="이메일 형식이 올바르지 않습니다."
android:textColor="#ff0000"
android:text="@string/sign_up_email_error"
android:textColor="@color/red"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_email" />
@@ -66,7 +66,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="비밀번호"
android:text="@string/sign_up_pw_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_email" />
@@ -77,16 +77,16 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="비밀번호를 입력하세요"
android:hint="@string/sign_up_pw_hint"
app:layout_constraintTop_toBottomOf="@+id/txt_password_title" />

<TextView
android:id="@+id/tv_pwerror"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:text="비밀번호 형식이 올바르지 않습니다."
android:textColor="#ff0000"
android:text="@string/sign_up_pw_error"
android:textColor="@color/red"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_pw" />
@@ -97,7 +97,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="이름"
android:text="@string/sign_up_name_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_pw" />
@@ -109,7 +109,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="이름을 입력하세요"
android:hint="@string/sign_up_name_hint"
app:layout_constraintTop_toBottomOf="@+id/txt_name_title" />

<Button
@@ -119,7 +119,7 @@
android:layout_marginHorizontal="40dp"
android:layout_marginTop="30dp"
android:enabled="false"
android:text="회원가입 완료"
android:text="@string/sign_up_finish"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_name" />
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_gallery.xml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="이미지 업로드!"
android:text="@string/gallery_image_upload"
app:layout_constraintEnd_toEndOf="@+id/iv_sample"
app:layout_constraintStart_toStartOf="@+id/iv_sample"
app:layout_constraintTop_toBottomOf="@+id/iv_sample" />
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="여기는 search fragment 입니다!"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
4 changes: 2 additions & 2 deletions app/src/main/res/layout/layout_github_repo.xml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
app:layout_constraintBottom_toTopOf="@+id/txt_github_author"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/img_github"
tools:text="Repo Name" />
tools:text="@string/github_repo" />

<TextView
android:id="@+id/txt_github_author"
@@ -32,7 +32,7 @@
app:layout_constraintBottom_toBottomOf="@+id/img_github"
app:layout_constraintEnd_toEndOf="@+id/txt_github_name"
app:layout_constraintTop_toBottomOf="@+id/txt_github_name"
tools:text="Dani Lee" />
tools:text="@string/github_user" />


</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/layout_header.xml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:text="다니의 레포지터리"
android:text="@string/header_name"
android:textSize="15sp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="10dp" />
6 changes: 3 additions & 3 deletions app/src/main/res/menu/item_menu.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/nav_home"
android:title=""
android:title="@string/menu_home"
android:icon="@drawable/ic_home_white" />
<item android:id="@+id/nav_gallery"
android:title="갤러리"
android:title="@string/menu_gallery"
android:icon="@drawable/ic_gallery_white" />
<item android:id="@+id/nav_search"
android:title="검색"
android:title="@string/menu_search"
android:icon="@drawable/ic_search_white" />
</menu>
38 changes: 38 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<resources>
<string name="app_name">INSOPTAndroidPractice</string>

<!--menu-->
<string name="menu_home">홈</string>
<string name="menu_gallery">갤러리</string>
<string name="menu_search">검색</string>

<!--Sign-->
<string name="sign_in_title">Welcome to SOPT</string>
<string name="sign_id_label">ID</string>
<string name="sign_id_hint">아이디를 입력하세요</string>
<string name="sign_pw_label">비밀번호</string>
<string name="sign_pw_hint">비밀번호를 입력하세요</string>
<string name="sign_in">LOGIN</string>
<string name="sign_up">SIGNUP</string>
<string name="sign_up_title">SIGNUP</string>
<string name="sign_up_email_label">이메일</string>
<string name="sign_up_email_hint">이메일을 입력하세요</string>
<string name="sign_up_email_error">이메일 형식이 올바르지 않습니다.</string>
<string name="sign_up_pw_label">비밀번호</string>
<string name="sign_up_pw_hint">비밀번호를 입력하세요</string>
<string name="sign_up_pw_error">비밀번호 형식이 올바르지 않습니다.</string>
<string name="sign_up_name_label">이름</string>
<string name="sign_up_name_hint">이름을 입력하세요</string>
<string name="sign_up_finish" >Sign Up</string>
<string name="sign_in_success_toast_msg">로그인을 성공했습니다</string>
<string name="sign_up_success_toast_msg">회원가입에 성공했습니다.</string>

<!--gallery-->
<string name="gallery_image_upload">이미지 업로드!</string>

<!--github-->
<string name="github_repo">Repo Name</string>
<string name="github_user">Dani Lee</string>

<!--header-->
<string name="header_name">다니의 레포지터리</string>


</resources>