Skip to content

Commit

Permalink
Merge pull request #100 from boostcampwm-2022/fix/bug
Browse files Browse the repository at this point in the history
각종 버그 수정
  • Loading branch information
jhg3410 authored Dec 13, 2022
2 parents 23615a5 + aef4099 commit 5056d5b
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 175 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/com/wakeup/buildsrc/Depends.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.wakeup.buildsrc.Depends.Versions.appVersionCode
object Depends {

object Versions {
const val appVersionCode = 1_000_000
const val appVersionCode = 1_002_000
const val gradleVersion = "7.3.1"
const val androidCompileSdkVersion = 32
const val targetSdkVersion = 32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.graphics.Canvas
import android.os.Build
import android.util.TypedValue
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -92,16 +91,3 @@ fun View.showSnackBar(text: String, anchorViewResId: Int? = null) {
}
}.show()
}

fun Fragment.setStatusBarTransparent() {
this.requireActivity().window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
}

fun Fragment.resetStatusBarTransparent() {
this.requireActivity().window.clearFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.InsetDrawable
import android.text.SpannableString
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import kotlin.properties.Delegates

abstract class BaseDialog<T : BaseDialog<T>>(protected val context: Context) {

protected lateinit var builder: AlertDialog.Builder
protected lateinit var dialog: AlertDialog
protected lateinit var dialogView: View
protected var baseLayoutId by Delegates.notNull<Int>()


@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -64,14 +65,13 @@ abstract class BaseDialog<T : BaseDialog<T>>(protected val context: Context) {
* @param onPositive dialog 의 positive 버튼 클릭 이벤트를 지정해준다.
*
*/
fun setOnPositive(resId: Int, text: String, onPositive: (dialog: T) -> Unit): T {
val positiveView = dialogView.findViewById<View>(resId)
if (positiveView is TextView) { // Button is TextView's expand class
positiveView.text = text
}
positiveView.setOnClickListener {
onPositive(self())
dialog.dismiss()
fun setOnPositive(resId: Int, text: CharSequence? = null, onPositive: (dialog: T) -> Unit): T {
dialogView.findViewById<TextView>(resId).apply {
this.text = text ?: this.text
setOnClickListener {
onPositive(self())
dialog.dismiss()
}
}
return self()
}
Expand All @@ -82,34 +82,23 @@ abstract class BaseDialog<T : BaseDialog<T>>(protected val context: Context) {
* @param resId dialog negative button 을 지정한다.
* @param onNegative dialog 의 negative 버튼 클릭 이벤트를 지정해준다.
*/
fun setOnNegative(resId: Int, text: String, onNegative: (dialog: T) -> Unit): T {
val negativeView = dialogView.findViewById<View>(resId)
if (negativeView is TextView) { // Button is TextView's expand class
negativeView.text = text
}
negativeView.setOnClickListener {
onNegative(self())
dialog.dismiss()
fun setOnNegative(resId: Int, text: CharSequence? = null, onNegative: (dialog: T) -> Unit): T {
dialogView.findViewById<TextView>(resId).apply {
this.text = text ?: this.text
setOnClickListener {
onNegative(self())
dialog.dismiss()
}
}
return self()
}

/**
*
* @param resId dialog 제목을 지정한다.
* @param text dialog 제목의 text를 결정한다.
* @param text dialog 제목의 text 를 결정한다.
*/
fun setTitle(resId: Int, text: String): T {
dialogView.findViewById<TextView>(resId).text = text
return self()
}

/**
*
* @param resId dialog 제목을 지정한다.
* @param text dialog 제목의 text를 결정한다. (SpannableString 적용한 Text 전용)
*/
fun setTitle(resId: Int, text: SpannableString): T {
fun setTitle(resId: Int, text: CharSequence): T {
dialogView.findViewById<TextView>(resId).text = text
return self()
}
Expand All @@ -124,6 +113,10 @@ abstract class BaseDialog<T : BaseDialog<T>>(protected val context: Context) {
dialog.show()
}

/**
*
* dialog 를 화면에서 없앤다.
*/
fun dismiss() {
dialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@ class EditDialog private constructor(context: Context) :
private lateinit var editText: EditText

companion object {
private var INSTANCE: EditDialog? = null

/**
* @param context 화면에 띄울 컨텍스트를 지정
* @param layoutId 원하는 dialog 레이아웃을 넣어준다.
* @param editTextId dialog 레이아웃 내부의 editText Id를 넣어준다.
*/
fun with(context: Context, layoutId: Int, editTextId: Int): EditDialog {
return EditDialog(context).apply {
val instance = INSTANCE
if (instance?.baseLayoutId == layoutId) return instance

INSTANCE = EditDialog(context).apply {
builder = AlertDialog.Builder(context)
dialogView = LayoutInflater.from(context).inflate(layoutId, null)
dialog = builder.setView(dialogView).create()
editText = dialogView.findViewById(editTextId)
editText.setSingleLine()
baseLayoutId = layoutId
}

return INSTANCE ?: throw IllegalStateException("Instance is null.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ class NormalDialog private constructor(context: Context) :
BaseDialog<NormalDialog>(context) {

companion object {
private var INSTANCE: NormalDialog? = null

/**
* @param context 화면에 띄울 컨텍스트를 지정
* @param layoutId 원하는 dialog 레이아웃을 넣어준다.
*/
fun with(context: Context, layoutId: Int): NormalDialog {
return NormalDialog(context).apply {
val instance = INSTANCE
if (instance?.baseLayoutId == layoutId) return instance

INSTANCE = NormalDialog(context).apply {
builder = AlertDialog.Builder(context)
dialogView = LayoutInflater.from(context).inflate(layoutId, null)
dialog = builder.setView(dialogView).create()
baseLayoutId = layoutId
}

return INSTANCE ?: throw IllegalStateException("Instance is null.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import java.io.File
import kotlin.properties.Delegates

/**
* 'glide' is a required ImageDialog.
Expand All @@ -16,36 +17,60 @@ import java.io.File
class PictureDialog private constructor(context: Context) :
BaseDialog<PictureDialog>(context) {

data class Size(
val width: Int,
val height: Int
)

private lateinit var imageView: ImageView
private lateinit var size: Size
private var errorImageId by Delegates.notNull<Int>()


companion object {
private var INSTANCE: PictureDialog? = null

/**
* @param context 화면에 띄울 컨텍스트를 지정
* @param layoutId 원하는 dialog 레이아웃을 넣어준다.
* @param imageViewId dialog 레이아웃 내부의 imageView Id를 넣어준다.
*/
fun with(context: Context, layoutId: Int, imageViewId: Int): PictureDialog {
return PictureDialog(context).apply {
val instance = INSTANCE
if (instance?.baseLayoutId == layoutId) return instance

INSTANCE = PictureDialog(context).apply {
builder = AlertDialog.Builder(context)
dialogView = LayoutInflater.from(context).inflate(layoutId, null)
dialog = builder.setView(dialogView).create()
imageView = dialogView.findViewById(imageViewId)
baseLayoutId = layoutId
}

return INSTANCE ?: throw IllegalStateException("Instance is null.")
}
}

fun setImageFilePath(
fun setSize(width: Int, height: Int): PictureDialog {
size = Size(width, height)
return this
}

fun setErrorImage(id: Int): PictureDialog {
errorImageId = id
return this
}


fun setImagePath(
filePath: String,
errorImageDrawableId: Int,
width: Int,
height: Int,
): PictureDialog {
Glide.with(imageView.context)
.load(File(filePath))
.placeholder(errorImageDrawableId)
.fallback(errorImageDrawableId)
.error(errorImageDrawableId)
.override(width, height)
.placeholder(errorImageId)
.fallback(errorImageId)
.error(errorImageId)
.override(size.width, size.height)
.transition(DrawableTransitionOptions.withCrossFade())
.into(imageView)
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import android.Manifest
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.graphics.Rect
import android.location.Location
import android.os.Build
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.view.ViewTreeObserver
import android.view.animation.AnticipateInterpolator
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import android.widget.EditText
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.animation.doOnEnd
Expand All @@ -21,6 +24,7 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupWithNavController
Expand All @@ -29,6 +33,7 @@ import com.google.android.gms.location.LocationServices
import com.google.android.gms.tasks.OnSuccessListener
import com.wakeup.presentation.R
import com.wakeup.presentation.databinding.ActivityMainBinding
import com.wakeup.presentation.extension.hideKeyboard
import com.wakeup.presentation.extension.showSnackBar
import com.wakeup.presentation.model.LocationModel
import com.wakeup.presentation.model.WeatherTheme
Expand Down Expand Up @@ -111,8 +116,12 @@ class MainActivity : AppCompatActivity() {
if (result == null) return@getLastLocation

launch {
viewModel.fetchWeather(LocationModel(result.latitude,
result.longitude))
viewModel.fetchWeather(
LocationModel(
result.latitude,
result.longitude
)
)
}
}

Expand Down Expand Up @@ -234,10 +243,14 @@ class MainActivity : AppCompatActivity() {
}

private fun initLocationPermission() {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
viewModel.permissionState.value = false
return
Expand All @@ -247,16 +260,38 @@ class MainActivity : AppCompatActivity() {
}

private fun hasLocationPermissions(): Boolean {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
return false
}
return true
}


override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
if (findNavController(R.id.nav_host_fragment).currentDestination?.id == R.id.home_fragment) {
if (ev?.action == MotionEvent.ACTION_DOWN) {
val v = currentFocus
if (v is EditText) {
val outRect = Rect()
v.getGlobalVisibleRect(outRect)
if (!outRect.contains(ev.rawX.toInt(), ev.rawY.toInt())) {
v.clearFocus()
hideKeyboard(v)
}
}
}
}
return super.dispatchTouchEvent(ev)
}

private companion object {
const val EXIT_ANIM_DURATION = 2000L
const val ONE_MINUTE = 60000L
Expand Down
Loading

0 comments on commit 5056d5b

Please sign in to comment.