Skip to content

Commit

Permalink
Merge branch 'master' into 4952-extend-december-challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Jan 7, 2025
2 parents da29f01 + 48badc8 commit 6f50b78
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ dependencies {
implementation 'org.osmdroid:osmdroid-android:6.1.20'
implementation 'org.jetbrains:annotations:26.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.29'

implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,26 @@ abstract class BaseResourceFragment : Fragment() {
}

protected fun showDownloadDialog(dbMyLibrary: List<RealmMyLibrary?>) {
if (isAdded) {
Service(MainApplication.context).isPlanetAvailable(object : PlanetAvailableListener {
override fun isAvailable() {
if (dbMyLibrary.isNotEmpty()) {
if (!isAdded) {
return
}
val inflater = activity?.layoutInflater
val rootView = requireActivity().findViewById<ViewGroup>(android.R.id.content)
convertView = inflater?.inflate(R.layout.my_library_alertdialog, rootView, false)
val alertDialogBuilder = AlertDialog.Builder(requireContext(), R.style.AlertDialogTheme)
alertDialogBuilder.setView(convertView).setTitle(R.string.download_suggestion)
alertDialogBuilder.setPositiveButton(R.string.download_selected) { _: DialogInterface?, _: Int ->
if (!isAdded) return
Service(MainApplication.context).isPlanetAvailable(object : PlanetAvailableListener {
override fun isAvailable() {
if (!isAdded) return
if (dbMyLibrary.isEmpty()) {
activity?.let {
Utilities.toast(it, getString(R.string.no_resources_to_download))
}
return
}

activity?.let { fragmentActivity ->
val inflater = fragmentActivity.layoutInflater
val rootView = fragmentActivity.findViewById<ViewGroup>(android.R.id.content)
convertView = inflater.inflate(R.layout.my_library_alertdialog, rootView, false)

val alertDialogBuilder = AlertDialog.Builder(fragmentActivity, R.style.AlertDialogTheme)
alertDialogBuilder.setView(convertView)
.setTitle(R.string.download_suggestion)
.setPositiveButton(R.string.download_selected) { _: DialogInterface?, _: Int ->
lv?.selectedItemsList?.let {
addToLibrary(dbMyLibrary, it)
downloadFiles(dbMyLibrary, it)
Expand All @@ -121,23 +128,20 @@ abstract class BaseResourceFragment : Fragment() {
}
startDownload(downloadAllFiles(dbMyLibrary))
}.setNegativeButton(R.string.txt_cancel, null)
val alertDialog = alertDialogBuilder.create()
createListView(dbMyLibrary, alertDialog)
alertDialog.show()
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = (lv?.selectedItemsList?.size ?: 0) > 0
} else {
Utilities.toast(requireContext(), getString(R.string.no_resources_to_download))
}
val alertDialog = alertDialogBuilder.create()
createListView(dbMyLibrary, alertDialog)
alertDialog.show()
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = (lv?.selectedItemsList?.size ?: 0) > 0
}
}

override fun notAvailable() {
if (!isAdded) {
return
}
Utilities.toast(requireContext(), getString(R.string.planet_not_available))
override fun notAvailable() {
if (!isAdded) return
activity?.let {
Utilities.toast(it, getString(R.string.planet_not_available))
}
})
}
}
})
}

fun showPendingSurveyDialog() {
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/org/ole/planet/myplanet/ui/team/TeamFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
.notEqualTo("status", "archived")
.contains("name", charSequence.toString(), Case.INSENSITIVE)
val (list, conditionApplied) = getList(query)
val sortedList = sortTeams(list)
val adapterTeamList = AdapterTeamList(
activity as Context, list, mRealm, childFragmentManager
activity as Context, sortedList, mRealm, childFragmentManager
)
adapterTeamList.setTeamListener(this@TeamFragment)
fragmentTeamBinding.rvTeamList.adapter = adapterTeamList
Expand Down Expand Up @@ -253,6 +254,17 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
}
}

private fun sortTeams(list: List<RealmMyTeam>): List<RealmMyTeam> {
val user = user?.id
return list.sortedWith(compareByDescending<RealmMyTeam> { team ->
when {
RealmMyTeam.isTeamLeader(team.teamId, user, mRealm) -> 3
team.isMyTeam(user, mRealm) -> 2
else -> 1
}
})
}

override fun onEditTeam(team: RealmMyTeam?) {
createTeamAlert(team!!)
}
Expand All @@ -261,7 +273,8 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
activity?.runOnUiThread {
val query = mRealm.where(RealmMyTeam::class.java).isEmpty("teamId").notEqualTo("status", "archived")
val (filteredList, conditionApplied) = getList(query)
val adapterTeamList = AdapterTeamList(activity as Context, filteredList, mRealm, childFragmentManager).apply {
val sortedList = sortTeams(filteredList)
val adapterTeamList = AdapterTeamList(activity as Context, sortedList, mRealm, childFragmentManager).apply {
setType(type)
setTeamListener(this@TeamFragment)
}
Expand Down

0 comments on commit 6f50b78

Please sign in to comment.