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

Feature/modify UI #141

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ dependencies {
implementation Dependencies.kakaoSdk

implementation Dependencies.glide
annotationProcessor Dependencies.glideannotation
implementation Dependencies.glideannotation
annotationProcessor Dependencies.glidecompiler
kapt Dependencies.glidecompiler
implementation Dependencies.glidesvgloader

implementation platform(Dependencies.firebaseBOM)
implementation Dependencies.firebasektx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ class AddDirectTodoFragment : Fragment() {
}

private fun initListener() {
binding.switchHouseworkTime.isChecked = false
binding.switchHouseworkRepeat.isChecked = false
binding.addDirectTodoTitleEt.signNameClear.setOnClickListener {
binding.addDirectTodoTitleEt.fairerEt.setText(R.string.sign_name_blank)
}
binding.addDirectTodoBackgroundCl.setOnClickListener {
//hideKeyboard(binding.addDirectTodoTitleEt)
hideKeyboard(binding.switchHouseworkTime)
binding.addDirectTodoTitleEt.fairerEt.isEnabled = false
binding.isTextChanged = false
binding.addDirectTodoTitleEt.fairerEt.isEnabled = true
Expand All @@ -132,21 +134,22 @@ class AddDirectTodoFragment : Fragment() {
}


binding.addDirectTodoTimePicker.setOnTimeChangedListener { _, _, _ ->
binding.todoTimePicker.setOnTimeChangedListener { _, _, _ ->
updateTime()
}

binding.addDirectTodoTimePicker.setMyMinChangedListener(object :
binding.todoTimePicker.setMyMinChangedListener(object :
FairerTimePicker.MyMinChangedListener {
override fun onMinChange() {
updateTime()
}
})

binding.addDirectTodoAllDayCheckBox.apply {
setOnClickListener {
val time = binding.addDirectTodoTimePicker.getDisPlayedTime()
binding.switchHouseworkTime.apply {
setOnCheckedChangeListener { buttonView, isChecked ->
val time = binding.todoTimePicker.getDisPlayedTime()
viewModel.updateTime(time.first, time.second)
binding.timeSwitch = isChecked
}
}

Expand Down Expand Up @@ -211,8 +214,7 @@ class AddDirectTodoFragment : Fragment() {
}

private fun updateTime() {
binding.addDirectTodoAllDayCheckBox.isChecked = false
val time = binding.addDirectTodoTimePicker.getDisPlayedTime()
val time = binding.todoTimePicker.getDisPlayedTime()
viewModel.updateTime(time.first, time.second)
}

Expand Down Expand Up @@ -283,8 +285,8 @@ class AddDirectTodoFragment : Fragment() {
binding.addDirectTodoTitleEt.fairerEt.setText(viewModel.chores.value[0].houseWorkName)
if (viewModel.chores.value[0].scheduledTime != null) {
val time: Pair<Int, Int> = parseTime(viewModel.chores.value[0].scheduledTime!!)
binding.addDirectTodoTimePicker.setDisPlayedValue(time.first, time.second)
binding.addDirectTodoAllDayCheckBox.isChecked = false
binding.todoTimePicker.setDisPlayedValue(time.first, time.second)

}
}

Expand All @@ -294,8 +296,8 @@ class AddDirectTodoFragment : Fragment() {

// time set
when {
binding.addDirectTodoAllDayCheckBox.isChecked -> viewModel.updateChoreTime(null)
else -> viewModel.updateChoreTime(viewModel.curTime.value!!)
binding.switchHouseworkTime.isChecked -> viewModel.updateChoreTime(viewModel.curTime.value!!)
else -> viewModel.updateChoreTime(null)
}

//date set
Expand All @@ -312,7 +314,7 @@ class AddDirectTodoFragment : Fragment() {
// 요일 반복 rv adapter
val days: Array<String> = resources.getStringArray(R.array.day_array)
dayRepeatAdapter = DayRepeatAdapter(days)
binding.addDirectTodoRepeatRv.adapter = dayRepeatAdapter
//binding.addDirectTodoRepeatRv.adapter = dayRepeatAdapter
}

private fun hideKeyboard(v: View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class AddHouseWorkFragment : Fragment() {

@SuppressLint("NotifyDataSetChanged")
private fun initListener() {
binding.switchHouseworkTime.isChecked = false
binding.switchHouseworkRepeat.isChecked = false
// header title
binding.addHouseWorkHeader.defaultHeaderTitleTv.text = ""

Expand Down Expand Up @@ -121,10 +123,11 @@ class AddHouseWorkFragment : Fragment() {
}
})

binding.addHouseWorkAllDayCheckBox.apply {
setOnClickListener {
binding.switchHouseworkTime.apply {
setOnCheckedChangeListener { _, isChecked ->
val time = binding.todoTimePicker.getDisPlayedTime()
viewModel.updateTime(time.first, time.second)
binding.timeSwitch = isChecked
}
}

Expand Down Expand Up @@ -185,30 +188,26 @@ class AddHouseWorkFragment : Fragment() {
}

private fun updateTime() {
binding.addHouseWorkAllDayCheckBox.isChecked = false
val time = binding.todoTimePicker.getDisPlayedTime()
viewModel.updateTime(time.first, time.second)
}

private fun updateChore(position: Int) {
when {
binding.addHouseWorkAllDayCheckBox.isChecked -> viewModel.updateChore(
null,
position
)
else -> viewModel.updateChore(viewModel.curTime.value, position)
binding.switchHouseworkTime.isChecked -> viewModel.updateChore(viewModel.curTime.value, position)
else -> viewModel.updateChore(null, position)
}
}

private fun updateView(position: Int) {
val chore = viewModel.getChore(position)
if (chore.scheduledTime == null) {
binding.todoTimePicker.initDisPlayedValue()
binding.addHouseWorkAllDayCheckBox.isChecked = true
binding.switchHouseworkTime.isChecked = false
} else {
val time = parseTime(chore.scheduledTime!!)
binding.todoTimePicker.setDisPlayedValue(time.first, time.second)
binding.addHouseWorkAllDayCheckBox.isChecked = false
binding.switchHouseworkTime.isChecked = true
}

val curAssignees = arrayListOf<Assignee>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SignProfileAdapter(
.placeholder(context.getDrawable(R.drawable.bg_profile_imageview_inactive))
.into(binding.signProfileImageview)


binding.signProfileImageview.isSelected = profileData.state
val pos = adapterPosition
if (pos != RecyclerView.NO_POSITION) {
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/com/depromeet/housekeeper/util/BindingAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.text.util.Linkify
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import coil.load
import com.bumptech.glide.Glide
import com.depromeet.housekeeper.R
import com.depromeet.housekeeper.model.enums.SignViewType
import java.util.regex.Pattern
Expand All @@ -25,9 +25,12 @@ object BindingAdapter {
@androidx.databinding.BindingAdapter("app:loadImage")
@JvmStatic
fun loadImage(imageView: ImageView, url: String) {
imageView.load(url) {
crossfade(true)
}
Glide.with(imageView.context)
.load(url)
.placeholder(R.drawable.bg_profile_imageview_inactive)
.error(R.drawable.bg_profile_imageview_inactive)
.fitCenter()
.into(imageView)
}

@androidx.databinding.BindingAdapter("app:signViewType")
Expand All @@ -52,11 +55,12 @@ object BindingAdapter {
@androidx.databinding.BindingAdapter("app:imageUrl", "app:placeholder")
@JvmStatic
fun loadImage(imageView: ImageView, url: String, placeholder: Drawable) {
imageView.load(url) {
placeholder(placeholder)
crossfade(true)
}

Glide.with(imageView.context)
.load(url)
.placeholder(R.drawable.bg_profile_imageview_inactive)
.error(R.drawable.bg_profile_imageview_inactive)
.fitCenter()
.into(imageView)
}

@androidx.databinding.BindingAdapter("app:setLinkify")
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/depromeet/housekeeper/util/MyGlideModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.depromeet.housekeeper.util

import android.content.Context
import android.graphics.drawable.PictureDrawable
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule
import com.caverock.androidsvg.SVG
import java.io.InputStream

@GlideModule
class MyGlideModule : AppGlideModule() {

override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
registry
.register(SVG::class.java, PictureDrawable::class.java, SvgDrawableTranscoder())
.append(InputStream::class.java, SVG::class.java, SvgDecoder())
}

override fun isManifestParsingEnabled(): Boolean {
return super.isManifestParsingEnabled()
}


}
41 changes: 41 additions & 0 deletions app/src/main/java/com/depromeet/housekeeper/util/SvgDecoder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.depromeet.housekeeper.util

import com.bumptech.glide.load.Options
import com.bumptech.glide.load.ResourceDecoder
import com.bumptech.glide.load.engine.Resource
import com.bumptech.glide.load.resource.SimpleResource
import com.bumptech.glide.request.target.Target.SIZE_ORIGINAL
import com.caverock.androidsvg.SVG
import com.caverock.androidsvg.SVGParseException
import java.io.IOException
import java.io.InputStream


class SvgDecoder : ResourceDecoder<InputStream?, SVG?> {
override fun decode(
source: InputStream,
width: Int,
height: Int,
options: Options
): Resource<SVG?>? {
return try {
val svg = SVG.getFromInputStream(source)
if (width != SIZE_ORIGINAL) {
svg.documentWidth = width.toFloat()
}
if (height != SIZE_ORIGINAL) {
svg.documentHeight = height.toFloat()
}
SimpleResource(svg)
} catch (ex: SVGParseException) {
throw IOException("Cannot load SVG from stream", ex)
}
}

override fun handles(source: InputStream, options: Options): Boolean {
return true
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.depromeet.housekeeper.util

import android.graphics.drawable.PictureDrawable
import androidx.annotation.Nullable
import com.bumptech.glide.load.Options
import com.bumptech.glide.load.engine.Resource
import com.bumptech.glide.load.resource.SimpleResource
import com.bumptech.glide.load.resource.transcode.ResourceTranscoder
import com.caverock.androidsvg.SVG


class SvgDrawableTranscoder : ResourceTranscoder<SVG?, PictureDrawable?> {
@Nullable
override fun transcode(
toTranscode: Resource<SVG?>,
options: Options
): Resource<PictureDrawable?>? {
val svg: SVG = toTranscode.get()
val picture = svg.renderToPicture()
val drawable = PictureDrawable(picture)
return SimpleResource(drawable)
}

}
Loading