mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Implement copy shared tasks setting
This commit is contained in:
parent
7e85b6e79b
commit
327f76db72
4 changed files with 88 additions and 0 deletions
45
Habitica/res/layout/preference_category_groups.xml
Normal file
45
Habitica/res/layout/preference_category_groups.xml
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dip"
|
||||
style="@style/Body1"
|
||||
android:textAllCaps="true"
|
||||
android:textSize="12sp"
|
||||
android:background="@color/transparent"
|
||||
android:textColor="@color/text_quad"
|
||||
android:paddingStart="32dip"
|
||||
android:paddingEnd="32dip"
|
||||
android:paddingTop="16dip"
|
||||
tools:text="Title" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Body1"
|
||||
android:textAllCaps="true"
|
||||
android:textSize="12sp"
|
||||
android:background="@color/transparent"
|
||||
android:textColor="@color/text_quad"
|
||||
android:paddingStart="32dip"
|
||||
android:paddingEnd="32dip"
|
||||
android:paddingTop="16dip"
|
||||
android:text="@string/copy_shared_tasks"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dip"
|
||||
style="@style/Body1"
|
||||
android:textSize="11sp"
|
||||
android:textColor="@color/text_dimmed"
|
||||
android:paddingStart="32dip"
|
||||
android:paddingEnd="32dip"
|
||||
android:paddingTop="4dp"
|
||||
android:text="@string/copy_tasks_description"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1252,4 +1252,6 @@
|
|||
<string name="self_improvement">Self Improvement</string>
|
||||
<string name="spirituality">Spirituality</string>
|
||||
<string name="time_management">Time Management + Accountability</string>
|
||||
<string name="copy_tasks_description">Show assigned and open tasks on your personal task lists</string>
|
||||
<string name="copy_shared_tasks">Copy shared tasks</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -191,6 +191,12 @@
|
|||
android:title="@string/day_start_adjustment"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="groups_category"
|
||||
android:title="@string/groups"
|
||||
android:layout="@layout/preference_category_groups"
|
||||
app:isPreferenceVisible="false"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_reminder_header"
|
||||
android:layout="@layout/preference_category">
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.habitrpg.android.habitica.BuildConfig
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
|
|
@ -33,6 +35,8 @@ import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
|||
import com.habitrpg.android.habitica.ui.views.insufficientCurrency.InsufficientGemsDialog
|
||||
import com.habitrpg.common.habitica.helpers.AppTestingLevel
|
||||
import com.habitrpg.common.habitica.helpers.LanguageHelper
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -64,6 +68,8 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
listView.itemAnimator = null
|
||||
|
||||
userRepository.retrieveTeamPlans().subscribe({}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
||||
override fun setupPreferences() {
|
||||
|
|
@ -355,6 +361,35 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
emailNotificationsPreference?.isEnabled = useEmailNotifications
|
||||
useEmailPreference?.isChecked = useEmailNotifications
|
||||
|
||||
lifecycleScope.launch {
|
||||
val teams = userRepository.getTeamPlans().firstOrNull() ?: return@launch
|
||||
val context = context ?: return@launch
|
||||
val groupCategory = findPreference<PreferenceCategory>("groups_category")
|
||||
groupCategory?.removeAll()
|
||||
if (teams.isEmpty()) {
|
||||
groupCategory?.isVisible = false
|
||||
} else {
|
||||
groupCategory?.isVisible = true
|
||||
for (team in teams) {
|
||||
val newPreference = CheckBoxPreference(context)
|
||||
newPreference.title = team.summary
|
||||
newPreference.key = "copy_tasks-${team.id}"
|
||||
newPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue ->
|
||||
val currentIds = user?.preferences?.tasks?.mirrorGroupTasks?.toMutableList() ?: mutableListOf()
|
||||
if (newValue == true && !currentIds.contains(team.id)) {
|
||||
currentIds.add(team.id)
|
||||
} else if (newValue == false && currentIds.contains(team.id)) {
|
||||
currentIds.remove(team.id)
|
||||
}
|
||||
userRepository.updateUser("preferences.tasks.mirrorGroupTasks", currentIds).subscribe({}, RxErrorHandler.handleEmptyError())
|
||||
true
|
||||
}
|
||||
groupCategory?.addPreference(newPreference)
|
||||
newPreference.isChecked = user?.preferences?.tasks?.mirrorGroupTasks?.contains(team.id) == true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (configManager.testingLevel() == AppTestingLevel.STAFF || BuildConfig.DEBUG) {
|
||||
serverUrlPreference?.isVisible = true
|
||||
taskListPreference?.isVisible = true
|
||||
|
|
|
|||
Loading…
Reference in a new issue