Skip to content
Snippets Groups Projects
Commit 8ed30f55 authored by Jawnnypoo's avatar Jawnnypoo
Browse files

Adding a user now working properly!

parent 44732ef9
No related branches found
No related tags found
No related merge requests found
Showing with 56 additions and 168 deletions
Loading
Loading
@@ -20,6 +20,7 @@ import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.NewUserAdapter;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.dialogs.UserRoleDialog;
import com.commit451.gitlab.events.UserAddedEvent;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.KeyboardUtil;
 
Loading
Loading
@@ -108,10 +109,16 @@ public class AddUserActivity extends BaseActivity {
@Override
public void onResponse(Response<User> response) {
if (!response.isSuccess()) {
//Conflict
if (response.code() == 409) {
Toast.makeText(AddUserActivity.this, R.string.error_user_conflict, Toast.LENGTH_SHORT).show();
}
return;
}
Toast.makeText(AddUserActivity.this, "User added successfully", Toast.LENGTH_SHORT).show();
Toast.makeText(AddUserActivity.this, R.string.user_added_successfully, Toast.LENGTH_SHORT).show();
mUserRoleDialog.dismiss();
finish();
GitLabApp.bus().post(new UserAddedEvent(response.body()));
}
 
@Override
Loading
Loading
Loading
Loading
@@ -69,8 +69,8 @@ public class NewUserAdapter extends RecyclerView.Adapter<UserViewHolder> {
}
 
public void addUser(User user) {
mValues.add(user);
notifyItemInserted(mValues.size() - 1);
mValues.add(0, user);
notifyItemInserted(0);
}
 
public void removeUser(long userId) {
Loading
Loading
package com.commit451.gitlab.dialogs;
import android.content.Context;
import android.support.v7.app.AppCompatDialog;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.UserAdapter;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit.Callback;
import retrofit.Response;
import timber.log.Timber;
/**
* Collabs FTW
* Created by Jawn on 8/16/2015.
*/
public class NewUserDialog extends AppCompatDialog {
@Bind(R.id.user_spinner) Spinner userSpinner;
@Bind(R.id.role_spinner) Spinner roleSpinner;
@Bind(R.id.progress) View progress;
public NewUserDialog(Context context) {
super(context);
setContentView(R.layout.dialog_add_user);
ButterKnife.bind(this);
UserAdapter adapter = new UserAdapter(getContext(), Repository.users);
userSpinner.setAdapter(adapter);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(getContext(),
R.array.role_names,
android.R.layout.simple_spinner_dropdown_item);
roleSpinner.setAdapter(adapter2);
}
@OnClick(R.id.add_button)
public void onAddClick() {
if(GitLabApp.instance().getSelectedProject().getGroup() == null) {
return;
}
progress.setVisibility(View.VISIBLE);
progress.setAlpha(0.0f);
progress.animate().alpha(1.0f);
long userId = ((User) userSpinner.getSelectedItem()).getId();
String accessLevel = getContext().getResources().getStringArray(R.array.role_values)[roleSpinner.getSelectedItemPosition()];
GitLabClient.instance().addGroupMember(GitLabApp.instance().getSelectedProject().getGroup().getId(), userId, accessLevel).enqueue(userCallback);
}
private Callback<User> userCallback = new Callback<User>() {
@Override
public void onResponse(Response<User> response) {
if (!response.isSuccess()) {
return;
}
progress.setVisibility(View.GONE);
if(response.body().getId() != 0) {
//TODO tell the parent to add the user to the list
}
else {
Toast.makeText(getContext(), getContext().getString(R.string.user_error), Toast.LENGTH_SHORT)
.show();
}
dismiss();
}
@Override
public void onFailure(Throwable t) {
Timber.e(t.toString());
progress.setVisibility(View.GONE);
Toast.makeText(getContext(), getContext().getString(R.string.user_error), Toast.LENGTH_SHORT)
.show();
dismiss();
}
};
@OnClick(R.id.cancel_button)
public void onCancelClick() {
this.dismiss();
}
}
Loading
Loading
@@ -4,6 +4,7 @@ import android.content.Context;
import android.support.v7.app.AppCompatDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;
 
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.ProjectAccessAdapter;
Loading
Loading
@@ -23,11 +24,20 @@ public class UserRoleDialog extends AppCompatDialog {
 
@Bind(R.id.list) RecyclerView mRecyclerView;
ProjectAccessAdapter mAdapter;
String[] mRoleNames;
String[] mRoleValues;
 
private final ProjectAccessAdapter.Listener mAccessListener = new ProjectAccessAdapter.Listener() {
@Override
public void onAccessLevelClicked(String accessLevel) {
mListener.onAccessLevelClicked(accessLevel);
for (int i=0; i<mRoleNames.length; i++) {
if (mRoleNames[i].equals(accessLevel)) {
mListener.onAccessLevelClicked(mRoleValues[i]);
return;
}
}
Toast.makeText(getContext(), R.string.user_error, Toast.LENGTH_SHORT)
.show();
}
};
 
Loading
Loading
@@ -35,6 +45,8 @@ public class UserRoleDialog extends AppCompatDialog {
super(context);
setContentView(R.layout.dialog_user_role);
ButterKnife.bind(this);
mRoleValues = getContext().getResources().getStringArray(R.array.role_values);
mRoleNames = getContext().getResources().getStringArray(R.array.role_names);
mListener = listener;
mAdapter = new ProjectAccessAdapter(getContext(), mAccessListener);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
Loading
Loading
package com.commit451.gitlab.events;
import com.commit451.gitlab.model.User;
/**
* Indicates that a user was added
* Created by Jawn on 9/17/2015.
*/
public class UserAddedEvent {
public User user;
public UserAddedEvent(User user) {
this.user = user;
}
}
Loading
Loading
@@ -15,8 +15,8 @@ import com.commit451.gitlab.R;
import com.commit451.gitlab.activities.AddUserActivity;
import com.commit451.gitlab.adapter.NewUserAdapter;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.dialogs.NewUserDialog;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.events.UserAddedEvent;
import com.commit451.gitlab.model.User;
import com.squareup.otto.Subscribe;
 
Loading
Loading
@@ -138,7 +138,6 @@ public class UsersFragment extends BaseFragment implements SwipeRefreshLayout.On
@OnClick(R.id.add_user_button)
public void onAddUserClick() {
startActivity(AddUserActivity.newInstance(getActivity()));
new NewUserDialog(getActivity()).show();
}
 
private class EventReceiver {
Loading
Loading
@@ -147,5 +146,12 @@ public class UsersFragment extends BaseFragment implements SwipeRefreshLayout.On
public void onProjectChanged(ProjectChangedEvent event) {
loadData();
}
@Subscribe
public void onUserAdded(UserAddedEvent event) {
if (mAdapter != null) {
mAdapter.addUser(event.user);
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:id="@+id/user_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<Spinner
android:id="@+id/role_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<View
android:id="@+id/lsep"
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/dividerHorizontal" />
<LinearLayout
android:id="@+id/lin"
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/cancel_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="true"
android:text="@string/cancel_button" />
<Button
android:id="@+id/add_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="true"
android:text="@string/add_button" />
</LinearLayout>
</LinearLayout>
<include layout="@layout/progress" />
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
android:orientation="vertical"
android:layout_width="256dp"
android:layout_height="300dp">
 
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/set_project_access"
android:id="@+id/textView" />
Loading
Loading
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView" />
\ No newline at end of file
android:padding="16dp"
android:id="@+id/textView"
android:background="?attr/selectableItemBackground"/>
\ No newline at end of file
Loading
Loading
@@ -54,6 +54,7 @@
<string name="not_in_group">User management is only available for projects that are assigned to groups</string>
<string name="error_could_not_share">Could not share the link</string>
<string name="error_no_browser">No browser on device. What are you doing?</string>
<string name="error_user_conflict">There is a conflict in adding this user.</string>
 
<string name="required_field">Required Field</string>
<!-- General -->
Loading
Loading
@@ -93,6 +94,7 @@
<string name="no_users_found">No users found.</string>
<string name="search_for_user">Search for user</string>
<string name="set_project_access">Project Access</string>
<string name="user_added_successfully">User added successfully</string>
 
<string-array name="role_names">
<item>Guest</item>
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment