Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6cbbf75
[add] add response parameter
chigichan24 May 3, 2018
774cb88
[add] add feature that can post public room
chigichan24 May 3, 2018
d947c0f
[add] 人気のルーム一覧のxmlを作成
May 7, 2018
a99888f
[add] 人気のルームを取得できるようにした
May 7, 2018
18c227f
[add] 今人気のルームを表示できるようにした
May 7, 2018
c3ed48b
[add] タイトルの表示非表示を切り替えられるようにした
May 7, 2018
9b24d3d
[change] 画面更新のタイミングを変更
May 7, 2018
9a97922
[fix] チャットが最後までスクロールされないバグを修正
May 8, 2018
f4d3bcb
[fix] Remove unused import and use ObservleBoolean
chigichan24 May 9, 2018
5433794
Merge remote-tracking branch 'upstream/development' into 258-post-pub…
chigichan24 May 10, 2018
ab01e7d
[delete] 使ってないメソッドを削除
May 12, 2018
b8a72eb
[clear] リファクタ
May 12, 2018
2091e79
[add] fixi gitignore
chigichan24 May 13, 2018
8c22813
[fix] Do git rm cache
chigichan24 May 13, 2018
7a9b9c1
Merge pull request #261 from chigichan24/258-post-public-room
May 13, 2018
6c5e829
Merge pull request #264 from cyder/120-popular-room
chigichan24 May 13, 2018
0504622
Merge pull request #268 from cyder/267-chat-scroll
chigichan24 May 13, 2018
b371105
[add] spinnerを表示
May 13, 2018
98883c9
[change] public設定を取得できるようにした
May 13, 2018
71b76e8
[change] 文字列の差し替え
May 13, 2018
ddefa9c
[change] デザイン調整
May 13, 2018
51a4772
[clear] リファクタ
May 13, 2018
6aab1ca
Merge pull request #274 from cyder/271-create-room-description
chigichan24 May 14, 2018
225ddc8
[update] version code
May 15, 2018
c33989e
Merge pull request #277 from cyder/v2.1.0
chigichan24 May 19, 2018
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
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def versionMajor = 2
def versionMinor = 0
def versionPatch = 2
def versionMinor = 1
def versionPatch = 0

def appVersionCode = versionMajor * 100 + versionMinor * 10 + versionPatch
def appVersionName = "${versionMajor}.${versionMinor}.${versionPatch}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ interface SyncPodApi {
@GET("joined_rooms")
fun getEnteredRooms(@Header("Authorization") token: String): Single<Response>

@GET("rooms/popular")
fun getPopularRooms(@Header("Authorization") token: String): Single<Response>

@GET("rooms")
fun getRoom(@Header("Authorization") token: String, @Query("room_key") roomKey: String): Single<Response>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fun RoomResponse.toModel(): Room =
this.name,
this.description,
this.key,
this.isPublic,
this.nowPlayingVideo?.toModel(),
this.lastPlayedVideo?.toModel(),
this.onlineUsers?.toModel())
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package com.cyder.android.syncpod.api.request
* Created by chigichan24 on 2018/03/31.
*/

class CreateRoom(name: String, description: String) {
private val room = Room(name, description)
class CreateRoom(name: String, description: String, isPublic: Boolean) {
private val room = Room(name, description, isPublic)
}

private data class Room (
val name: String,
val description: String
val description: String,
val public: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class Response(
val result: String,
val user: User?,
val room: Room?,
@SerializedName("joined_rooms") val joinedRooms: List<Room>?
@SerializedName("joined_rooms") val joinedRooms: List<Room>?,
@SerializedName("rooms") val popularRooms: List<Room>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class Room(
val name: String,
val description: String,
val key: String,
@SerializedName("public") val isPublic: Boolean,
@SerializedName("now_playing_video") val nowPlayingVideo: Video?,
@SerializedName("last_played_video") val lastPlayedVideo: Video?,
@SerializedName("online_users") val onlineUsers: List<User>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class Room(
val name: String,
val description: String,
val key: String,
val isPublic: Boolean,
val nowPlayingVideo: Video?,
val lastPlayedVideo: Video?,
val onlineUsers: List<User>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class RoomDataRepository @Inject constructor(
return syncPodWsApi.exitRoom()
}

override fun createNewRoom(name: String, description: String): Single<Room> {
override fun createNewRoom(name: String, description: String, isPublic: Boolean): Single<Room> {
return createNewRoomValidation(name, description)
.andThen(syncPodApi.createNewRoom(token, CreateRoom(name, description)))
.andThen(syncPodApi.createNewRoom(token, CreateRoom(name, description, isPublic)))
.map { it.room }
.map { it.toModel() }
.subscribeOn(Schedulers.computation())
Expand All @@ -58,6 +58,14 @@ class RoomDataRepository @Inject constructor(
.observeOn(AndroidSchedulers.mainThread())
}

override fun fetchPopularRooms(): Single<List<Room>> {
return syncPodApi.getPopularRooms(token)
.map { it.popularRooms }
.map { it.toModel() }
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
}

override fun exitForce(user: User) {
syncPodWsApi.exitForce(user)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import io.reactivex.Single
*/
interface RoomRepository {
val isEntered: Flowable<Boolean>
fun createNewRoom(name: String, description: String): Single<Room>
fun createNewRoom(name: String, description: String, isPublic: Boolean): Single<Room>
fun fetchJoinedRooms(): Single<List<Room>>
fun fetchPopularRooms(): Single<List<Room>>
fun fetch(roomKey: String): Single<Room>
fun joinRoom(roomKey: String): Completable
fun exitRoom(): Completable
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/kotlin/com/cyder/android/syncpod/util/CustomBinder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package com.cyder.android.syncpod.util
import android.databinding.BindingAdapter
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.SwitchCompat
import android.support.v7.widget.Toolbar
import android.text.method.LinkMovementMethod
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.Animation
import android.widget.CompoundButton
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.Animation
import com.cyder.android.syncpod.view.helper.ResizeAnimation
import com.cyder.android.syncpod.view.helper.dpToPx
import com.cyder.android.syncpod.view.helper.hideSoftwareKeyBoard
Expand Down Expand Up @@ -102,4 +104,9 @@ fun View.hideSoftwareKeyboard(flag: Boolean) {
if (flag) {
hideSoftwareKeyBoard()
}
}
}

@BindingAdapter("isChecked")
fun SwitchCompat.setCheck(listener: CompoundButton.OnCheckedChangeListener) {
setOnCheckedChangeListener(listener)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.widget.SimpleAdapter
import com.cyder.android.syncpod.R
import com.cyder.android.syncpod.databinding.ActivityCreateRoomBinding
import com.cyder.android.syncpod.view.helper.setUpSnackbar
Expand All @@ -26,7 +27,19 @@ class CreateRoomActivity : BaseActivity() {
binding = DataBindingUtil.setContentView(this, R.layout.activity_create_room)
binding.viewModel = viewModel

viewModel.resources = this.resources
viewModel.callback = setUpSnackbar()
setUpSpinner()
}

private fun setUpSpinner() {
val adapter = SimpleAdapter(
this,
viewModel.publishingSettingItems,
R.layout.spinner_item_with_description,
viewModel.publishingSettingKeys,
intArrayOf(R.id.title, R.id.description))
binding.publishingSetting.adapter = adapter
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.databinding.DataBindingUtil
import android.databinding.ObservableList
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.cyder.android.syncpod.R
import com.cyder.android.syncpod.databinding.ActivityTopBinding
Expand Down Expand Up @@ -41,7 +42,8 @@ class TopActivity : BaseActivity() {

setUpDialog()
viewModel.snackbarCallback = setUpSnackbar()
initRecyclerView()
initRecyclerView(binding.joinedRoomRecycler, viewModel.joinedRoomViewModels)
initRecyclerView(binding.popularRoomRecycler, viewModel.populardRoomViewModels)
}

private fun setUpDialog() {
Expand All @@ -62,15 +64,15 @@ class TopActivity : BaseActivity() {
viewModel.dialogCallback = callback
}

private fun initRecyclerView() {
binding.joinedRoomRecycler.isNestedScrollingEnabled = false
val adapter = JoinedRoomAdapter(viewModel.roomViewModels)
binding.joinedRoomRecycler.adapter = adapter
binding.joinedRoomRecycler.layoutManager = LinearLayoutManager(this)
private fun initRecyclerView(recyclerView: RecyclerView, viewModels: ObservableList<RoomViewModel>) {
recyclerView.isNestedScrollingEnabled = false
val adapter = RoomAdapter(viewModels)
recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(this@TopActivity)
}


inner class JoinedRoomAdapter(list: ObservableList<RoomViewModel>) : ObservableListAdapter<RoomViewModel, BindingHolder<ItemRoomBinding>>(list) {
inner class RoomAdapter(list: ObservableList<RoomViewModel>) : ObservableListAdapter<RoomViewModel, BindingHolder<ItemRoomBinding>>(list) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindingHolder<ItemRoomBinding> = BindingHolder(parent, R.layout.item_room)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ChatFragment : BaseFragment() {
val lastVisiblePosition = manager.findLastVisibleItemPosition()
val lastListPosition = adapter.itemCount - 1
if (lastListPosition - 1 == lastVisiblePosition) {
binding.chatList.smoothScrollToPosition(lastListPosition)
binding.chatList.smoothScrollToPosition(lastListPosition + 1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.cyder.android.syncpod.viewmodel

import android.content.res.Resources
import android.databinding.ObservableField
import android.databinding.ObservableInt
import com.cyder.android.syncpod.R
import com.cyder.android.syncpod.repository.RoomRepository
import com.cyder.android.syncpod.util.NotFilledFormsException
Expand All @@ -17,6 +19,21 @@ class CreateRoomActivityViewModel @Inject constructor(
) : ActivityViewModel() {
var roomName: ObservableField<String?> = ObservableField()
var roomDescription: ObservableField<String?> = ObservableField()
var publishingSetting = ObservableInt()
lateinit var resources: Resources
val publishingSettingItems: MutableList<HashMap<String, String>> by lazy {
val publicRoom = hashMapOf(
ID to PUBLIC_ROOM,
TITLE to resources.getString(R.string.public_room),
DESCRIPTION to resources.getString(R.string.public_room_description))
val privateRoom = hashMapOf(
ID to PRIVATE_ROOM,
TITLE to resources.getString(R.string.private_room),
DESCRIPTION to resources.getString(R.string.private_room_description))
mutableListOf(publicRoom, privateRoom)
}

val publishingSettingKeys = arrayOf(TITLE, DESCRIPTION)
var callback: SnackbarCallback? = null

override fun onStart() {
Expand All @@ -37,7 +54,9 @@ class CreateRoomActivityViewModel @Inject constructor(
fun onBackButtonClicked() = navigator.closeActivity()

fun onSubmit() {
repository.createNewRoom(roomName.get() ?: "", roomDescription.get() ?: "")
val isPublic = publishingSettingItems[publishingSetting.get()][ID] == PUBLIC_ROOM

repository.createNewRoom(roomName.get() ?: "", roomDescription.get() ?: "", isPublic)
.subscribe({ response ->
repository.joinRoom(response.key)
.subscribe({
Expand All @@ -53,4 +72,12 @@ class CreateRoomActivityViewModel @Inject constructor(
}
})
}

companion object {
private const val ID = "id"
private const val TITLE = "title"
private const val DESCRIPTION = "description"
private const val PUBLIC_ROOM = "public_room"
private const val PRIVATE_ROOM = "private_room"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.cyder.android.syncpod.util.CannotJoinRoomException
import com.cyder.android.syncpod.view.helper.Navigator
import com.cyder.android.syncpod.viewmodel.base.ActivityViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.rxkotlin.Singles
import javax.inject.Inject

/**
Expand All @@ -22,9 +23,11 @@ class TopActivityViewModel @Inject constructor(
private val navigator: Navigator
) : ActivityViewModel() {

var roomViewModels: ObservableList<RoomViewModel> = ObservableArrayList()
var joinedRoomViewModels: ObservableList<RoomViewModel> = ObservableArrayList()
var populardRoomViewModels: ObservableList<RoomViewModel> = ObservableArrayList()
var isLoading: ObservableBoolean = ObservableBoolean()
var hasEntered: ObservableBoolean = ObservableBoolean(false)
var hasPopularRoom: ObservableBoolean = ObservableBoolean(false)
var errorMessageId: Int? = null
var dialogCallback: DialogCallback? = null
var snackbarCallback: SnackbarCallback? = null
Expand Down Expand Up @@ -73,23 +76,26 @@ class TopActivityViewModel @Inject constructor(
}

private fun getRooms() {
roomRepository.fetchJoinedRooms()
.map { convertToViewModel(it) }
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ response ->
response.forEachIndexed { index, viewModel ->
when (index) {
in 0..(this.roomViewModels.size - 1) ->
if (isChanged(this.roomViewModels[index], viewModel)) {
this.roomViewModels[index] = viewModel
}
else -> this.roomViewModels.add(viewModel)
}
}
Singles.zip(
roomRepository.fetchJoinedRooms()
.map { convertToViewModel(it) }
.observeOn(AndroidSchedulers.mainThread()),
roomRepository.fetchPopularRooms()
.map { convertToViewModel(it) }
.observeOn(AndroidSchedulers.mainThread())
)
.subscribe({
val joinedRooms = it.first
joinedRoomViewModels.clear()
joinedRoomViewModels.addAll(joinedRooms)
hasEntered.set(joinedRooms.isNotEmpty())

val popularRooms = it.second
populardRoomViewModels.clear()
populardRoomViewModels.addAll(popularRooms)
hasPopularRoom.set(popularRooms.isNotEmpty())

isLoading.set(false)
if (response.isNotEmpty()) {
hasEntered.set(true)
}
}, {
isLoading.set(false)
})
Expand All @@ -98,8 +104,4 @@ class TopActivityViewModel @Inject constructor(
private fun convertToViewModel(rooms: List<Room>): List<RoomViewModel> {
return rooms.map { RoomViewModel(roomRepository, navigator, ObservableField(it)) }
}

private fun isChanged(a: RoomViewModel, b: RoomViewModel): Boolean {
return a.room.get() != b.room.get()
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_create_room.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@
android:inputType="textMultiLine"
android:text="@={viewModel.roomDescription}" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginVertical="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/publishing_setting" />


<Spinner
android:id="@+id/publishing_setting"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"
android:selectedItemPosition="@={viewModel.publishingSetting}" />
</LinearLayout>


<Button
android:id="@+id/create_room_submit"
android:layout_width="match_parent"
Expand Down
Loading