Skip to content

Fixes #4329 "Back button in edit categories triggers back of media details." #4346

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

Merged
merged 4 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ public void setupTabLayout(){


public void onBackPressed() {
((BookmarkListRootFragment) (adapter.getItem(tabLayout.getSelectedTabPosition())))
.backPressed();
if(((BookmarkListRootFragment)(adapter.getItem(tabLayout.getSelectedTabPosition()))).backPressed()) {
// The event is handled internally by the adapter , no further action required.
return;
}
// Event is not handled by the adapter ( performed back action ) change action bar.
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,14 @@ public void viewPagerNotifyDataSetChanged() {
}
}

public void backPressed() {
public boolean backPressed() {
//check mediaDetailPage fragment is not null then we check mediaDetail.is Visible or not to avoid NullPointerException
if(mediaDetails!=null) {
if (mediaDetails.isVisible()) {
if(mediaDetails.backButtonClicked()) {
// mediaDetails handled the back clicked , no further action required.
return true;
}
// todo add get list fragment
((BookmarkFragment) getParentFragment()).setupTabLayout();
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
Expand All @@ -206,6 +210,8 @@ public void backPressed() {
} else {
moveToContributionsFragment();
}
// notify mediaDetails did not handled the backPressed further actions required.
return false;
}

void moveToContributionsFragment(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onBackPressed() {
if (supportFragmentManager.getBackStackEntryCount() == 1){
// back to search so show search toolbar and hide navigation toolbar

// the back press is handled by the mediaDetails , no further action required.
if(mediaDetails.backButtonClicked()){
return;
}

tabLayout.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.VISIBLE);
mediaContainer.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ public Integer getContributionStateAt(int position) {

public void backButtonClicked() {
if (mediaDetailPagerFragment.isVisible()) {
if(mediaDetailPagerFragment.backButtonClicked()) {
// MediaDetailed handled the backPressed no further action required.
return;
}
if (store.getBoolean("displayNearbyCardView", true)) {
if (nearbyNotificationCardView.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
nearbyNotificationCardView.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ public void setTabs() {

public void onBackPressed() {
if (tabLayout.getSelectedTabPosition() == 0) {
featuredRootFragment.backPressed();
if(featuredRootFragment.backPressed()){
// Event is handled by the Fragment we need not do anything.
return;
}
} else {
mobileRootFragment.backPressed();
if(mobileRootFragment.backPressed()){
// Event is handled by the Fragment we need not do anything.
return;
}
}
// Event is not handled by the fragment ( i.e performed back action ) therefore change action bar.
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,18 @@ public void viewPagerNotifyDataSetChanged() {
}
}

public void backPressed() {
/**
* Performs back pressed action on the fragment.
* Return true if the event was handled by the mediaDetails otherwise returns false.
* @return
*/
public boolean backPressed() {
if (null!=mediaDetails && mediaDetails.isVisible()) {
// todo add get list fragment
if(mediaDetails.backButtonClicked()) {
// MediaDetails handled the event no further action required.
return true;
}
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
removeFragment(mediaDetails);
((ExploreFragment) getParentFragment()).setScroll(true);
Expand All @@ -175,5 +184,6 @@ public void backPressed() {
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
}
((MainActivity)getActivity()).showTabs();
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ protected void onResume() {
@Override
public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() == 1){

// the back press is handled by the mediaDetails , no further action required.
if(mediaDetails.backButtonClicked()){
return;
}

// back to search so show search toolbar and hide navigation toolbar
searchView.setVisibility(View.VISIBLE);//set the searchview
tabLayout.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public Media getMediaAtPosition(int i) {
@Override
public void onBackPressed() {
if (supportFragmentManager.getBackStackEntryCount() == 1){
// back to search so show search toolbar and hide navigation toolbar

// back pressed is handled by the mediaDetails , no further action required.
if(mediaDetailPagerFragment.backButtonClicked()){
return;
}

tabLayout.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.VISIBLE);
mediaContainer.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Expand Down Expand Up @@ -298,6 +301,7 @@ public void run() {
updateAspectRatio(scrollView.getWidth());
}
});

return view;
}

Expand Down Expand Up @@ -702,6 +706,22 @@ public void onCategoryEditButtonClicked(){
displayHideCategorySearch();
}

/**
* Hides the categoryEditContainer.
* returns true after closing the categoryEditContainer if open, implying that event was handled.
* else returns false
* @return
*/
public boolean hideCategoryEditContainerIfOpen(){
if (dummyCategoryEditContainer.getVisibility() == VISIBLE) {
// editCategory is open, close it and return true as the event was handled.
dummyCategoryEditContainer.setVisibility(GONE);
return true;
}
// Event was not handled.
return false;
}

public void displayHideCategorySearch() {
if (dummyCategoryEditContainer.getVisibility() != VISIBLE) {
dummyCategoryEditContainer.setVisibility(VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
Expand Down Expand Up @@ -374,6 +375,16 @@ public void onDataSetChanged() {
}
}

/**
* backButtonClicked is called on a back event in the media details pager.
* returns true after closing the categoryEditContainer if open, implying that event was handled.
* else returns false
* @return
*/
public boolean backButtonClicked(){
return ((MediaDetailFragment)(adapter.getCurrentFragment())).hideCategoryEditContainerIfOpen();
}

public interface MediaDetailProvider {
Media getMediaAtPosition(int i);

Expand All @@ -385,6 +396,11 @@ public interface MediaDetailProvider {
//FragmentStatePagerAdapter allows user to swipe across collection of images (no. of images undetermined)
private class MediaDetailAdapter extends FragmentStatePagerAdapter {

/**
* Keeps track of the current displayed fragment.
*/
private Fragment mCurrentFragment;

public MediaDetailAdapter(FragmentManager fm) {
super(fm);
}
Expand Down Expand Up @@ -414,5 +430,30 @@ public int getCount() {
}
return provider.getTotalMediaCount();
}

/**
* Get the currently displayed fragment.
* @return
*/
public Fragment getCurrentFragment() {
return mCurrentFragment;
}

/**
* Called to inform the adapter of which item is currently considered to be the "primary",
* that is the one show to the user as the current page.
* @param container
* @param position
* @param object
*/
@Override
public void setPrimaryItem(@NonNull final ViewGroup container, final int position,
@NonNull final Object object) {
// Update the current fragment if changed
if(getCurrentFragment() != object) {
mCurrentFragment = ((Fragment)object);
}
super.setPrimaryItem(container, position, object);
}
}
}