Skip to content

Commit

Permalink
Merge branch 'master' into 4821-startactivityforresult-unit-is-deprec…
Browse files Browse the repository at this point in the history
…ated
  • Loading branch information
dogi authored Dec 2, 2024
2 parents 833b381 + f519ca6 commit c2b9e0e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ dependencies {
implementation "io.noties.markwon:image:$markwon_version"
implementation "io.noties.markwon:html:$markwon_version"
implementation "io.noties.markwon:ext-tables:$markwon_version"
implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.0.21"))
implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.1.0"))

implementation 'com.github.chrisbanes:PhotoView:2.3.0'
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/org/ole/planet/myplanet/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks {

suspend fun isServerReachable(urlString: String): Boolean {
return try {
val url = URL(urlString)
if (urlString.isBlank()) return false

val formattedUrl = if (!urlString.startsWith("http://") && !urlString.startsWith("https://")) {
"http://$urlString"
} else {
urlString
}

val url = URL(formattedUrl)
val connection = withContext(Dispatchers.IO) {
url.openConnection()
} as HttpURLConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class TakeExamFragment : BaseExamFragment(), View.OnClickListener, CompoundButto
if (isRadio) {
fragmentTakeExamBinding.groupChoices.addView(rdBtn)
} else {
rdBtn.setTextColor(resources.getColor(R.color.daynight_textColor))
rdBtn.setTextColor(ContextCompat.getColor(requireContext(), R.color.daynight_textColor))
rdBtn.buttonTintList = ContextCompat.getColorStateList(requireContext(), R.color.daynight_textColor)
fragmentTakeExamBinding.llCheckbox.addView(rdBtn)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import io.realm.Realm
Expand Down Expand Up @@ -81,10 +82,10 @@ class AdapterMyLife(private val context: Context, private val myLifeList: List<R
it, myLifeList[position].userId)
}
}, {
Handler(Looper.getMainLooper()).post {
if (isVisible) {
changeVisibility(holder, R.drawable.ic_visibility, hide)
Utilities.toast(context, myLifeList[position].title + context.getString(R.string.is_now_hidden))
Handler(Looper.getMainLooper()).post {
if (isVisible) {
changeVisibility(holder, R.drawable.ic_visibility, hide)
Utilities.toast(context, myLifeList[position].title + context.getString(R.string.is_now_hidden))
} else {
changeVisibility(holder, R.drawable.ic_visibility_off, show)
Utilities.toast(context, myLifeList[position].title + context.getString(R.string.is_now_shown))
Expand Down Expand Up @@ -120,11 +121,11 @@ class AdapterMyLife(private val context: Context, private val myLifeList: List<R
var rvItemContainer: LinearLayout = itemView.findViewById(R.id.rv_item_parent_layout)

override fun onItemSelected() {
itemView.setBackgroundColor(context.resources.getColor(R.color.user_profile_background))
itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.user_profile_background))
}

override fun onItemClear(viewHolder: RecyclerView.ViewHolder?) {
itemView.setBackgroundColor(context.resources.getColor(R.color.daynight_grey))
itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.daynight_grey))
if (viewHolder != null) {
if (!myLifeList[viewHolder.bindingAdapterPosition].isVisible) {
(viewHolder as ViewHolderMyLife?)?.rvItemContainer?.alpha = hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,34 @@ class TeamDetailFragment : BaseTeamFragment() {
fragmentTeamDetailBinding.subtitle.text = team?.type

if (!isMyTeam) {
fragmentTeamDetailBinding.llActionButtons.visibility = View.GONE
fragmentTeamDetailBinding.btnAddDoc.isEnabled = false
fragmentTeamDetailBinding.btnAddDoc.visibility = View.GONE
val currentTeam = team
if (currentTeam != null && !currentTeam._id.isNullOrEmpty()) {

val isUserRequested = currentTeam.requested(user?.id, mRealm)

if (isUserRequested) {
fragmentTeamDetailBinding.btnLeave.text = getString(R.string.requested)
fragmentTeamDetailBinding.btnLeave.isEnabled = false
} else {
fragmentTeamDetailBinding.btnLeave.text = getString(R.string.join)
fragmentTeamDetailBinding.btnLeave.setOnClickListener {
RealmMyTeam.requestToJoin(currentTeam._id!!, user, mRealm)
fragmentTeamDetailBinding.btnLeave.text = getString(R.string.requested)
fragmentTeamDetailBinding.btnLeave.isEnabled = false
}
}
} else {
throw IllegalStateException("Team or team ID is null, cannot proceed.")
}

} else {

fragmentTeamDetailBinding.btnAddDoc.isEnabled = true
fragmentTeamDetailBinding.btnAddDoc.visibility = View.VISIBLE
fragmentTeamDetailBinding.btnLeave.isEnabled = true
fragmentTeamDetailBinding.btnLeave.visibility = View.VISIBLE
fragmentTeamDetailBinding.btnLeave.setOnClickListener {
AlertDialog.Builder(requireContext()).setMessage(R.string.confirm_exit)
.setPositiveButton(R.string.yes) { _: DialogInterface?, _: Int ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.ole.planet.myplanet.model.RealmTeamLog
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import io.realm.Realm
import io.realm.Sort
import org.ole.planet.myplanet.utilities.Utilities

class AdapterJoinedMember(private val context: Context, private val list: List<RealmUserModel>, private val mRealm: Realm, private val teamId: String) : RecyclerView.Adapter<AdapterJoinedMember.ViewHolderUser>() {
Expand Down Expand Up @@ -78,7 +79,7 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
overflowMenuOptions: Array<String>,
isLoggedInUserTeamLeader: Boolean
) {
if (isLoggedInUserTeamLeader) {
if (isLoggedInUserTeamLeader && list.size>1) {
rowJoinedUserBinding.icMore.visibility = View.VISIBLE
rowJoinedUserBinding.icMore.setOnClickListener {
val builder = AlertDialog.Builder(context, R.style.AlertDialogTheme)
Expand All @@ -95,14 +96,20 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
}
}
builder.setAdapter(adapter) { _, i ->

if (position >= 0 && position < list.size) {
when (i) {
0 -> {
if (currentUser.id != list[position].id) {
reject(list[position], position)
} else {
Toast.makeText(context, R.string.cannot_remove_user, Toast.LENGTH_SHORT).show()
val nextOfKin= getNextOfKin()
if(nextOfKin!=null){
makeLeader(nextOfKin)
reject(list[position], position)
}
else {
Toast.makeText(context, R.string.cannot_remove_user, Toast.LENGTH_SHORT).show()
}
}
}
1 -> {
Expand All @@ -122,7 +129,29 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
}
}

private fun getNextOfKin(): RealmUserModel? {
val members: List<RealmMyTeam> = mRealm.where(RealmMyTeam::class.java)
.equalTo("teamId", teamId)
.equalTo("isLeader", false)
.notEqualTo("status","archived")
.sort("createdDate", Sort.DESCENDING)
.findAll()
val successor = if (members.isNotEmpty()) members?.first() else null
if(successor==null){
return null
}
else{
val user= mRealm.where(RealmUserModel::class.java).equalTo("id", successor.userId).findFirst()
return user
}
return null
}

private fun makeLeader(userModel: RealmUserModel) {
if(userModel==null){
Utilities.toast(context, context.getString(R.string.cannot_remove_user))
return
}
mRealm.executeTransaction { realm ->
val team = realm.where(RealmMyTeam::class.java)
.equalTo("teamId", teamId)
Expand All @@ -134,6 +163,7 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
.findFirst()
teamLeader?.isLeader = false
team?.isLeader = true
team?.updated=true
}
notifyDataSetChanged()
Utilities.toast(context, context.getString(R.string.leader_selected))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_team_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<Button
android:id="@+id/btn_leave"
style="@style/YellowButtons"
android:layout_width="59dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/leave" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<string name="showing_reply_of">Showing reply of:</string>
<string name="open_date">Open Date</string>
<string name="my_survey">mySurvey</string>
<string name="cannot_remove_user">User couldnot be removed</string>
<string name="cannot_remove_user">User could not be removed</string>
<string name="no_members_task">No Team members present to assign tasks</string>
<string name="no_member_selected">No member selected. Please try again</string>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = '2.0.21'
kotlin_version = '2.1.0'
setup = [
compileSdk : 34,
buildTools : "28.0.0",
Expand Down

0 comments on commit c2b9e0e

Please sign in to comment.