-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
765 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/mashup/app/attendees/AttendeesDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NoticeAttendance>) : DialogFragment() { | ||
|
||
companion object { | ||
fun newInstance(attendanceList: List<NoticeAttendance>) = 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 | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/mashup/app/attendees/AttendeesDialogModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NoticeAttendance>) -> AttendeesDialogViewModel(attendanceList) } | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/mashup/app/attendees/AttendeesDialogViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NoticeAttendance> | ||
) : ViewModel() { | ||
private val _items = MutableLiveData<List<NoticeAttendance>>().apply { value = emptyList() } | ||
val items: LiveData<List<NoticeAttendance>> = _items | ||
|
||
init { | ||
_items.value = attendanceList | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/mashup/app/attendees/AttendeesListBindings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NoticeAttendance>) { | ||
(listView.adapter as AttendessDialogAdapter).submitList(items) | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/mashup/app/attendees/AttendessDialogAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NoticeAttendance, AttendessDialogAdapter.ViewHolder>(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<NoticeAttendance>() { | ||
override fun areItemsTheSame(oldItem: NoticeAttendance, newItem: NoticeAttendance): Boolean { | ||
return oldItem.pk == newItem.pk | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: NoticeAttendance, newItem: NoticeAttendance): Boolean { | ||
return oldItem == newItem | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/mashup/app/noticedetail/NoticeDetailActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Notice>(NoticeDetailFragment.EXTRA_NOTICE)) | ||
) | ||
.commitNow() | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/mashup/app/noticedetail/NoticeDetailFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/mashup/app/noticedetail/NoticeDetailModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) } | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/mashup/app/noticedetail/NoticeDetailViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Notice>() | ||
val item: LiveData<Notice> = _item | ||
|
||
init { | ||
_item.value = notice | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.