2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2020-03-29 16:24:38 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.TextView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.adapters.UserSearchAdapter;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivityAddCollaboratorToRepositoryBinding;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.Authorization;
|
|
|
|
import org.mian.gitnex.models.UserInfo;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.models.UserSearch;
|
2019-06-03 23:25:05 +02:00
|
|
|
import java.util.List;
|
2020-07-07 19:15:01 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-04 20:37:28 +01:00
|
|
|
public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private TextView addCollaboratorSearch;
|
|
|
|
private TextView noData;
|
|
|
|
private ProgressBar mProgressBar;
|
|
|
|
|
|
|
|
private RecyclerView mRecyclerView;
|
|
|
|
|
|
|
|
@Override
|
2020-03-04 20:37:28 +01:00
|
|
|
protected int getLayoutResourceId(){
|
|
|
|
return R.layout.activity_add_collaborator_to_repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2020-04-28 15:47:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
ActivityAddCollaboratorToRepositoryBinding activityAddCollaboratorToRepositoryBinding = ActivityAddCollaboratorToRepositoryBinding.inflate(getLayoutInflater());
|
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
ImageView closeActivity = activityAddCollaboratorToRepositoryBinding.close;
|
|
|
|
addCollaboratorSearch = activityAddCollaboratorToRepositoryBinding.addCollaboratorSearch;
|
|
|
|
mRecyclerView = activityAddCollaboratorToRepositoryBinding.recyclerViewUserSearch;
|
|
|
|
mProgressBar = activityAddCollaboratorToRepositoryBinding.progressBar;
|
|
|
|
noData = activityAddCollaboratorToRepositoryBinding.noData;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
addCollaboratorSearch.requestFocus();
|
|
|
|
assert imm != null;
|
|
|
|
imm.showSoftInput(addCollaboratorSearch, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2020-05-20 20:21:09 +02:00
|
|
|
addCollaboratorSearch.setOnEditorActionListener((v, actionId, event) -> {
|
|
|
|
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2020-05-20 20:21:09 +02:00
|
|
|
if(!addCollaboratorSearch.getText().toString().equals("")) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
|
|
|
mProgressBar.setVisibility(View.VISIBLE);
|
2020-11-02 16:17:00 +01:00
|
|
|
loadUserSearchList(addCollaboratorSearch.getText().toString());
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
public void loadUserSearchList(String searchKeyword) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
Call<UserSearch> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(appCtx)
|
|
|
|
.getUserBySearch(Authorization.get(ctx), searchKeyword, 10);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<UserSearch>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
|
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
mProgressBar.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (response.code() == 200) {
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
assert response.body() != null;
|
2020-04-28 15:47:25 +02:00
|
|
|
getUsersList(response.body().getData(), ctx);
|
2020-10-20 20:09:07 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
Log.i("onResponse", String.valueOf(response.code()));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserSearch> call, @NonNull Throwable t) {
|
2019-11-13 16:52:49 +01:00
|
|
|
Log.i("onFailure", t.toString());
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getUsersList(List<UserInfo> dataList, Context context) {
|
|
|
|
|
|
|
|
UserSearchAdapter adapter = new UserSearchAdapter(dataList, context);
|
|
|
|
|
|
|
|
mRecyclerView.setHasFixedSize(true);
|
2020-04-28 15:47:25 +02:00
|
|
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
2019-06-03 23:25:05 +02:00
|
|
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
|
|
|
DividerItemDecoration.VERTICAL);
|
|
|
|
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
|
|
|
|
|
|
|
mProgressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
if(adapter.getItemCount() > 0) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
mRecyclerView.setAdapter(adapter);
|
|
|
|
noData.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
else {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
noData.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
mProgressBar.setVisibility(View.GONE);
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
2020-05-20 20:21:09 +02:00
|
|
|
onClickListener = view -> finish();
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|