Skip to content

Commit

Permalink
(#2) Update notice list UI and model.
Browse files Browse the repository at this point in the history
  • Loading branch information
myung6024 committed Oct 11, 2019
1 parent cb5e3b7 commit 58f15f3
Show file tree
Hide file tree
Showing 62 changed files with 742 additions and 12 deletions.
24 changes: 18 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ android {
buildConfigField "String", "BASE_URL", "\"\""
}
}
dataBinding {
enabled = true
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-alpha1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "com.google.android.material:material:1.0.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Expand All @@ -54,14 +60,13 @@ dependencies {
// Android Architecture component
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version"
// kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

// MvRx + Epoxy + Koin
implementation "com.airbnb.android:mvrx:$mvrx_version"
implementation "com.airbnb.android:epoxy:$epoxy_version"
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation "org.koin:koin-android:$koin_version"

// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
Expand All @@ -88,6 +93,13 @@ dependencies {
implementation "com.facebook.stetho:stetho:$stetho_version"
implementation "com.facebook.stetho:stetho-okhttp3:$stetho_version"

// Koin for Kotlin
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-core:$koin_version"
implementation "org.koin:koin-core-ext:$koin_version"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</activity>
<activity android:name=".app.home.HomeActivity"/>
<activity
android:name=".app.notice.NoticeActivity"
android:name=".notices.NoticesActivity"
android:label="@string/title_activity_notice"
android:theme="@style/AppTheme.NoActionBar">
</activity>
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/mashup/MashupApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.mashup
import android.app.Application
import com.facebook.stetho.Stetho
import com.jakewharton.threetenabp.AndroidThreeTen
import com.mashup.notices.noticeModule
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

class MashupApplication: Application() {

Expand All @@ -14,7 +17,10 @@ class MashupApplication: Application() {
override fun onCreate() {
super.onCreate()
instance = this

startKoin {
androidContext(this@MashupApplication)
modules(noticeModule)
}
initJSR310()

if (BuildConfig.DEBUG) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/mashup/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mashup

import android.app.Application
import com.mashup.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)
}
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/mashup/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import com.mashup.app.auth.LoginActivity
import com.mashup.notices.NoticesActivity

class SplashActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
Handler().postDelayed({
startActivity(Intent(this, LoginActivity::class.java))
startActivity(Intent(this, NoticesActivity::class.java))
finish()
},3000)
},2000)

}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/mashup/data/model/Notice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mashup.data.model

data class Notice(
val pk: Int,
val team: Team,
val title: String,
val author: User,
val startAt: String,
val duration: String,
val address1: String,
val address2: String,
val description: String,
val attendanceSet: ArrayList<NoticeAttendance>
)
8 changes: 8 additions & 0 deletions app/src/main/java/com/mashup/data/model/NoticeAttendance.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mashup.data.model

data class NoticeAttendance(
val pk:Int,
val user:User,
val vote: String,
val voteDisplay: String
)
7 changes: 7 additions & 0 deletions app/src/main/java/com/mashup/data/model/Period.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mashup.data.model

data class Period(
val pk: Int,
val isCurrent: Boolean,
val number: Int
)
6 changes: 6 additions & 0 deletions app/src/main/java/com/mashup/data/model/Team.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mashup.data.model

data class Team(
val pk: Int,
val name: String
)
10 changes: 10 additions & 0 deletions app/src/main/java/com/mashup/data/model/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mashup.data.model

data class User(
val pk: Int,
val name: String,
val phoneNumber: String,
val email: String,
val github: String,
val userPeriodTeamSet: ArrayList<UserPeriodTeam>
)
6 changes: 6 additions & 0 deletions app/src/main/java/com/mashup/data/model/UserPeriodTeam.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mashup.data.model

data class UserPeriodTeam(
val period: Period,
val team: Team
)
10 changes: 10 additions & 0 deletions app/src/main/java/com/mashup/notices/NoticeListBindings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mashup.notices

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import com.mashup.data.model.Notice

@BindingAdapter("app:items")
fun setItems(listView: RecyclerView, items: List<Notice>) {
(listView.adapter as NoticeAdapter).submitList(items)
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/mashup/notices/NoticeModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mashup.notices

import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val noticeModule = module {
viewModel { NoticesViewModel() }
}
19 changes: 19 additions & 0 deletions app/src/main/java/com/mashup/notices/NoticesActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mashup.notices

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.mashup.R

class NoticesActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.notices_activity)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, NoticesFragment.newInstance())
.commitNow()
}
}

}
59 changes: 59 additions & 0 deletions app/src/main/java/com/mashup/notices/NoticesAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.mashup.notices

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.data.model.Notice
import com.mashup.databinding.NoticeItemBinding

class NoticeAdapter(private val viewModel: NoticesViewModel) :
ListAdapter<Notice, NoticeAdapter.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: NoticeItemBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bind(viewModel: NoticesViewModel, item: Notice) {

binding.viewmodel = viewModel
binding.notice = item
binding.executePendingBindings()
}

companion object {
fun from(parent: ViewGroup): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = NoticeItemBinding.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<Notice>() {
override fun areItemsTheSame(oldItem: Notice, newItem: Notice): Boolean {
return oldItem.pk == newItem.pk
}

override fun areContentsTheSame(oldItem: Notice, newItem: Notice): Boolean {
return oldItem == newItem
}
}
46 changes: 46 additions & 0 deletions app/src/main/java/com/mashup/notices/NoticesFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.mashup.notices

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.mashup.databinding.NoticesFragmentBinding
import org.koin.androidx.viewmodel.ext.android.viewModel

class NoticesFragment : Fragment() {

companion object {
fun newInstance() = NoticesFragment()
}

private val viewModel: NoticesViewModel by viewModel()
private lateinit var viewDataBinding: NoticesFragmentBinding
private lateinit var listAdapter: NoticeAdapter


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
viewDataBinding = NoticesFragmentBinding.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 = NoticeAdapter(viewModel)
viewDataBinding.tasksList.adapter = listAdapter
}
}

}
43 changes: 43 additions & 0 deletions app/src/main/java/com/mashup/notices/NoticesViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mashup.notices

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.mashup.data.model.Notice
import com.mashup.data.model.Team
import com.mashup.data.model.User

class NoticesViewModel : ViewModel() {
private val _items = MutableLiveData<List<Notice>>().apply { value = emptyList() }
val items: LiveData<List<Notice>> = _items

init {
loadNotice()
}

private fun loadNotice() {
val user = User(0, "이동근", "010", "ee", "ee", ArrayList())
val noticeArray = ArrayList<Notice>()
noticeArray.add(Notice(
0, Team(0, "Mash-up"), "전체 회의", user, "2019-10-10", "2시까지", "행신역에서", "", "재밌게 놀아봐요",
ArrayList()))
noticeArray.add(Notice(
0, Team(0, "Mash-up"), "전체 회의", user, "2019-10-10", "2시까지", "행신역에서", "", "재밌게 놀아봐요",
ArrayList()))
noticeArray.add(Notice(
0, Team(0, "Mash-up"), "전체 회의", user, "2019-10-10", "2시까지", "행신역에서", "", "재밌게 놀아봐요",
ArrayList()))
noticeArray.add(Notice(
0, Team(0, "Mash-up"), "전체 회의", user, "2019-10-10", "2시까지", "행신역에서", "", "재밌게 놀아봐요",
ArrayList()))
noticeArray.add(Notice(
0, Team(0, "Mash-up"), "전체 회의", user, "2019-10-10", "2시까지", "행신역에서", "", "재밌게 놀아봐요",
ArrayList()))
noticeArray.add(Notice(
0, Team(0, "Mash-up"), "전체 회의", user, "2019-10-10", "2시까지", "행신역에서", "", "재밌게 놀아봐요",
ArrayList()))

_items.value = noticeArray
}

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

import android.content.Context
import android.util.AttributeSet
import androidx.constraintlayout.motion.widget.MotionLayout
import com.google.android.material.appbar.AppBarLayout

class CollapsibleToolbar @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener {

override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!!
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()
(parent as? AppBarLayout)?.addOnOffsetChangedListener(this)
}
}
Binary file added app/src/main/res/drawable-hdpi/icon_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_date.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_place.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_vote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_writer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/msg_mashup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_date.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_place.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_vote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_writer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/msg_mashup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_date.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_place.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_vote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/msg_mashup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_date.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_place.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_vote.png
Binary file added app/src/main/res/drawable-xxhdpi/icon_writer.png
Binary file added app/src/main/res/drawable-xxhdpi/msg_mashup.png
Binary file added app/src/main/res/drawable-xxxhdpi/icon_arrow.png
Binary file added app/src/main/res/drawable-xxxhdpi/icon_clock.png
Binary file added app/src/main/res/drawable-xxxhdpi/icon_date.png
Binary file added app/src/main/res/drawable-xxxhdpi/icon_place.png
Binary file added app/src/main/res/drawable-xxxhdpi/icon_vote.png
Binary file added app/src/main/res/drawable-xxxhdpi/icon_writer.png
Binary file added app/src/main/res/drawable-xxxhdpi/msg_mashup.png
Loading

0 comments on commit 58f15f3

Please sign in to comment.