This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1364 from RocketChat/beta
[RELEASE] Merge beta into master
- Loading branch information
Showing
46 changed files
with
661 additions
and
43 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
48 changes: 48 additions & 0 deletions
48
app/src/main/java/chat/rocket/android/chatinformation/adapter/ReadReceiptAdapter.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 chat.rocket.android.chatinformation.adapter | ||
|
||
import android.support.v7.widget.RecyclerView | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import chat.rocket.android.R | ||
import chat.rocket.android.chatinformation.adapter.ReadReceiptAdapter.ReadReceiptViewHolder | ||
import chat.rocket.android.chatinformation.viewmodel.ReadReceiptViewModel | ||
import chat.rocket.android.util.extensions.inflate | ||
import kotlinx.android.synthetic.main.avatar.view.* | ||
import kotlinx.android.synthetic.main.item_read_receipt.view.* | ||
|
||
class ReadReceiptAdapter : RecyclerView.Adapter<ReadReceiptViewHolder>() { | ||
private val data = ArrayList<ReadReceiptViewModel>() | ||
|
||
init { | ||
setHasStableIds(true) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReadReceiptViewHolder { | ||
return ReadReceiptViewHolder(parent.inflate(R.layout.item_read_receipt, false)) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return data.size | ||
} | ||
|
||
override fun onBindViewHolder(holder: ReadReceiptViewHolder, position: Int) { | ||
holder.bind(data[position]) | ||
} | ||
|
||
fun addAll(items: List<ReadReceiptViewModel>) { | ||
data.clear() | ||
data.addAll(items) | ||
notifyItemRangeInserted(0, items.size) | ||
} | ||
|
||
class ReadReceiptViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
|
||
fun bind(readReceipt: ReadReceiptViewModel) { | ||
with(itemView) { | ||
image_avatar.setImageURI(readReceipt.avatar) | ||
receipt_name.text = readReceipt.name | ||
receipt_time.text = readReceipt.time | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/chat/rocket/android/chatinformation/di/MessageInfoFragmentModule.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,30 @@ | ||
package chat.rocket.android.chatinformation.di | ||
|
||
import android.arch.lifecycle.LifecycleOwner | ||
import chat.rocket.android.chatinformation.presentation.MessageInfoView | ||
import chat.rocket.android.chatinformation.ui.MessageInfoFragment | ||
import chat.rocket.android.core.lifecycle.CancelStrategy | ||
import chat.rocket.android.dagger.scope.PerFragment | ||
import dagger.Module | ||
import dagger.Provides | ||
import kotlinx.coroutines.experimental.Job | ||
|
||
@Module | ||
@PerFragment | ||
class MessageInfoFragmentModule { | ||
|
||
@Provides | ||
fun messageInfoView(frag: MessageInfoFragment): MessageInfoView { | ||
return frag | ||
} | ||
|
||
@Provides | ||
fun provideLifecycleOwner(frag: MessageInfoFragment): LifecycleOwner { | ||
return frag | ||
} | ||
|
||
@Provides | ||
fun provideCancelStrategy(owner: LifecycleOwner, jobs: Job): CancelStrategy { | ||
return CancelStrategy(owner, jobs) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/chat/rocket/android/chatinformation/di/MessageInfoFragmentProvider.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,14 @@ | ||
package chat.rocket.android.chatinformation.di | ||
|
||
import chat.rocket.android.chatinformation.ui.MessageInfoFragment | ||
import chat.rocket.android.dagger.scope.PerFragment | ||
import dagger.Module | ||
import dagger.android.ContributesAndroidInjector | ||
|
||
@Module | ||
abstract class MessageInfoFragmentProvider { | ||
|
||
@ContributesAndroidInjector(modules = [MessageInfoFragmentModule::class]) | ||
@PerFragment | ||
abstract fun provideMessageInfoFragment(): MessageInfoFragment | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/chat/rocket/android/chatinformation/presentation/MessageInfoPresenter.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,46 @@ | ||
package chat.rocket.android.chatinformation.presentation | ||
|
||
import chat.rocket.android.chatinformation.viewmodel.ReadReceiptViewModel | ||
import chat.rocket.android.chatroom.viewmodel.ViewModelMapper | ||
import chat.rocket.android.core.lifecycle.CancelStrategy | ||
import chat.rocket.android.helper.UserHelper | ||
import chat.rocket.android.server.domain.GetCurrentServerInteractor | ||
import chat.rocket.android.server.domain.MessagesRepository | ||
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory | ||
import chat.rocket.android.util.extensions.launchUI | ||
import chat.rocket.android.util.retryIO | ||
import chat.rocket.common.RocketChatException | ||
import chat.rocket.core.internal.rest.getMessageReadReceipts | ||
import chat.rocket.core.internal.rest.queryUsers | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class MessageInfoPresenter @Inject constructor( | ||
private val view: MessageInfoView, | ||
private val strategy: CancelStrategy, | ||
private val mapper: ViewModelMapper, | ||
serverInteractor: GetCurrentServerInteractor, | ||
factory: ConnectionManagerFactory | ||
) { | ||
|
||
private val currentServer = serverInteractor.get()!! | ||
private val manager = factory.create(currentServer) | ||
private val client = manager.client | ||
|
||
fun loadReadReceipts(messageId: String) { | ||
launchUI(strategy) { | ||
try { | ||
view.showLoading() | ||
val readReceipts = retryIO(description = "getMessageReadReceipts") { | ||
client.getMessageReadReceipts(messageId = messageId).result | ||
} | ||
view.showReadReceipts(mapper.map(readReceipts)) | ||
} catch (ex: RocketChatException) { | ||
Timber.e(ex) | ||
view.showGenericErrorMessage() | ||
} finally { | ||
view.hideLoading() | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/chat/rocket/android/chatinformation/presentation/MessageInfoView.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,11 @@ | ||
package chat.rocket.android.chatinformation.presentation | ||
|
||
import chat.rocket.android.chatinformation.viewmodel.ReadReceiptViewModel | ||
import chat.rocket.android.core.behaviours.LoadingView | ||
|
||
interface MessageInfoView : LoadingView { | ||
|
||
fun showGenericErrorMessage() | ||
|
||
fun showReadReceipts(messageReceipts: List<ReadReceiptViewModel>) | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/main/java/chat/rocket/android/chatinformation/ui/MessageInfoActivity.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,64 @@ | ||
package chat.rocket.android.chatinformation.ui | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.v4.app.Fragment | ||
import android.support.v7.app.AppCompatActivity | ||
import chat.rocket.android.R | ||
import chat.rocket.android.chatinformation.ui.MessageInfoFragment.Companion.TAG_MESSAGE_INFO_FRAGMENT | ||
import chat.rocket.android.util.extensions.addFragment | ||
import chat.rocket.android.util.extensions.textContent | ||
import dagger.android.AndroidInjection | ||
import dagger.android.AndroidInjector | ||
import dagger.android.DispatchingAndroidInjector | ||
import dagger.android.support.HasSupportFragmentInjector | ||
import kotlinx.android.synthetic.main.app_bar_chat_room.* | ||
import javax.inject.Inject | ||
|
||
fun Context.messageInformationIntent(messageId: String): Intent { | ||
return Intent(this, MessageInfoActivity::class.java).apply { | ||
putExtra(INTENT_MESSAGE_ID, messageId) | ||
} | ||
} | ||
|
||
private const val INTENT_MESSAGE_ID = "message_id" | ||
|
||
class MessageInfoActivity : AppCompatActivity(), HasSupportFragmentInjector { | ||
|
||
@Inject | ||
lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment> | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
AndroidInjection.inject(this) | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_chat_room) | ||
setupToolbar() | ||
|
||
val messageId = intent.getStringExtra(INTENT_MESSAGE_ID) | ||
requireNotNull(messageId) { "no message_id provided in Intent extras" } | ||
|
||
if (supportFragmentManager.findFragmentByTag(TAG_MESSAGE_INFO_FRAGMENT) == null) { | ||
addFragment(TAG_MESSAGE_INFO_FRAGMENT, R.id.fragment_container) { | ||
newInstance(messageId = messageId) | ||
} | ||
} | ||
} | ||
|
||
private fun setupToolbar() { | ||
text_room_name.textContent = getString(R.string.message_information_title) | ||
setSupportActionBar(toolbar) | ||
supportActionBar?.setDisplayShowTitleEnabled(false) | ||
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp) | ||
toolbar.setNavigationOnClickListener { finishActivity() } | ||
} | ||
|
||
private fun finishActivity() { | ||
super.onBackPressed() | ||
overridePendingTransition(R.anim.close_enter, R.anim.close_exit) | ||
} | ||
|
||
override fun supportFragmentInjector(): AndroidInjector<Fragment> { | ||
return fragmentDispatchingAndroidInjector | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
app/src/main/java/chat/rocket/android/chatinformation/ui/MessageInfoFragment.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,111 @@ | ||
package chat.rocket.android.chatinformation.ui | ||
|
||
import android.os.Bundle | ||
import android.support.v4.app.Fragment | ||
import android.support.v7.widget.DefaultItemAnimator | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import chat.rocket.android.R | ||
import chat.rocket.android.chatinformation.adapter.ReadReceiptAdapter | ||
import chat.rocket.android.chatinformation.presentation.MessageInfoPresenter | ||
import chat.rocket.android.chatinformation.presentation.MessageInfoView | ||
import chat.rocket.android.chatinformation.viewmodel.ReadReceiptViewModel | ||
import chat.rocket.android.helper.EndlessRecyclerViewScrollListener | ||
import chat.rocket.android.util.extensions.setVisible | ||
import chat.rocket.android.util.extensions.showToast | ||
import chat.rocket.core.model.ReadReceipt | ||
import dagger.android.support.AndroidSupportInjection | ||
import kotlinx.android.synthetic.main.fragment_message_info.* | ||
import javax.inject.Inject | ||
|
||
fun newInstance(messageId: String): Fragment { | ||
return MessageInfoFragment().apply { | ||
arguments = Bundle(1).apply { | ||
putString(BUNDLE_MESSAGE_ID, messageId) | ||
} | ||
} | ||
} | ||
|
||
private const val BUNDLE_MESSAGE_ID = "message_id" | ||
|
||
class MessageInfoFragment : Fragment(), MessageInfoView { | ||
|
||
@Inject | ||
lateinit var presenter: MessageInfoPresenter | ||
|
||
private lateinit var adapter: ReadReceiptAdapter | ||
private lateinit var endlessRecyclerViewScrollListener: EndlessRecyclerViewScrollListener | ||
private lateinit var messageId: String | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
AndroidSupportInjection.inject(this) | ||
setHasOptionsMenu(true) | ||
|
||
val bundle = arguments | ||
if (bundle != null) { | ||
messageId = bundle.getString(BUNDLE_MESSAGE_ID) | ||
} else { | ||
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" } | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return inflater.inflate(R.layout.fragment_message_info, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setupRecyclerView() | ||
presenter.loadReadReceipts(messageId = messageId) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
receipt_list.removeOnScrollListener(endlessRecyclerViewScrollListener) | ||
} | ||
|
||
private fun setupRecyclerView() { | ||
// Initialize the endlessRecyclerViewScrollListener so we don't NPE at onDestroyView | ||
val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true) | ||
adapter = ReadReceiptAdapter() | ||
linearLayoutManager.stackFromEnd = true | ||
receipt_list.layoutManager = linearLayoutManager | ||
receipt_list.itemAnimator = DefaultItemAnimator() | ||
receipt_list.adapter = adapter | ||
endlessRecyclerViewScrollListener = object : | ||
EndlessRecyclerViewScrollListener(receipt_list.layoutManager as LinearLayoutManager) { | ||
override fun onLoadMore(page: Int, totalItemsCount: Int, recyclerView: RecyclerView?) { | ||
} | ||
} | ||
} | ||
|
||
override fun showGenericErrorMessage() { | ||
showToast(R.string.msg_generic_error) | ||
} | ||
|
||
override fun showLoading() { | ||
view_loading.setVisible(true) | ||
view_loading.show() | ||
} | ||
|
||
override fun hideLoading() { | ||
view_loading.hide() | ||
view_loading.setVisible(false) | ||
} | ||
|
||
override fun showReadReceipts(messageReceipts: List<ReadReceiptViewModel>) { | ||
adapter.addAll(messageReceipts) | ||
} | ||
|
||
companion object { | ||
const val TAG_MESSAGE_INFO_FRAGMENT = "MessageInfoFragment" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/chat/rocket/android/chatinformation/viewmodel/ReadReceiptViewModel.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,7 @@ | ||
package chat.rocket.android.chatinformation.viewmodel | ||
|
||
data class ReadReceiptViewModel( | ||
val avatar: String, | ||
val name: String, | ||
val time: String | ||
) |
Oops, something went wrong.