diff --git a/app/build.gradle b/app/build.gradle index 2adfb7d..4af601e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,7 +38,7 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.1.0' + implementation "androidx.appcompat:appcompat:$appcompat_version" implementation 'androidx.core:core-ktx:1.1.0' implementation "androidx.fragment:fragment:1.2.0-rc02" implementation 'androidx.constraintlayout:constraintlayout:1.1.3' @@ -61,7 +61,6 @@ dependencies { } implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation "androidx.appcompat:appcompat:$appcompat_version" implementation "androidx.constraintlayout:constraintlayout:$constraint_version" implementation "androidx.cardview:cardview:1.0.0" diff --git a/app/src/main/java/com/mashup/app/notices/NoticeListBindings.kt b/app/src/main/java/com/mashup/app/notices/NoticeListBindings.kt index 3884123..c8514ac 100644 --- a/app/src/main/java/com/mashup/app/notices/NoticeListBindings.kt +++ b/app/src/main/java/com/mashup/app/notices/NoticeListBindings.kt @@ -1,13 +1,12 @@ package com.mashup.app.notices +import android.view.View import android.widget.TextView import androidx.core.content.ContextCompat import androidx.databinding.BindingAdapter import androidx.recyclerview.widget.RecyclerView import com.mashup.R import com.mashup.model.Notice -import com.mashup.model.NoticeAttendance -import com.mashup.model.VoteStatus import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat import java.util.* @@ -40,3 +39,33 @@ fun setVoteTextColor(textView: TextView, isSelected: Boolean) { else textView.setTextColor(ContextCompat.getColor(textView.context, R.color.colorPrimary)) } + +@BindingAdapter(value = ["app:seeMoreVisibility", "app:position", "app:setPosition"]) +fun setSeeMoreTextVisibility(textView: TextView, targetText: TextView, position: Int, setPosition : (Int) -> Unit) { + targetText.post { + if (targetText.lineCount >= 5) { + textView.setOnClickListener { + if (targetText.maxLines == 100) { + targetText.maxLines = 5 + textView.text = textView.context.getString(R.string.notice_see_more) + } else { + targetText.maxLines = 100 + textView.text = textView.context.getString(R.string.notice_collapse) + } + setPosition(position) + } + targetText.setOnClickListener { + if (targetText.maxLines == 100) { + targetText.maxLines = 5 + textView.text = textView.context.getString(R.string.notice_see_more) + } else { + targetText.maxLines = 100 + textView.text = textView.context.getString(R.string.notice_collapse) + } + setPosition(position) + } + textView.visibility = View.VISIBLE + } else + textView.visibility = View.GONE + } +} diff --git a/app/src/main/java/com/mashup/app/notices/NoticesAdapter.kt b/app/src/main/java/com/mashup/app/notices/NoticesAdapter.kt index 4936f81..be599a3 100644 --- a/app/src/main/java/com/mashup/app/notices/NoticesAdapter.kt +++ b/app/src/main/java/com/mashup/app/notices/NoticesAdapter.kt @@ -2,19 +2,21 @@ package com.mashup.app.notices import android.view.LayoutInflater import android.view.ViewGroup +import android.view.animation.OvershootInterpolator import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView +import com.mashup.R import com.mashup.databinding.NoticeItemBinding import com.mashup.model.Notice class NoticeAdapter(private val viewModel: NoticesViewModel) : - ListAdapter(TaskDiffCallback()) { + ListAdapter(TaskDiffCallback()) { override fun onBindViewHolder(holder: ViewHolder, position: Int) { val item = getItem(position) - holder.bind(viewModel, item) + holder.bind(viewModel, item, position) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -22,12 +24,22 @@ class NoticeAdapter(private val viewModel: NoticesViewModel) : } class ViewHolder private constructor(val binding: NoticeItemBinding) : - RecyclerView.ViewHolder(binding.root) { + RecyclerView.ViewHolder(binding.root) { - fun bind(viewModel: NoticesViewModel, item: Notice) { + fun bind(viewModel: NoticesViewModel, item: Notice, position: Int) { + if (position == viewModel.expandPosition) { + binding.descriptionText.maxLines = 100 + binding.toggleButton.text = + binding.toggleButton.context.getString(R.string.notice_collapse) + } else { + binding.descriptionText.maxLines = 5 + binding.toggleButton.text = + binding.toggleButton.context.getString(R.string.notice_see_more) + } binding.viewmodel = viewModel binding.notice = item + binding.position = position binding.executePendingBindings() } diff --git a/app/src/main/java/com/mashup/app/notices/NoticesViewModel.kt b/app/src/main/java/com/mashup/app/notices/NoticesViewModel.kt index ab36b5b..4647216 100644 --- a/app/src/main/java/com/mashup/app/notices/NoticesViewModel.kt +++ b/app/src/main/java/com/mashup/app/notices/NoticesViewModel.kt @@ -41,6 +41,8 @@ class NoticesViewModel( private lateinit var authToken: AuthToken + var expandPosition: Int = -1 + init { checkAuthToken() getNotice(false) @@ -121,6 +123,15 @@ class NoticesViewModel( } } + val setExpandPosition: (Int) -> Unit + get() = fun(position: Int) { + expandPosition = if (expandPosition == position) { + -1 + } else { + position + } + } + override fun onCleared() { compositeDisposable.clear() super.onCleared() diff --git a/app/src/main/res/layout/notice_item.xml b/app/src/main/res/layout/notice_item.xml index dfba10b..a1fda99 100644 --- a/app/src/main/res/layout/notice_item.xml +++ b/app/src/main/res/layout/notice_item.xml @@ -1,11 +1,11 @@ - + - + @@ -20,17 +20,20 @@ + + + app:cardCornerRadius="@dimen/card_radius" + app:cardElevation="@dimen/card_elevation"> + + + android:textSize="@dimen/text_small" + app:voteTextColor="@{notice.userAttendance == VoteStatus.ATTEND}" /> + android:textSize="@dimen/text_small" + app:voteTextColor="@{notice.userAttendance == VoteStatus.ABSENT}" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd481da..41ea455 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,4 +38,7 @@ 로그아웃하기 전체공지 설정 + + 더 보기 + 다시 접기 diff --git a/build.gradle b/build.gradle index f27268b..10161be 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { ext { kotlin_version = '1.3.11' - appcompat_version="1.0.2" + appcompat_version="1.1.0-rc01" lifecycle_version = "2.0.0" constraint_version = "2.0.0-beta2"