Add search to list
This commit is contained in:
parent
7191fcf6e7
commit
aa3dbfb185
@ -57,6 +57,5 @@ dependencies {
|
||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
||||
implementation 'com.annimon:stream:1.2.1'
|
||||
implementation 'com.facebook.shimmer:shimmer:0.3.0'
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
@ -13,14 +13,10 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.uam.wmi.findmytutor.ListViewAdapter;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
@ -32,17 +28,13 @@ public abstract class BaseActivity
|
||||
implements BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
protected BottomNavigationView navigationView;
|
||||
|
||||
protected Toolbar toolbar;
|
||||
|
||||
public DrawerLayout drawerLayout;
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
// 4 search
|
||||
private ListView listView;
|
||||
private ArrayList<String> stringArrayList;
|
||||
private ListViewAdapter adapter;
|
||||
|
||||
private SharingFragment sharingFragment;
|
||||
private Fragment userListFragment;
|
||||
private String activeFragment = "";
|
||||
|
||||
|
||||
@Override
|
||||
@ -54,14 +46,12 @@ public abstract class BaseActivity
|
||||
navigationView.setOnNavigationItemSelectedListener(this);
|
||||
sharingFragment = new SharingFragment();
|
||||
userListFragment = new UsersListActivity();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int layoutResID) {
|
||||
DrawerLayout fullView = (DrawerLayout) getLayoutInflater().inflate(R.layout.base_activity, null);
|
||||
FrameLayout activityContainer = (FrameLayout) fullView.findViewById(R.id.activity_content);
|
||||
FrameLayout activityContainer = fullView.findViewById(R.id.activity_content);
|
||||
getLayoutInflater().inflate(layoutResID, activityContainer, true);
|
||||
super.setContentView(fullView);
|
||||
|
||||
@ -69,7 +59,7 @@ public abstract class BaseActivity
|
||||
}
|
||||
|
||||
private void initToolbar() {
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
@ -117,12 +107,10 @@ public abstract class BaseActivity
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (TextUtils.isEmpty(newText)) {
|
||||
adapter.filter("");
|
||||
listView.clearTextFilter();
|
||||
} else {
|
||||
adapter.filter(newText);
|
||||
if(activeFragment.equals("userList")){
|
||||
((UsersListActivity) userListFragment).searchUser(newText);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@ -150,15 +138,10 @@ public abstract class BaseActivity
|
||||
overridePendingTransition(0,0);
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.activity_content, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void removeFragment(Fragment fragment) {
|
||||
activeFragment = "map";
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.remove(fragment);
|
||||
fragmentTransaction.hide(fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@ -171,16 +154,10 @@ public abstract class BaseActivity
|
||||
if (itemId == R.id.nav_map) {
|
||||
removeFragment(sharingFragment);
|
||||
removeFragment(userListFragment);
|
||||
// startActivity(new Intent(this, MapActivity.class));
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
// startActivity(new Intent(this, ProfileActivity.class));
|
||||
setFragment(sharingFragment);
|
||||
removeFragment(userListFragment);
|
||||
|
||||
loadUserSettingsFragment();
|
||||
} else if (itemId == R.id.nav_user_list) {
|
||||
removeFragment(sharingFragment);
|
||||
setFragment(userListFragment);
|
||||
//startActivity(new Intent(this, UsersListActivity.class));
|
||||
loadUserListFragment();
|
||||
}
|
||||
//finish();
|
||||
}, 300);
|
||||
@ -188,6 +165,24 @@ public abstract class BaseActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
private void loadUserSettingsFragment() {
|
||||
activeFragment = "sharedSettings";
|
||||
sharingFragment = SharingFragment.newInstance();
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.activity_content, sharingFragment);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
private void loadUserListFragment() {
|
||||
activeFragment = "userList";
|
||||
|
||||
userListFragment = UsersListActivity.newInstance();
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.activity_content, userListFragment);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
|
||||
private void updateNavigationBarState() {
|
||||
int actionId = getNavigationMenuItemId();
|
||||
selectBottomNavigationBarItem(actionId);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
@ -21,6 +22,7 @@ import java.util.Set;
|
||||
//}
|
||||
|
||||
public class SharingFragment extends PreferenceFragment {
|
||||
@SuppressLint("ResourceType")
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -46,6 +48,13 @@ public class SharingFragment extends PreferenceFragment {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static SharingFragment newInstance() {
|
||||
|
||||
return new SharingFragment();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
@ -53,19 +53,28 @@ public class UsersListActivity extends Fragment {
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
@BindView(R.id.txt_empty_notes_view)
|
||||
TextView noNotesView;
|
||||
|
||||
private UserService userService;
|
||||
private TutorTabApi tutorTabService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private TutorsAdapter mAdapter;
|
||||
private List<User> tutorsList = new ArrayList<>();
|
||||
private List<User> tutorsFiltered = new ArrayList<>();
|
||||
|
||||
public static UsersListActivity newInstance() {
|
||||
|
||||
return new UsersListActivity();
|
||||
}
|
||||
|
||||
public UsersListActivity() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mAdapter = new TutorsAdapter(getActivity().getApplicationContext(), tutorsList);
|
||||
mAdapter = new TutorsAdapter(getActivity().getApplicationContext(), tutorsFiltered);
|
||||
View view = inflater.inflate(R.layout.users_list, container, false);
|
||||
view.setBackgroundColor(getResources().getColor(android.R.color.white));
|
||||
return view;
|
||||
@ -81,11 +90,10 @@ public class UsersListActivity extends Fragment {
|
||||
tutorTabService = ApiClient.getClient(getActivity().getApplicationContext())
|
||||
.create(TutorTabApi.class);
|
||||
|
||||
|
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
|
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerView.setLayoutManager(mLayoutManager);
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(getActivity().getApplicationContext(), LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
fetchAllTutors();
|
||||
@ -94,21 +102,30 @@ public class UsersListActivity extends Fragment {
|
||||
recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position) {
|
||||
showNoteDialog(true, tutorsList.get(position), position);
|
||||
showNoteDialog(tutorsFiltered.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(View view, int position) {
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void searchUser( String textToSearch){
|
||||
Log.e("SEARCH","textToSearch");
|
||||
|
||||
private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) {
|
||||
tutorsFiltered.clear();
|
||||
tutorsFiltered.addAll(Stream.of(tutorsList).filter(t -> t.toSearchString().contains(textToSearch)).toList());
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void showNoteDialog(final User user) {
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
|
||||
View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null);
|
||||
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity().getApplicationContext());
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity());
|
||||
alertDialogBuilderUserInput.setView(view);
|
||||
|
||||
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||
@ -135,11 +152,13 @@ public class UsersListActivity extends Fragment {
|
||||
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
|
||||
.map(DutyHourViewModel::getSummary).toList();
|
||||
|
||||
Log.e("DUTY",dutyHoursList.toString());
|
||||
|
||||
userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom()));
|
||||
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
|
||||
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
|
||||
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity().getApplicationContext(),
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),
|
||||
android.R.layout.simple_list_item_activated_1, dutyHoursList);
|
||||
|
||||
userDutyHours.setAdapter(arrayAdapter);
|
||||
@ -183,10 +202,11 @@ public class UsersListActivity extends Fragment {
|
||||
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> users) {
|
||||
//toggleEmptyNotes();
|
||||
tutorsList.clear();
|
||||
tutorsList.addAll(users);
|
||||
tutorsFiltered.addAll(users);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
toggleEmptyNotes();
|
||||
|
||||
}
|
||||
|
||||
@ -217,13 +237,13 @@ public class UsersListActivity extends Fragment {
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
/* private void toggleEmptyNotes() {
|
||||
private void toggleEmptyNotes() {
|
||||
if (tutorsList.size() > 0) {
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
} else {
|
||||
noNotesView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
@ -254,4 +274,6 @@ public class UsersListActivity extends Fragment {
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,17 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_empty_notes_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/margin_top_no_notes"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:text="@string/there_is_no_users_in_system"
|
||||
android:textColor="@color/msg_no_notes"
|
||||
android:textSize="@dimen/msg_no_notes" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user