mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-26 16:04:07 +08:00
Implemented search ui and screen for exploring repositories.
This commit is contained in:
parent
2fe175223c
commit
d5cffddc72
@ -0,0 +1,214 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.view.ContextThemeWrapper;
|
||||||
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||||
|
import com.squareup.picasso.Picasso;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
|
||||||
|
import org.mian.gitnex.activities.RepoStargazersActivity;
|
||||||
|
import org.mian.gitnex.activities.RepoWatchersActivity;
|
||||||
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepositoriesAdapter.ReposSearchViewHolder> {
|
||||||
|
|
||||||
|
|
||||||
|
private List<UserRepositories> searchedReposList;
|
||||||
|
private Context mCtx;
|
||||||
|
|
||||||
|
public ExploreRepositoriesAdapter(List<UserRepositories> dataList, Context mCtx) {
|
||||||
|
this.mCtx = mCtx;
|
||||||
|
this.searchedReposList = dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ReposSearchViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private ImageView image;
|
||||||
|
private TextView mTextView1;
|
||||||
|
private TextView mTextView2;
|
||||||
|
private TextView fullName;
|
||||||
|
private ImageView repoPrivatePublic;
|
||||||
|
private TextView repoStars;
|
||||||
|
private TextView repoForks;
|
||||||
|
private TextView repoOpenIssuesCount;
|
||||||
|
|
||||||
|
private ReposSearchViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mTextView1 = itemView.findViewById(R.id.repoName);
|
||||||
|
mTextView2 = itemView.findViewById(R.id.repoDescription);
|
||||||
|
image = itemView.findViewById(R.id.imageAvatar);
|
||||||
|
fullName = itemView.findViewById(R.id.repoFullName);
|
||||||
|
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||||
|
repoStars = itemView.findViewById(R.id.repoStars);
|
||||||
|
repoForks = itemView.findViewById(R.id.repoForks);
|
||||||
|
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||||
|
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
|
||||||
|
|
||||||
|
/*itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
Context context = v.getContext();
|
||||||
|
TextView repoFullName = v.findViewById(R.id.repoFullName);
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||||
|
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||||
|
|
||||||
|
TinyDB tinyDb = new TinyDB(context);
|
||||||
|
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||||
|
tinyDb.putBoolean("resumeIssues", true);
|
||||||
|
context.startActivity(intent);
|
||||||
|
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
|
reposDropdownMenu.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
final Context context = v.getContext();
|
||||||
|
Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle);
|
||||||
|
|
||||||
|
PopupMenu popupMenu = new PopupMenu(context_, v);
|
||||||
|
popupMenu.inflate(R.menu.repo_dotted_list_menu);
|
||||||
|
|
||||||
|
Object menuHelper;
|
||||||
|
Class[] argTypes;
|
||||||
|
try {
|
||||||
|
|
||||||
|
Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
|
||||||
|
fMenuHelper.setAccessible(true);
|
||||||
|
menuHelper = fMenuHelper.get(popupMenu);
|
||||||
|
argTypes = new Class[] { boolean.class };
|
||||||
|
menuHelper.getClass().getDeclaredMethod("setForceShowIcon",
|
||||||
|
argTypes).invoke(menuHelper, true);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
popupMenu.show();
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.repoStargazers:
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, RepoStargazersActivity.class);
|
||||||
|
intent.putExtra("repoFullNameForStars", fullName.getText());
|
||||||
|
context.startActivity(intent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.repoWatchers:
|
||||||
|
|
||||||
|
Intent intentW = new Intent(context, RepoWatchersActivity.class);
|
||||||
|
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
|
||||||
|
context.startActivity(intentW);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.repoOpenInBrowser:
|
||||||
|
|
||||||
|
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
|
||||||
|
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
|
||||||
|
context.startActivity(intentOpenInBrowser);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
popupMenu.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ExploreRepositoriesAdapter.ReposSearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.repos_list, parent, false);
|
||||||
|
return new ExploreRepositoriesAdapter.ReposSearchViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull final ExploreRepositoriesAdapter.ReposSearchViewHolder holder, int position) {
|
||||||
|
|
||||||
|
final UserRepositories currentItem = searchedReposList.get(position);
|
||||||
|
|
||||||
|
|
||||||
|
holder.mTextView2.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||||
|
int color = generator.getColor(currentItem.getName());
|
||||||
|
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
|
||||||
|
|
||||||
|
TextDrawable drawable = TextDrawable.builder()
|
||||||
|
.beginConfig()
|
||||||
|
.useFont(Typeface.DEFAULT)
|
||||||
|
.fontSize(18)
|
||||||
|
.toUpperCase()
|
||||||
|
.width(28)
|
||||||
|
.height(28)
|
||||||
|
.endConfig()
|
||||||
|
.buildRoundRect(firstCharacter, color, 3);
|
||||||
|
|
||||||
|
if (currentItem.getAvatar_url() != null) {
|
||||||
|
if (!currentItem.getAvatar_url().equals("")) {
|
||||||
|
Picasso.get().load(currentItem.getAvatar_url()).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||||
|
} else {
|
||||||
|
holder.image.setImageDrawable(drawable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
holder.image.setImageDrawable(drawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.mTextView1.setText(currentItem.getName());
|
||||||
|
if (!currentItem.getDescription().equals("")) {
|
||||||
|
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||||
|
holder.mTextView2.setText(currentItem.getDescription());
|
||||||
|
}
|
||||||
|
holder.fullName.setText(currentItem.getFullname());
|
||||||
|
if(currentItem.getPrivateFlag()) {
|
||||||
|
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
|
||||||
|
}
|
||||||
|
holder.repoStars.setText(currentItem.getStars_count());
|
||||||
|
holder.repoForks.setText(currentItem.getForks_count());
|
||||||
|
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return searchedReposList.size();
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +1,35 @@
|
|||||||
package org.mian.gitnex.fragments;
|
package org.mian.gitnex.fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.MainActivity;
|
import org.mian.gitnex.activities.MainActivity;
|
||||||
import org.mian.gitnex.adapters.MyReposListAdapter;
|
import org.mian.gitnex.adapters.ExploreRepositoriesAdapter;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.models.ExploreRepositories;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.util.AppUtil;
|
import org.mian.gitnex.util.AppUtil;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import org.mian.gitnex.viewmodels.ExploreRepoListViewModel;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+ * Template Author M M Arif
|
+ * Template Author M M Arif
|
||||||
@ -39,16 +38,15 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class ExploreRepositoriesFragment extends Fragment {
|
public class ExploreRepositoriesFragment extends Fragment {
|
||||||
|
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static String repoNameF = "param2";
|
||||||
private static final String ARG_PARAM2 = "param2";
|
private static String repoOwnerF = "param1";
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private MyReposListAdapter adapter;
|
|
||||||
private TextView noData;
|
private TextView noData;
|
||||||
private String searchKeyword = "test"; //test value
|
private TextView searchKeyword;
|
||||||
|
private Boolean repoTypeInclude = true;
|
||||||
private String mParam1;
|
private String sort = "updated";
|
||||||
private String mParam2;
|
private String order = "asc";
|
||||||
|
|
||||||
private OnFragmentInteractionListener mListener;
|
private OnFragmentInteractionListener mListener;
|
||||||
|
|
||||||
@ -58,8 +56,8 @@ public class ExploreRepositoriesFragment extends Fragment {
|
|||||||
public static ExploreRepositoriesFragment newInstance(String param1, String param2) {
|
public static ExploreRepositoriesFragment newInstance(String param1, String param2) {
|
||||||
ExploreRepositoriesFragment fragment = new ExploreRepositoriesFragment();
|
ExploreRepositoriesFragment fragment = new ExploreRepositoriesFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_PARAM1, param1);
|
args.putString(repoOwnerF, param1);
|
||||||
args.putString(ARG_PARAM2, param2);
|
args.putString(repoNameF, param2);
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
@ -68,8 +66,8 @@ public class ExploreRepositoriesFragment extends Fragment {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
String repoName = getArguments().getString(repoNameF);
|
||||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
String repoOwner = getArguments().getString(repoOwnerF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +78,7 @@ public class ExploreRepositoriesFragment extends Fragment {
|
|||||||
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
|
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
|
||||||
|
|
||||||
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
||||||
setHasOptionsMenu(true);
|
//setHasOptionsMenu(true);
|
||||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleExplore));
|
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleExplore));
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(getContext());
|
TinyDB tinyDb = new TinyDB(getContext());
|
||||||
@ -88,42 +86,26 @@ public class ExploreRepositoriesFragment extends Fragment {
|
|||||||
final String loginUid = tinyDb.getString("loginUid");
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
|
|
||||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
searchKeyword = v.findViewById(R.id.searchKeyword);
|
||||||
|
|
||||||
noData = v.findViewById(R.id.noData);
|
noData = v.findViewById(R.id.noData);
|
||||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||||
mRecyclerView = v.findViewById(R.id.recyclerView);
|
mRecyclerView = v.findViewById(R.id.recyclerViewReposSearch);
|
||||||
mRecyclerView.setHasFixedSize(true);
|
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
||||||
|
|
||||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
|
||||||
DividerItemDecoration.VERTICAL);
|
|
||||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
|
||||||
|
|
||||||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
||||||
@Override
|
|
||||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
|
||||||
super.onScrollStateChanged(recyclerView, newState);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(connToInternet) {
|
if(connToInternet) {
|
||||||
|
|
||||||
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
searchKeyword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
new Handler().postDelayed(new Runnable() {
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||||
@Override
|
if(!searchKeyword.getText().toString().equals("")) {
|
||||||
public void run() {
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
swipeRefresh.setRefreshing(false);
|
loadSearchReposList(instanceUrl, instanceToken, loginUid, searchKeyword.getText().toString(), repoTypeInclude, sort, order, getContext());
|
||||||
ExploreRepoListViewModel.loadReposList(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword);
|
|
||||||
}
|
}
|
||||||
}, 50);
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
@ -133,74 +115,59 @@ public class ExploreRepositoriesFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void loadSearchReposList(String instanceUrl, String instanceToken, String loginUid, String searchKeyword, Boolean repoTypeInclude, String sort, String order, final Context context) {
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
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");
|
|
||||||
|
|
||||||
ExploreRepoListViewModel.loadReposList(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword);
|
Call<ExploreRepositories> call = RetrofitClient
|
||||||
|
.getInstance(instanceUrl)
|
||||||
|
.getApiInterface()
|
||||||
|
.queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword, repoTypeInclude, sort, order);
|
||||||
|
|
||||||
}
|
call.enqueue(new Callback<ExploreRepositories>() {
|
||||||
|
|
||||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String searchKeyword) {
|
|
||||||
|
|
||||||
searchKeyword = this.searchKeyword; //test
|
|
||||||
|
|
||||||
ExploreRepoListViewModel RepoModel = new ViewModelProvider(this).get(ExploreRepoListViewModel.class);
|
|
||||||
|
|
||||||
RepoModel.getUserRepositories(instanceUrl, instanceToken, searchKeyword).observe(this, new Observer<List<UserRepositories>>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nullable List<UserRepositories> myReposListMain) {
|
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||||
adapter = new MyReposListAdapter(getContext(), myReposListMain);
|
|
||||||
if(adapter.getItemCount() > 0) {
|
if (response.isSuccessful()) {
|
||||||
mRecyclerView.setAdapter(adapter);
|
assert response.body() != null;
|
||||||
noData.setVisibility(View.GONE);
|
getReposList(response.body().getSearchedData(), context);
|
||||||
|
} else {
|
||||||
|
Log.i("onResponse", String.valueOf(response.code()));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
|
||||||
noData.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||||
|
Log.i("onFailure", t.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void getReposList(List<UserRepositories> dataList, Context context) {
|
||||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
|
ExploreRepositoriesAdapter adapter = new ExploreRepositoriesAdapter(dataList, context);
|
||||||
|
|
||||||
inflater.inflate(R.menu.search_menu, menu);
|
mRecyclerView.setHasFixedSize(true);
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||||
|
DividerItemDecoration.VERTICAL);
|
||||||
|
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
MenuItem searchItem = menu.findItem(R.id.action_search);
|
if(adapter.getItemCount() > 0) {
|
||||||
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
|
|
||||||
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
mRecyclerView.setAdapter(adapter);
|
||||||
searchView.setQueryHint(getContext().getString(R.string.strFilter));
|
noData.setVisibility(View.GONE);
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
if(!connToInternet) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
|
noData.setVisibility(View.VISIBLE);
|
||||||
@Override
|
mProgressBar.setVisibility(View.GONE);
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
if(mRecyclerView.getAdapter() != null) {
|
|
||||||
adapter.getFilter().filter(newText);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package org.mian.gitnex.interfaces;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import org.mian.gitnex.models.AddEmail;
|
import org.mian.gitnex.models.AddEmail;
|
||||||
import org.mian.gitnex.models.Branches;
|
import org.mian.gitnex.models.Branches;
|
||||||
|
import org.mian.gitnex.models.ExploreRepositories;
|
||||||
import org.mian.gitnex.models.Files;
|
import org.mian.gitnex.models.Files;
|
||||||
import org.mian.gitnex.models.NewFile;
|
import org.mian.gitnex.models.NewFile;
|
||||||
import org.mian.gitnex.models.UpdateIssueAssignee;
|
import org.mian.gitnex.models.UpdateIssueAssignee;
|
||||||
@ -213,8 +214,8 @@ public interface ApiInterface {
|
|||||||
@GET("repos/{owner}/{repo}/subscribers") // get all repo watchers
|
@GET("repos/{owner}/{repo}/subscribers") // get all repo watchers
|
||||||
Call<List<UserInfo>> getRepoWatchers(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
Call<List<UserInfo>> getRepoWatchers(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
|
|
||||||
@GET("repos/search") // get all repos who match query string
|
@GET("repos/search") // get all the repos which match the query string
|
||||||
Call<List<UserRepositories>> queryRepos(@Header("Authorization") String token, @Query("q") String searchKeyword, @Query("limit") int limit, @Query("mode") String mode, @Query("sort") String sort, @Query("order") String order);
|
Call<ExploreRepositories> queryRepos(@Header("Authorization") String token, @Query("q") String searchKeyword, @Query("private") Boolean repoTypeInclude, @Query("sort") String sort, @Query("order") String order);
|
||||||
|
|
||||||
@POST("repos/{owner}/{repo}/contents/{file}") // create new file
|
@POST("repos/{owner}/{repo}/contents/{file}") // create new file
|
||||||
Call<JsonElement> createNewFile(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("file") String fileName, @Body NewFile jsonStr);
|
Call<JsonElement> createNewFile(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("file") String fileName, @Body NewFile jsonStr);
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package org.mian.gitnex.models;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ExploreRepositories {
|
||||||
|
|
||||||
|
private ArrayList<UserRepositories> data;
|
||||||
|
private Boolean ok;
|
||||||
|
|
||||||
|
public ArrayList<UserRepositories> getSearchedData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getOk() {
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,74 +0,0 @@
|
|||||||
package org.mian.gitnex.viewmodels;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.Callback;
|
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template Author M M Arif
|
|
||||||
* Author 6543
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ExploreRepoListViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private static MutableLiveData<List<UserRepositories>> reposList;
|
|
||||||
|
|
||||||
public LiveData<List<UserRepositories>> getUserRepositories(String instanceUrl, String token, String searchKeyword) {
|
|
||||||
|
|
||||||
//if (reposList == null) {
|
|
||||||
reposList = new MutableLiveData<>();
|
|
||||||
loadReposList(instanceUrl, token, searchKeyword);
|
|
||||||
//}
|
|
||||||
|
|
||||||
return reposList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void loadReposList(String instanceUrl, String token, String searchKeyword) {
|
|
||||||
|
|
||||||
int limit = 10; //page size of results, maximum page size is 50
|
|
||||||
String mode = ""; //type of repository to search for. Supported values are "fork", "source", “mirror” and “collaborative”
|
|
||||||
String sort = "alpha"; //sort repos by attribute. Supported values are "alpha", "created", "updated", "size", and "id". Default is “alpha”
|
|
||||||
String order = "asc"; //sort order, either “asc” (ascending) or “desc” (descending). Default is "asc", ignored if “sort” is not specified.
|
|
||||||
|
|
||||||
Call<List<UserRepositories>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl)
|
|
||||||
.getApiInterface()
|
|
||||||
.queryRepos(token, searchKeyword, limit, mode, sort, order);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<UserRepositories>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
|
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
if(response.code() == 200) {
|
|
||||||
reposList.postValue(response.body());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<UserRepositories>> call, Throwable t) {
|
|
||||||
Log.i("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".activities.MainActivity">
|
android:background="@color/colorPrimary"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<EditText
|
||||||
android:id="@+id/pullToRefresh"
|
android:id="@+id/searchKeyword"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp"
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
android:textSize="14sp"
|
||||||
android:id="@+id/recyclerView"
|
android:layout_marginStart="10dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_marginEnd="10dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_marginTop="20dp"
|
||||||
android:background="@color/colorPrimary"
|
android:layout_marginBottom="20dp"
|
||||||
android:padding="4dp"
|
android:inputType="text"
|
||||||
android:scrollbars="vertical"
|
android:background="@drawable/shape_inputs"
|
||||||
/>
|
android:textColor="@color/white"
|
||||||
|
android:textColorHint="@color/colorAccent"
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
android:hint="@string/exploreTextBoxHint"
|
||||||
|
android:textColorHighlight="@color/white"
|
||||||
|
android:imeOptions="actionSend" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/noData"
|
android:id="@+id/noData"
|
||||||
@ -27,7 +30,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_margin="15dp"
|
android:layout_margin="15dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/noData"
|
android:text="@string/noDataFound"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
@ -37,8 +40,18 @@
|
|||||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:indeterminate="true"
|
android:indeterminate="true"
|
||||||
android:visibility="visible" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
</RelativeLayout>
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerViewReposSearch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/colorPrimary"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="0dp"
|
||||||
|
android:scrollbars="vertical" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -503,5 +503,6 @@
|
|||||||
<!-- generic copy -->
|
<!-- generic copy -->
|
||||||
|
|
||||||
<string name="translateText">Translate GitNex with Crowdin</string>
|
<string name="translateText">Translate GitNex with Crowdin</string>
|
||||||
|
<string name="exploreTextBoxHint">Explore repositories</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user