Add example User list class

This commit is contained in:
Mieszko Wrzeszczyński 2018-10-25 11:51:22 +02:00
parent 1d677ac7e1
commit 69e85db8ed
15 changed files with 514 additions and 313 deletions

View File

@ -44,6 +44,10 @@
android:name=".activity.SharingActivity"
android:label="@string/title_activity_sharing" />
<activity
android:name=".activity.UsersListActivity"
android:label="@string/title_activity_sharing" />
@ -55,8 +59,8 @@
/>
<activity android:name=".activity.ProfileActivity" />
<!--<activity android:name=".activity.MapActivity" />-->
<activity android:name=".activity.NotificationsActivity" />
<!-- &lt;!&ndash;<activity android:name=".activity.MapActivity" />&ndash;&gt;
<activity android:name=".activity.NotificationsActivity" />-->
</application>
</manifest>

View File

@ -12,6 +12,7 @@ import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.uam.wmi.findmytutor.activity.MainActivity;
import com.uam.wmi.findmytutor.activity.UsersListActivity;
import java.util.ArrayList;
import java.util.List;
@ -20,11 +21,11 @@ import java.util.Locale;
public class ListViewAdapter extends ArrayAdapter<String> {
private MainActivity activity;
private UsersListActivity activity;
private List<String> friendList;
private List<String> searchList;
public ListViewAdapter(MainActivity context, int resource, List<String> objects) {
public ListViewAdapter(UsersListActivity context, int resource, List<String> objects) {
super(context, resource, objects);
this.activity = context;
this.friendList = objects;
@ -102,8 +103,8 @@ public class ListViewAdapter extends ArrayAdapter<String> {
private TextView friendName;
public ViewHolder(View v) {
imageView = (ImageView) v.findViewById(R.id.image_view);
friendName = (TextView) v.findViewById(R.id.text);
imageView = v.findViewById(R.id.image_view);
friendName = v.findViewById(R.id.text);
}
}
}

View File

@ -62,31 +62,12 @@ public abstract class BaseActivity
}
private void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
private void setData() {
stringArrayList = new ArrayList<>();
stringArrayList.add("Quynh Trang");
stringArrayList.add("Hoang Bien");
stringArrayList.add("Duc Tuan");
stringArrayList.add("Dang Thanh");
stringArrayList.add("Xuan Luu");
stringArrayList.add("Phan Thanh");
stringArrayList.add("Kim Kien");
stringArrayList.add("Ngo Trang");
stringArrayList.add("Thanh Ngan");
stringArrayList.add("Nguyen Duong");
stringArrayList.add("Quoc Cuong");
stringArrayList.add("Tran Ha");
stringArrayList.add("Vu Danh");
stringArrayList.add("Minh Meo");
}
private void setUpNav() {
drawerLayout = (DrawerLayout) findViewById(R.id.activity_container);
drawerLayout = findViewById(R.id.activity_container);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
@ -171,26 +152,12 @@ public abstract class BaseActivity
} else if (itemId == R.id.nav_profile) {
startActivity(new Intent(this, ProfileActivity.class));
} else if (itemId == R.id.nav_notif) {
startActivity(new Intent(this, NotificationsActivity.class));
startActivity(new Intent(this, UsersListActivity.class));
}
finish();
}, 300);
}, 0);
return true;
// navigationView.postDelayed(() -> {
// int itemId = item.getItemId();
// switch (itemId) {
// case R.id.nav_profile:
// startActivity(new Intent(this, ProfileActivity.class));
// case R.id.nav_map:
// startActivity(new Intent(this, MapActivity.class));
// case R.id.nav_notif:
// startActivity(new Intent(this, NotificationsActivity.class));
// }
//
// finish();
// }, 300);
// return true;
}
private void updateNavigationBarState() {

View File

@ -76,8 +76,10 @@ public class MainActivity extends AppCompatActivity {
setSupportActionBar(toolbar);
setData();
/*
adapter = new ListViewAdapter(this, R.layout.item_listview, stringArrayList);
listView.setAdapter(adapter);
*/
listView.setOnItemClickListener((parent, view, position, id) -> Toast.makeText(MainActivity.this, (String)parent.getItemAtPosition(position), Toast.LENGTH_SHORT).show());

View File

@ -1,266 +0,0 @@
package com.uam.wmi.findmytutor.activity;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
import com.uam.wmi.findmytutor.service.CoordinateService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
public class NotificationsActivity extends BaseActivity implements
OnMapReadyCallback {
private int mInterval = 10000;
private Handler mHandler;
private MapView mapView;
private MapboxMap mapboxMap;
private Map<String,Coordinate> coordsMap = new HashMap<>();
private CoordinateService coordinateService;
private CompositeDisposable disposable = new CompositeDisposable();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_notifications);
// mapInit(savedInstanceState);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));
mapView = findViewById(R.id.mapView2);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
final String authToken = sharedPref.getString("authToken",null);
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
mHandler = new Handler();
// fetchTopCoords();
}
@Override
public void onMapReady(MapboxMap map) {
mapboxMap = map;
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
.position(new LatLng(52.466782,16.927549)));
mStatusChecker.run();
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
// When the user clicks on the map, we want to animate the marker to that
// location.
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(), marker.getPosition(), point);
markerAnimator.setDuration(2000);
markerAnimator.start();
}
});
}
Runnable mStatusChecker = new Runnable() {
@Override
public void run() {
try{
fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
}
};
/*
private void mapInit(Bundle savedInstanceState) {
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));
// This contains the MapView in XML and needs to be called after the access token is configured.
// setContentView(R.layout.activity_notifications);
mapView = (MapView) findViewById(R.id.mapView2);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
.position(new LatLng(52.466782,16.927549)));
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
// When the user clicks on the map, we want to animate the marker to that
// location.
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(), marker.getPosition(), point);
markerAnimator.setDuration(2000);
markerAnimator.start();
}
});
}
});
}*/
private void fetchTopCoords() {
disposable.add(
// coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
@Override
public void onSuccess(List<Coordinate> coordsList) {
for (Coordinate element : coordsList) {
String id = element.getUserId();
Coordinate cord = coordsMap.get(id);
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
Log.d("mapper", "b " + coordsMap.size());
if (cord != null) {
if (!cord.getLongitude().equals(element.getLongitude())
) {
Log.d("mapper", " cos sie zienilo ");
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
.title(cord.getUserId())
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
markerAnimator.setDuration(2000);
markerAnimator.start();
coordsMap.replace(id,element);
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
Log.d("mapper", "update");
Log.d("mapper", " "+cord.getTimeStamp());
Log.d("mapper", " "+element.getTimeStamp());
coordsMap.replace(id,element);
}
} else {
coordsMap.put(id,element);
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
}
}
}
@Override
public void onError(Throwable e) {
Log.e("Error",e.toString());
}
})
);
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
private LatLng latLng = new LatLng();
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
latLng.setLatitude(startValue.getLatitude()
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
latLng.setLongitude(startValue.getLongitude()
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
return latLng;
}
}
@Override
protected int getContentViewId() { return R.layout.activity_notifications; }
@Override
protected int getNavigationMenuItemId() { return R.id.nav_notif; }
}

View File

@ -0,0 +1,92 @@
package com.uam.wmi.findmytutor.activity;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.PagedResult;
import com.uam.wmi.findmytutor.model.ReturnedTutors;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.view.TutorsAdapter;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
public class UsersListActivity extends AppCompatActivity {
private static final String TAG = UsersListActivity.class.getSimpleName();
private UserService apiService;
private CompositeDisposable disposable = new CompositeDisposable();
private TutorsAdapter mAdapter;
private ReturnedTutors tutorsList ;
@BindView(R.id.coordinator_layout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
setContentView(R.layout.users_list);
ButterKnife.bind(this);
apiService = ApiClient.getClient(getApplicationContext())
.create(UserService.class);
mAdapter = new TutorsAdapter(this, tutorsList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
recyclerView.setAdapter(mAdapter);
fetchAllTutors();
}
private void fetchAllTutors() {
disposable.add(
apiService.getPagedTutors("1")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver <PagedResult>() {
@Override
public void onSuccess(PagedResult pagedResult) {
tutorsList = (ReturnedTutors) pagedResult.getResults();
// tutorsList = pagedResult.getResults();
mAdapter.notifyDataSetChanged();
}
@Override
public void onError(Throwable e) {
Log.e("Error",e.toString());
}
}));
}
@Override
protected void onDestroy() {
super.onDestroy();
disposable.dispose();
}
}

View File

@ -0,0 +1,4 @@
package com.uam.wmi.findmytutor.activity;
public class UsersListFragment {
}

View File

@ -3,13 +3,14 @@ package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.Collection;
import java.util.List;
public class PagedResult {
@SerializedName("results")
@Expose
private List<User> results = null;
private List<ReturnedTutors> results = null;
@SerializedName("currentPage")
@Expose
private Integer currentPage;
@ -29,11 +30,11 @@ public class PagedResult {
@Expose
private Integer lastRowOnPage;
public List<User> getResults() {
public Collection<ReturnedTutors> getResults() {
return results;
}
public void setResults(List<User> results) {
public void setResults(List<ReturnedTutors> results) {
this.results = results;
}
@ -86,3 +87,14 @@ public class PagedResult {
}
}

View File

@ -0,0 +1,122 @@
package com.uam.wmi.findmytutor.model;
import java.util.Objects;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
/**
* ReturnedTutors
*/
public class ReturnedTutors {
@SerializedName("tutors")
@Expose
private List<User> tutors = null;
@SerializedName("blacklistersTutors")
@Expose
private List<User> blacklistersTutors = null;
public ReturnedTutors tutors(List<User> tutors) {
this.tutors = tutors;
return this;
}
public ReturnedTutors addTutorsItem(User tutorsItem) {
if (this.tutors == null) {
this.tutors = new ArrayList<User>();
}
this.tutors.add(tutorsItem);
return this;
}
/**
* Get tutors
* @return tutors
**/
public List<User> getTutors() {
return tutors;
}
public void setTutors(List<User> tutors) {
this.tutors = tutors;
}
public ReturnedTutors blacklistersTutors(List<User> blacklistersTutors) {
this.blacklistersTutors = blacklistersTutors;
return this;
}
public ReturnedTutors addBlacklistersTutorsItem(User blacklistersTutorsItem) {
if (this.blacklistersTutors == null) {
this.blacklistersTutors = new ArrayList<User>();
}
this.blacklistersTutors.add(blacklistersTutorsItem);
return this;
}
/**
* Get blacklistersTutors
* @return blacklistersTutors
**/
@ApiModelProperty(value = "")
public List<User> getBlacklistersTutors() {
return blacklistersTutors;
}
public void setBlacklistersTutors(List<User> blacklistersTutors) {
this.blacklistersTutors = blacklistersTutors;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ReturnedTutors returnedTutors = (ReturnedTutors) o;
return Objects.equals(this.tutors, returnedTutors.tutors) &&
Objects.equals(this.blacklistersTutors, returnedTutors.blacklistersTutors);
}
@Override
public int hashCode() {
return Objects.hash(tutors, blacklistersTutors);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ReturnedTutors {\n");
sb.append(" tutors: ").append(toIndentedString(tutors)).append("\n");
sb.append(" blacklistersTutors: ").append(toIndentedString(blacklistersTutors)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -0,0 +1,98 @@
package com.uam.wmi.findmytutor.utils;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
public class MyDividerItemDecoration extends RecyclerView.ItemDecoration {
private static final int[] ATTRS = new int[]{
android.R.attr.listDivider
};
public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
private Drawable mDivider;
private int mOrientation;
private Context context;
private int margin;
public MyDividerItemDecoration(Context context, int orientation, int margin) {
this.context = context;
this.margin = margin;
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();
setOrientation(orientation);
}
public void setOrientation(int orientation) {
if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
throw new IllegalArgumentException("invalid orientation");
}
mOrientation = orientation;
}
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == VERTICAL_LIST) {
drawVertical(c, parent);
} else {
drawHorizontal(c, parent);
}
}
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left + dpToPx(margin), top, right - dpToPx(margin), bottom);
mDivider.draw(c);
}
}
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top + dpToPx(margin), right, bottom - dpToPx(margin));
mDivider.draw(c);
}
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
private int dpToPx(int dp) {
Resources r = context.getResources();
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()));
}
}

View File

@ -0,0 +1,54 @@
package com.uam.wmi.findmytutor.utils;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
private ClickListener clicklistener;
private GestureDetector gestureDetector;
public RecyclerTouchListener(Context context, final RecyclerView recycleView, final ClickListener clicklistener) {
this.clicklistener = clicklistener;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
View child = recycleView.findChildViewUnder(e.getX(), e.getY());
if (child != null && clicklistener != null) {
clicklistener.onLongClick(child, recycleView.getChildAdapterPosition(child));
}
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clicklistener != null && gestureDetector.onTouchEvent(e)) {
clicklistener.onClick(child, rv.getChildAdapterPosition(child));
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
public interface ClickListener {
void onClick(View view, int position);
void onLongClick(View view, int position);
}
}

View File

@ -0,0 +1,75 @@
package com.uam.wmi.findmytutor.view;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.ReturnedTutors;
import com.uam.wmi.findmytutor.model.User;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class TutorsAdapter extends RecyclerView.Adapter<TutorsAdapter.MyViewHolder> {
private Context context;
private List<User> tutorsList;
public class MyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.firstName)
TextView firstName;
@BindView(R.id.lastName)
TextView lastName;
@BindView(R.id.isOnline)
TextView isOnline;
public MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
public TutorsAdapter(Context context, ReturnedTutors tutors) {
this.context = context;
this.tutorsList = tutors.getTutors();
Log.e("USERS", String.valueOf(tutors.getTutors()));
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.tutor_list_row, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
User tutor = tutorsList.get(position);
Log.e("tutor", tutor.toString());
holder.firstName.setText(tutor.getFirstName());
holder.isOnline.setText(Html.fromHtml("&#8226;"));
holder.lastName.setText(tutor.getLastName());
}
@Override
public int getItemCount() {
return tutorsList.size();
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coordinator_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.UsersListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include layout="@layout/users_list_main" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.UsersListActivity"
tools:showIn="@layout/users_list_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>