Show ContributorsTab only if you have permission to (#402)
add isRepoAdmin extend Adapters add check to RepoDetails refactor var names reformat code Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/402 Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
@@ -30,187 +30,194 @@ import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
+ * Template Author M M Arif
|
||||
+ * Author 6543
|
||||
+ */
|
||||
* + * Template Author M M Arif
|
||||
* + * Author 6543
|
||||
* +
|
||||
*/
|
||||
|
||||
public class ExploreRepositoriesFragment extends Fragment {
|
||||
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noData;
|
||||
private TextView searchKeyword;
|
||||
private Boolean repoTypeInclude = true;
|
||||
private String sort = "updated";
|
||||
private String order = "desc";
|
||||
private int limit = 50;
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noData;
|
||||
private TextView searchKeyword;
|
||||
private Boolean repoTypeInclude = true;
|
||||
private String sort = "updated";
|
||||
private String order = "desc";
|
||||
private int limit = 50;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
public ExploreRepositoriesFragment() {
|
||||
}
|
||||
public ExploreRepositoriesFragment() {
|
||||
|
||||
public static ExploreRepositoriesFragment newInstance(String param1, String param2) {
|
||||
ExploreRepositoriesFragment fragment = new ExploreRepositoriesFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
args.putString(repoNameF, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
String repoName = getArguments().getString(repoNameF);
|
||||
String repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
public static ExploreRepositoriesFragment newInstance(String param1, String param2) {
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
ExploreRepositoriesFragment fragment = new ExploreRepositoriesFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
args.putString(repoNameF, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
||||
//setHasOptionsMenu(true);
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
super.onCreate(savedInstanceState);
|
||||
if(getArguments() != null) {
|
||||
String repoName = getArguments().getString(repoNameF);
|
||||
String repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
|
||||
searchKeyword = v.findViewById(R.id.searchKeyword);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerViewReposSearch);
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
||||
//setHasOptionsMenu(true);
|
||||
|
||||
searchKeyword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
if(!searchKeyword.getText().toString().equals("")) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
loadSearchReposList(instanceUrl, instanceToken, loginUid, searchKeyword.getText().toString(), repoTypeInclude, sort, order, getContext(), limit);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
int limitDefault = 10;
|
||||
loadDefaultList(instanceUrl, instanceToken, loginUid, repoTypeInclude, sort, order, getContext(), limitDefault);
|
||||
searchKeyword = v.findViewById(R.id.searchKeyword);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerViewReposSearch);
|
||||
|
||||
return v;
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
searchKeyword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
|
||||
private void loadDefaultList(String instanceUrl, String instanceToken, String loginUid, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
|
||||
Call<ExploreRepositories> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getContext())
|
||||
.getApiInterface()
|
||||
.queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), null, repoTypeInclude, sort, order, limit);
|
||||
if(actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
if(!searchKeyword.getText().toString().equals("")) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
loadSearchReposList(instanceUrl, instanceToken, loginUid, searchKeyword.getText().toString(), repoTypeInclude, sort, order, getContext(), limit);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
int limitDefault = 10;
|
||||
loadDefaultList(instanceUrl, instanceToken, loginUid, repoTypeInclude, sort, order, getContext(), limitDefault);
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
return v;
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
} else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void loadDefaultList(String instanceUrl, String instanceToken, String loginUid, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
Call<ExploreRepositories> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), null, repoTypeInclude, sort, order, limit);
|
||||
|
||||
});
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
|
||||
private void loadSearchReposList(String instanceUrl, String instanceToken, String loginUid, String searchKeyword, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
if(response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
}
|
||||
else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
Call<ExploreRepositories> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getContext())
|
||||
.getApiInterface()
|
||||
.queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword, repoTypeInclude, sort, order, limit);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
} else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
private void loadSearchReposList(String instanceUrl, String instanceToken, String loginUid, String searchKeyword, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
|
||||
});
|
||||
Call<ExploreRepositories> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword, repoTypeInclude, sort, order, limit);
|
||||
|
||||
}
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
|
||||
private void getReposList(List<UserRepositories> dataList, Context context) {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
|
||||
ExploreRepositoriesAdapter adapter = new ExploreRepositoriesAdapter(dataList, context);
|
||||
if(response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
}
|
||||
else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
|
||||
if(adapter.getItemCount() > 0) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
private void getReposList(List<UserRepositories> dataList, Context context) {
|
||||
|
||||
}
|
||||
ExploreRepositoriesAdapter adapter = new ExploreRepositoriesAdapter(dataList, context);
|
||||
|
||||
}
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
|
||||
public void onButtonPressed(Uri uri) {
|
||||
if (mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
if(adapter.getItemCount() > 0) {
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onButtonPressed(Uri uri) {
|
||||
|
||||
if(mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
|
||||
void onFragmentInteraction(Uri uri);
|
||||
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
void onFragmentInteraction(Uri uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ public class MyRepositoriesFragment extends Fragment {
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final String userLogin = tinyDb.getString("userLogin");
|
||||
tinyDb.putBoolean("isRepoAdmin", true);
|
||||
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user