Skip to content

Commit 97c7620

Browse files
author
maskara
committed
Fix issue where there was no way to back from MediaDetailFragment
1 parent f6a7759 commit 97c7620

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsActivity.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,15 @@ protected void onCreate(Bundle savedInstanceState) {
126126
setContentView(R.layout.activity_contributions);
127127
ButterKnife.bind(this);
128128

129-
// Activity can call methods in the fragment by acquiring a reference to the Fragment from FragmentManager, using findFragmentById()
130-
contributionsList = (ContributionsListFragment)getSupportFragmentManager().findFragmentById(R.id.contributionsListFragment);
129+
// Activity can call methods in the fragment by acquiring a
130+
// reference to the Fragment from FragmentManager, using findFragmentById()
131+
contributionsList = (ContributionsListFragment)getSupportFragmentManager()
132+
.findFragmentById(R.id.contributionsListFragment);
131133

132134
getSupportFragmentManager().addOnBackStackChangedListener(this);
133135
if (savedInstanceState != null) {
134-
mediaDetails = (MediaDetailPagerFragment)getSupportFragmentManager().findFragmentById(R.id.contributionsFragmentContainer);
135-
// onBackStackChanged uses mediaDetails.isVisible() but this returns false now.
136-
// Use the saved value from before pause or orientation change.
137-
if (mediaDetails != null && savedInstanceState.getBoolean("mediaDetailsVisible")) {
138-
// Feels awful that we have to reset this manually!
139-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
140-
}
136+
mediaDetails = (MediaDetailPagerFragment)getSupportFragmentManager()
137+
.findFragmentById(R.id.contributionsFragmentContainer);
141138
}
142139
requestAuthToken();
143140
initDrawer();
@@ -241,7 +238,10 @@ public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
241238
getSupportActionBar().setSubtitle(getResources()
242239
.getString(R.string.contributions_subtitle_zero));
243240
} else {
244-
getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.contributions_subtitle, cursor.getCount(), cursor.getCount()));
241+
getSupportActionBar().setSubtitle(getResources()
242+
.getQuantityString(R.plurals.contributions_subtitle,
243+
cursor.getCount(),
244+
cursor.getCount()));
245245
}
246246

247247
contributionsList.clearSyncMessage();
@@ -314,11 +314,7 @@ public void unregisterDataSetObserver(DataSetObserver observer) {
314314

315315
@Override
316316
public void onBackStackChanged() {
317-
if(mediaDetails != null && mediaDetails.isVisible()) {
318-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
319-
} else {
320-
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
321-
}
317+
initBackButton();
322318
}
323319

324320
@Override

app/src/main/java/fr/free/nrw/commons/theme/NavigationBaseActivity.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import android.support.v4.widget.DrawerLayout;
55
import android.support.v7.app.ActionBarDrawerToggle;
66
import android.support.v7.widget.Toolbar;
7+
import android.view.View;
78
import android.view.ViewGroup;
89
import android.widget.RelativeLayout;
910

1011
import butterknife.BindView;
11-
import butterknife.ButterKnife;
1212
import fr.free.nrw.commons.R;
1313
import fr.free.nrw.commons.hamburger.HamburgerMenuContainer;
1414
import fr.free.nrw.commons.hamburger.NavigationBaseFragment;
@@ -26,6 +26,8 @@ public class NavigationBaseActivity extends BaseActivity implements HamburgerMen
2626
@BindView(R.id.drawer_pane)
2727
RelativeLayout drawerPane;
2828

29+
private ActionBarDrawerToggle toggle;
30+
2931
@Override
3032
protected void onCreate(Bundle savedInstanceState) {
3133
super.onCreate(savedInstanceState);
@@ -40,10 +42,10 @@ public void initDrawer() {
4042
baseFragment);
4143
}
4244

43-
private void initSubviews() {
45+
public void initSubviews() {
4446
setSupportActionBar(toolbar);
4547
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
46-
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
48+
toggle = new ActionBarDrawerToggle(this,
4749
drawerLayout,
4850
toolbar,
4951
R.string.navigation_drawer_open,
@@ -54,6 +56,17 @@ private void initSubviews() {
5456
setDrawerPaneWidth();
5557
}
5658

59+
public void initBackButton() {
60+
int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
61+
toggle.setDrawerIndicatorEnabled(backStackEntryCount == 0);
62+
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
63+
@Override
64+
public void onClick(View v) {
65+
onBackPressed();
66+
}
67+
});
68+
}
69+
5770
private void setDrawerPaneWidth() {
5871
ViewGroup.LayoutParams params = drawerPane.getLayoutParams();
5972
// set width to lowerBound of 80% of the screen size

0 commit comments

Comments
 (0)