Commit d4424583 authored by M M Arif's avatar M M Arif

Merge branch '2-filters' into 'develop'

implemented search filter in org list #2

See merge request mmarif4u/gitnex!5
parents 6e0239c1 05e4f481
......@@ -6,22 +6,26 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.mian.gitnex.R;
import org.mian.gitnex.models.UserOrganizations;
import org.mian.gitnex.util.RoundedTransformation;
import java.util.ArrayList;
import java.util.List;
/**
* Author M M Arif
*/
public class OrganizationsListAdaptor extends RecyclerView.Adapter<OrganizationsListAdaptor.OrganizationsViewHolder> {
public class OrganizationsListAdaptor extends RecyclerView.Adapter<OrganizationsListAdaptor.OrganizationsViewHolder> implements Filterable {
private List<UserOrganizations> orgsList;
private Context mCtx;
private List<UserOrganizations> orgListFull;
static class OrganizationsViewHolder extends RecyclerView.ViewHolder {
......@@ -40,6 +44,7 @@ public class OrganizationsListAdaptor extends RecyclerView.Adapter<Organizations
public OrganizationsListAdaptor(Context mCtx, List<UserOrganizations> orgsListMain) {
this.mCtx = mCtx;
this.orgsList = orgsListMain;
orgListFull = new ArrayList<UserOrganizations>(orgsList);
}
@NonNull
......@@ -70,5 +75,40 @@ public class OrganizationsListAdaptor extends RecyclerView.Adapter<Organizations
return orgsList.size();
}
@Override
public Filter getFilter() {
return orgFilter;
}
private Filter orgFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<UserOrganizations> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(orgListFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (UserOrganizations item : orgListFull) {
if (item.getUsername().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
orgsList.clear();
orgsList.addAll((List) results.values);
notifyDataSetChanged();
}
};
}
......@@ -7,22 +7,27 @@ import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import org.mian.gitnex.R;
import org.mian.gitnex.models.UserRepositories;
import java.util.ArrayList;
import java.util.List;
/**
* Author M M Arif
*/
public class ReposListAdaptor extends RecyclerView.Adapter<ReposListAdaptor.ReposViewHolder> {
public class ReposListAdaptor extends RecyclerView.Adapter<ReposListAdaptor.ReposViewHolder> implements Filterable {
private List<UserRepositories> reposList;
private Context mCtx;
private List<UserRepositories> reposListFull;
static class ReposViewHolder extends RecyclerView.ViewHolder {
......@@ -45,6 +50,7 @@ public class ReposListAdaptor extends RecyclerView.Adapter<ReposListAdaptor.Repo
public ReposListAdaptor(Context mCtx, List<UserRepositories> reposListMain) {
this.mCtx = mCtx;
this.reposList = reposListMain;
reposListFull = new ArrayList<UserRepositories>(reposList);
}
@NonNull
......@@ -82,7 +88,7 @@ public class ReposListAdaptor extends RecyclerView.Adapter<ReposListAdaptor.Repo
}
holder.fullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_24dp);
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
}
else {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
......@@ -95,4 +101,40 @@ public class ReposListAdaptor extends RecyclerView.Adapter<ReposListAdaptor.Repo
return reposList.size();
}
@Override
public Filter getFilter() {
return orgFilter;
}
private Filter orgFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<UserRepositories> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(reposListFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (UserRepositories item : reposListFull) {
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
reposList.clear();
reposList.addAll((List) results.values);
notifyDataSetChanged();
}
};
}
package org.mian.gitnex.fragments;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
......@@ -13,8 +14,13 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.ProgressBar;
import org.mian.gitnex.R;
......@@ -44,6 +50,7 @@ public class OrganizationsFragment extends Fragment {
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleOrganizations));
final View v = inflater.inflate(R.layout.fragment_organizations, container, false);
setHasOptionsMenu(true);
TinyDB tinyDb = new TinyDB(getContext());
final String instanceUrl = tinyDb.getString("instanceUrl");
......@@ -74,6 +81,19 @@ public class OrganizationsFragment extends Fragment {
});
v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
v.getWindowVisibleDisplayFrame(r);
int heightDiff = v.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 500) {
createNewOrganization.setVisibility(View.GONE);
}
}
});
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
......@@ -81,13 +101,11 @@ public class OrganizationsFragment extends Fragment {
createNewOrganization.setVisibility(View.GONE);
} else if (dy < 0 ) {
createNewOrganization.setVisibility(View.VISIBLE);
}
}
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
......@@ -136,4 +154,29 @@ public class OrganizationsFragment extends Fragment {
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.search_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
MenuItem searchItem = menu.findItem(R.id.action_search);
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}
});
}
}
......@@ -22,6 +22,6 @@ public class ProfileFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleProfile));
return inflater.inflate(R.layout.repos_list, container, false);
return inflater.inflate(R.layout.fragment_profile, container, false);
}
}
package org.mian.gitnex.fragments;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
......@@ -12,8 +13,13 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.ProgressBar;
import org.mian.gitnex.R;
......@@ -45,8 +51,9 @@ public class RepositoriesFragment extends Fragment {
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
View v = inflater.inflate(R.layout.fragment_repositories, container, false);
final View v = inflater.inflate(R.layout.fragment_repositories, container, false);
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleRepositories));
setHasOptionsMenu(true);
TinyDB tinyDb = new TinyDB(getContext());
final String instanceUrl = tinyDb.getString("instanceUrl");
......@@ -76,6 +83,19 @@ public class RepositoriesFragment extends Fragment {
});
v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
v.getWindowVisibleDisplayFrame(r);
int heightDiff = v.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 500) {
createNewRepo.setVisibility(View.GONE);
}
}
});
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
......@@ -144,4 +164,29 @@ public class RepositoriesFragment extends Fragment {
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
MenuItem searchItem = menu.findItem(R.id.action_search);
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}
});
}
}
package org.mian.gitnex.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.MainActivity;
import java.util.Objects;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class SettingsFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleSettings));
return inflater.inflate(R.layout.fragment_settings, container, false);
}
}
<vector android:height="24dp" android:tint="#CFCFCF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
</vector>
<vector android:height="24dp" android:tint="#CFCFCF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
......@@ -23,6 +23,7 @@
android:id="@+id/toolbar"
app:titleTextColor="@color/colorWhite"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:elevation="4dp"/>
<FrameLayout
......
......@@ -7,10 +7,9 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Home fragment"
android:text="@string/wip"
android:layout_centerInParent="true"
android:textColor="@color/colorWhite"
android:textSize="30sp"
android:id="@+id/tvEmail"/>
android:textSize="30sp" />
</RelativeLayout>
\ No newline at end of file
......@@ -7,9 +7,9 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Issues fragment"
android:text="@string/wip"
android:layout_centerInParent="true"
android:textColor="@color/colorWhite"
android:textSize="30sp"/>
android:textSize="30sp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wip"
android:layout_centerInParent="true"
android:textColor="@color/colorWhite"
android:textSize="30sp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wip"
android:layout_centerInParent="true"
android:textColor="@color/colorWhite"
android:textSize="30sp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search"
android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
</menu>
\ No newline at end of file
......@@ -24,6 +24,7 @@
<string name="pageTitleNewRepo">Créer un référentiel</string>
<string name="pageTitleOrganizations">Les organisations</string>
<string name="pageTitleIssues">Issues</string>
<string name="pageTitleSettings">Settings</string>
<string name="pageTitleCreateOrganization">Créer une organisation</string>
<!-- page titles -->
......@@ -77,6 +78,8 @@
<string name="orgCreatedError">Une erreur s\'est produite. Veuillez réessayer</string>
<string name="processingText">En traitement</string>
<string name="search">Search</string>
<string name="wip">Work in progress</string>
<string name="close">Fermer</string>
<string name="addNewContent">Add</string>
......
......@@ -34,6 +34,7 @@
<string name="pageTitleNewRepo">Create Repository</string>
<string name="pageTitleOrganizations">Organizations</string>
<string name="pageTitleIssues">Issues</string>
<string name="pageTitleSettings">Settings</string>
<string name="pageTitleCreateOrganization">Create Organization</string>
<!-- page titles -->
......@@ -87,6 +88,8 @@
<string name="orgCreatedError">Something went wrong, please try again</string>
<string name="processingText">Processing</string>
<string name="search">Search</string>
<string name="wip">Work in progress</string>
<string name="close">Close</string>
<string name="addNewContent">Add</string>
......
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