-
Notifications
You must be signed in to change notification settings - Fork 42
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 #36 from sendbird/release/3.17.1
3.17.1
- Loading branch information
Showing
21 changed files
with
543 additions
and
74 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
32 changes: 32 additions & 0 deletions
32
...t-samples/src/main/java/com/sendbird/uikit/samples/customization/OpenChannelRepository.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,32 @@ | ||
package com.sendbird.uikit.samples.customization | ||
|
||
import android.app.Activity | ||
import com.sendbird.android.channel.OpenChannel | ||
import com.sendbird.android.params.OpenChannelListQueryParams | ||
import com.sendbird.uikit.samples.common.widgets.WaitingDialog | ||
import com.sendbird.uikit.utils.ContextUtils | ||
import java.util.concurrent.Executors | ||
|
||
internal object OpenChannelRepository { | ||
private val worker = Executors.newSingleThreadExecutor() | ||
private var channelCache = mutableListOf<OpenChannel>() | ||
|
||
fun getRandomChannel(activity: Activity, callback: (OpenChannel) -> Unit) { | ||
if (channelCache.isNotEmpty()) { | ||
callback(channelCache.random()) | ||
return | ||
} | ||
WaitingDialog.show(activity) | ||
worker.submit { | ||
OpenChannel.createOpenChannelListQuery(OpenChannelListQueryParams()).next { channels, e -> | ||
WaitingDialog.dismiss() | ||
if (e != null || channels.isNullOrEmpty()) { | ||
ContextUtils.toastError(activity, "No channels") | ||
return@next | ||
} | ||
channelCache.addAll(channels) | ||
activity.runOnUiThread { callback(channelCache.random()) } | ||
} | ||
} | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
.../java/com/sendbird/uikit/samples/customization/moderation/ModerationGroupChannelSample.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,171 @@ | ||
package com.sendbird.uikit.samples.customization.moderation | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.view.View | ||
import android.view.inputmethod.InputMethodManager | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sendbird.android.channel.ReportCategory | ||
import com.sendbird.android.exception.SendbirdException | ||
import com.sendbird.android.message.BaseMessage | ||
import com.sendbird.android.message.SendingStatus | ||
import com.sendbird.uikit.activities.ChannelActivity | ||
import com.sendbird.uikit.activities.viewholder.MessageType | ||
import com.sendbird.uikit.activities.viewholder.MessageViewHolderFactory | ||
import com.sendbird.uikit.fragments.ChannelFragment | ||
import com.sendbird.uikit.interfaces.OnCompleteHandler | ||
import com.sendbird.uikit.interfaces.providers.ChannelFragmentProvider | ||
import com.sendbird.uikit.interfaces.providers.ChannelViewModelProvider | ||
import com.sendbird.uikit.model.DialogListItem | ||
import com.sendbird.uikit.providers.FragmentProviders | ||
import com.sendbird.uikit.providers.ViewModelProviders | ||
import com.sendbird.uikit.samples.R | ||
import com.sendbird.uikit.samples.customization.GroupChannelRepository | ||
import com.sendbird.uikit.utils.MessageUtils | ||
import com.sendbird.uikit.vm.ChannelViewModel | ||
import com.sendbird.uikit.vm.ViewModelFactory | ||
import java.util.Arrays | ||
import java.util.Objects | ||
|
||
fun showModerationGroupChannelSample(activity: Activity) { | ||
setModerationGroupChannelViewModelProviders() | ||
|
||
FragmentProviders.channel = ChannelFragmentProvider { channelUrl, args -> | ||
ChannelFragment.Builder(channelUrl).withArguments(args) | ||
.setCustomFragment(ModerationGroupChannelFragment()) | ||
.setUseHeader(true) | ||
.build() | ||
} | ||
|
||
GroupChannelRepository.getRandomChannel(activity) { channel -> | ||
activity.startActivity( | ||
ChannelActivity.newIntent(activity, channel.url) | ||
) | ||
} | ||
} | ||
|
||
class ModerationGroupChannelFragment : ChannelFragment() { | ||
override fun makeMessageContextMenu(message: BaseMessage): MutableList<DialogListItem> { | ||
val items: MutableList<DialogListItem> = super.makeMessageContextMenu(message) | ||
val status = message.sendingStatus | ||
if (status == SendingStatus.PENDING) return items | ||
|
||
val type = MessageViewHolderFactory.getMessageType(message) | ||
val report = DialogListItem(R.string.text_report, R.drawable.icon_error) | ||
|
||
when (type) { | ||
MessageType.VIEW_TYPE_USER_MESSAGE_ME -> if (status == SendingStatus.SUCCEEDED) { | ||
items.add(report) | ||
} | ||
MessageType.VIEW_TYPE_USER_MESSAGE_OTHER -> { | ||
items.add(report) | ||
} | ||
else -> {} | ||
} | ||
|
||
return items | ||
} | ||
|
||
override fun onMessageContextMenuItemClicked(message: BaseMessage, view: View, position: Int, item: DialogListItem): Boolean { | ||
val key = item.key | ||
|
||
if (key == R.string.text_report) { | ||
showSelectReportCategory(message) | ||
return true | ||
} | ||
|
||
super.onMessageContextMenuItemClicked(message, view, position, item) | ||
|
||
return false | ||
} | ||
|
||
private fun showSelectReportCategory(message: BaseMessage) { | ||
if (context == null) return | ||
|
||
val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext()) | ||
var category: ReportCategory | ||
|
||
builder.setTitle(getString(R.string.text_choose_report_category_dialog)) | ||
.setNegativeButton(R.string.text_cancel) { dialog, which -> | ||
dialog.dismiss() | ||
} | ||
.setItems( | ||
arrayOf( | ||
getString(R.string.text_report_suspicious), | ||
getString(R.string.text_report_harassing), | ||
getString(R.string.text_report_spam), | ||
getString(R.string.text_report_inappropriate) | ||
)) { dialog, which -> | ||
when (which) { | ||
0 -> { | ||
category = ReportCategory.SUSPICIOUS | ||
} | ||
|
||
1 -> { | ||
category = ReportCategory.HARASSING | ||
} | ||
|
||
2 -> { | ||
category = ReportCategory.SPAM | ||
} | ||
|
||
else -> { | ||
category = ReportCategory.INAPPROPRIATE | ||
} | ||
} | ||
|
||
reportMessage(message, category, "") | ||
} | ||
|
||
val dialog: AlertDialog = builder.create() | ||
dialog.show() | ||
} | ||
|
||
private fun reportMessage(message: BaseMessage, reportCategory: ReportCategory, reason: String) { | ||
(viewModel as ModerationGroupChannelViewModel).reportMessage( | ||
message, | ||
reportCategory, | ||
reason | ||
) { e: SendbirdException? -> | ||
if (e == null) { | ||
toastSuccess(R.string.sb_view_toast_success_description, false) | ||
} else { | ||
toastError(R.string.text_report_error, false) | ||
} | ||
} | ||
} | ||
} | ||
|
||
class ModerationGroupChannelViewModel(channelUrl: String) : ChannelViewModel(channelUrl, null) { | ||
fun reportMessage(message: BaseMessage, reportCategory: ReportCategory, reason: String, handler: OnCompleteHandler?) { | ||
if (channel == null) return | ||
channel?.let { | ||
it.reportMessage(message, reportCategory, reason) { e: SendbirdException? -> handler?.onComplete(e) } | ||
} | ||
} | ||
} | ||
|
||
|
||
fun setModerationGroupChannelViewModelProviders() { | ||
@Suppress("UNCHECKED_CAST") | ||
class ModerationGroupChannelViewModelFactory(private vararg val params: Any?) : ViewModelFactory(*params) { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass == ModerationGroupChannelViewModel::class.java) { | ||
return ModerationGroupChannelViewModel( | ||
(Objects.requireNonNull(params)[0] as String) | ||
) as T | ||
} | ||
|
||
return super.create(modelClass) | ||
} | ||
} | ||
|
||
ViewModelProviders.channel = ChannelViewModelProvider { owner, channelUrl, _, _ -> | ||
ViewModelProvider( | ||
owner, | ||
ModerationGroupChannelViewModelFactory(channelUrl) | ||
)[channelUrl, ModerationGroupChannelViewModel::class.java] | ||
} | ||
} |
Oops, something went wrong.