Skip to content

Fixes #3732 Achievements: redirecting to the proper fragment #3805

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

Closed
wants to merge 1 commit into from
Closed
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
@@ -1,8 +1,10 @@
package fr.free.nrw.commons.contributions;

import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -12,6 +14,7 @@
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -164,26 +167,44 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse

@Override
public void onPageSelected(int position) {
switch (position) {
switch (position){
case CONTRIBUTIONS_TAB_POSITION:
Timber.d("Contributions tab selected");
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
isContributionsFragmentVisible = true;
ViewUtil.hideKeyboard(tabLayout.getRootView());
updateMenuItem();
selectScreen(true, "Contributions");
break;
case NEARBY_TAB_POSITION:
Timber.d("Nearby tab selected");
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
isContributionsFragmentVisible = false;
updateMenuItem();
if (ContextCompat.checkSelfPermission(
MainActivity.this, permission.ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED) {
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
Timber.d("Nearby tab selected");
selectScreen(false, "Nearby location granted");
} else {
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
Timber.d("Contributions tab redirected");
selectScreen(true, "Nearby location not granted");
}
break;
default:
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
break;
}
}

/*
* This method allow us to display the correct fragment according to
* the Permission request
* @param contributionsFragmentFlag
* @param message
*/

public void selectScreen(boolean contributionsFragmentFlag, String message){
isContributionsFragmentVisible = contributionsFragmentFlag;
ViewUtil.hideKeyboard(tabLayout.getRootView());
ViewUtil.showShortToast(MainActivity.this, message);
updateMenuItem();
}

@Override
public void onPageScrollStateChanged(int state) {

Expand Down Expand Up @@ -312,6 +333,7 @@ private void updateMenuItem() {
menu.findItem(R.id.notifications).setVisible(true);
menu.findItem(R.id.list_sheet).setVisible(false);
Timber.d("Contributions fragment notifications menu item is visible");

} else {
// Display bottom list menu item
menu.findItem(R.id.notifications).setVisible(false);
Expand Down