Skip to content

Commit

Permalink
teams: smoother message dialog (fixes #4920) (#4921)
Browse files Browse the repository at this point in the history
Co-authored-by: Gideon Okuro <gideonollonde@gmail.com>
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent a4cd17d commit 06e8152
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2159
versionName "0.21.59"
versionCode 2160
versionName "0.21.60"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.PopupMenu
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ContextThemeWrapper
Expand Down Expand Up @@ -343,10 +344,15 @@ class AdapterNews(var context: Context, private val list: MutableList<RealmNews?
v.findViewById<View>(R.id.ll_image).visibility = if (showBetaFeature(Constants.KEY_NEWSADDIMAGE, context)) View.VISIBLE else View.GONE
val llImage = v.findViewById<LinearLayout>(R.id.ll_alert_image)
v.findViewById<View>(R.id.add_news_image).setOnClickListener { listener?.addImage(llImage) }
val message = v.findViewById<TextView>(R.id.cust_msg)
message.text = context.getString(if (isEdit) R.string.edit_post else R.string.reply)
val icon = v.findViewById<ImageView>(R.id.alert_icon)
icon.setImageResource(R.drawable.ic_edit)

val news = mRealm.where(RealmNews::class.java).equalTo("id", id).findFirst()
if (isEdit) et.setText(context.getString(R.string.message_placeholder, news?.message))
val dialog = AlertDialog.Builder(context, R.style.AlertDialogTheme).setTitle(if (isEdit) R.string.edit_post else R.string.reply)
.setIcon(R.drawable.ic_edit).setView(v)
val dialog = AlertDialog.Builder(context, R.style.CustomAlertDialog)
.setView(v)
.setPositiveButton(R.string.button_submit) { _: DialogInterface?, _: Int ->
val s = et.text.toString()
if (isEdit) {
Expand All @@ -361,8 +367,6 @@ class AdapterNews(var context: Context, private val list: MutableList<RealmNews?
.create()

dialog.show()
dialog.getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryWhite))
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryWhite))
}

private fun postReply(s: String?, news: RealmNews?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
private fun showAddMessage() {
val alertInputBinding = AlertInputBinding.inflate(layoutInflater)
alertInputBinding.tlInput.hint = getString(R.string.enter_message)
AlertDialog.Builder(requireActivity()).setView(alertInputBinding.root)
.setTitle(R.string.add_message)
alertInputBinding.custMsg.text = getString(R.string.add_message)

val dialog = AlertDialog.Builder(requireActivity(), R.style.CustomAlertDialog)
.setView(alertInputBinding.root)
.setPositiveButton(R.string.save) { _: DialogInterface?, _: Int ->
val msg = "${alertInputBinding.tlInput.editText?.text}".trim { it <= ' ' }
if (msg.isEmpty()) {
Expand All @@ -114,7 +116,8 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
map["messagePlanetCode"] = team?.teamPlanetCode!!
createNews(map, mRealm, user, imageList)
rvDiscussion.adapter?.notifyItemInserted(0)
}.setNegativeButton(R.string.cancel, null).show()
}.setNegativeButton(R.string.cancel, null).create()
dialog.show()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ class DiscussionListFragment : BaseTeamFragment() {
binding.llImage.visibility = if (showBetaFeature(Constants.KEY_NEWSADDIMAGE, requireContext())) View.VISIBLE else View.GONE
layout.hint = getString(R.string.enter_message)
layout.editText?.setHintTextColor(ContextCompat.getColor(requireContext(), R.color.daynight_textColor))
binding.custMsg.text = getString(R.string.add_message)

val dialog = AlertDialog.Builder(requireActivity(), R.style.CustomAlertDialog)
.setView(binding.root)
.setTitle(getString(R.string.add_message))
.setPositiveButton(getString(R.string.save)) { _: DialogInterface?, _: Int ->
val msg = "${layout.editText?.text}".trim { it <= ' ' }
if (msg.isEmpty()) {
Expand Down Expand Up @@ -188,8 +189,6 @@ class DiscussionListFragment : BaseTeamFragment() {
.create()

dialog.show()
dialog.getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorPrimaryWhite))
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorPrimaryWhite))
}

override fun setData(list: List<RealmNews?>?) {
Expand Down
29 changes: 26 additions & 3 deletions app/src/main/res/layout/alert_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/secondary_bg"
android:background="@color/daynight_grey"
android:padding="@dimen/padding_normal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
android:padding="10dp">

<ImageView
android:id="@+id/alert_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/cust_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:textColor="@color/daynight_textColor"
android:layout_marginStart="8dp" />
</LinearLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tl_input"
Expand All @@ -13,11 +34,13 @@
android:textColorHint="@color/hint_color"
android:hint="@string/what_would">

<com.google.android.material.textfield.TextInputEditText
<EditText
android:id="@+id/et_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/daynight_textColor" />
android:textColorHint="@color/hint_color"
android:textColor="@color/daynight_textColor"
android:backgroundTint="@color/daynight_textColor" />
</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
Expand Down

0 comments on commit 06e8152

Please sign in to comment.