mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-31 19:20:34 +00:00
merge TeamBoardFragment and TasksFragment
This commit is contained in:
parent
3e20f25a4d
commit
b8922a8b52
9 changed files with 123 additions and 427 deletions
|
|
@ -74,7 +74,7 @@
|
|||
android:layout_toStartOf="@id/toolbar_accessory_container"
|
||||
android:layout_alignParentStart="true"
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
tools:text="Habitica"/>
|
||||
tools:text="Habitica" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/toolbar_accessory_container"
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@
|
|||
app:argType="string"
|
||||
app:nullable="true"
|
||||
android:defaultValue=""/>
|
||||
<argument
|
||||
android:name="ownerID"
|
||||
app:argType="string"
|
||||
app:nullable="true"
|
||||
android:defaultValue=""/>
|
||||
<deepLink app:uri="habitica.com/user/tasks/{taskType}" />
|
||||
<deepLink app:uri="habitica.com/tasks" />
|
||||
<deepLink app:uri="habitica.com" />
|
||||
|
|
@ -483,12 +488,4 @@
|
|||
app:argType="string" />
|
||||
<deepLink app:uri="habitica.com/promo/web?url={url}" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/teamBoardFragment"
|
||||
android:name="com.habitrpg.android.habitica.ui.fragments.tasks.TeamBoardFragment"
|
||||
android:label="TeamBoardFragment" >
|
||||
<argument
|
||||
android:name="teamID"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
</navigation>
|
||||
|
|
@ -99,13 +99,13 @@ import com.habitrpg.android.habitica.ui.fragments.support.FAQOverviewFragment;
|
|||
import com.habitrpg.android.habitica.ui.fragments.support.SupportMainFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.tasks.TaskRecyclerViewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.tasks.TasksFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.tasks.TeamBoardFragment;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.AuthenticationViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.GroupViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.InboxViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.MainActivityViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.NotificationsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.TasksViewModel;
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.inventory.equipment.EquipmentOverviewViewModel;
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.PetSuggestHatchDialog;
|
||||
import com.habitrpg.android.habitica.ui.views.insufficientCurrency.InsufficientGemsDialog;
|
||||
|
|
@ -338,8 +338,6 @@ public interface UserComponent {
|
|||
|
||||
void inject(PromoInfoFragment promoInfoFragment);
|
||||
|
||||
void inject(@NotNull TeamBoardFragment teamBoardFragment);
|
||||
|
||||
void inject(@NotNull GuildOverviewFragment guildOverviewFragment);
|
||||
|
||||
void inject(@NotNull PromoWebFragment promoWebFragment);
|
||||
|
|
@ -361,4 +359,6 @@ public interface UserComponent {
|
|||
void inject(@NotNull PetSuggestHatchDialog petSuggestHatchDialog);
|
||||
|
||||
void inject(@NotNull ArmoireActivity armoireActivity);
|
||||
|
||||
void inject(@NotNull TasksViewModel tasksViewModel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,6 +136,9 @@ class AppConfigManager(contentRepository: ContentRepository?) {
|
|||
}
|
||||
|
||||
fun enableTeamBoards(): Boolean {
|
||||
if (BuildConfig.DEBUG) {
|
||||
return true
|
||||
}
|
||||
return remoteConfig.getBoolean("enableTeamBoards")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ class NavigationDrawerAdapter(tintColor: Int, backgroundTintColor: Int) : Recycl
|
|||
notifyItemRemoved(x)
|
||||
}
|
||||
for ((index, team) in teams.withIndex()) {
|
||||
val item = HabiticaDrawerItem(R.id.teamBoardFragment, team.id, team.summary)
|
||||
item.bundle = bundleOf(Pair("teamID", team.id))
|
||||
val item = HabiticaDrawerItem(R.id.tasksFragment, team.id, team.summary)
|
||||
item.bundle = bundleOf(Pair("ownerID", team.id))
|
||||
val newIndex = teamHeaderIndex + index + 1
|
||||
items.add(newIndex, item)
|
||||
notifyItemInserted(newIndex)
|
||||
|
|
|
|||
|
|
@ -52,11 +52,20 @@ import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
|||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBinding>(), androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener {
|
||||
private var taskSubscription: Disposable? = null
|
||||
var ownerID: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
if (recyclerAdapter != null) {
|
||||
updateTaskSubscription()
|
||||
}
|
||||
}
|
||||
internal var canEditTasks: Boolean = true
|
||||
internal var canScoreTaks: Boolean = true
|
||||
override var binding: FragmentRefreshRecyclerviewBinding? = null
|
||||
|
|
@ -136,14 +145,7 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
|
|||
recyclerAdapter?.brokenTaskEvents?.subscribeWithErrorHandler { showBrokenChallengeDialog(it) }?.let { recyclerSubscription.add(it) }
|
||||
recyclerAdapter?.adventureGuideOpenEvents?.subscribeWithErrorHandler { MainNavigationController.navigate(R.id.adventureGuideActivity) }?.let { recyclerSubscription.add(it) }
|
||||
|
||||
recyclerSubscription.add(
|
||||
taskRepository.getTasks(this.taskType).subscribe(
|
||||
{
|
||||
this.recyclerAdapter?.updateUnfilteredData(it)
|
||||
},
|
||||
RxErrorHandler.handleEmptyError()
|
||||
)
|
||||
)
|
||||
updateTaskSubscription()
|
||||
}
|
||||
|
||||
private fun handleTaskResult(result: TaskScoringResult, value: Int) {
|
||||
|
|
@ -318,6 +320,16 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
private fun updateTaskSubscription() {
|
||||
taskSubscription = taskRepository.getTasks(this.taskType, ownerID).subscribe(
|
||||
{
|
||||
this.recyclerAdapter?.updateUnfilteredData(it)
|
||||
},
|
||||
RxErrorHandler.handleEmptyError()
|
||||
)
|
||||
}
|
||||
|
||||
protected fun showBrokenChallengeDialog(task: Task) {
|
||||
context?.let {
|
||||
if (!task.isValid) {
|
||||
|
|
@ -512,9 +524,10 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
|
|||
companion object {
|
||||
private const val CLASS_TYPE_KEY = "CLASS_TYPE_KEY"
|
||||
|
||||
fun newInstance(context: Context?, classType: TaskType): TaskRecyclerViewFragment {
|
||||
fun newInstance(context: Context?, classType: TaskType, ownerID: String?): TaskRecyclerViewFragment {
|
||||
val fragment = TaskRecyclerViewFragment()
|
||||
fragment.taskType = classType
|
||||
fragment.ownerID = ownerID
|
||||
var tutorialTexts: List<String>? = null
|
||||
if (context != null) {
|
||||
when (fragment.taskType) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
|
|
@ -28,12 +30,15 @@ import com.habitrpg.android.habitica.extensions.getThemeColor
|
|||
import com.habitrpg.android.habitica.extensions.setTintWith
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.helpers.TaskFilterHelper
|
||||
import com.habitrpg.android.habitica.models.tasks.TaskType
|
||||
import com.habitrpg.android.habitica.modules.AppModule
|
||||
import com.habitrpg.android.habitica.ui.activities.TaskFormActivity
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.TasksViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.navigation.HabiticaBottomNavigationViewListener
|
||||
import com.habitrpg.android.habitica.ui.views.tasks.TaskFilterDialog
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
|
|
@ -50,6 +55,16 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
return FragmentViewpagerBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
internal val viewModel: TasksViewModel by viewModels()
|
||||
|
||||
var owners: List<Pair<String, CharSequence>> = listOf()
|
||||
var ownerID: String? = null
|
||||
|
||||
val isPersonalBoard: Boolean
|
||||
get() {
|
||||
return ownerID == userViewModel.userID
|
||||
}
|
||||
|
||||
@field:[Inject Named(AppModule.NAMED_USER_ID)]
|
||||
lateinit var userID: String
|
||||
@Inject
|
||||
|
|
@ -60,6 +75,8 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
lateinit var appConfigManager: AppConfigManager
|
||||
@Inject
|
||||
lateinit var sharedPreferences: SharedPreferences
|
||||
@Inject
|
||||
lateinit var userViewModel: MainUserViewModel
|
||||
|
||||
private var refreshItem: MenuItem? = null
|
||||
internal var viewFragmentsDictionary: MutableMap<Int, TaskRecyclerViewFragment>? = WeakHashMap()
|
||||
|
|
@ -92,6 +109,7 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
loadTaskLists()
|
||||
arguments?.let {
|
||||
val args = TasksFragmentArgs.fromBundle(it)
|
||||
ownerID = args.ownerID ?: userID
|
||||
val taskTypeValue = args.taskType
|
||||
if (taskTypeValue?.isNotBlank() == true) {
|
||||
val taskType = TaskType.from(taskTypeValue)
|
||||
|
|
@ -105,6 +123,12 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
compositeSubscription.add(userRepository.getTeamPlans()
|
||||
.subscribe({
|
||||
owners = listOf(Pair(userViewModel.userID ?: "", userViewModel.displayName)) + it.map { Pair(it.id, it.summary) }
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(userRepository.retrieveTeamPlans().subscribe({}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
@ -118,7 +142,11 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
}
|
||||
binding?.viewPager?.currentItem = binding?.viewPager?.currentItem ?: 0
|
||||
bottomNavigation?.listener = this
|
||||
bottomNavigation?.canAddTasks = true
|
||||
bottomNavigation?.canAddTasks = isPersonalBoard
|
||||
|
||||
activity?.binding?.toolbarTitle?.setOnClickListener {
|
||||
cycleOwnerIDs()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
|
@ -138,7 +166,11 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_main_activity, menu)
|
||||
if (isPersonalBoard) {
|
||||
inflater.inflate(R.menu.menu_main_activity, menu)
|
||||
} else {
|
||||
inflater.inflate(R.menu.menu_team_board, menu)
|
||||
}
|
||||
|
||||
filterMenuItem = menu.findItem(R.id.action_filter)
|
||||
updateFilterIcon()
|
||||
|
|
@ -183,6 +215,10 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
refresh()
|
||||
true
|
||||
}
|
||||
R.id.action_team_info -> {
|
||||
MainNavigationController.navigate(R.id.guildFragment, bundleOf(Pair("groupID", ownerID)))
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
|
@ -230,6 +266,26 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
activeFragment?.onRefresh()
|
||||
}
|
||||
|
||||
private fun refreshData(onComplete: () -> Unit) {
|
||||
if (isPersonalBoard) {
|
||||
compositeSubscription.add(
|
||||
userRepository.retrieveUser(
|
||||
withTasks = true,
|
||||
forced = true
|
||||
).doOnTerminate {
|
||||
onComplete()
|
||||
}.subscribe({ }, RxErrorHandler.handleEmptyError())
|
||||
)
|
||||
} else {
|
||||
compositeSubscription.add(
|
||||
userRepository.retrieveTeamPlan(ownerID ?: "")
|
||||
.doOnTerminate {
|
||||
onComplete()
|
||||
}.subscribe({ }, RxErrorHandler.handleEmptyError())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadTaskLists() {
|
||||
val fragmentManager = childFragmentManager
|
||||
|
||||
|
|
@ -237,20 +293,15 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
val fragment: TaskRecyclerViewFragment = when (position) {
|
||||
0 -> TaskRecyclerViewFragment.newInstance(context, TaskType.HABIT)
|
||||
1 -> TaskRecyclerViewFragment.newInstance(context, TaskType.DAILY)
|
||||
0 -> TaskRecyclerViewFragment.newInstance(context, TaskType.HABIT, ownerID)
|
||||
1 -> TaskRecyclerViewFragment.newInstance(context, TaskType.DAILY, ownerID)
|
||||
3 -> RewardsRecyclerviewFragment.newInstance(context, TaskType.REWARD, true)
|
||||
else -> TaskRecyclerViewFragment.newInstance(context, TaskType.TODO)
|
||||
else -> TaskRecyclerViewFragment.newInstance(context, TaskType.TODO, ownerID)
|
||||
}
|
||||
fragment.canEditTasks = isPersonalBoard
|
||||
fragment.canScoreTaks = isPersonalBoard
|
||||
fragment.refreshAction = {
|
||||
compositeSubscription.add(
|
||||
userRepository.retrieveUser(
|
||||
withTasks = true,
|
||||
forced = true
|
||||
).doOnTerminate {
|
||||
it()
|
||||
}.subscribe({ }, RxErrorHandler.handleEmptyError())
|
||||
)
|
||||
refreshData(it)
|
||||
}
|
||||
viewFragmentsDictionary?.put(position, fragment)
|
||||
|
||||
|
|
@ -448,4 +499,25 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
override fun onAdd(taskType: TaskType) {
|
||||
openNewTaskActivity(taskType)
|
||||
}
|
||||
|
||||
fun cycleOwnerIDs() {
|
||||
val nextIndex = owners.indexOfFirst { it.first == ownerID } + 1
|
||||
if (nextIndex < owners.size) {
|
||||
ownerID = owners[nextIndex].first
|
||||
activity?.title = owners[nextIndex].second
|
||||
} else {
|
||||
ownerID = owners[0].first
|
||||
activity?.title = owners[0].second
|
||||
}
|
||||
updateBoardDisplay()
|
||||
}
|
||||
|
||||
private fun updateBoardDisplay() {
|
||||
bottomNavigation?.canAddTasks = isPersonalBoard
|
||||
viewFragmentsDictionary?.values?.forEach {
|
||||
it.ownerID = ownerID
|
||||
it.canEditTasks = isPersonalBoard
|
||||
it.canScoreTaks = isPersonalBoard
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,391 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.tasks
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.data.TagRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentViewpagerBinding
|
||||
import com.habitrpg.android.habitica.extensions.getThemeColor
|
||||
import com.habitrpg.android.habitica.extensions.setTintWith
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.helpers.TaskFilterHelper
|
||||
import com.habitrpg.android.habitica.models.tasks.TaskType
|
||||
import com.habitrpg.android.habitica.ui.activities.TaskFormActivity
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.views.navigation.HabiticaBottomNavigationViewListener
|
||||
import com.habitrpg.android.habitica.ui.views.tasks.TaskFilterDialog
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import java.util.Date
|
||||
import java.util.WeakHashMap
|
||||
import javax.inject.Inject
|
||||
|
||||
class TeamBoardFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.OnQueryTextListener, HabiticaBottomNavigationViewListener {
|
||||
|
||||
override var binding: FragmentViewpagerBinding? = null
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentViewpagerBinding {
|
||||
return FragmentViewpagerBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
var teamID: String = ""
|
||||
|
||||
@Inject
|
||||
lateinit var taskFilterHelper: TaskFilterHelper
|
||||
@Inject
|
||||
lateinit var tagRepository: TagRepository
|
||||
@Inject
|
||||
lateinit var appConfigManager: AppConfigManager
|
||||
|
||||
private var refreshItem: MenuItem? = null
|
||||
internal var viewFragmentsDictionary: MutableMap<Int, TaskRecyclerViewFragment>? = WeakHashMap()
|
||||
|
||||
private var filterMenuItem: MenuItem? = null
|
||||
|
||||
private val activeFragment: TaskRecyclerViewFragment?
|
||||
get() {
|
||||
var fragment = viewFragmentsDictionary?.get(binding?.viewPager?.currentItem)
|
||||
if (fragment == null) {
|
||||
if (isAdded) {
|
||||
fragment = (childFragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + binding?.viewPager?.currentItem) as? TaskRecyclerViewFragment)
|
||||
}
|
||||
}
|
||||
return fragment
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
this.usesTabLayout = false
|
||||
this.hidesToolbar = true
|
||||
this.usesBottomNavigation = true
|
||||
return super.onCreateView(inflater, container, savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
arguments?.let {
|
||||
val args = TeamBoardFragmentArgs.fromBundle(it)
|
||||
teamID = args.teamID
|
||||
}
|
||||
|
||||
compositeSubscription.add(
|
||||
userRepository.getTeamPlan(teamID)
|
||||
.subscribe(
|
||||
{
|
||||
activity?.title = it.name
|
||||
},
|
||||
RxErrorHandler.handleEmptyError()
|
||||
)
|
||||
)
|
||||
|
||||
compositeSubscription.add(userRepository.retrieveTeamPlan(teamID).subscribe({ }, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
loadTaskLists()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
bottomNavigation?.activeTaskType = when (binding?.viewPager?.currentItem) {
|
||||
0 -> TaskType.HABIT
|
||||
1 -> TaskType.DAILY
|
||||
2 -> TaskType.TODO
|
||||
3 -> TaskType.REWARD
|
||||
else -> TaskType.HABIT
|
||||
}
|
||||
bottomNavigation?.listener = this
|
||||
bottomNavigation?.canAddTasks = false
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
if (bottomNavigation?.listener == this) {
|
||||
bottomNavigation?.listener = null
|
||||
}
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
tagRepository.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun injectFragment(component: UserComponent) {
|
||||
component.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_team_board, menu)
|
||||
|
||||
filterMenuItem = menu.findItem(R.id.action_filter)
|
||||
updateFilterIcon()
|
||||
|
||||
val item = menu.findItem(R.id.action_search)
|
||||
tintMenuIcon(item)
|
||||
val sv = item.actionView as? SearchView
|
||||
sv?.setOnQueryTextListener(this)
|
||||
sv?.setIconifiedByDefault(false)
|
||||
item.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||
filterMenuItem?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||
// Do something when expanded
|
||||
filterMenuItem?.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
taskFilterHelper.searchQuery = newText
|
||||
viewFragmentsDictionary?.values?.forEach { values -> values.recyclerAdapter?.filter() }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_filter -> {
|
||||
showFilterDialog()
|
||||
true
|
||||
}
|
||||
R.id.action_reload -> {
|
||||
refreshItem = item
|
||||
refresh()
|
||||
true
|
||||
}
|
||||
R.id.action_team_info -> {
|
||||
MainNavigationController.navigate(R.id.guildFragment, bundleOf(Pair("groupID", teamID)))
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showFilterDialog() {
|
||||
context?.let {
|
||||
val disposable: Disposable
|
||||
val dialog = TaskFilterDialog(it, HabiticaBaseApplication.userComponent)
|
||||
disposable = tagRepository.getTags().subscribe({ tagsList -> dialog.setTags(tagsList) }, RxErrorHandler.handleEmptyError())
|
||||
dialog.setActiveTags(taskFilterHelper.tags)
|
||||
if (activeFragment != null) {
|
||||
val taskType = activeFragment?.taskType
|
||||
if (taskType != null) {
|
||||
dialog.setTaskType(taskType, taskFilterHelper.getActiveFilter(taskType))
|
||||
}
|
||||
}
|
||||
dialog.setListener(object : TaskFilterDialog.OnFilterCompletedListener {
|
||||
override fun onFilterCompleted(
|
||||
activeTaskFilter: String?,
|
||||
activeTags: MutableList<String>
|
||||
) {
|
||||
if (viewFragmentsDictionary == null) {
|
||||
return
|
||||
}
|
||||
taskFilterHelper.tags = activeTags
|
||||
if (activeTaskFilter != null) {
|
||||
activeFragment?.setActiveFilter(activeTaskFilter)
|
||||
}
|
||||
viewFragmentsDictionary?.values?.forEach { values -> values.recyclerAdapter?.filter() }
|
||||
updateFilterIcon()
|
||||
}
|
||||
})
|
||||
dialog.setOnDismissListener {
|
||||
if (!disposable.isDisposed) {
|
||||
disposable.dispose()
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
activeFragment?.onRefresh()
|
||||
}
|
||||
|
||||
private fun loadTaskLists() {
|
||||
val fragmentManager = childFragmentManager
|
||||
|
||||
binding?.viewPager?.adapter = object : FragmentStateAdapter(fragmentManager, lifecycle) {
|
||||
|
||||
override fun createFragment(position: Int): androidx.fragment.app.Fragment {
|
||||
val fragment: TaskRecyclerViewFragment = when (position) {
|
||||
0 -> TaskRecyclerViewFragment.newInstance(context, TaskType.HABIT)
|
||||
1 -> TaskRecyclerViewFragment.newInstance(context, TaskType.DAILY)
|
||||
3 -> RewardsRecyclerviewFragment.newInstance(context, TaskType.REWARD, false)
|
||||
else -> TaskRecyclerViewFragment.newInstance(context, TaskType.TODO)
|
||||
}
|
||||
fragment.canEditTasks = false
|
||||
fragment.canScoreTaks = false
|
||||
fragment.refreshAction = {
|
||||
compositeSubscription.add(
|
||||
userRepository.retrieveTeamPlan(teamID)
|
||||
.doOnTerminate {
|
||||
it()
|
||||
}.subscribe({ }, RxErrorHandler.handleEmptyError())
|
||||
)
|
||||
}
|
||||
|
||||
viewFragmentsDictionary?.put(position, fragment)
|
||||
|
||||
return fragment
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 4
|
||||
}
|
||||
|
||||
binding?.viewPager?.registerOnPageChangeCallback(object :
|
||||
ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
bottomNavigation?.selectedPosition = position
|
||||
updateFilterIcon()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateFilterIcon() {
|
||||
if (filterMenuItem == null) {
|
||||
return
|
||||
}
|
||||
var filterCount = 0
|
||||
if (activeFragment != null) {
|
||||
filterCount = taskFilterHelper.howMany(activeFragment?.taskType)
|
||||
}
|
||||
if (filterCount == 0) {
|
||||
filterMenuItem?.setIcon(R.drawable.ic_action_filter_list)
|
||||
context?.let {
|
||||
val filterIcon = ContextCompat.getDrawable(it, R.drawable.ic_action_filter_list)
|
||||
filterIcon?.setTintWith(it.getThemeColor(R.attr.headerTextColor), PorterDuff.Mode.MULTIPLY)
|
||||
filterMenuItem?.setIcon(filterIcon)
|
||||
}
|
||||
} else {
|
||||
context?.let {
|
||||
val filterIcon = ContextCompat.getDrawable(it, R.drawable.ic_filters_active)
|
||||
filterIcon?.setTintWith(it.getThemeColor(R.attr.textColorPrimaryDark), PorterDuff.Mode.MULTIPLY)
|
||||
filterMenuItem?.setIcon(filterIcon)
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
||||
private fun openNewTaskActivity(type: TaskType) {
|
||||
if (Date().time - (lastTaskFormOpen?.time ?: 0) < 2000) {
|
||||
return
|
||||
}
|
||||
|
||||
val additionalData = HashMap<String, Any>()
|
||||
additionalData["created task type"] = type
|
||||
additionalData["viewed task type"] = when (binding?.viewPager?.currentItem) {
|
||||
0 -> TaskType.HABIT
|
||||
1 -> TaskType.DAILY
|
||||
2 -> TaskType.TODO
|
||||
3 -> TaskType.REWARD
|
||||
else -> ""
|
||||
}
|
||||
AmplitudeManager.sendEvent("open create task form", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData)
|
||||
|
||||
val bundle = Bundle()
|
||||
bundle.putString(TaskFormActivity.TASK_TYPE_KEY, type.value)
|
||||
bundle.putStringArrayList(TaskFormActivity.SELECTED_TAGS_KEY, ArrayList(taskFilterHelper.tags))
|
||||
|
||||
val intent = Intent(activity, TaskFormActivity::class.java)
|
||||
intent.putExtras(bundle)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|
||||
if (this.isAdded) {
|
||||
lastTaskFormOpen = Date()
|
||||
taskCreatedResult.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
//endregion Events
|
||||
|
||||
private val taskCreatedResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
onTaskCreatedResult(it.resultCode, it.data)
|
||||
}
|
||||
|
||||
private fun onTaskCreatedResult(resultCode: Int, data: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val taskTypeValue = data?.getStringExtra(TaskFormActivity.TASK_TYPE_KEY)
|
||||
if (taskTypeValue != null) {
|
||||
val taskType = TaskType.from(taskTypeValue)
|
||||
switchToTaskTab(taskType)
|
||||
|
||||
val index = indexForTaskType(taskType)
|
||||
if (index != -1) {
|
||||
val fragment = viewFragmentsDictionary?.get(index)
|
||||
fragment?.binding?.recyclerView?.scrollToPosition(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun switchToTaskTab(taskType: TaskType?) {
|
||||
val index = indexForTaskType(taskType)
|
||||
if (binding?.viewPager != null && index != -1) {
|
||||
binding?.viewPager?.currentItem = index
|
||||
}
|
||||
}
|
||||
|
||||
private fun indexForTaskType(taskType: TaskType?): Int {
|
||||
if (taskType != null) {
|
||||
for (index in 0 until (viewFragmentsDictionary?.size ?: 0)) {
|
||||
val fragment = viewFragmentsDictionary?.get(index)
|
||||
if (fragment != null && taskType == fragment.className) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
override val displayedClassName: String?
|
||||
get() = null
|
||||
|
||||
override fun addToBackStack(): Boolean = false
|
||||
|
||||
companion object {
|
||||
var lastTaskFormOpen: Date? = null
|
||||
}
|
||||
|
||||
override fun onTabSelected(taskType: TaskType, smooth: Boolean) {
|
||||
val newItem = when (taskType) {
|
||||
TaskType.HABIT -> 0
|
||||
TaskType.DAILY -> 1
|
||||
TaskType.TODO -> 2
|
||||
TaskType.REWARD -> 3
|
||||
else -> 0
|
||||
}
|
||||
binding?.viewPager?.setCurrentItem(newItem, smooth)
|
||||
}
|
||||
|
||||
override fun onAdd(taskType: TaskType) {
|
||||
openNewTaskActivity(taskType)
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ class MainUserViewModel(val userRepository: UserRepository) {
|
|||
get() = user.value?.id
|
||||
val username: CharSequence
|
||||
get() = user.value?.username ?: ""
|
||||
val displayName: CharSequence
|
||||
get() = user.value?.profile?.name ?: ""
|
||||
val partyID: String?
|
||||
get() = user.value?.party?.id
|
||||
val isUserFainted: Boolean
|
||||
|
|
|
|||
Loading…
Reference in a new issue