From 69e85db8edca0f575054a10d35da0a7ccec70992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Thu, 25 Oct 2018 11:51:22 +0200 Subject: [PATCH] Add example User list class --- app/src/main/AndroidManifest.xml | 8 +- .../uam/wmi/findmytutor/ListViewAdapter.java | 9 +- .../findmytutor/activity/BaseActivity.java | 41 +-- .../findmytutor/activity/MainActivity.java | 2 + .../activity/NotificationsActivity.java | 266 ------------------ .../activity/UsersListActivity.java | 92 ++++++ .../activity/UsersListFragment.java | 4 + .../wmi/findmytutor/model/PagedResult.java | 18 +- .../wmi/findmytutor/model/ReturnedTutors.java | 122 ++++++++ .../wmi/findmytutor/service/UserService.java | 2 +- .../utils/MyDividerItemDecoration.java | 98 +++++++ .../utils/RecyclerTouchListener.java | 54 ++++ .../wmi/findmytutor/view/TutorsAdapter.java | 75 +++++ app/src/main/res/layout/users_list.xml | 18 ++ app/src/main/res/layout/users_list_main.xml | 18 ++ 15 files changed, 514 insertions(+), 313 deletions(-) delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/utils/MyDividerItemDecoration.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/utils/RecyclerTouchListener.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java create mode 100644 app/src/main/res/layout/users_list.xml create mode 100644 app/src/main/res/layout/users_list_main.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ce8be37..dcdab05 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -44,6 +44,10 @@ android:name=".activity.SharingActivity" android:label="@string/title_activity_sharing" /> + + @@ -55,8 +59,8 @@ /> - - + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java index 8fd91a7..f8fb999 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java @@ -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 { - private MainActivity activity; + private UsersListActivity activity; private List friendList; private List searchList; - public ListViewAdapter(MainActivity context, int resource, List objects) { + public ListViewAdapter(UsersListActivity context, int resource, List objects) { super(context, resource, objects); this.activity = context; this.friendList = objects; @@ -102,8 +103,8 @@ public class ListViewAdapter extends ArrayAdapter { 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); } } } \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index 4b0e776..5ea8808 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -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() { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java index 6d040a3..d21d637 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java @@ -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()); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java deleted file mode 100644 index 6af733e..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java +++ /dev/null @@ -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 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>() { - @Override - public void onSuccess(List 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 { - // 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; } -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java new file mode 100644 index 0000000..a555fca --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -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 () { + @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(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java new file mode 100644 index 0000000..044e7d4 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java @@ -0,0 +1,4 @@ +package com.uam.wmi.findmytutor.activity; + +public class UsersListFragment { +} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResult.java b/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResult.java index db05386..74126c3 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResult.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResult.java @@ -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 results = null; + private List results = null; @SerializedName("currentPage") @Expose private Integer currentPage; @@ -29,11 +30,11 @@ public class PagedResult { @Expose private Integer lastRowOnPage; - public List getResults() { + public Collection getResults() { return results; } - public void setResults(List results) { + public void setResults(List results) { this.results = results; } @@ -86,3 +87,14 @@ public class PagedResult { } } + + + + + + + + + + + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java b/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java new file mode 100644 index 0000000..1f0bf0a --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java @@ -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 tutors = null; + + @SerializedName("blacklistersTutors") + @Expose + private List blacklistersTutors = null; + + public ReturnedTutors tutors(List tutors) { + this.tutors = tutors; + return this; + } + + public ReturnedTutors addTutorsItem(User tutorsItem) { + if (this.tutors == null) { + this.tutors = new ArrayList(); + } + this.tutors.add(tutorsItem); + return this; + } + + /** + * Get tutors + * @return tutors + **/ + + public List getTutors() { + return tutors; + } + + public void setTutors(List tutors) { + this.tutors = tutors; + } + + public ReturnedTutors blacklistersTutors(List blacklistersTutors) { + this.blacklistersTutors = blacklistersTutors; + return this; + } + + public ReturnedTutors addBlacklistersTutorsItem(User blacklistersTutorsItem) { + if (this.blacklistersTutors == null) { + this.blacklistersTutors = new ArrayList(); + } + this.blacklistersTutors.add(blacklistersTutorsItem); + return this; + } + + /** + * Get blacklistersTutors + * @return blacklistersTutors + **/ + @ApiModelProperty(value = "") + public List getBlacklistersTutors() { + return blacklistersTutors; + } + + public void setBlacklistersTutors(List 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 "); + } + +} + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java index a0dbea3..7415de2 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java @@ -74,4 +74,4 @@ public interface UserService { @DELETE("api/users/whitelist/{tutorID}") Completable removeStudentFromWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student); -} +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/MyDividerItemDecoration.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/MyDividerItemDecoration.java new file mode 100644 index 0000000..96a4d62 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/MyDividerItemDecoration.java @@ -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())); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/RecyclerTouchListener.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/RecyclerTouchListener.java new file mode 100644 index 0000000..28aef5d --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/RecyclerTouchListener.java @@ -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); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java new file mode 100644 index 0000000..908c9fc --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java @@ -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 { + + private Context context; + private List 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("•")); + holder.lastName.setText(tutor.getLastName()); + } + + @Override + public int getItemCount() { + return tutorsList.size(); + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/users_list.xml b/app/src/main/res/layout/users_list.xml new file mode 100644 index 0000000..0ab367c --- /dev/null +++ b/app/src/main/res/layout/users_list.xml @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/users_list_main.xml b/app/src/main/res/layout/users_list_main.xml new file mode 100644 index 0000000..f160738 --- /dev/null +++ b/app/src/main/res/layout/users_list_main.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file