mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Back button on fragment * Handled back events * minor changes * removed extra lines
This commit is contained in:
parent
fd247f6321
commit
f8a8f92070
10 changed files with 115 additions and 8 deletions
|
|
@ -100,8 +100,11 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
((BookmarkListRootFragment) (adapter.getItem(tabLayout.getSelectedTabPosition())))
|
if(((BookmarkListRootFragment)(adapter.getItem(tabLayout.getSelectedTabPosition()))).backPressed()) {
|
||||||
.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);
|
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,10 +180,14 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backPressed() {
|
public boolean backPressed() {
|
||||||
//check mediaDetailPage fragment is not null then we check mediaDetail.is Visible or not to avoid NullPointerException
|
//check mediaDetailPage fragment is not null then we check mediaDetail.is Visible or not to avoid NullPointerException
|
||||||
if(mediaDetails!=null) {
|
if(mediaDetails!=null) {
|
||||||
if (mediaDetails.isVisible()) {
|
if (mediaDetails.isVisible()) {
|
||||||
|
if(mediaDetails.backButtonClicked()) {
|
||||||
|
// mediaDetails handled the back clicked , no further action required.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// todo add get list fragment
|
// todo add get list fragment
|
||||||
((BookmarkFragment) getParentFragment()).setupTabLayout();
|
((BookmarkFragment) getParentFragment()).setupTabLayout();
|
||||||
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
|
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
|
||||||
|
|
@ -206,6 +210,8 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
} else {
|
} else {
|
||||||
moveToContributionsFragment();
|
moveToContributionsFragment();
|
||||||
}
|
}
|
||||||
|
// notify mediaDetails did not handled the backPressed further actions required.
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToContributionsFragment(){
|
void moveToContributionsFragment(){
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,12 @@ public class CategoryDetailsActivity extends BaseActivity
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (supportFragmentManager.getBackStackEntryCount() == 1){
|
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);
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
viewPager.setVisibility(View.VISIBLE);
|
viewPager.setVisibility(View.VISIBLE);
|
||||||
mediaContainer.setVisibility(View.GONE);
|
mediaContainer.setVisibility(View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -594,6 +594,10 @@ public class ContributionsFragment
|
||||||
|
|
||||||
public void backButtonClicked() {
|
public void backButtonClicked() {
|
||||||
if (mediaDetailPagerFragment.isVisible()) {
|
if (mediaDetailPagerFragment.isVisible()) {
|
||||||
|
if(mediaDetailPagerFragment.backButtonClicked()) {
|
||||||
|
// MediaDetailed handled the backPressed no further action required.
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (store.getBoolean("displayNearbyCardView", true)) {
|
if (store.getBoolean("displayNearbyCardView", true)) {
|
||||||
if (nearbyNotificationCardView.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
|
if (nearbyNotificationCardView.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
|
||||||
nearbyNotificationCardView.setVisibility(View.VISIBLE);
|
nearbyNotificationCardView.setVisibility(View.VISIBLE);
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,17 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (tabLayout.getSelectedTabPosition() == 0) {
|
if (tabLayout.getSelectedTabPosition() == 0) {
|
||||||
featuredRootFragment.backPressed();
|
if(featuredRootFragment.backPressed()){
|
||||||
|
// Event is handled by the Fragment we need not do anything.
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} 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);
|
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,9 +164,18 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()) {
|
if (null!=mediaDetails && mediaDetails.isVisible()) {
|
||||||
// todo add get list fragment
|
// todo add get list fragment
|
||||||
|
if(mediaDetails.backButtonClicked()) {
|
||||||
|
// MediaDetails handled the event no further action required.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
||||||
removeFragment(mediaDetails);
|
removeFragment(mediaDetails);
|
||||||
((ExploreFragment) getParentFragment()).setScroll(true);
|
((ExploreFragment) getParentFragment()).setScroll(true);
|
||||||
|
|
@ -175,5 +184,6 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
||||||
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
|
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
|
||||||
}
|
}
|
||||||
((MainActivity)getActivity()).showTabs();
|
((MainActivity)getActivity()).showTabs();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,12 @@ public class SearchActivity extends BaseActivity
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (getSupportFragmentManager().getBackStackEntryCount() == 1){
|
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
|
// back to search so show search toolbar and hide navigation toolbar
|
||||||
searchView.setVisibility(View.VISIBLE);//set the searchview
|
searchView.setVisibility(View.VISIBLE);//set the searchview
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,12 @@ public class WikidataItemDetailsActivity extends BaseActivity implements MediaDe
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (supportFragmentManager.getBackStackEntryCount() == 1){
|
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);
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
viewPager.setVisibility(View.VISIBLE);
|
viewPager.setVisibility(View.VISIBLE);
|
||||||
mediaContainer.setVisibility(View.GONE);
|
mediaContainer.setVisibility(View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,11 @@ import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnKeyListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||||
|
|
@ -298,6 +301,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
||||||
updateAspectRatio(scrollView.getWidth());
|
updateAspectRatio(scrollView.getWidth());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -702,6 +706,22 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
||||||
displayHideCategorySearch();
|
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() {
|
public void displayHideCategorySearch() {
|
||||||
if (dummyCategoryEditContainer.getVisibility() != VISIBLE) {
|
if (dummyCategoryEditContainer.getVisibility() != VISIBLE) {
|
||||||
dummyCategoryEditContainer.setVisibility(VISIBLE);
|
dummyCategoryEditContainer.setVisibility(VISIBLE);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
|
|
@ -381,6 +382,16 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
public interface MediaDetailProvider {
|
||||||
Media getMediaAtPosition(int i);
|
Media getMediaAtPosition(int i);
|
||||||
|
|
||||||
|
|
@ -392,6 +403,11 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
||||||
//FragmentStatePagerAdapter allows user to swipe across collection of images (no. of images undetermined)
|
//FragmentStatePagerAdapter allows user to swipe across collection of images (no. of images undetermined)
|
||||||
private class MediaDetailAdapter extends FragmentStatePagerAdapter {
|
private class MediaDetailAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps track of the current displayed fragment.
|
||||||
|
*/
|
||||||
|
private Fragment mCurrentFragment;
|
||||||
|
|
||||||
public MediaDetailAdapter(FragmentManager fm) {
|
public MediaDetailAdapter(FragmentManager fm) {
|
||||||
super(fm);
|
super(fm);
|
||||||
}
|
}
|
||||||
|
|
@ -421,5 +437,30 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
||||||
}
|
}
|
||||||
return provider.getTotalMediaCount();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue