Skip to content

Commit

Permalink
add : extension 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
SeonHwan-Kim committed Apr 7, 2023
1 parent 24a8556 commit be5017b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/org/android/go/sopt/util/ContextExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.android.go.sopt.util

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import com.google.android.material.snackbar.Snackbar

fun Context.showShortToast(message: String){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}

fun Context.hideKeyboard(view: View){
val inputManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
// hideSoftInputFromWindow는 첫번째 인자로 windowToken을 받아야함. windowToken은 View에서 사용?
inputManager.hideSoftInputFromWindow(view.windowToken, 0)
}

fun Context.showShortSnackbar(view: View, message: String){
// Snackbar.make는 첫번째 인자로 View를 받아야한다. 그래서 this(context)를 쓰면 에러남
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show()
}
9 changes: 9 additions & 0 deletions app/src/main/java/org/android/go/sopt/util/ViewExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.android.go.sopt.util

import android.view.View
import com.google.android.material.snackbar.Snackbar

// View 객체를 상속받는 곳에서만 사용 가능~
//fun View.showShortSnackBar(message: String){
// Snackbar.make(this, message, Snackbar.LENGTH_SHORT).show()
//}

0 comments on commit be5017b

Please sign in to comment.