mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 11:46:32 +00:00
correctly show joined guilds in public guild list
This commit is contained in:
parent
4129fcd08e
commit
bc02b4661e
6 changed files with 79 additions and 19 deletions
|
|
@ -153,7 +153,7 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
multiDexEnabled true
|
||||
|
||||
versionCode 2105
|
||||
versionCode 2110
|
||||
versionName "1.9"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@
|
|||
android:layout_weight="1"
|
||||
android:layout_height="28dp"
|
||||
android:text="@string/repeatables_frequency_day_of_month"
|
||||
android:layout_marginRight="@dimen/spacing_medium"/>
|
||||
android:layout_marginEnd="@dimen/spacing_medium"/>
|
||||
<TextView
|
||||
android:id="@+id/monthly_repeat_weeks"
|
||||
style="@style/TaskFormToggle"
|
||||
|
|
@ -138,12 +138,13 @@
|
|||
android:layout_weight="1"
|
||||
android:layout_height="28dp"
|
||||
android:text="@string/repeatables_frequency_day_of_week"
|
||||
android:layout_marginLeft="@dimen/spacing_medium"/>
|
||||
android:layout_marginStart="@dimen/spacing_medium"/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/summary_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/gray_300"
|
||||
android:textSize="12sp" />
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="@dimen/spacing_medium"/>
|
||||
</merge>
|
||||
|
|
@ -1,22 +1,19 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.social
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.Filter
|
||||
import android.widget.Filterable
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.data.ApiClient
|
||||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.social.Group
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.GuildFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.GuildsOverviewFragmentDirections
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.PublicGuildsFragmentDirections
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
|
|
@ -24,14 +21,13 @@ import io.reactivex.functions.Consumer
|
|||
import io.realm.Case
|
||||
import io.realm.OrderedRealmCollection
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, autoUpdate: Boolean) : RealmRecyclerViewAdapter<Group, PublicGuildsRecyclerViewAdapter.GuildViewHolder>(data, autoUpdate), Filterable {
|
||||
|
||||
var socialRepository: SocialRepository? = null
|
||||
private var memberGuildIDs: MutableList<String> = mutableListOf()
|
||||
private var memberGuildIDs: List<String> = listOf()
|
||||
|
||||
fun setMemberGuildIDs(memberGuildIDs: MutableList<String>) {
|
||||
fun setMemberGuildIDs(memberGuildIDs: List<String>) {
|
||||
this.memberGuildIDs = memberGuildIDs
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +45,6 @@ class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, auto
|
|||
if (isMember) {
|
||||
this@PublicGuildsRecyclerViewAdapter.socialRepository?.leaveGroup(guild.id)
|
||||
?.subscribe(Consumer {
|
||||
memberGuildIDs.remove(guild.id)
|
||||
if (data != null) {
|
||||
val indexOfGroup = data?.indexOf(guild)
|
||||
notifyItemChanged(indexOfGroup ?: 0)
|
||||
|
|
@ -58,7 +53,6 @@ class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, auto
|
|||
} else {
|
||||
this@PublicGuildsRecyclerViewAdapter.socialRepository?.joinGroup(guild.id)
|
||||
?.subscribe(Consumer { group ->
|
||||
memberGuildIDs.add(group.id)
|
||||
if (data != null) {
|
||||
val indexOfGroup = data?.indexOf(group)
|
||||
notifyItemChanged(indexOfGroup ?: 0)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.habitrpg.android.habitica.components.AppComponent
|
|||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.extensions.subscribeWithErrorHandler
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.PublicGuildsRecyclerViewAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
|
|
@ -24,8 +25,6 @@ class PublicGuildsFragment : BaseMainFragment(), SearchView.OnQueryTextListener
|
|||
@Inject
|
||||
lateinit var socialRepository: SocialRepository
|
||||
|
||||
var memberGuildIDs: List<String>? = null
|
||||
|
||||
private val recyclerView: androidx.recyclerview.widget.RecyclerView? by bindView(R.id.recyclerView)
|
||||
|
||||
private var viewAdapter = PublicGuildsRecyclerViewAdapter(null, true)
|
||||
|
|
@ -44,10 +43,12 @@ class PublicGuildsFragment : BaseMainFragment(), SearchView.OnQueryTextListener
|
|||
|
||||
resetViews()
|
||||
|
||||
recyclerView?.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this.activity)
|
||||
recyclerView?.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(getActivity()!!, androidx.recyclerview.widget.DividerItemDecoration.VERTICAL))
|
||||
recyclerView?.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(activity)
|
||||
recyclerView?.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(activity, androidx.recyclerview.widget.DividerItemDecoration.VERTICAL))
|
||||
viewAdapter = PublicGuildsRecyclerViewAdapter(null, true)
|
||||
viewAdapter.setMemberGuildIDs(this.memberGuildIDs?.toMutableList() ?: mutableListOf())
|
||||
compositeSubscription.add(socialRepository.getGroupMemberships()
|
||||
.map { it.map { membership -> membership.groupID } }
|
||||
.subscribeWithErrorHandler(Consumer { viewAdapter.setMemberGuildIDs(it) }))
|
||||
viewAdapter.socialRepository = socialRepository
|
||||
recyclerView?.adapter = viewAdapter
|
||||
recyclerView?.itemAnimator = SafeDefaultItemAnimator()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.views.tasks.form
|
|||
import android.app.DatePickerDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -52,6 +53,7 @@ class TaskSchedulingControls @JvmOverloads constructor(
|
|||
field = value
|
||||
startDateTextView.text = dateFormatter.format(value)
|
||||
startDateCalendar.time = value
|
||||
generateSummary()
|
||||
}
|
||||
private var startDateCalendar = Calendar.getInstance()
|
||||
var dueDate: Date? = null
|
||||
|
|
@ -69,6 +71,7 @@ class TaskSchedulingControls @JvmOverloads constructor(
|
|||
else -> 0
|
||||
})
|
||||
configureViewsForFrequency()
|
||||
generateSummary()
|
||||
}
|
||||
var everyX
|
||||
get() = (repeatsEveryEdittext.text ?: "1").toString().toIntOrNull() ?: 1
|
||||
|
|
@ -78,22 +81,26 @@ class TaskSchedulingControls @JvmOverloads constructor(
|
|||
} catch (e: NumberFormatException) {
|
||||
repeatsEveryEdittext.setText("1")
|
||||
}
|
||||
generateSummary()
|
||||
}
|
||||
var weeklyRepeat: Days = Days()
|
||||
set(value) {
|
||||
field = value
|
||||
createWeeklyRepeatViews()
|
||||
generateSummary()
|
||||
}
|
||||
|
||||
var daysOfMonth: List<Int>? = null
|
||||
set(value) {
|
||||
field = value
|
||||
configureMonthlyRepeatViews()
|
||||
generateSummary()
|
||||
}
|
||||
var weeksOfMonth: List<Int>? = null
|
||||
set(value) {
|
||||
field = value
|
||||
configureMonthlyRepeatViews()
|
||||
generateSummary()
|
||||
}
|
||||
|
||||
private val weekdays: Array<String> by lazy {
|
||||
|
|
@ -152,10 +159,12 @@ class TaskSchedulingControls @JvmOverloads constructor(
|
|||
monthlyRepeatDaysButton.setOnClickListener {
|
||||
daysOfMonth = mutableListOf(startDateCalendar.get(Calendar.DATE))
|
||||
weeksOfMonth = null
|
||||
generateSummary()
|
||||
}
|
||||
monthlyRepeatWeeksButton.setOnClickListener {
|
||||
weeksOfMonth = mutableListOf(startDateCalendar.get(Calendar.WEEK_OF_MONTH))
|
||||
daysOfMonth = null
|
||||
generateSummary()
|
||||
}
|
||||
|
||||
orientation = VERTICAL
|
||||
|
|
@ -166,6 +175,7 @@ class TaskSchedulingControls @JvmOverloads constructor(
|
|||
private fun configureViewsForType() {
|
||||
startDateTitleView.text = context.getString(if (taskType == Task.TYPE_DAILY) R.string.start_date else R.string.due_date)
|
||||
repeatsEveryWrapper.visibility = if (taskType == Task.TYPE_DAILY) View.VISIBLE else View.GONE
|
||||
summaryTextView.visibility = if (taskType == Task.TYPE_DAILY) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
override fun onDateSet(view: DatePicker?, year: Int, month: Int, dayOfMonth: Int) {
|
||||
|
|
@ -272,4 +282,57 @@ class TaskSchedulingControls @JvmOverloads constructor(
|
|||
monthlyRepeatWeeksButton.background.mutate().setTint(unselectedBackground)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateSummary() {
|
||||
var frequencyQualifier = ""
|
||||
|
||||
when (frequency) {
|
||||
"daily" -> frequencyQualifier = "day(s)"
|
||||
"weekly" -> frequencyQualifier = "week(s)"
|
||||
"monthly" -> frequencyQualifier = "month(s)"
|
||||
"yearly" -> frequencyQualifier = "year(s)"
|
||||
}
|
||||
|
||||
var weekdays: String
|
||||
val weekdayStrings = ArrayList<String>()
|
||||
if (weeklyRepeat.m) {
|
||||
weekdayStrings.add("Monday")
|
||||
}
|
||||
if (weeklyRepeat.t) {
|
||||
weekdayStrings.add("Tuesday")
|
||||
}
|
||||
if (weeklyRepeat.w) {
|
||||
weekdayStrings.add("Wednesday")
|
||||
}
|
||||
if (weeklyRepeat.th) {
|
||||
weekdayStrings.add("Thursday")
|
||||
}
|
||||
if (weeklyRepeat.f) {
|
||||
weekdayStrings.add("Friday")
|
||||
}
|
||||
if (weeklyRepeat.s) {
|
||||
weekdayStrings.add("Saturday")
|
||||
}
|
||||
if (weeklyRepeat.su) {
|
||||
weekdayStrings.add("Sunday")
|
||||
}
|
||||
weekdays = " on " + TextUtils.join(", ", weekdayStrings)
|
||||
if (frequency != "weekly") {
|
||||
weekdays = ""
|
||||
}
|
||||
|
||||
if (frequency == "monthly") {
|
||||
weekdays = if (daysOfMonth != null) {
|
||||
val date = startDateCalendar.get(Calendar.DATE)
|
||||
" on the $date"
|
||||
} else {
|
||||
val week = startDateCalendar.get(Calendar.WEEK_OF_MONTH)
|
||||
val dayLongName = startDateCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
|
||||
" on the $week week on $dayLongName"
|
||||
}
|
||||
}
|
||||
|
||||
val summary = resources.getString(R.string.repeat_summary, frequency, everyX.toString(), frequencyQualifier, weekdays)
|
||||
summaryTextView.text = summary
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
android.enableR8=false
|
||||
android.debug.obsoleteApi=true
|
||||
org.gradle.configureondemand=true
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xmx6656M
|
||||
org.gradle.warning.mode=all
|
||||
org.gradle.warning.mode=all
|
||||
|
|
|
|||
Loading…
Reference in a new issue