Skip to content

Commit

Permalink
Add onclick event
Browse files Browse the repository at this point in the history
  • Loading branch information
cooltey committed Oct 23, 2023
1 parent b03fae9 commit cf1c0f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 9 additions & 9 deletions app/src/main/java/org/wikipedia/talk/TalkReplyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import org.wikipedia.util.ResourceUtil
import org.wikipedia.util.ShareUtil
import org.wikipedia.util.StringUtil
import org.wikipedia.util.UriUtil
import org.wikipedia.util.log.L
import org.wikipedia.views.UserMentionInputView
import org.wikipedia.views.ViewUtil

Expand All @@ -60,7 +59,6 @@ class TalkReplyActivity : BaseActivity(), LinkPreviewDialog.Callback, UserMentio
private val viewModel: TalkReplyViewModel by viewModels { TalkReplyViewModel.Factory(intent.extras!!) }
private var userMentionScrolled = false
private var savedSuccess = false
private var fromDiff = false

private val linkMovementMethod = LinkMovementMethodExt { url, title, linkText, x, y ->
linkHandler.onUrlClick(url, title, linkText, x, y)
Expand Down Expand Up @@ -108,9 +106,7 @@ class TalkReplyActivity : BaseActivity(), LinkPreviewDialog.Callback, UserMentio
supportActionBar?.setDisplayHomeAsUpEnabled(true)
title = ""

fromDiff = intent.getBooleanExtra(EXTRA_FROM_DIFF, false)

if (fromDiff) {
if (viewModel.isFromDiff) {
binding.talkTemplateContainer.isVisible = true
binding.talkTemplateButton.setOnClickListener {
requestManageTalkTemplate.launch(TalkTemplatesActivity.newIntent(this))
Expand Down Expand Up @@ -232,7 +228,7 @@ class TalkReplyActivity : BaseActivity(), LinkPreviewDialog.Callback, UserMentio
}

private fun setToolbarTitle(pageTitle: PageTitle) {
if (fromDiff) {
if (viewModel.isFromDiff) {
supportActionBar?.title = getString(R.string.talk_warn)
return
}
Expand All @@ -257,8 +253,12 @@ class TalkReplyActivity : BaseActivity(), LinkPreviewDialog.Callback, UserMentio
L10nUtil.setConditionalTextDirection(binding.talkTemplateSpinner, viewModel.pageTitle.wikiSite.languageCode)
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, viewModel.talkTemplatesList)
binding.talkTemplateSpinner.setAdapter(adapter)
binding.talkTemplateSpinner.setOnItemClickListener { adapterView, view, i, l ->
L.d("setTalkTemplateSpinnerAdapter " + i)
binding.talkTemplateSpinner.setOnItemClickListener { _, _, position, _ ->
viewModel.selectedTemplate = viewModel.talkTemplatesList[position]
viewModel.selectedTemplate?.let { talkTemplate ->
binding.replySubjectText.setText(talkTemplate.subject)
binding.replyInputView.editText.setText(talkTemplate.message)
}
}
}

Expand Down Expand Up @@ -380,7 +380,7 @@ class TalkReplyActivity : BaseActivity(), LinkPreviewDialog.Callback, UserMentio

setSaveButtonEnabled(false)

if (fromDiff) {
if (viewModel.isFromDiff) {
showSaveDialog(subject, body)
} else {
binding.progressBar.visibility = View.VISIBLE
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/wikipedia/talk/TalkReplyViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ class TalkReplyViewModel(bundle: Bundle) : ViewModel() {

var talkTemplateSaved = false
val talkTemplatesList = mutableListOf<TalkTemplate>()
var selectedTemplate: TalkTemplate? = null

val pageTitle = bundle.parcelable<PageTitle>(Constants.ARG_TITLE)!!
val topic = bundle.parcelable<ThreadItem>(TalkReplyActivity.EXTRA_TOPIC)
val isFromDiff = bundle.getBoolean(TalkReplyActivity.EXTRA_FROM_DIFF, false)
val isNewTopic = topic == null
val postReplyData = SingleLiveData<Resource<Long>>()
val saveTemplateData = SingleLiveData<Resource<TalkTemplate>>()
val loadTemplateData = SingleLiveData<Resource<Int>>()

init {
loadTemplates()
if (isFromDiff) {
loadTemplates()
}
}

fun postReply(subject: String, body: String) {
Expand Down

0 comments on commit cf1c0f1

Please sign in to comment.