generated from DO-SOPT-ANDROID/do-sopt-android-repo-template
-
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
[FEAT/seminar1] 심화과제 / 도전과제 #6
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
40896cd
[FEAT] windowSoftInputMode 적용
emjayMJkim 07337f0
[FEAT] hideKeyBoard 구현
emjayMJkim 2d01187
[MOD] 코드 수정
emjayMJkim 0886fef
[REFACT] 파일 수정
emjayMJkim c4c95b9
[FEAT] 자동 로그인 구현
emjayMJkim 2e78af9
[FEAT] 로그아웃 구현
emjayMJkim 2756f5f
[MOD] 로그아웃 후 로그인 문제 관련 코드 수정
emjayMJkim 4bc018e
[FEAT] 뒤로 가기 로직 구현
emjayMJkim f3091c5
[MOD] 뒤로 가기 로직 BaseActivity로 이동
emjayMJkim ccbd78c
[MOD] logIn 코드 수정
emjayMJkim 8279a42
[MOD] 코리 반영 코드 수정
emjayMJkim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/main/java/org/sopt/dosopttemplate/base/BaseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,55 @@ | ||
package org.sopt.dosopttemplate.base | ||
|
||
import android.os.Bundle | ||
import android.view.MotionEvent | ||
import android.view.inputmethod.InputMethodManager | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.annotation.LayoutRes | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
import org.sopt.dosopttemplate.util.SnackBar | ||
|
||
abstract class BaseActivity<T : ViewDataBinding>( | ||
@LayoutRes private val layoutRes: Int, | ||
) : AppCompatActivity() { | ||
lateinit var binding: T | ||
|
||
private var backPressedTime = 0L | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = DataBindingUtil.setContentView(this, layoutRes) | ||
binding.lifecycleOwner = this | ||
|
||
initPressedBackBtn() | ||
} | ||
|
||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { | ||
hideKeyboard() | ||
return super.dispatchTouchEvent(ev) | ||
} | ||
|
||
private fun hideKeyboard() { | ||
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager | ||
inputMethodManager.hideSoftInputFromWindow(currentFocus?.windowToken, 0) | ||
} | ||
|
||
private fun initPressedBackBtn() { | ||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
if (System.currentTimeMillis() - backPressedTime >= 2000L) { | ||
backPressedTime = System.currentTimeMillis() | ||
SnackBar.makeSnackBar(binding.root, BACK_MESSAGE) | ||
} else { | ||
finishAffinity() | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
companion object { | ||
const val BACK_MESSAGE = "뒤로가기 버튼을 한번 더 누르면 종료됩니다." | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/org/sopt/dosopttemplate/data/datasource/local/SharedPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.sopt.dosopttemplate.data.datasource.local | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import org.sopt.dosopttemplate.data.entity.UserData | ||
|
||
|
||
object SharedPreference { | ||
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. 오.. 저도 SharedPreference 사용할 때 object 를 사용하면 범용성있게 사용할 수 있겠네요.. 저도 리팩토링할 때 참고하도록 하겠습니다 |
||
private lateinit var prefs: SharedPreferences | ||
|
||
fun initSetSharedPreference(context: Context) { | ||
prefs = context.getSharedPreferences(USER_PREFS, Context.MODE_PRIVATE) | ||
} | ||
|
||
fun isValidUserData() = prefs.getString(USER_ID, "")?.isNotBlank() ?: false | ||
|
||
fun setUserData(user: UserData) { | ||
with(prefs.edit()) { | ||
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. 요 부분 SharedPreference ktx 사용하면 아래 코드처럼 사용할 수 있더라구요 (의진이가 알려줬습니다!) prefs.edit(commit = true) {
putString(USER_ID, user.id)
putString(USER_PW, user.pw)
putString(USER_NICKNAME, user.nickName)
putString(USER_MBTI, user.mbti)
} |
||
putString(USER_ID, user.id) | ||
putString(USER_PW, user.pw) | ||
putString(USER_NICKNAME, user.nickName) | ||
putString(USER_MBTI, user.mbti) | ||
}.commit() | ||
} | ||
|
||
fun getUserData(): UserData { | ||
with(prefs) { | ||
return UserData( | ||
getString(USER_ID, "").toString(), | ||
getString(USER_PW, "").toString(), | ||
getString(USER_NICKNAME, "").toString(), | ||
getString(USER_MBTI, "").toString() | ||
) | ||
} | ||
} | ||
|
||
fun clearUserData() { | ||
with(prefs.edit()) { | ||
clear() | ||
commit() | ||
} | ||
} | ||
|
||
} | ||
|
||
const val USER_PREFS = "user_prefs" | ||
const val USER_ID = "user_id" | ||
const val USER_PW = "user_pw" | ||
const val USER_NICKNAME = "user_nickname" | ||
const val USER_MBTI = "user_mbti" |
2 changes: 1 addition & 1 deletion
2
...a/org/sopt/dosopttemplate/data/Profile.kt → ...opt/dosopttemplate/data/entity/Profile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.sopt.dosopttemplate.data | ||
package org.sopt.dosopttemplate.data.entity | ||
|
||
|
||
sealed class Profile { | ||
|
2 changes: 1 addition & 1 deletion
2
.../org/sopt/dosopttemplate/data/UserData.kt → ...pt/dosopttemplate/data/entity/UserData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/org/sopt/dosopttemplate/presentation/home/home/HomeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
저도 이 부분 코드리뷰로 확장함수를 처리해서 사용하니 다른 곳에서도 확장성있게 사용할 수 있어서! 좋았습니다!