Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: back funtionality of the app #804

Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/src/main/java/org/fossasia/openevent/general/MainActivity.kt
Expand Up @@ -8,14 +8,17 @@ import kotlinx.android.synthetic.main.activity_main.frameContainer
import kotlinx.android.synthetic.main.activity_main.navigation
import org.fossasia.openevent.general.R.id.navigation_events
import org.fossasia.openevent.general.R.id.navigation_search
import org.fossasia.openevent.general.attendees.AttendeeFragment
import org.fossasia.openevent.general.auth.ProfileFragment
import org.fossasia.openevent.general.event.EventDetailsFragment
import org.fossasia.openevent.general.event.EventsFragment
import org.fossasia.openevent.general.favorite.FavoriteFragment
import org.fossasia.openevent.general.order.LAUNCH_TICKETS
import org.fossasia.openevent.general.order.OrderDetailsFragment
import org.fossasia.openevent.general.order.OrdersUnderUserFragment
import org.fossasia.openevent.general.order.TICKETS
import org.fossasia.openevent.general.search.SearchFragment
import org.fossasia.openevent.general.ticket.TicketsFragment
import org.fossasia.openevent.general.utils.Utils.checkAndLoadFragment
import org.fossasia.openevent.general.utils.Utils.loadFragment

Expand Down Expand Up @@ -88,10 +91,12 @@ class MainActivity : AppCompatActivity() {
override fun onBackPressed() {
val currentFragment = this.supportFragmentManager.findFragmentById(R.id.frameContainer)
val rootFragment = this.supportFragmentManager.findFragmentById(R.id.rootLayout)
if (rootFragment is EventDetailsFragment)
super.onBackPressed()
else
when (currentFragment) {
when (rootFragment) {
is EventDetailsFragment,
is TicketsFragment,
is AttendeeFragment,
is OrderDetailsFragment -> super.onBackPressed()
pranavpandey1998official marked this conversation as resolved.
Show resolved Hide resolved
else -> when (currentFragment) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both when conditions can be written separately. Let mentors review it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is massive duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal how about this the rootFragment is null when we are in the main page so

  if (rootFragment == null) {
             when (currentFragment) {
                is SearchFragment,
                is FavoriteFragment,
                is OrdersUnderUserFragment,
                is ProfileFragment -> {
                    loadFragment(supportFragmentManager, EventsFragment(), frameContainer.id)
                    navigation.selectedItemId = navigation_events
                }
                is EventsFragment -> finish()
                else -> super.onBackPressed()
            }
        }
    else super.onBackPressed() 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems better but reverse the condition and use early return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal like this

if (rootFragment != null) {
            super.onBackPressed()
            return
        }
    when (currentFragment) {
        is SearchFragment,
        is FavoriteFragment,
        is OrdersUnderUserFragment,
        is ProfileFragment -> {
            loadFragment(supportFragmentManager, EventsFragment(), frameContainer.id)
            navigation.selectedItemId = navigation_events
        }
        is EventsFragment -> finish()
        else -> super.onBackPressed()
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

is SearchFragment,
is FavoriteFragment,
is OrdersUnderUserFragment,
Expand All @@ -102,5 +107,6 @@ class MainActivity : AppCompatActivity() {
is EventsFragment -> finish()
else -> super.onBackPressed()
}
}
}
}