Commit fe4b5615 authored by Varun Patil's avatar Varun Patil

Show edit body fab only when user has role

parent 18d998ba
......@@ -472,6 +472,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return false;
}
public boolean editBodyAccess(Body toEditBody) {
if (currentUser == null || currentUser.getUserRoles() == null || currentUser.getUserRoles().size() == 0)
return false;
for (Role role : currentUser.getUserRoles()) {
for (Body body : role.getRoleBodies()) {
if (body.getBodyID().equals(toEditBody.getBodyID())) {
return true;
}
}
}
return false;
}
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
......
......@@ -349,27 +349,29 @@ public class BodyFragment extends BackHandledFragment {
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
/* Show update button if role */
final FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab);
fab.setVisibility(View.VISIBLE);
NestedScrollView nsv = (NestedScrollView) getView().findViewById(R.id.body_scrollview);
nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) fab.hide();
else fab.show();
}
});
if (((MainActivity) getActivity()).editBodyAccess(body)) {
final FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab);
fab.setVisibility(View.VISIBLE);
NestedScrollView nsv = (NestedScrollView) getView().findViewById(R.id.body_scrollview);
nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) fab.hide();
else fab.show();
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment();
Bundle bundle = new Bundle();
bundle.putString("bodyId", body.getBodyID());
addEventFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment();
Bundle bundle = new Bundle();
bundle.putString("bodyId", body.getBodyID());
addEventFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment