diff --git a/app/build.gradle b/app/build.gradle index b956607..f57d454 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -104,4 +104,4 @@ dependencies { implementation 'joda-time:joda-time:2.10.4' } apply plugin: 'com.google.gms.google-services' -com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true \ No newline at end of file +com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8b3bd87..051f3a5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.mashup"> @@ -11,18 +11,19 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> + - - + + + - - + android:theme="@style/AppTheme.NoActionBar"> + - \ No newline at end of file + diff --git a/app/src/main/java/com/mashup/MashupApplication.kt b/app/src/main/java/com/mashup/MashupApplication.kt index 7f4296e..ededd99 100644 --- a/app/src/main/java/com/mashup/MashupApplication.kt +++ b/app/src/main/java/com/mashup/MashupApplication.kt @@ -3,6 +3,8 @@ package com.mashup import android.app.Application import com.facebook.stetho.Stetho import com.jakewharton.threetenabp.AndroidThreeTen +import com.mashup.app.attendees.AttendeesDialogModule +import com.mashup.app.noticedetail.NoticeDetailModule import com.mashup.app.notices.NoticeModule import com.mashup.di.ApiModule import com.mashup.di.ApplicationModule @@ -27,7 +29,9 @@ class MashupApplication : Application() { ApplicationModule, ApiModule, NetworkModule, - NoticeModule + NoticeModule, + NoticeDetailModule, + AttendeesDialogModule )) } initJSR310() diff --git a/app/src/main/java/com/mashup/MyApplication.kt b/app/src/main/java/com/mashup/MyApplication.kt deleted file mode 100644 index ab7c2b9..0000000 --- a/app/src/main/java/com/mashup/MyApplication.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mashup - -import android.app.Application -import com.mashup.app.notices.NoticeModule -import org.koin.android.ext.koin.androidContext -import org.koin.core.context.startKoin - -class MyApplication : Application() { - override fun onCreate() { - super.onCreate() - - startKoin { - androidContext(this@MyApplication) - modules(NoticeModule) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/mashup/app/attendees/AttendeesDialogFragment.kt b/app/src/main/java/com/mashup/app/attendees/AttendeesDialogFragment.kt new file mode 100644 index 0000000..a6d7098 --- /dev/null +++ b/app/src/main/java/com/mashup/app/attendees/AttendeesDialogFragment.kt @@ -0,0 +1,48 @@ +package com.mashup.app.attendees + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import com.mashup.databinding.AttendeesDialogFragmentBinding +import com.mashup.model.NoticeAttendance +import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf + +class AttendeesDialogFragment(attendanceList: List) : DialogFragment() { + + companion object { + fun newInstance(attendanceList: List) = AttendeesDialogFragment(attendanceList) + const val TAG_ATTENDEES_DIALOG = "tag_attendees_dialog" + } + + private val viewModel: AttendeesDialogViewModel by viewModel { parametersOf(attendanceList) } + private lateinit var viewDataBinding: AttendeesDialogFragmentBinding + private lateinit var listAdapter: AttendessDialogAdapter + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + viewDataBinding = AttendeesDialogFragmentBinding.inflate(inflater, container, false).apply { + viewmodel = viewModel + } + return viewDataBinding.root + } + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + viewDataBinding.setLifecycleOwner(this.viewLifecycleOwner) + setupListAdapter() + } + + private fun setupListAdapter() { + val viewModel = viewDataBinding.viewmodel + if (viewModel != null) { + listAdapter = AttendessDialogAdapter(viewModel) + viewDataBinding.attendanceList.adapter = listAdapter + } + } +} diff --git a/app/src/main/java/com/mashup/app/attendees/AttendeesDialogModule.kt b/app/src/main/java/com/mashup/app/attendees/AttendeesDialogModule.kt new file mode 100644 index 0000000..3cca127 --- /dev/null +++ b/app/src/main/java/com/mashup/app/attendees/AttendeesDialogModule.kt @@ -0,0 +1,9 @@ +package com.mashup.app.attendees + +import com.mashup.model.NoticeAttendance +import org.koin.androidx.viewmodel.dsl.viewModel +import org.koin.dsl.module + +val AttendeesDialogModule = module { + viewModel { (attendanceList: List) -> AttendeesDialogViewModel(attendanceList) } +} \ No newline at end of file diff --git a/app/src/main/java/com/mashup/app/attendees/AttendeesDialogViewModel.kt b/app/src/main/java/com/mashup/app/attendees/AttendeesDialogViewModel.kt new file mode 100644 index 0000000..056835b --- /dev/null +++ b/app/src/main/java/com/mashup/app/attendees/AttendeesDialogViewModel.kt @@ -0,0 +1,17 @@ +package com.mashup.app.attendees + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mashup.model.NoticeAttendance + +class AttendeesDialogViewModel( + attendanceList: List +) : ViewModel() { + private val _items = MutableLiveData>().apply { value = emptyList() } + val items: LiveData> = _items + + init { + _items.value = attendanceList + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mashup/app/attendees/AttendeesListBindings.kt b/app/src/main/java/com/mashup/app/attendees/AttendeesListBindings.kt new file mode 100644 index 0000000..431bab9 --- /dev/null +++ b/app/src/main/java/com/mashup/app/attendees/AttendeesListBindings.kt @@ -0,0 +1,10 @@ +package com.mashup.app.attendees + +import androidx.databinding.BindingAdapter +import androidx.recyclerview.widget.RecyclerView +import com.mashup.model.NoticeAttendance + +@BindingAdapter("app:items") +fun setItems(listView: RecyclerView, items: List) { + (listView.adapter as AttendessDialogAdapter).submitList(items) +} \ No newline at end of file diff --git a/app/src/main/java/com/mashup/app/attendees/AttendessDialogAdapter.kt b/app/src/main/java/com/mashup/app/attendees/AttendessDialogAdapter.kt new file mode 100644 index 0000000..07e1926 --- /dev/null +++ b/app/src/main/java/com/mashup/app/attendees/AttendessDialogAdapter.kt @@ -0,0 +1,59 @@ +package com.mashup.app.attendees + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import com.mashup.databinding.AttendeesDialogItemBinding +import com.mashup.model.NoticeAttendance + +class AttendessDialogAdapter(private val viewModel: AttendeesDialogViewModel) : + ListAdapter(TaskDiffCallback()) { + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = getItem(position) + + holder.bind(viewModel, item) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + return ViewHolder.from(parent) + } + + class ViewHolder private constructor(val binding: AttendeesDialogItemBinding) : + RecyclerView.ViewHolder(binding.root) { + + fun bind(viewModel: AttendeesDialogViewModel, item: NoticeAttendance) { + + binding.viewmodel = viewModel + binding.item = item + binding.executePendingBindings() + } + + companion object { + fun from(parent: ViewGroup): ViewHolder { + val layoutInflater = LayoutInflater.from(parent.context) + val binding = AttendeesDialogItemBinding.inflate(layoutInflater, parent, false) + + return ViewHolder(binding) + } + } + } +} + +/** + * Callback for calculating the diff between two non-null items in a list. + * + * Used by ListAdapter to calculate the minimum number of changes between and old list and a new + * list that's been passed to `submitList`. + */ +class TaskDiffCallback : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: NoticeAttendance, newItem: NoticeAttendance): Boolean { + return oldItem.pk == newItem.pk + } + + override fun areContentsTheSame(oldItem: NoticeAttendance, newItem: NoticeAttendance): Boolean { + return oldItem == newItem + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailActivity.kt b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailActivity.kt new file mode 100644 index 0000000..63a9cfb --- /dev/null +++ b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailActivity.kt @@ -0,0 +1,22 @@ +package com.mashup.app.noticedetail + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import com.mashup.R +import com.mashup.model.Notice + +class NoticeDetailActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.notice_detail_activity) + if (savedInstanceState == null) { + supportFragmentManager.beginTransaction() + .replace(R.id.container, NoticeDetailFragment.newInstance( + intent.getParcelableExtra(NoticeDetailFragment.EXTRA_NOTICE)) + ) + .commitNow() + } + } + +} diff --git a/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailFragment.kt b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailFragment.kt new file mode 100644 index 0000000..b586e1c --- /dev/null +++ b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailFragment.kt @@ -0,0 +1,40 @@ +package com.mashup.app.noticedetail + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.mashup.databinding.NoticeDetailFragmentBinding +import com.mashup.model.Notice +import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf + +class NoticeDetailFragment(notice: Notice) : Fragment() { + + companion object { + fun newInstance(notice: Notice) = NoticeDetailFragment(notice) + const val EXTRA_NOTICE = "ExtraNotice" + const val REQUEST_NOTICE_ACTION = 1100 + } + + private val viewModel: NoticeDetailViewModel by viewModel { parametersOf(notice) } + private lateinit var viewDataBinding: NoticeDetailFragmentBinding + + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + viewDataBinding = NoticeDetailFragmentBinding.inflate(inflater, container, false).apply { + viewmodel = viewModel + } + return viewDataBinding.root + } + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + viewDataBinding.setLifecycleOwner(this.viewLifecycleOwner) + } + +} diff --git a/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailModule.kt b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailModule.kt new file mode 100644 index 0000000..c5fe0bc --- /dev/null +++ b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailModule.kt @@ -0,0 +1,9 @@ +package com.mashup.app.noticedetail + +import com.mashup.model.Notice +import org.koin.androidx.viewmodel.dsl.viewModel +import org.koin.dsl.module + +val NoticeDetailModule = module { + viewModel { (notice: Notice) -> NoticeDetailViewModel(notice) } +} diff --git a/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailViewModel.kt b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailViewModel.kt new file mode 100644 index 0000000..cab1961 --- /dev/null +++ b/app/src/main/java/com/mashup/app/noticedetail/NoticeDetailViewModel.kt @@ -0,0 +1,19 @@ +package com.mashup.app.noticedetail + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mashup.model.Notice + +class NoticeDetailViewModel( + notice: Notice +) : ViewModel() { + + private val _item = MutableLiveData() + val item: LiveData = _item + + init { + _item.value = notice + } + +} 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 fe38ce8..e67134a 100644 --- a/app/src/main/java/com/mashup/app/notices/NoticeListBindings.kt +++ b/app/src/main/java/com/mashup/app/notices/NoticeListBindings.kt @@ -3,7 +3,10 @@ package com.mashup.app.notices import android.widget.TextView 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.* @@ -14,13 +17,22 @@ fun setItems(listView: RecyclerView, items: List) { } @BindingAdapter("app:noticeTime") -fun setNoticeTimeFormat(textView: TextView, date: Date) { +fun setNoticeTimeFormat(textView: TextView, date: Date?) { + if (date == null) + return textView.text = DateTimeFormat.forPattern("yyyy년 M월 dd일 (E)").print(DateTime(date)) } @BindingAdapter(value = ["app:startAt", "app:duration"]) -fun setNoticeDurationFormat(textView: TextView, startAt: Date, duration: String) { +fun setNoticeDurationFormat(textView: TextView, startAt: Date?, duration: String?) { + if (startAt == null || duration == null) + return val startDate = DateTime(startAt) val endDate = startDate.plusHours(DateTimeFormat.forPattern("HH:mm:ss").parseLocalTime(duration).hourOfDay) textView.text = "${DateTimeFormat.forPattern("a h시").print(startDate)}-${DateTimeFormat.forPattern("h시").print(endDate)}" +} + +@BindingAdapter("app:attendanceSize") +fun setAttendanceSize(textView: TextView, attendanceList: List) { + textView.text = textView.context.getString(R.string.notice_attendance_set_format(attendanceList.count { it.vote != VoteStatus.UNSELECTED })) } \ No newline at end of file diff --git a/app/src/main/java/com/mashup/app/notices/NoticesFragment.kt b/app/src/main/java/com/mashup/app/notices/NoticesFragment.kt index 4cf6084..e5b6474 100644 --- a/app/src/main/java/com/mashup/app/notices/NoticesFragment.kt +++ b/app/src/main/java/com/mashup/app/notices/NoticesFragment.kt @@ -1,10 +1,14 @@ package com.mashup.app.notices +import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import com.mashup.app.attendees.AttendeesDialogFragment +import com.mashup.app.noticedetail.NoticeDetailActivity +import com.mashup.app.noticedetail.NoticeDetailFragment import com.mashup.databinding.NoticesFragmentBinding import com.mashup.util.EventObserver import org.koin.androidx.viewmodel.ext.android.viewModel @@ -34,7 +38,7 @@ class NoticesFragment : Fragment() { super.onActivityCreated(savedInstanceState) viewDataBinding.setLifecycleOwner(this.viewLifecycleOwner) setupListAdapter() - setupObserver() + setupEventObserver() } private fun setupListAdapter() { @@ -45,10 +49,23 @@ class NoticesFragment : Fragment() { } } - private fun setupObserver() { + private fun setupEventObserver() { viewModel.itemChangedEvent.observe(this, EventObserver { position -> listAdapter.notifyItemChanged(position) }) - } + viewModel.showDetailEvent.observe(this, EventObserver { notice -> + val intent = Intent(this@NoticesFragment.context, NoticeDetailActivity::class.java).apply { + putExtra(NoticeDetailFragment.EXTRA_NOTICE, notice) + } + startActivityForResult(intent, NoticeDetailFragment.REQUEST_NOTICE_ACTION) + }) + + viewModel.showAttendeesEvent.observe(this, EventObserver { attendees -> + fragmentManager?.let { + AttendeesDialogFragment.newInstance(attendees) + .show(it, AttendeesDialogFragment.TAG_ATTENDEES_DIALOG) + } + }) + } } 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 cae9f9d..5e5aaef 100644 --- a/app/src/main/java/com/mashup/app/notices/NoticesViewModel.kt +++ b/app/src/main/java/com/mashup/app/notices/NoticesViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.mashup.model.Notice +import com.mashup.model.NoticeAttendance import com.mashup.model.VoteStatus import com.mashup.repository.NoticesRepository import com.mashup.util.Event @@ -20,6 +21,12 @@ class NoticesViewModel( private val _itemChangedEvent = MutableLiveData>() val itemChangedEvent: LiveData> = _itemChangedEvent + private val _showDetailEvent = MutableLiveData>() + val showDetailEvent: LiveData> = _showDetailEvent + + private val _showAttendeesEvent = MutableLiveData>>() + val showAttendeesEvent: LiveData>> = _showAttendeesEvent + private val compositeDisposable = CompositeDisposable() private val dummyUserId = 1 @@ -64,6 +71,18 @@ class NoticesViewModel( ) } + fun onClickItem(notice: Notice) { + _items.value?.let { + _showDetailEvent.value = Event(notice) + } + } + + fun onClickAttendeesButton(attendees: List) { + _items.value?.let { + _showAttendeesEvent.value = Event(attendees) + } + } + private fun updateList(noticeId: Int, voteStatus: VoteStatus) { var position = 0 _items.value?.apply { diff --git a/app/src/main/res/layout/attendees_dialog_fragment.xml b/app/src/main/res/layout/attendees_dialog_fragment.xml new file mode 100644 index 0000000..d04e498 --- /dev/null +++ b/app/src/main/res/layout/attendees_dialog_fragment.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/attendees_dialog_item.xml b/app/src/main/res/layout/attendees_dialog_item.xml new file mode 100644 index 0000000..96364fb --- /dev/null +++ b/app/src/main/res/layout/attendees_dialog_item.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/notice_detail_activity.xml b/app/src/main/res/layout/notice_detail_activity.xml new file mode 100644 index 0000000..89bc5e5 --- /dev/null +++ b/app/src/main/res/layout/notice_detail_activity.xml @@ -0,0 +1,7 @@ + + diff --git a/app/src/main/res/layout/notice_detail_fragment.xml b/app/src/main/res/layout/notice_detail_fragment.xml new file mode 100644 index 0000000..29d2fa6 --- /dev/null +++ b/app/src/main/res/layout/notice_detail_fragment.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/notice_item.xml b/app/src/main/res/layout/notice_item.xml index d8691a4..f21e2c6 100644 --- a/app/src/main/res/layout/notice_item.xml +++ b/app/src/main/res/layout/notice_item.xml @@ -24,7 +24,8 @@ android:layout_height="400dp" android:layout_marginStart="30dp" android:layout_marginEnd="30dp" - android:layout_marginBottom="50dp"> + android:layout_marginBottom="50dp" + android:onClick="@{() -> viewmodel.onClickItem(notice)}"> , var userAttendance: VoteStatus = VoteStatus.NONE -) +) : Parcelable { + constructor(source: Parcel) : this( + source.readInt(), + source.readParcelable(Team::class.java.classLoader), + source.readString(), + source.readParcelable(User::class.java.classLoader), + source.readSerializable() as Date, + source.readString(), + source.readString(), + source.readString(), + source.readString(), + source.createTypedArrayList(NoticeAttendance.CREATOR), + VoteStatus.values()[source.readInt()] + ) + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { + writeInt(pk) + writeParcelable(team, 0) + writeString(title) + writeParcelable(author, 0) + writeSerializable(startAt) + writeString(duration) + writeString(address1) + writeString(address2) + writeString(description) + writeTypedList(attendanceSet) + writeInt(userAttendance.ordinal) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): Notice = Notice(source) + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + } +} diff --git a/model/src/main/java/com/mashup/model/NoticeAttendance.kt b/model/src/main/java/com/mashup/model/NoticeAttendance.kt index 68bc7c4..bd3b413 100644 --- a/model/src/main/java/com/mashup/model/NoticeAttendance.kt +++ b/model/src/main/java/com/mashup/model/NoticeAttendance.kt @@ -1,5 +1,7 @@ package com.mashup.model +import android.os.Parcel +import android.os.Parcelable import com.google.gson.annotations.SerializedName enum class VoteStatus { @@ -15,8 +17,35 @@ enum class VoteStatus { } data class NoticeAttendance( - val pk:Int, + val pk: Int, val user: User, val vote: VoteStatus, val voteDisplay: String -) +) : Parcelable { + constructor(source: Parcel) : this( + source.readInt(), + source.readParcelable(User::class.java.classLoader), + VoteStatus.values()[source.readInt()], + source.readString() + ) + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { + writeInt(pk) + writeParcelable(user, 0) + writeInt(vote.ordinal) + writeString(voteDisplay) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = + object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): NoticeAttendance = + NoticeAttendance(source) + + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + } +} diff --git a/model/src/main/java/com/mashup/model/Period.kt b/model/src/main/java/com/mashup/model/Period.kt index 7561c7a..5d263cc 100644 --- a/model/src/main/java/com/mashup/model/Period.kt +++ b/model/src/main/java/com/mashup/model/Period.kt @@ -1,7 +1,32 @@ package com.mashup.model +import android.os.Parcel +import android.os.Parcelable + data class Period( val pk: Int, val isCurrent: Boolean, val number: Int -) +) : Parcelable { + constructor(source: Parcel) : this( + source.readInt(), + 1 == source.readInt(), + source.readInt() + ) + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { + writeInt(pk) + writeInt((if (isCurrent) 1 else 0)) + writeInt(number) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): Period = Period(source) + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + } +} diff --git a/model/src/main/java/com/mashup/model/Team.kt b/model/src/main/java/com/mashup/model/Team.kt index 76b636c..f158c68 100644 --- a/model/src/main/java/com/mashup/model/Team.kt +++ b/model/src/main/java/com/mashup/model/Team.kt @@ -1,6 +1,29 @@ package com.mashup.model +import android.os.Parcel +import android.os.Parcelable + data class Team( val pk: Int, val name: String -) +) : Parcelable { + constructor(source: Parcel) : this( + source.readInt(), + source.readString() + ) + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { + writeInt(pk) + writeString(name) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): Team = Team(source) + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + } +} diff --git a/model/src/main/java/com/mashup/model/User.kt b/model/src/main/java/com/mashup/model/User.kt index 0c0d5af..1d4c75a 100644 --- a/model/src/main/java/com/mashup/model/User.kt +++ b/model/src/main/java/com/mashup/model/User.kt @@ -1,10 +1,41 @@ package com.mashup.model +import android.os.Parcel +import android.os.Parcelable + data class User( val pk: Int, val name: String, - val phoneNumber: String, - val email: String, + val phoneNumber: String?, + val email: String?, val github: String, val userPeriodTeamSet: ArrayList -) +) : Parcelable { + constructor(source: Parcel) : this( + source.readInt(), + source.readString(), + source.readString(), + source.readString(), + source.readString(), + source.createTypedArrayList(UserPeriodTeam.CREATOR) + ) + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { + writeInt(pk) + writeString(name) + writeString(phoneNumber) + writeString(email) + writeString(github) + writeTypedList(userPeriodTeamSet) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): User = User(source) + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + } +} diff --git a/model/src/main/java/com/mashup/model/UserPeriodTeam.kt b/model/src/main/java/com/mashup/model/UserPeriodTeam.kt index 5372d1d..7ba9524 100644 --- a/model/src/main/java/com/mashup/model/UserPeriodTeam.kt +++ b/model/src/main/java/com/mashup/model/UserPeriodTeam.kt @@ -1,6 +1,33 @@ package com.mashup.model +import android.os.Parcel +import android.os.Parcelable + data class UserPeriodTeam( val period: Period, val team: Team -) +) : Parcelable { + constructor(source: Parcel) : this( + source.readParcelable(Period::class.java.classLoader), + source.readParcelable(Team::class.java.classLoader) + ) + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { + writeParcelable(period, 0) + writeParcelable(team, 0) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = + object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): UserPeriodTeam = + UserPeriodTeam(source) + + override fun newArray(size: Int): Array = + arrayOfNulls(size) + } + } +}