allow items and guild pages to be opened to pages other than the first one

This commit is contained in:
Phillip Thelen 2019-06-12 18:00:41 +02:00
parent 4461d10353
commit 73eece277c
5 changed files with 34 additions and 11 deletions

View file

@ -110,6 +110,10 @@
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemsFragment"
android:label="@string/sidebar_items">
<deepLink app:uri="habitica.com/inventory/items" />
<argument
android:name="itemType"
app:argType="string"
app:nullable="true" />
</fragment>
<fragment
android:id="@+id/stableFragment"
@ -164,6 +168,10 @@
android:name="isMember"
app:argType="boolean"
android:defaultValue="false"/>
<argument
android:name="tabToOpen"
app:argType="integer"
android:defaultValue="0"/>
</fragment>
<fragment
android:id="@+id/publicGuildsFragment"

View file

@ -32,7 +32,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
lateinit var viewModel: NotificationsViewModel
lateinit var inflater: LayoutInflater
var inflater: LayoutInflater? = null
override fun getLayoutResId(): Int = R.layout.activity_notifications
@ -43,7 +43,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
setupToolbar(toolbar)
inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater
viewModel = ViewModelProviders.of(this)
.get(NotificationsViewModel::class.java)
@ -94,9 +94,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
private fun displayNoNotificationsView() {
notification_items.showDividers = LinearLayout.SHOW_DIVIDER_NONE
notification_items.addView(
inflater.inflate(R.layout.no_notifications, notification_items, false)
)
notification_items.addView(inflater?.inflate(R.layout.no_notifications, notification_items, false))
}
private fun displayNotificationsListView(notifications: List<Notification>) {
@ -127,7 +125,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
}
private fun createNotificationsHeaderView(notificationCount: Int): View? {
val header = inflater.inflate(R.layout.notifications_header, notification_items, false)
val header = inflater?.inflate(R.layout.notifications_header, notification_items, false)
val badge = header?.findViewById(R.id.notifications_title_badge) as? TextView
badge?.text = notificationCount.toString()
@ -220,7 +218,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
imageResourceId: Int? = null,
textColor: Int? = null
): View? {
val item = inflater.inflate(R.layout.notification_item, notification_items, false)
val item = inflater?.inflate(R.layout.notification_item, notification_items, false)
val container = item?.findViewById(R.id.notification_item) as? View
container?.setOnClickListener {

View file

@ -30,6 +30,17 @@ class ItemsFragment : BaseMainFragment() {
viewPager?.currentItem = 0
setViewPagerAdapter()
arguments?.let {
val args = ItemsFragmentArgs.fromBundle(it)
viewPager?.currentItem = when (args.itemType) {
"hatchingPotions" -> 1
"food" -> 2
"quests" -> 3
"special" -> 4
else -> 0
}
}
}
override fun injectFragment(component: UserComponent) {

View file

@ -48,9 +48,8 @@ class GuildFragment : BaseMainFragment() {
viewModel.getGroupData().observe(viewLifecycleOwner, Observer { setGroup(it) })
viewModel.getIsMemberData().observe(viewLifecycleOwner, Observer { activity?.invalidateOptionsMenu() })
val newArguments = arguments
if (newArguments != null) {
val args = GuildFragmentArgs.fromBundle(newArguments)
arguments?.let {
val args = GuildFragmentArgs.fromBundle(it)
viewModel.setGroupID(args.groupID)
}
@ -59,6 +58,11 @@ class GuildFragment : BaseMainFragment() {
setViewPagerAdapter()
setFragments()
arguments?.let {
val args = GuildFragmentArgs.fromBundle(it)
viewPager?.currentItem = args.tabToOpen
}
if (viewModel.groupID == "f2db2a7f-13c5-454d-b3ee-ea1f5089e601") {
context?.let { FirebaseAnalytics.getInstance(it).logEvent("opened_no_party_guild", null) }
}

View file

@ -1,6 +1,7 @@
package com.habitrpg.android.habitica.ui.viewmodels
import android.os.Bundle
import androidx.core.os.bundleOf
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.data.SocialRepository
@ -230,7 +231,7 @@ open class NotificationsViewModel : BaseViewModel() {
when (notification.type) {
Notification.Type.NEW_STUFF.type -> navController.navigate(R.id.newsFragment)
Notification.Type.NEW_CHAT_MESSAGE.type -> clickNewChatMessage(notification, navController)
Notification.Type.NEW_MYSTERY_ITEMS.type -> navController.navigate(R.id.itemsFragment)
Notification.Type.NEW_MYSTERY_ITEMS.type -> navController.navigate(R.id.itemsFragment, bundleOf(Pair("itemType", "special")))
Notification.Type.UNALLOCATED_STATS_POINTS.type -> navController.navigate(R.id.statsFragment)
// Group tasks should go to Group tasks view if that is added to this app at some point
Notification.Type.GROUP_TASK_APPROVED.type -> navController.navigate(R.id.tasksFragment)
@ -246,6 +247,7 @@ open class NotificationsViewModel : BaseViewModel() {
val bundle = Bundle()
bundle.putString("groupID", data?.group?.id)
bundle.putBoolean("isMember", true) // safe to assume user is member since they got the notification
bundle.putInt("tabToOpen", 1)
navController.navigate(R.id.guildFragment, bundle)
}
}