Working user list

This commit is contained in:
Mieszko Wrzeszczyński 2018-10-26 13:57:50 +02:00
parent 5dab4eaf4b
commit aa6810a633
22 changed files with 873 additions and 16 deletions

View File

@ -48,6 +48,11 @@
android:label="@string/title_activity_sharing" android:label="@string/title_activity_sharing"
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<activity
android:name=".activity.UsersListActivity"
android:label="@string/title_activity_sharing"
android:launchMode="singleTop" />
<service <service
android:name=".service.BackgroundLocalizationService" android:name=".service.BackgroundLocalizationService"
android:exported="false" android:exported="false"

View File

@ -1,6 +1,7 @@
package com.uam.wmi.findmytutor; package com.uam.wmi.findmytutor;
import android.app.Activity; import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -16,6 +17,7 @@ import com.uam.wmi.findmytutor.activity.MainActivity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
public class ListViewAdapter extends ArrayAdapter<String> { public class ListViewAdapter extends ArrayAdapter<String> {
@ -47,8 +49,9 @@ public class ListViewAdapter extends ArrayAdapter<String> {
return position; return position;
} }
@NonNull
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ViewHolder holder; ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// If holder not exist then locate all view from UI file. // If holder not exist then locate all view from UI file.
@ -67,11 +70,11 @@ public class ListViewAdapter extends ArrayAdapter<String> {
holder.friendName.setText(getItem(position)); holder.friendName.setText(getItem(position));
//get first letter of each String item //get first letter of each String item
String firstLetter = String.valueOf(getItem(position).charAt(0)); String firstLetter = String.valueOf(Objects.requireNonNull(getItem(position)).charAt(0));
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate random color // generate random color
int color = generator.getColor(getItem(position)); int color = generator.getColor(Objects.requireNonNull(getItem(position)));
TextDrawable drawable = TextDrawable.builder() TextDrawable drawable = TextDrawable.builder()
.buildRound(firstLetter, color); // radius in px .buildRound(firstLetter, color); // radius in px
@ -101,7 +104,7 @@ public class ListViewAdapter extends ArrayAdapter<String> {
private ImageView imageView; private ImageView imageView;
private TextView friendName; private TextView friendName;
public ViewHolder(View v) { ViewHolder(View v) {
imageView = (ImageView) v.findViewById(R.id.image_view); imageView = (ImageView) v.findViewById(R.id.image_view);
friendName = (TextView) v.findViewById(R.id.text); friendName = (TextView) v.findViewById(R.id.text);
} }

View File

@ -191,7 +191,7 @@ public abstract class BaseActivity
setFragment(sharingFragment); setFragment(sharingFragment);
} else if (itemId == R.id.nav_notif) { } else if (itemId == R.id.nav_notif) {
startActivity(new Intent(this, NotificationsActivity.class)); startActivity(new Intent(this, UsersListActivity.class));
} }
//finish(); //finish();
}, 300); }, 300);

View File

@ -0,0 +1,111 @@
package com.uam.wmi.findmytutor.activity;
import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.uam.wmi.findmytutor.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class ListViewAdapter extends ArrayAdapter<String> {
private UsersListActivity activity;
private List<String> friendList;
private List<String> searchList;
public ListViewAdapter(UsersListActivity context, int resource, List<String> objects) {
super(context, resource, objects);
this.activity = context;
this.friendList = objects;
this.searchList = new ArrayList<>();
this.searchList.addAll(friendList);
}
@Override
public int getCount() {
return friendList.size();
}
@Override
public String getItem(int position) {
return friendList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// If holder not exist then locate all view from UI file.
if (convertView == null) {
// inflate UI from XML file
convertView = inflater.inflate(R.layout.item_listview, parent, false);
// get all UI view
holder = new ViewHolder(convertView);
// set tag for holder
convertView.setTag(holder);
} else {
// if holder created, get tag from view
holder = (ViewHolder) convertView.getTag();
}
holder.friendName.setText(getItem(position));
//get first letter of each String item
String firstLetter = String.valueOf(Objects.requireNonNull(getItem(position)).charAt(0));
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate random color
int color = generator.getColor(Objects.requireNonNull(getItem(position)));
TextDrawable drawable = TextDrawable.builder()
.buildRound(firstLetter, color); // radius in px
holder.imageView.setImageDrawable(drawable);
return convertView;
}
// Filter method
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
friendList.clear();
if (charText.length() == 0) {
friendList.addAll(searchList);
} else {
for (String s : searchList) {
if (s.toLowerCase(Locale.getDefault()).contains(charText)) {
friendList.add(s);
}
}
}
notifyDataSetChanged();
}
private class ViewHolder {
private ImageView imageView;
private TextView friendName;
public ViewHolder(View v) {
imageView = v.findViewById(R.id.image_view);
friendName = v.findViewById(R.id.text);
}
}
}

View File

@ -395,7 +395,9 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
.subscribeWith(new DisposableSingleObserver<JwtToken>() { .subscribeWith(new DisposableSingleObserver<JwtToken>() {
@Override @Override
public void onSuccess(JwtToken jwtToken) { public void onSuccess(JwtToken jwtToken) {
String token = jwtToken.getToken(); //String token = jwtToken.getToken();
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzY2QyMWFlYi00ZGRmLTQ0YTktOWM3OC1kNGE3MjVlN2MwNDkiLCJzdWIiOiJhc2RAYXNkc2FkYWEiLCJqdGkiOiIwMDMzYWZhMy0yNDZhLTQ1YTYtOWZmYi1lNzhiYjg3MDMzMmIiLCJleHAiOjE1NDMxMzUwNjAsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.rzks6-yjvVuYoO0pdiBwAfqDnMg8C8XrM9eA4h692m0";
JWT jwt = new JWT(token); JWT jwt = new JWT(token);
Claim role = jwt.getClaim("nameid"); Claim role = jwt.getClaim("nameid");

View File

@ -0,0 +1,95 @@
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.PagedResultReturnedTutors;
import com.uam.wmi.findmytutor.model.Tutor;
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 List<Tutor> tutorsList = new ArrayList<>();
@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);
fetchAllTutors();
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);
}
private void fetchAllTutors() {
disposable.add(
apiService.getPagedTutors(1)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver <PagedResultReturnedTutors>() {
@Override
public void onSuccess(PagedResultReturnedTutors pagedResult) {
tutorsList.clear();
tutorsList.addAll(pagedResult.getResults().getTutors());
mAdapter.notifyDataSetChanged();
Log.e("TUTORS", String.valueOf(pagedResult.getResults().getTutors()));
}
@Override
public void onError(Throwable e) {
Log.e("TUTORS_Error",e.toString());
}
}));
}
@Override
protected void onDestroy() {
super.onDestroy();
disposable.dispose();
}
}

View File

@ -11,7 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
* LdapUser * LdapUser
*/ */
public class LdapUser extends BaseResponse{ public class LdapUser extends BaseResponse {
@SerializedName("login") @SerializedName("login")
private String login = null; private String login = null;

View File

@ -1,3 +1,4 @@
/*
package com.uam.wmi.findmytutor.model; package com.uam.wmi.findmytutor.model;
@ -14,3 +15,4 @@ public class Model
} }
} }
*/

View File

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

View File

@ -0,0 +1,89 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.uam.wmi.findmytutor.model.Results;
public class PagedResultReturnedTutors extends BaseResponse{
@SerializedName("results")
@Expose
private Results results;
@SerializedName("currentPage")
@Expose
private Integer currentPage;
@SerializedName("pageCount")
@Expose
private Integer pageCount;
@SerializedName("pageSize")
@Expose
private Integer pageSize;
@SerializedName("rowCount")
@Expose
private Integer rowCount;
@SerializedName("firstRowOnPage")
@Expose
private Integer firstRowOnPage;
@SerializedName("lastRowOnPage")
@Expose
private Integer lastRowOnPage;
public Results getResults() {
return results;
}
public void setResults(Results results) {
this.results = results;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageCount() {
return pageCount;
}
public void setPageCount(Integer pageCount) {
this.pageCount = pageCount;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getRowCount() {
return rowCount;
}
public void setRowCount(Integer rowCount) {
this.rowCount = rowCount;
}
public Integer getFirstRowOnPage() {
return firstRowOnPage;
}
public void setFirstRowOnPage(Integer firstRowOnPage) {
this.firstRowOnPage = firstRowOnPage;
}
public Integer getLastRowOnPage() {
return lastRowOnPage;
}
public void setLastRowOnPage(Integer lastRowOnPage) {
this.lastRowOnPage = lastRowOnPage;
}
}

View File

@ -1,5 +1,6 @@
package com.uam.wmi.findmytutor.model; package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,24 +15,31 @@ import io.swagger.annotations.ApiModelProperty;
public class PagedResultUserResponseModel extends BaseResponse { public class PagedResultUserResponseModel extends BaseResponse {
@SerializedName("results") @SerializedName("results")
@Expose
private List<UserResponseModel> results = null; private List<UserResponseModel> results = null;
@SerializedName("currentPage") @SerializedName("currentPage")
@Expose
private Integer currentPage = null; private Integer currentPage = null;
@SerializedName("pageCount") @SerializedName("pageCount")
@Expose
private Integer pageCount = null; private Integer pageCount = null;
@SerializedName("pageSize") @SerializedName("pageSize")
@Expose
private Integer pageSize = null; private Integer pageSize = null;
@SerializedName("rowCount") @SerializedName("rowCount")
@Expose
private Integer rowCount = null; private Integer rowCount = null;
@SerializedName("firstRowOnPage") @SerializedName("firstRowOnPage")
@Expose
private Integer firstRowOnPage = null; private Integer firstRowOnPage = null;
@SerializedName("lastRowOnPage") @SerializedName("lastRowOnPage")
@Expose
private Integer lastRowOnPage = null; private Integer lastRowOnPage = null;
public PagedResultUserResponseModel results(List<UserResponseModel> results) { public PagedResultUserResponseModel results(List<UserResponseModel> results) {

View File

@ -0,0 +1,33 @@
package com.uam.wmi.findmytutor.model;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Results extends BaseResponse {
@SerializedName("tutors")
@Expose
private List<Tutor> tutors = null;
@SerializedName("blacklistersTutors")
@Expose
private List<Object> blacklistersTutors = null;
public List<Tutor> getTutors() {
return tutors;
}
public void setTutors(List<Tutor> tutors) {
this.tutors = tutors;
}
public List<Object> getBlacklistersTutors() {
return blacklistersTutors;
}
public void setBlacklistersTutors(List<Object> blacklistersTutors) {
this.blacklistersTutors = blacklistersTutors;
}
}

View File

@ -0,0 +1,121 @@
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 extends User {
@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 List<User> getTutors() {
return tutors;
}
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 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,109 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Tutor {
@SerializedName("id")
@Expose
private String id;
@SerializedName("isOnline")
@Expose
private Boolean isOnline;
@SerializedName("title")
@Expose
private String title;
@SerializedName("firstName")
@Expose
private String firstName;
@SerializedName("lastName")
@Expose
private String lastName;
@SerializedName("department")
@Expose
private String department;
@SerializedName("userName")
@Expose
private String userName;
@SerializedName("email")
@Expose
private String email;
@SerializedName("isActive")
@Expose
private Boolean isActive;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Boolean getIsOnline() {
return isOnline;
}
public void setIsOnline(Boolean isOnline) {
this.isOnline = isOnline;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
}

View File

@ -33,8 +33,8 @@ public class ApiClient {
retrofit = new Retrofit.Builder() retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(BASE_URL)
.client(okHttpClient) .client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build(); .build();
} }
return retrofit; return retrofit;
@ -59,6 +59,7 @@ public class ApiClient {
.addHeader("Accept", "application/json") .addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json"); .addHeader("Content-Type", "application/json");
// Adding Authorization token (API Key) // Adding Authorization token (API Key)
// Requests will be denied without API key // Requests will be denied without API key
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) { if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {

View File

@ -51,4 +51,5 @@ public class RetrofitClientInstance {
} }
return retrofit.create(serviceClass); return retrofit.create(serviceClass);
} }
} }

View File

@ -1,14 +1,16 @@
package com.uam.wmi.findmytutor.service; package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.IsUsingListBool; import com.uam.wmi.findmytutor.model.IsUsingListBool;
import com.uam.wmi.findmytutor.model.PagedResult; import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors;
import com.uam.wmi.findmytutor.model.StudentIdModel; import com.uam.wmi.findmytutor.model.StudentIdModel;
import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.User;
import java.util.List; import java.util.List;
import io.reactivex.Completable; import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single; import io.reactivex.Single;
import retrofit2.Response;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.DELETE; import retrofit2.http.DELETE;
import retrofit2.http.GET; import retrofit2.http.GET;
@ -25,13 +27,20 @@ public interface UserService {
Completable createUser(@Body User user); Completable createUser(@Body User user);
@GET("api/users/page/{pageNum}") @GET("api/users/page/{pageNum}")
Single <PagedResult> getPagedUsers(@Path("pageNum") String pageNum ); Single <PagedResultReturnedTutors> getPagedUsers(@Path("pageNum") String pageNum );
/* @GET("api/users/tutors/page/{pageNum}")
//Observable <PagedResultReturnedTutors> getPagedTutors(@Path("pageNum") String pageNum);
Single <PagedResultReturnedTutors> getPagedTutors(@Path("pageNum") String pageNum);*/
@GET("api/users/tutors/page/{pageNum}") @GET("api/users/tutors/page/{pageNum}")
Single <PagedResult> getPagedTutors(@Path("pageNum") String pageNum); Single<PagedResultReturnedTutors> getPagedTutors(
@retrofit2.http.Path("pageNum") Integer pageNum
);
@GET("api/users/students/page/{pageNum}") @GET("api/users/students/page/{pageNum}")
Single<PagedResult> getPagedStudents(@Path("pageNum") String pageNum); Single<PagedResultReturnedTutors> getPagedStudents(@Path("pageNum") String pageNum);
@GET("api/users/{id}") @GET("api/users/{id}")
Single<User> getUserByID(@Path("id") String userID); Single<User> getUserByID(@Path("id") String userID);

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,79 @@
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.Tutor;
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<Tutor> tutorsList;
public TutorsAdapter(Context context, List<Tutor> tutors) {
this.context = context;
this.tutorsList = tutors;
Log.e("USERS", String.valueOf(tutors));
}
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);
}
}
@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) {
Tutor 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,42 @@
<?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="80dp"
android:clickable="true"
android:paddingBottom="@dimen/dimen_10"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/dimen_10">
<TextView
android:id="@+id/firstName"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:textColor="@color/note_list_text"
android:textSize="@dimen/note_list_text" />
<TextView
android:id="@+id/lastName"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_below="@+id/firstName"
android:layout_centerHorizontal="true"
android:textColor="@color/note_list_text"
android:textSize="@dimen/note_list_text" />
<TextView
android:id="@+id/isOnline"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_below="@+id/lastName"
android:layout_centerHorizontal="true"
android:textColor="@color/note_list_text"
android:textSize="@dimen/note_list_text" />
</RelativeLayout>

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>