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,6 +349,7 @@ public class BodyFragment extends BackHandledFragment {
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
/* Show update button if role */
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);
......@@ -371,6 +372,7 @@ public class BodyFragment extends BackHandledFragment {
}
});
}
}
/**
* Open body fragment for a body
......
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