From aa6810a633c108c6782362117d218694e89e5b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 26 Oct 2018 13:57:50 +0200 Subject: [PATCH 01/16] Working user list --- app/src/main/AndroidManifest.xml | 5 + .../uam/wmi/findmytutor/ListViewAdapter.java | 11 +- .../findmytutor/activity/BaseActivity.java | 2 +- .../findmytutor/activity/ListViewAdapter.java | 111 ++++++++++++++++ .../findmytutor/activity/LoginActivity.java | 4 +- .../activity/UsersListActivity.java | 95 ++++++++++++++ .../uam/wmi/findmytutor/model/LdapUser.java | 2 +- .../com/uam/wmi/findmytutor/model/Model.java | 2 + .../wmi/findmytutor/model/PagedResult.java | 19 ++- .../model/PagedResultReturnedTutors.java | 89 +++++++++++++ .../model/PagedResultUserResponseModel.java | 8 ++ .../uam/wmi/findmytutor/model/Results.java | 33 +++++ .../wmi/findmytutor/model/ReturnedTutors.java | 121 ++++++++++++++++++ .../com/uam/wmi/findmytutor/model/Tutor.java | 109 ++++++++++++++++ .../wmi/findmytutor/network/ApiClient.java | 3 +- .../network/RetrofitClientInstance.java | 3 +- .../wmi/findmytutor/service/UserService.java | 17 ++- .../utils/MyDividerItemDecoration.java | 98 ++++++++++++++ .../wmi/findmytutor/view/TutorsAdapter.java | 79 ++++++++++++ app/src/main/res/layout/tutor_list_view.xml | 42 ++++++ app/src/main/res/layout/users_list.xml | 18 +++ app/src/main/res/layout/users_list_main.xml | 18 +++ 22 files changed, 873 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.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/model/PagedResultReturnedTutors.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/model/Results.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/model/Tutor.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/view/TutorsAdapter.java create mode 100644 app/src/main/res/layout/tutor_list_view.xml 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 b5a061b..4fbfa6b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,6 +48,11 @@ android:label="@string/title_activity_sharing" android:launchMode="singleTop" /> + + { @@ -47,8 +49,9 @@ public class ListViewAdapter extends ArrayAdapter { return position; } + @NonNull @Override - public View getView(int position, View convertView, ViewGroup parent) { + 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. @@ -67,11 +70,11 @@ public class ListViewAdapter extends ArrayAdapter { holder.friendName.setText(getItem(position)); //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 // generate random color - int color = generator.getColor(getItem(position)); + int color = generator.getColor(Objects.requireNonNull(getItem(position))); TextDrawable drawable = TextDrawable.builder() .buildRound(firstLetter, color); // radius in px @@ -101,7 +104,7 @@ public class ListViewAdapter extends ArrayAdapter { private ImageView imageView; private TextView friendName; - public ViewHolder(View v) { + ViewHolder(View v) { imageView = (ImageView) v.findViewById(R.id.image_view); friendName = (TextView) v.findViewById(R.id.text); } 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 8c0b5ba..8ae2465 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 @@ -191,7 +191,7 @@ public abstract class BaseActivity setFragment(sharingFragment); } else if (itemId == R.id.nav_notif) { - startActivity(new Intent(this, NotificationsActivity.class)); + startActivity(new Intent(this, UsersListActivity.class)); } //finish(); }, 300); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java new file mode 100644 index 0000000..51592d1 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java @@ -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 { + + private UsersListActivity activity; + private List friendList; + private List searchList; + + public ListViewAdapter(UsersListActivity context, int resource, List 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); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index 9047291..3b1dc78 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -395,7 +395,9 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks< .subscribeWith(new DisposableSingleObserver() { @Override public void onSuccess(JwtToken jwtToken) { - String token = jwtToken.getToken(); + //String token = jwtToken.getToken(); + + String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzY2QyMWFlYi00ZGRmLTQ0YTktOWM3OC1kNGE3MjVlN2MwNDkiLCJzdWIiOiJhc2RAYXNkc2FkYWEiLCJqdGkiOiIwMDMzYWZhMy0yNDZhLTQ1YTYtOWZmYi1lNzhiYjg3MDMzMmIiLCJleHAiOjE1NDMxMzUwNjAsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.rzks6-yjvVuYoO0pdiBwAfqDnMg8C8XrM9eA4h692m0"; JWT jwt = new JWT(token); Claim role = jwt.getClaim("nameid"); 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..c801e28 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -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 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 () { + @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(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/LdapUser.java b/app/src/main/java/com/uam/wmi/findmytutor/model/LdapUser.java index b57c702..51f5cb9 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/LdapUser.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/LdapUser.java @@ -11,7 +11,7 @@ import io.swagger.annotations.ApiModelProperty; * LdapUser */ -public class LdapUser extends BaseResponse{ +public class LdapUser extends BaseResponse { @SerializedName("login") private String login = null; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/Model.java b/app/src/main/java/com/uam/wmi/findmytutor/model/Model.java index 3b5ee47..bca9777 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/Model.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/Model.java @@ -1,3 +1,4 @@ +/* package com.uam.wmi.findmytutor.model; @@ -14,3 +15,4 @@ public class Model } } +*/ 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..a5dab31 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 @@ -1,3 +1,4 @@ + package com.uam.wmi.findmytutor.model; import com.google.gson.annotations.Expose; @@ -9,7 +10,7 @@ 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 List getResults() { return results; } - public void setResults(List results) { + public void setResults(List results) { this.results = results; } @@ -86,3 +87,15 @@ public class PagedResult { } } + + + + + + + + + + + + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultReturnedTutors.java b/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultReturnedTutors.java new file mode 100644 index 0000000..4e98f5f --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultReturnedTutors.java @@ -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; + } + +} + + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultUserResponseModel.java b/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultUserResponseModel.java index 0e16bb2..2927d71 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultUserResponseModel.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/PagedResultUserResponseModel.java @@ -1,5 +1,6 @@ package com.uam.wmi.findmytutor.model; +import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import java.util.ArrayList; @@ -14,24 +15,31 @@ import io.swagger.annotations.ApiModelProperty; public class PagedResultUserResponseModel extends BaseResponse { @SerializedName("results") + @Expose private List results = null; @SerializedName("currentPage") + @Expose private Integer currentPage = null; @SerializedName("pageCount") + @Expose private Integer pageCount = null; @SerializedName("pageSize") + @Expose private Integer pageSize = null; @SerializedName("rowCount") + @Expose private Integer rowCount = null; @SerializedName("firstRowOnPage") + @Expose private Integer firstRowOnPage = null; @SerializedName("lastRowOnPage") + @Expose private Integer lastRowOnPage = null; public PagedResultUserResponseModel results(List results) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/Results.java b/app/src/main/java/com/uam/wmi/findmytutor/model/Results.java new file mode 100644 index 0000000..c57f109 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/Results.java @@ -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 tutors = null; + @SerializedName("blacklistersTutors") + @Expose + private List blacklistersTutors = null; + + public List getTutors() { + return tutors; + } + + public void setTutors(List tutors) { + this.tutors = tutors; + } + + public List getBlacklistersTutors() { + return blacklistersTutors; + } + + public void setBlacklistersTutors(List blacklistersTutors) { + this.blacklistersTutors = blacklistersTutors; + } + +} \ No newline at end of file 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..f4a327f --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java @@ -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 tutors = null; + + @SerializedName("blacklistersTutors") + @Expose + private List blacklistersTutors = null; + + public ReturnedTutors tutors(List tutors) { + this.tutors = tutors; + return this; + } + + public List getTutors() { + return tutors; + } + + public ReturnedTutors addTutorsItem(User tutorsItem) { + if (this.tutors == null) { + this.tutors = new ArrayList(); + } + this.tutors.add(tutorsItem); + return this; + } + + /** + * Get tutors + * @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/model/Tutor.java b/app/src/main/java/com/uam/wmi/findmytutor/model/Tutor.java new file mode 100644 index 0000000..623c366 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/Tutor.java @@ -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; + } + +} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java index 70e3a9e..e95a240 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java @@ -33,8 +33,8 @@ public class ApiClient { retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .client(okHttpClient) - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); } return retrofit; @@ -59,6 +59,7 @@ public class ApiClient { .addHeader("Accept", "application/json") .addHeader("Content-Type", "application/json"); + // Adding Authorization token (API Key) // Requests will be denied without API key if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/network/RetrofitClientInstance.java b/app/src/main/java/com/uam/wmi/findmytutor/network/RetrofitClientInstance.java index a3e3ee3..c59609b 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/network/RetrofitClientInstance.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/network/RetrofitClientInstance.java @@ -51,4 +51,5 @@ public class RetrofitClientInstance { } return retrofit.create(serviceClass); } -} \ No newline at end of file +} + 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..883dcfd 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 @@ -1,14 +1,16 @@ package com.uam.wmi.findmytutor.service; 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.User; import java.util.List; import io.reactivex.Completable; +import io.reactivex.Observable; import io.reactivex.Single; +import retrofit2.Response; import retrofit2.http.Body; import retrofit2.http.DELETE; import retrofit2.http.GET; @@ -25,13 +27,20 @@ public interface UserService { Completable createUser(@Body User user); @GET("api/users/page/{pageNum}") - Single getPagedUsers(@Path("pageNum") String pageNum ); + Single getPagedUsers(@Path("pageNum") String pageNum ); + + /* @GET("api/users/tutors/page/{pageNum}") + //Observable getPagedTutors(@Path("pageNum") String pageNum); + Single getPagedTutors(@Path("pageNum") String pageNum);*/ @GET("api/users/tutors/page/{pageNum}") - Single getPagedTutors(@Path("pageNum") String pageNum); + Single getPagedTutors( + @retrofit2.http.Path("pageNum") Integer pageNum + ); + @GET("api/users/students/page/{pageNum}") - Single getPagedStudents(@Path("pageNum") String pageNum); + Single getPagedStudents(@Path("pageNum") String pageNum); @GET("api/users/{id}") Single getUserByID(@Path("id") String userID); 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/view/TutorsAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java new file mode 100644 index 0000000..73264b6 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java @@ -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 { + + private Context context; + private List tutorsList; + + public TutorsAdapter(Context context, List 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("•")); + 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/tutor_list_view.xml b/app/src/main/res/layout/tutor_list_view.xml new file mode 100644 index 0000000..8ec9c3d --- /dev/null +++ b/app/src/main/res/layout/tutor_list_view.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + \ 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 From 31f7408ea65a58d5060f4e293856941a4132cf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 26 Oct 2018 14:04:52 +0200 Subject: [PATCH 02/16] get all tutors --- .../findmytutor/activity/UsersListActivity.java | 14 ++++++++------ .../uam/wmi/findmytutor/service/UserService.java | 4 ++++ .../uam/wmi/findmytutor/view/TutorsAdapter.java | 6 +++--- 3 files changed, 15 insertions(+), 9 deletions(-) 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 index c801e28..89a7d3c 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -12,7 +12,9 @@ import android.view.View; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors; +import com.uam.wmi.findmytutor.model.ReturnedTutors; import com.uam.wmi.findmytutor.model.Tutor; +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; @@ -33,7 +35,7 @@ public class UsersListActivity extends AppCompatActivity { private UserService apiService; private CompositeDisposable disposable = new CompositeDisposable(); private TutorsAdapter mAdapter; - private List tutorsList = new ArrayList<>(); + private List tutorsList = new ArrayList<>(); @BindView(R.id.coordinator_layout) CoordinatorLayout coordinatorLayout; @@ -62,18 +64,18 @@ public class UsersListActivity extends AppCompatActivity { private void fetchAllTutors() { disposable.add( - apiService.getPagedTutors(1) + apiService.apiUsersGet() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver () { + .subscribeWith(new DisposableSingleObserver () { @Override - public void onSuccess(PagedResultReturnedTutors pagedResult) { + public void onSuccess(ReturnedTutors pagedResult) { tutorsList.clear(); - tutorsList.addAll(pagedResult.getResults().getTutors()); + tutorsList.addAll(pagedResult.getTutors()); mAdapter.notifyDataSetChanged(); - Log.e("TUTORS", String.valueOf(pagedResult.getResults().getTutors())); + Log.e("TUTORS", String.valueOf(pagedResult.getTutors())); } 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 883dcfd..e4a80ec 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 @@ -2,6 +2,7 @@ package com.uam.wmi.findmytutor.service; import com.uam.wmi.findmytutor.model.IsUsingListBool; import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors; +import com.uam.wmi.findmytutor.model.ReturnedTutors; import com.uam.wmi.findmytutor.model.StudentIdModel; import com.uam.wmi.findmytutor.model.User; @@ -23,6 +24,9 @@ public interface UserService { @GET("api/users") Single > getAllUsers(); + @GET("api/users") + Single apiUsersGet(); + @POST("api/users") Completable createUser(@Body User user); 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 index 73264b6..d3f24f1 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java @@ -23,9 +23,9 @@ import butterknife.ButterKnife; public class TutorsAdapter extends RecyclerView.Adapter { private Context context; - private List tutorsList; + private List tutorsList; - public TutorsAdapter(Context context, List tutors) { + public TutorsAdapter(Context context, List tutors) { this.context = context; this.tutorsList = tutors; @@ -63,7 +63,7 @@ public class TutorsAdapter extends RecyclerView.Adapter Date: Fri, 26 Oct 2018 20:08:52 +0200 Subject: [PATCH 03/16] Sort users by online category --- app/src/main/AndroidManifest.xml | 1 - .../findmytutor/activity/BaseActivity.java | 21 +- .../findmytutor/activity/LoginActivity.java | 4 +- .../findmytutor/activity/MainActivity.java | 7 +- .../activity/NotificationsActivity.java | 179 ------------------ .../activity/UsersListActivity.java | 102 ++++++++-- .../wmi/findmytutor/model/ReturnedTutors.java | 2 +- .../utils/RecyclerTouchListener.java | 62 ++++++ .../wmi/findmytutor/view/TutorsAdapter.java | 25 ++- app/src/main/res/layout/tutor_list_row.xml | 41 ++-- app/src/main/res/layout/tutor_list_view.xml | 42 ---- app/src/main/res/layout/users_list.xml | 4 +- app/src/main/res/layout/users_list_main.xml | 13 +- app/src/main/res/menu/nav_items.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 15 files changed, 211 insertions(+), 295 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/utils/RecyclerTouchListener.java delete mode 100644 app/src/main/res/layout/tutor_list_view.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4fbfa6b..f0599bd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -62,7 +62,6 @@ - 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 8ae2465..ccfbdd9 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 @@ -70,24 +70,6 @@ public abstract class BaseActivity 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() { @@ -190,7 +172,8 @@ public abstract class BaseActivity // startActivity(new Intent(this, ProfileActivity.class)); setFragment(sharingFragment); - } else if (itemId == R.id.nav_notif) { + } else if (itemId == R.id.nav_user_list) { + //removeFragment(sharingFragment); startActivity(new Intent(this, UsersListActivity.class)); } //finish(); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index 3b1dc78..d76c182 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -395,9 +395,9 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks< .subscribeWith(new DisposableSingleObserver() { @Override public void onSuccess(JwtToken jwtToken) { - //String token = jwtToken.getToken(); + String token = jwtToken.getToken(); - String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzY2QyMWFlYi00ZGRmLTQ0YTktOWM3OC1kNGE3MjVlN2MwNDkiLCJzdWIiOiJhc2RAYXNkc2FkYWEiLCJqdGkiOiIwMDMzYWZhMy0yNDZhLTQ1YTYtOWZmYi1lNzhiYjg3MDMzMmIiLCJleHAiOjE1NDMxMzUwNjAsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.rzks6-yjvVuYoO0pdiBwAfqDnMg8C8XrM9eA4h692m0"; + //String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzY2QyMWFlYi00ZGRmLTQ0YTktOWM3OC1kNGE3MjVlN2MwNDkiLCJzdWIiOiJhc2RAYXNkc2FkYWEiLCJqdGkiOiIwMDMzYWZhMy0yNDZhLTQ1YTYtOWZmYi1lNzhiYjg3MDMzMmIiLCJleHAiOjE1NDMxMzUwNjAsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.rzks6-yjvVuYoO0pdiBwAfqDnMg8C8XrM9eA4h692m0"; JWT jwt = new JWT(token); Claim role = jwt.getClaim("nameid"); 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 6926c8c..9cce13f 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 @@ -198,9 +198,6 @@ public class MainActivity extends AppCompatActivity implements case R.id.nav_map: // setFragment(mapFragment); return true; - case R.id.nav_notif: - setFragment(notificationFragment); - return true; case R.id.nav_profile: setFragment(sharingFragment); return true; @@ -373,12 +370,12 @@ public class MainActivity extends AppCompatActivity implements markerAnimator.setDuration(2000); markerAnimator.start(); - coordsMap.replace(id,element); + coordsMap.put(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); + coordsMap.put(id,element); } } else { coordsMap.put(id,element); 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 30045ae..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java +++ /dev/null @@ -1,179 +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.support.annotation.NonNull; -import android.util.Log; - -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.annotations.Marker; -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.ArrayList; -import java.util.List; - -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.observers.DisposableSingleObserver; -import io.reactivex.schedulers.Schedulers; - - -public class NotificationsActivity extends BaseActivity { - - private MapView mapView; - private CoordinateService coordinateService; - private CompositeDisposable disposable = new CompositeDisposable(); - private List coordinatesList = new ArrayList<>(); - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mapInit(savedInstanceState); - -// coordinateService = ApiClient.getClient(getApplicationContext()) -// .create(CoordinateService.class); - 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"); - - fetchTopCoords(); - } - - 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(64.900932, -18.167040))); - - mapboxMap.setOnMapClickListener(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() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List coordsList) { - - Log.d("mapTag", "co?"); - for (Coordinate element: - coordsList) { - Log.d("mapTag", element.getUserId()); - } - } - - @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(); - 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 index 89a7d3c..321d76b 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,36 +1,44 @@ package com.uam.wmi.findmytutor.activity; +import android.graphics.Color; import android.os.Bundle; import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.Snackbar; 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.MenuItem; import android.view.View; +import android.widget.TextView; +import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors; import com.uam.wmi.findmytutor.model.ReturnedTutors; -import com.uam.wmi.findmytutor.model.Tutor; 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.utils.RecyclerTouchListener; +import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.view.TutorsAdapter; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.functions.Function; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; +import okhttp3.ResponseBody; -public class UsersListActivity extends AppCompatActivity { +public class UsersListActivity extends BaseActivity { private static final String TAG = UsersListActivity.class.getSimpleName(); private UserService apiService; private CompositeDisposable disposable = new CompositeDisposable(); @@ -41,17 +49,21 @@ public class UsersListActivity extends AppCompatActivity { @BindView(R.id.recycler_view) RecyclerView recyclerView; + + + @BindView(R.id.txt_empty_notes_view) + TextView noNotesView; + @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); @@ -59,39 +71,93 @@ public class UsersListActivity extends AppCompatActivity { recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16)); recyclerView.setAdapter(mAdapter); + fetchAllTutors(); + recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, + recyclerView, new RecyclerTouchListener.ClickListener() { + @Override + public void onClick(View view, final int position) { + } + + @Override + public void onLongClick(View view, int position) { + //showActionsDialog(position); + } + })); } + private void fetchAllTutors() { - disposable.add( + disposable.add( apiService.apiUsersGet() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver () { + .map(tutors -> { + List tutorsList = new ArrayList<>(tutors.getTutors()); + Collections.sort(tutorsList, (t1, t2) -> t2.isIsOnline().compareTo(t1.isIsOnline())); + + return tutorsList; + }) + .subscribeWith(new DisposableSingleObserver >() { @Override - public void onSuccess(ReturnedTutors pagedResult) { - - tutorsList.clear(); - tutorsList.addAll(pagedResult.getTutors()); - mAdapter.notifyDataSetChanged(); - - Log.e("TUTORS", String.valueOf(pagedResult.getTutors())); - - + public void onSuccess(List users) { + tutorsList.clear(); + tutorsList.addAll(users); + mAdapter.notifyDataSetChanged(); + toggleEmptyNotes(); } @Override public void onError(Throwable e) { - Log.e("TUTORS_Error",e.toString()); + showError(e); } })); } + private void showError(Throwable e) { + String message = "Something went wrong!"; + + if (e instanceof HttpException) { + ResponseBody responseBody = ((HttpException) e).response().errorBody(); + message = RestApiHelper.getErrorMessage(responseBody); + } + + Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG); + View sbView = snackbar.getView(); + TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text); + textView.setTextColor(Color.BLUE); + snackbar.show(); + } + + private void toggleEmptyNotes() { + if (tutorsList.size() > 0) { + noNotesView.setVisibility(View.GONE); + } else { + noNotesView.setVisibility(View.VISIBLE); + } + + } + @Override protected void onDestroy() { super.onDestroy(); disposable.dispose(); } + + @Override + protected int getContentViewId() { + return R.layout.users_list; + } + + @Override + protected int getNavigationMenuItemId() { + return R.id.nav_user_list; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + } } \ No newline at end of file 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 index f4a327f..23a897a 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java @@ -13,7 +13,7 @@ import java.util.List; * ReturnedTutors */ -public class ReturnedTutors extends User { +public class ReturnedTutors extends User{ @SerializedName("tutors") @Expose private List tutors = null; 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..35aef4b --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/RecyclerTouchListener.java @@ -0,0 +1,62 @@ +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; + +/** + * Created by ravi on 21/02/18. + */ + +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); + } +} 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 index d3f24f1..0fedcad 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java @@ -1,6 +1,8 @@ package com.uam.wmi.findmytutor.view; import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.text.Html; import android.util.Log; @@ -64,11 +66,17 @@ public class TutorsAdapter extends RecyclerView.Adapter - + android:paddingBottom="@dimen/dimen_10"> + android:id="@+id/isOnline" + android:layout_width="wrap_content" + android:layout_height="@dimen/dot_height" + android:layout_marginTop="@dimen/dimen_10" + android:layout_marginEnd="@dimen/dot_margin_right" + android:includeFontPadding="false" + android:lineSpacingExtra="10dp" + android:textSize="@dimen/dot_text_size" /> - - - \ No newline at end of file + diff --git a/app/src/main/res/layout/tutor_list_view.xml b/app/src/main/res/layout/tutor_list_view.xml deleted file mode 100644 index 8ec9c3d..0000000 --- a/app/src/main/res/layout/tutor_list_view.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - \ 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 index 0ab367c..2feba05 100644 --- a/app/src/main/res/layout/users_list.xml +++ b/app/src/main/res/layout/users_list.xml @@ -6,7 +6,6 @@ android:layout_height="match_parent" tools:context=".activity.UsersListActivity"> - - \ 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 index f160738..47b4d8e 100644 --- a/app/src/main/res/layout/users_list_main.xml +++ b/app/src/main/res/layout/users_list_main.xml @@ -14,5 +14,16 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> + + + - \ No newline at end of file diff --git a/app/src/main/res/menu/nav_items.xml b/app/src/main/res/menu/nav_items.xml index 588a4b4..310e506 100644 --- a/app/src/main/res/menu/nav_items.xml +++ b/app/src/main/res/menu/nav_items.xml @@ -11,7 +11,7 @@ android:icon="@drawable/outline_map_white_24dp" android:title="@string/nav_map" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5d9839..8a70684 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -197,4 +197,5 @@ functionality. Main2Activity + There is no users in system From 49199ccc440a0d0837a96a5e73599e858b2dad09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 26 Oct 2018 21:52:19 +0200 Subject: [PATCH 04/16] Add badgers --- .../findmytutor/activity/BaseActivity.java | 2 +- .../wmi/findmytutor/view/TutorsAdapter.java | 20 +++++-- app/src/main/res/drawable/not_active_user.xml | 5 ++ app/src/main/res/drawable/not_online.xml | 5 ++ app/src/main/res/drawable/not_online_user.xml | 5 ++ app/src/main/res/drawable/online_user.xml | 5 ++ app/src/main/res/layout/tutor_list_row.xml | 53 +++++++++++-------- 7 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/drawable/not_active_user.xml create mode 100644 app/src/main/res/drawable/not_online.xml create mode 100644 app/src/main/res/drawable/not_online_user.xml create mode 100644 app/src/main/res/drawable/online_user.xml 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 ccfbdd9..6fe2d49 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 @@ -176,7 +176,7 @@ public abstract class BaseActivity //removeFragment(sharingFragment); startActivity(new Intent(this, UsersListActivity.class)); } - //finish(); + finish(); }, 300); return true; 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 index 0fedcad..6d79212 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java @@ -3,6 +3,7 @@ package com.uam.wmi.findmytutor.view; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.support.v7.widget.RecyclerView; import android.text.Html; import android.util.Log; @@ -69,13 +70,22 @@ public class TutorsAdapter extends RecyclerView.Adapter + + diff --git a/app/src/main/res/drawable/not_online.xml b/app/src/main/res/drawable/not_online.xml new file mode 100644 index 0000000..84bf716 --- /dev/null +++ b/app/src/main/res/drawable/not_online.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/not_online_user.xml b/app/src/main/res/drawable/not_online_user.xml new file mode 100644 index 0000000..2bac8fe --- /dev/null +++ b/app/src/main/res/drawable/not_online_user.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/online_user.xml b/app/src/main/res/drawable/online_user.xml new file mode 100644 index 0000000..2bac8fe --- /dev/null +++ b/app/src/main/res/drawable/online_user.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/tutor_list_row.xml b/app/src/main/res/layout/tutor_list_row.xml index 43a9cf5..d5b0cce 100644 --- a/app/src/main/res/layout/tutor_list_row.xml +++ b/app/src/main/res/layout/tutor_list_row.xml @@ -1,39 +1,48 @@ - - - + + + + + - + + \ No newline at end of file From 1e281b3ea54c10a8dc295cd3b151ea8a4688c613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 26 Oct 2018 23:29:45 +0200 Subject: [PATCH 05/16] Add status of particular user --- app/build.gradle | 1 + .../activity/UsersListActivity.java | 26 ++++++++++++++++--- .../wmi/findmytutor/view/TutorsAdapter.java | 12 --------- app/src/main/res/layout/tutor_list_row.xml | 18 ++++++------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 595676b..72c08c7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,5 +56,6 @@ dependencies { implementation "com.squareup.okhttp3:logging-interceptor:3.11.0" implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.auth0.android:jwtdecode:1.1.1' + implementation 'com.annimon:stream:1.2.1' } 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 index 321d76b..cde7804 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,7 +1,9 @@ package com.uam.wmi.findmytutor.activity; import android.graphics.Color; +import android.os.Build; import android.os.Bundle; +import android.support.annotation.RequiresApi; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; @@ -12,6 +14,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.TextView; +import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; @@ -28,6 +31,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; import butterknife.BindView; import butterknife.ButterKnife; @@ -54,6 +58,7 @@ public class UsersListActivity extends BaseActivity { @BindView(R.id.txt_empty_notes_view) TextView noNotesView; + @RequiresApi(api = Build.VERSION_CODES.N) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -87,6 +92,7 @@ public class UsersListActivity extends BaseActivity { } + private void fetchAllTutors() { disposable.add( apiService.apiUsersGet() @@ -94,9 +100,23 @@ public class UsersListActivity extends BaseActivity { .observeOn(AndroidSchedulers.mainThread()) .map(tutors -> { List tutorsList = new ArrayList<>(tutors.getTutors()); - Collections.sort(tutorsList, (t1, t2) -> t2.isIsOnline().compareTo(t1.isIsOnline())); - return tutorsList; + List onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList(); + List activeNotOnlineTutors = Stream.of(tutorsList) + .filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList();; + + List notActiveTutors = Stream.of(tutorsList) + .filterNot(User::isIsActive).toList();; + + Collections.sort(onlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); + Collections.sort(activeNotOnlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); + Collections.sort(notActiveTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); + + List sortedUserList = new ArrayList<>(onlineTutors); + sortedUserList.addAll(activeNotOnlineTutors); + sortedUserList.addAll(notActiveTutors); + + return sortedUserList; }) .subscribeWith(new DisposableSingleObserver >() { @Override @@ -117,7 +137,7 @@ public class UsersListActivity extends BaseActivity { } private void showError(Throwable e) { - String message = "Something went wrong!"; + String message = e.toString(); if (e instanceof HttpException) { ResponseBody responseBody = ((HttpException) e).response().errorBody(); 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 index 6d79212..3b623e3 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java @@ -94,17 +94,5 @@ public class TutorsAdapter extends RecyclerView.Adapter From b87646088c39af21b7ed083d572031def444c10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 26 Oct 2018 23:50:03 +0200 Subject: [PATCH 06/16] Add modal with more comprehensive information about specific user --- .../activity/UsersListActivity.java | 39 ++++++++++++++++++- app/src/main/res/layout/note_dialog.xml | 33 ++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/layout/note_dialog.xml 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 index cde7804..35a6efa 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,18 +1,24 @@ package com.uam.wmi.findmytutor.activity; +import android.content.DialogInterface; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; +import android.support.v7.app.AlertDialog; 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.text.TextUtils; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; +import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; @@ -82,16 +88,47 @@ public class UsersListActivity extends BaseActivity { recyclerView, new RecyclerTouchListener.ClickListener() { @Override public void onClick(View view, final int position) { + showNoteDialog(true, tutorsList.get(position), position); } @Override public void onLongClick(View view, int position) { - //showActionsDialog(position); + showActionsDialog(position); } })); } + private void showActionsDialog(final int position) { + CharSequence colors[] = new CharSequence[]{"Edit", "Delete"}; + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Choose option"); + builder.setItems(colors, (dialog, which) -> { + if (which == 0) { + showNoteDialog(true, tutorsList.get(position), position); + } else { + //deleteNote(tutorsList.get(position).getId(), position); + } + }); + builder.show(); + } + + private void showNoteDialog(final boolean shouldUpdate, final User note, final int position) { + LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); + View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null); + + AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); + alertDialogBuilderUserInput.setView(view); + + final EditText inputNote = view.findViewById(R.id.note); + TextView dialogTitle = view.findViewById(R.id.dialog_title); + dialogTitle.setText(note.getTitle() + note.getFirstName() + note.getDepartment()); + + } + + + private void fetchAllTutors() { disposable.add( diff --git a/app/src/main/res/layout/note_dialog.xml b/app/src/main/res/layout/note_dialog.xml new file mode 100644 index 0000000..2fc7ee8 --- /dev/null +++ b/app/src/main/res/layout/note_dialog.xml @@ -0,0 +1,33 @@ + + + + + + + + \ No newline at end of file From edd5fb76a3b6db1a6f076af73ab42a8717dbac72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 26 Oct 2018 23:54:18 +0200 Subject: [PATCH 07/16] A little refactor of user modal --- .../findmytutor/activity/UsersListActivity.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 index 35a6efa..5333ebe 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -93,7 +93,8 @@ public class UsersListActivity extends BaseActivity { @Override public void onLongClick(View view, int position) { - showActionsDialog(position); + //showActionsDialog(position); + showNoteDialog(true, tutorsList.get(position), position); } })); } @@ -121,9 +122,16 @@ public class UsersListActivity extends BaseActivity { AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); alertDialogBuilderUserInput.setView(view); - final EditText inputNote = view.findViewById(R.id.note); + final TextView inputNote = view.findViewById(R.id.note); TextView dialogTitle = view.findViewById(R.id.dialog_title); - dialogTitle.setText(note.getTitle() + note.getFirstName() + note.getDepartment()); + dialogTitle.setText(note.getNormalizedUserName()); + + + inputNote.setText(note.getNormalizedUserName() + note.getTitle() + note.getDepartment()); + + final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); + alertDialog.show(); + } From 299e25d0f98f7d37250b58e872645dae4b672ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Sat, 27 Oct 2018 23:58:51 +0200 Subject: [PATCH 08/16] Add primitive modal about user --- .../activity/UsersListActivity.java | 103 +++++---- .../findmytutor/model/DutyHourViewModel.java | 122 +++++++++++ .../findmytutor/model/TutorTabViewModel.java | 199 ++++++++++++++++++ .../wmi/findmytutor/service/TutorTabApi.java | 58 +++++ app/src/main/res/layout/note_dialog.xml | 37 +++- app/src/main/res/layout/tutor_list_row.xml | 12 +- 6 files changed, 475 insertions(+), 56 deletions(-) create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/service/TutorTabApi.java 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 index 5333ebe..7e053e4 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,6 +1,5 @@ package com.uam.wmi.findmytutor.activity; -import android.content.DialogInterface; import android.graphics.Color; import android.os.Build; import android.os.Bundle; @@ -8,25 +7,25 @@ import android.support.annotation.RequiresApi; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; -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.text.TextUtils; +import android.util.Log; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; -import android.widget.EditText; +import android.widget.ArrayAdapter; +import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; - -import com.uam.wmi.findmytutor.model.ReturnedTutors; +import com.uam.wmi.findmytutor.model.DutyHour; +import com.uam.wmi.findmytutor.model.DutyHourViewModel; +import com.uam.wmi.findmytutor.model.TutorTabViewModel; import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.network.ApiClient; +import com.uam.wmi.findmytutor.service.TutorTabApi; import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration; import com.uam.wmi.findmytutor.utils.RecyclerTouchListener; @@ -35,34 +34,29 @@ import com.uam.wmi.findmytutor.view.TutorsAdapter; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; import butterknife.BindView; import butterknife.ButterKnife; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.functions.Function; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; -public class UsersListActivity extends BaseActivity { +public class UsersListActivity extends BaseActivity { private static final String TAG = UsersListActivity.class.getSimpleName(); - private UserService apiService; + @BindView(R.id.coordinator_layout) + 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 tutorsList = new ArrayList<>(); - @BindView(R.id.coordinator_layout) - CoordinatorLayout coordinatorLayout; - - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - - - @BindView(R.id.txt_empty_notes_view) - TextView noNotesView; @RequiresApi(api = Build.VERSION_CODES.N) @Override @@ -72,9 +66,12 @@ public class UsersListActivity extends BaseActivity { setContentView(R.layout.users_list); ButterKnife.bind(this); - apiService = ApiClient.getClient(getApplicationContext()) + userService = ApiClient.getClient(getApplicationContext()) .create(UserService.class); + tutorTabService = ApiClient.getClient(getApplicationContext()) + .create(TutorTabApi.class); + mAdapter = new TutorsAdapter(this, tutorsList); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); recyclerView.setLayoutManager(mLayoutManager); @@ -94,7 +91,8 @@ public class UsersListActivity extends BaseActivity { @Override public void onLongClick(View view, int position) { //showActionsDialog(position); - showNoteDialog(true, tutorsList.get(position), position); + + //showNoteDialog(true, tutorsList.get(position), position); } })); } @@ -115,43 +113,70 @@ public class UsersListActivity extends BaseActivity { builder.show(); } - private void showNoteDialog(final boolean shouldUpdate, final User note, final int position) { + private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) { LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null); AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); alertDialogBuilderUserInput.setView(view); - final TextView inputNote = view.findViewById(R.id.note); - TextView dialogTitle = view.findViewById(R.id.dialog_title); - dialogTitle.setText(note.getNormalizedUserName()); + TextView userName = view.findViewById(R.id.userName); + TextView userDutyHours = view.findViewById(R.id.userDutyHours); + TextView userNote = view.findViewById(R.id.userNote); + TextView userRoom = view.findViewById(R.id.userRoom); + TextView userEmail = view.findViewById(R.id.userEmail); + + userName.setText(user.getFirstName() + " " + user.getLastName()); + + disposable.add( + tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver() { + @Override + public void onSuccess(TutorTabViewModel tutorTabViewModel) { + Log.e("TUTOR_TAB",tutorTabViewModel.toString()); + + List dutyHourslist = Stream.of(tutorTabViewModel.getDutyHours()) + .map(DutyHourViewModel::toString).toList(); + + userRoom.setText(tutorTabViewModel.getRoom()); + userEmail.setText(tutorTabViewModel.getEmailTutorTab()); + userNote.setText(tutorTabViewModel.getNote()); + + if(dutyHourslist.size() > 0) + userDutyHours.setText(dutyHourslist.get(0)); - inputNote.setText(note.getNormalizedUserName() + note.getTitle() + note.getDepartment()); + } + + @Override + public void onError(Throwable e) { + showError(e); + } + })); + final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); alertDialog.show(); - - } - - private void fetchAllTutors() { disposable.add( - apiService.apiUsersGet() + userService.apiUsersGet() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .map(tutors -> { List tutorsList = new ArrayList<>(tutors.getTutors()); List onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList(); - List activeNotOnlineTutors = Stream.of(tutorsList) - .filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList();; - List notActiveTutors = Stream.of(tutorsList) - .filterNot(User::isIsActive).toList();; + List activeNotOnlineTutors = Stream.of(tutorsList) + .filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList(); + + List notActiveTutors = Stream.of(tutorsList) + .filterNot(User::isIsActive).toList(); Collections.sort(onlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); Collections.sort(activeNotOnlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); @@ -163,7 +188,7 @@ public class UsersListActivity extends BaseActivity { return sortedUserList; }) - .subscribeWith(new DisposableSingleObserver >() { + .subscribeWith(new DisposableSingleObserver>() { @Override public void onSuccess(List users) { tutorsList.clear(); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java b/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java new file mode 100644 index 0000000..36e688e --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java @@ -0,0 +1,122 @@ +package com.uam.wmi.findmytutor.model; + + +import java.util.Objects; +import com.google.gson.annotations.SerializedName; +import io.swagger.annotations.ApiModelProperty; + + +/** + * DutyHourViewModel + */ + +public class DutyHourViewModel { + @SerializedName("day") + private String day = null; + + @SerializedName("start") + private String start = null; + + @SerializedName("end") + private String end = null; + + public DutyHourViewModel day(String day) { + this.day = day; + return this; + } + + /** + * Get day + * @return day + **/ + @ApiModelProperty(value = "") + public String getDay() { + return day; + } + + public void setDay(String day) { + this.day = day; + } + + public DutyHourViewModel start(String start) { + this.start = start; + return this; + } + + /** + * Get start + * @return start + **/ + @ApiModelProperty(value = "") + public String getStart() { + return start; + } + + public void setStart(String start) { + this.start = start; + } + + public DutyHourViewModel end(String end) { + this.end = end; + return this; + } + + /** + * Get end + * @return end + **/ + @ApiModelProperty(value = "") + public String getEnd() { + return end; + } + + public void setEnd(String end) { + this.end = end; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DutyHourViewModel dutyHourViewModel = (DutyHourViewModel) o; + return Objects.equals(this.day, dutyHourViewModel.day) && + Objects.equals(this.start, dutyHourViewModel.start) && + Objects.equals(this.end, dutyHourViewModel.end); + } + + @Override + public int hashCode() { + return Objects.hash(day, start, end); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DutyHourViewModel {\n"); + + sb.append(" day: ").append(toIndentedString(day)).append("\n"); + sb.append(" start: ").append(toIndentedString(start)).append("\n"); + sb.append(" end: ").append(toIndentedString(end)).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/model/TutorTabViewModel.java b/app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java new file mode 100644 index 0000000..8c7bb97 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java @@ -0,0 +1,199 @@ +package com.uam.wmi.findmytutor.model; + + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import com.google.gson.annotations.SerializedName; + +import io.swagger.annotations.ApiModelProperty; + +import java.util.UUID; + +/** + * TutorTabViewModel + */ + +public class TutorTabViewModel { + @SerializedName("tutorTabId") + private UUID tutorTabId = null; + + @SerializedName("userId") + private String userId = null; + + @SerializedName("room") + private String room = null; + + @SerializedName("emailTutorTab") + private String emailTutorTab = null; + + @SerializedName("note") + private String note = null; + + @SerializedName("dutyHours") + private List dutyHours = null; + + public TutorTabViewModel tutorTabId(UUID tutorTabId) { + this.tutorTabId = tutorTabId; + return this; + } + + /** + * Get tutorTabId + * @return tutorTabId + **/ + @ApiModelProperty(value = "") + public UUID getTutorTabId() { + return tutorTabId; + } + + public void setTutorTabId(UUID tutorTabId) { + this.tutorTabId = tutorTabId; + } + + public TutorTabViewModel userId(String userId) { + this.userId = userId; + return this; + } + + /** + * Get userId + * @return userId + **/ + @ApiModelProperty(value = "") + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public TutorTabViewModel room(String room) { + this.room = room; + return this; + } + + /** + * Get room + * @return room + **/ + @ApiModelProperty(value = "") + public String getRoom() { + return room; + } + + public void setRoom(String room) { + this.room = room; + } + + public TutorTabViewModel emailTutorTab(String emailTutorTab) { + this.emailTutorTab = emailTutorTab; + return this; + } + + /** + * Get emailTutorTab + * @return emailTutorTab + **/ + @ApiModelProperty(value = "") + public String getEmailTutorTab() { + return emailTutorTab; + } + + public void setEmailTutorTab(String emailTutorTab) { + this.emailTutorTab = emailTutorTab; + } + + public TutorTabViewModel note(String note) { + this.note = note; + return this; + } + + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public TutorTabViewModel dutyHours(List dutyHours) { + this.dutyHours = dutyHours; + return this; + } + + public TutorTabViewModel addDutyHoursItem(DutyHourViewModel dutyHoursItem) { + if (this.dutyHours == null) { + this.dutyHours = new ArrayList(); + } + this.dutyHours.add(dutyHoursItem); + return this; + } + + /** + * Get dutyHours + * @return dutyHours + **/ + @ApiModelProperty(value = "") + public List getDutyHours() { + return dutyHours; + } + + public void setDutyHours(List dutyHours) { + this.dutyHours = dutyHours; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TutorTabViewModel tutorTabViewModel = (TutorTabViewModel) o; + return Objects.equals(this.tutorTabId, tutorTabViewModel.tutorTabId) && + Objects.equals(this.userId, tutorTabViewModel.userId) && + Objects.equals(this.room, tutorTabViewModel.room) && + Objects.equals(this.emailTutorTab, tutorTabViewModel.emailTutorTab) && + Objects.equals(this.note, tutorTabViewModel.note) && + Objects.equals(this.dutyHours, tutorTabViewModel.dutyHours); + } + + @Override + public int hashCode() { + return Objects.hash(tutorTabId, userId, room, emailTutorTab, note, dutyHours); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TutorTabViewModel {\n"); + + sb.append(" tutorTabId: ").append(toIndentedString(tutorTabId)).append("\n"); + sb.append(" userId: ").append(toIndentedString(userId)).append("\n"); + sb.append(" room: ").append(toIndentedString(room)).append("\n"); + sb.append(" emailTutorTab: ").append(toIndentedString(emailTutorTab)).append("\n"); + sb.append(" note: ").append(toIndentedString(note)).append("\n"); + sb.append(" dutyHours: ").append(toIndentedString(dutyHours)).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/TutorTabApi.java b/app/src/main/java/com/uam/wmi/findmytutor/service/TutorTabApi.java new file mode 100644 index 0000000..e2f6d9a --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/TutorTabApi.java @@ -0,0 +1,58 @@ +package com.uam.wmi.findmytutor.service; + + +import com.uam.wmi.findmytutor.model.TutorTabViewModel; + +import io.reactivex.Observable; +import io.reactivex.Single; +import retrofit2.http.*; + + +public interface TutorTabApi { + /** + * Scrap all tutor tabs + * With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source + * @param tutorId (required) + * @return Call<Void> + */ + @POST("api/users/scrapTutorTab/{tutorId}") + Observable apiUsersScrapTutorTabByTutorIdPost( + @retrofit2.http.Path("tutorId") String tutorId + ); + + /** + * Scrap all tutor tabs + * With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source + * @return Call<Void> + */ + @POST("api/users/scrapTutorTab") + Observable apiUsersScrapTutorTabPost(); + + + /** + * + * + * @param tutorId (required) + * @return Call<TutorTabViewModel> + */ + @GET("api/users/tutorTab/{tutorId}") + Single apiUsersTutorTabByTutorIdGet( + @retrofit2.http.Path("tutorId") String tutorId + ); + + /** + * + * + * @param tutorId (required) + * @param tutorTab (optional) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @PUT("api/users/tutorTab/{tutorId}") + Observable apiUsersTutorTabByTutorIdPut( + @retrofit2.http.Path("tutorId") String tutorId, @retrofit2.http.Body TutorTabViewModel tutorTab + ); + +} diff --git a/app/src/main/res/layout/note_dialog.xml b/app/src/main/res/layout/note_dialog.xml index 2fc7ee8..08dcdd2 100644 --- a/app/src/main/res/layout/note_dialog.xml +++ b/app/src/main/res/layout/note_dialog.xml @@ -1,5 +1,6 @@ - - + android:textColor="@color/note_list_text" + /> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/tutor_list_row.xml b/app/src/main/res/layout/tutor_list_row.xml index f1c59c4..d31fb60 100644 --- a/app/src/main/res/layout/tutor_list_row.xml +++ b/app/src/main/res/layout/tutor_list_row.xml @@ -1,7 +1,7 @@ + android:textSize="15sp" /> + android:textSize="15sp" /> Date: Sun, 28 Oct 2018 12:18:49 +0100 Subject: [PATCH 09/16] Add duty hours to user information modal --- app/build.gradle | 1 + .../activity/UsersListActivity.java | 32 ++++++++++++------- .../findmytutor/model/DutyHourViewModel.java | 5 +++ .../findmytutor/model/TutorTabViewModel.java | 9 ++++-- app/src/main/res/layout/note_dialog.xml | 10 +++++- app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 5 +++ 7 files changed, 48 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 72c08c7..054989e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,5 +57,6 @@ 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' } 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 index 7e053e4..cfce872 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,5 +1,7 @@ package com.uam.wmi.findmytutor.activity; +import android.annotation.SuppressLint; +import android.content.DialogInterface; import android.graphics.Color; import android.os.Build; import android.os.Bundle; @@ -18,6 +20,7 @@ import android.widget.ListView; import android.widget.TextView; import com.annimon.stream.Stream; +import com.facebook.shimmer.ShimmerFrameLayout; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.model.DutyHour; @@ -44,6 +47,8 @@ import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; +import static java.util.stream.Collectors.toList; + public class UsersListActivity extends BaseActivity { private static final String TAG = UsersListActivity.class.getSimpleName(); @BindView(R.id.coordinator_layout) @@ -120,8 +125,12 @@ public class UsersListActivity extends BaseActivity { AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); alertDialogBuilderUserInput.setView(view); + alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> { + // User cancelled the dialog + }); + TextView userName = view.findViewById(R.id.userName); - TextView userDutyHours = view.findViewById(R.id.userDutyHours); + ListView userDutyHours = view.findViewById(R.id.userDutyHours); TextView userNote = view.findViewById(R.id.userNote); TextView userRoom = view.findViewById(R.id.userRoom); TextView userEmail = view.findViewById(R.id.userEmail); @@ -133,19 +142,22 @@ public class UsersListActivity extends BaseActivity { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSingleObserver() { + @SuppressLint("SetTextI18n") @Override public void onSuccess(TutorTabViewModel tutorTabViewModel) { Log.e("TUTOR_TAB",tutorTabViewModel.toString()); - List dutyHourslist = Stream.of(tutorTabViewModel.getDutyHours()) - .map(DutyHourViewModel::toString).toList(); + List dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours()) + .map(DutyHourViewModel::getSummary).toList(); - userRoom.setText(tutorTabViewModel.getRoom()); - userEmail.setText(tutorTabViewModel.getEmailTutorTab()); - userNote.setText(tutorTabViewModel.getNote()); + userRoom.setText(getString(R.string.userRoom) + ": " + tutorTabViewModel.getRoom()); + userEmail.setText(getString(R.string.userEmail) + ": " + tutorTabViewModel.getEmailTutorTab()); + userNote.setText(getString(R.string.userNote) + ": " + tutorTabViewModel.getNote()); - if(dutyHourslist.size() > 0) - userDutyHours.setText(dutyHourslist.get(0)); + final ArrayAdapter arrayAdapter = new ArrayAdapter(UsersListActivity.this, + android.R.layout.simple_list_item_activated_1,dutyHoursList); + + userDutyHours.setAdapter(arrayAdapter); } @@ -159,7 +171,7 @@ public class UsersListActivity extends BaseActivity { final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); alertDialog.show(); - } + } private void fetchAllTutors() { @@ -202,8 +214,6 @@ public class UsersListActivity extends BaseActivity { showError(e); } })); - - } private void showError(Throwable e) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java b/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java index 36e688e..d3bcbe2 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/DutyHourViewModel.java @@ -94,6 +94,11 @@ public class DutyHourViewModel { return Objects.hash(day, start, end); } + public String getSummary() { + return this.getDay() + " " + this.getStart() + " " + this.getEnd(); + } + + @Override public String toString() { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java b/app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java index 8c7bb97..f74d50c 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/TutorTabViewModel.java @@ -22,13 +22,13 @@ public class TutorTabViewModel { private String userId = null; @SerializedName("room") - private String room = null; + private String room = ""; @SerializedName("emailTutorTab") - private String emailTutorTab = null; + private String emailTutorTab = ""; @SerializedName("note") - private String note = null; + private String note = ""; @SerializedName("dutyHours") private List dutyHours = null; @@ -112,6 +112,9 @@ public class TutorTabViewModel { public String getNote() { + if(note == null) + return ""; + return note; } diff --git a/app/src/main/res/layout/note_dialog.xml b/app/src/main/res/layout/note_dialog.xml index 08dcdd2..8b0ae93 100644 --- a/app/src/main/res/layout/note_dialog.xml +++ b/app/src/main/res/layout/note_dialog.xml @@ -8,6 +8,7 @@ android:paddingRight="@dimen/activity_margin" android:paddingTop="@dimen/activity_margin"> + + + - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 387faef..f21ae63 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,7 +2,7 @@ #3F51B5 #303F9F - #9ef13f + #dc0004 #999 #89c3c3c3 #858585 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8a70684..4e32e8f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -198,4 +198,9 @@ functionality. Main2Activity There is no users in system + Close + Pokój + Email + Notatka + Dyżury: From d4aa5b526119ff123f0f209219006e0f25cc1ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Sun, 28 Oct 2018 17:40:16 +0100 Subject: [PATCH 10/16] Refactor & don't show user information when tutor tab does not exist --- .../activity/UsersListActivity.java | 63 ++----- .../wmi/findmytutor/model/ReturnedTutors.java | 161 ++++++++---------- .../wmi/findmytutor/service/UserService.java | 2 +- app/src/main/res/layout/note_dialog.xml | 3 +- app/src/main/res/values/strings.xml | 1 + 5 files changed, 95 insertions(+), 135 deletions(-) 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 index cfce872..525ee06 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,7 +1,6 @@ package com.uam.wmi.findmytutor.activity; import android.annotation.SuppressLint; -import android.content.DialogInterface; import android.graphics.Color; import android.os.Build; import android.os.Bundle; @@ -20,10 +19,8 @@ import android.widget.ListView; import android.widget.TextView; import com.annimon.stream.Stream; -import com.facebook.shimmer.ShimmerFrameLayout; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.model.DutyHour; import com.uam.wmi.findmytutor.model.DutyHourViewModel; import com.uam.wmi.findmytutor.model.TutorTabViewModel; import com.uam.wmi.findmytutor.model.User; @@ -47,8 +44,6 @@ import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; -import static java.util.stream.Collectors.toList; - public class UsersListActivity extends BaseActivity { private static final String TAG = UsersListActivity.class.getSimpleName(); @BindView(R.id.coordinator_layout) @@ -67,7 +62,6 @@ public class UsersListActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.users_list); ButterKnife.bind(this); @@ -95,29 +89,10 @@ public class UsersListActivity extends BaseActivity { @Override public void onLongClick(View view, int position) { - //showActionsDialog(position); - - //showNoteDialog(true, tutorsList.get(position), position); } })); } - - private void showActionsDialog(final int position) { - CharSequence colors[] = new CharSequence[]{"Edit", "Delete"}; - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Choose option"); - builder.setItems(colors, (dialog, which) -> { - if (which == 0) { - showNoteDialog(true, tutorsList.get(position), position); - } else { - //deleteNote(tutorsList.get(position).getId(), position); - } - }); - builder.show(); - } - private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) { LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null); @@ -135,7 +110,7 @@ public class UsersListActivity extends BaseActivity { TextView userRoom = view.findViewById(R.id.userRoom); TextView userEmail = view.findViewById(R.id.userEmail); - userName.setText(user.getFirstName() + " " + user.getLastName()); + userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); disposable.add( tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId()) @@ -145,21 +120,19 @@ public class UsersListActivity extends BaseActivity { @SuppressLint("SetTextI18n") @Override public void onSuccess(TutorTabViewModel tutorTabViewModel) { - Log.e("TUTOR_TAB",tutorTabViewModel.toString()); - + final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); List dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours()) .map(DutyHourViewModel::getSummary).toList(); - userRoom.setText(getString(R.string.userRoom) + ": " + tutorTabViewModel.getRoom()); - userEmail.setText(getString(R.string.userEmail) + ": " + tutorTabViewModel.getEmailTutorTab()); - userNote.setText(getString(R.string.userNote) + ": " + tutorTabViewModel.getNote()); + 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 arrayAdapter = new ArrayAdapter(UsersListActivity.this, - android.R.layout.simple_list_item_activated_1,dutyHoursList); + final ArrayAdapter arrayAdapter = new ArrayAdapter<>(UsersListActivity.this, + android.R.layout.simple_list_item_activated_1, dutyHoursList); userDutyHours.setAdapter(arrayAdapter); - - + alertDialog.show(); } @Override @@ -167,11 +140,7 @@ public class UsersListActivity extends BaseActivity { showError(e); } })); - - - final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); - alertDialog.show(); - } + } private void fetchAllTutors() { @@ -180,7 +149,7 @@ public class UsersListActivity extends BaseActivity { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .map(tutors -> { - List tutorsList = new ArrayList<>(tutors.getTutors()); + List tutorsList = new ArrayList<>(tutors); List onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList(); @@ -190,9 +159,9 @@ public class UsersListActivity extends BaseActivity { List notActiveTutors = Stream.of(tutorsList) .filterNot(User::isIsActive).toList(); - Collections.sort(onlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); - Collections.sort(activeNotOnlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); - Collections.sort(notActiveTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName())); + Collections.sort(onlineTutors, this::sortByUserName); + Collections.sort(activeNotOnlineTutors, this::sortByUserName); + Collections.sort(notActiveTutors, this::sortByUserName); List sortedUserList = new ArrayList<>(onlineTutors); sortedUserList.addAll(activeNotOnlineTutors); @@ -216,6 +185,11 @@ public class UsersListActivity extends BaseActivity { })); } + + private int sortByUserName(User t1, User t2) { + return t1.getFirstName().compareTo(t2.getFirstName()); + } + private void showError(Throwable e) { String message = e.toString(); @@ -237,7 +211,6 @@ public class UsersListActivity extends BaseActivity { } else { noNotesView.setVisibility(View.VISIBLE); } - } @Override 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 index 23a897a..d336ddd 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/ReturnedTutors.java @@ -1,121 +1,108 @@ 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; +public class ReturnedTutors { -/** - * ReturnedTutors - */ - -public class ReturnedTutors extends User{ - @SerializedName("tutors") + @SerializedName("id") @Expose - private List tutors = null; - - @SerializedName("blacklistersTutors") + private String id; + @SerializedName("isOnline") @Expose - private List blacklistersTutors = null; + 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 ReturnedTutors tutors(List tutors) { - this.tutors = tutors; - return this; + public String getId() { + return id; } - public List getTutors() { - return tutors; + public void setId(String id) { + this.id = id; } - public ReturnedTutors addTutorsItem(User tutorsItem) { - if (this.tutors == null) { - this.tutors = new ArrayList(); - } - this.tutors.add(tutorsItem); - return this; + public Boolean getIsOnline() { + return isOnline; } - /** - * Get tutors - * @return tutors - **/ - - - public void setTutors(List tutors) { - this.tutors = tutors; + public void setIsOnline(Boolean isOnline) { + this.isOnline = isOnline; } - public ReturnedTutors blacklistersTutors(List blacklistersTutors) { - this.blacklistersTutors = blacklistersTutors; - return this; + public String getTitle() { + return title; } - public ReturnedTutors addBlacklistersTutorsItem(User blacklistersTutorsItem) { - if (this.blacklistersTutors == null) { - this.blacklistersTutors = new ArrayList(); - } - this.blacklistersTutors.add(blacklistersTutorsItem); - return this; + public void setTitle(String title) { + this.title = title; } - /** - * Get blacklistersTutors - * @return blacklistersTutors - **/ - @ApiModelProperty(value = "") - public List getBlacklistersTutors() { - return blacklistersTutors; + public String getFirstName() { + return firstName; } - public void setBlacklistersTutors(List blacklistersTutors) { - this.blacklistersTutors = blacklistersTutors; + public void setFirstName(String firstName) { + this.firstName = firstName; } - - @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); + public String getLastName() { + return lastName; } - @Override - public int hashCode() { - return Objects.hash(tutors, blacklistersTutors); + public void setLastName(String lastName) { + this.lastName = lastName; } - - @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(); + public String getDepartment() { + return department; } - /** - * 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 "); + 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; } } - 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 e4a80ec..19152bf 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 @@ -25,7 +25,7 @@ public interface UserService { Single > getAllUsers(); @GET("api/users") - Single apiUsersGet(); + Single > apiUsersGet(); @POST("api/users") Completable createUser(@Body User user); diff --git a/app/src/main/res/layout/note_dialog.xml b/app/src/main/res/layout/note_dialog.xml index 8b0ae93..e0ed238 100644 --- a/app/src/main/res/layout/note_dialog.xml +++ b/app/src/main/res/layout/note_dialog.xml @@ -8,7 +8,6 @@ android:paddingRight="@dimen/activity_margin" android:paddingTop="@dimen/activity_margin"> - + tools:text="@string/dutyHours" /> Email Notatka Dyżury: + Dyżury: From f5edf67c1511fc20a62e99f6453b1ef27b7b88fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Tue, 30 Oct 2018 19:03:20 +0100 Subject: [PATCH 11/16] Working activity without bottom navigation --- .../java/com/uam/wmi/findmytutor/activity/BaseActivity.java | 4 ++-- .../com/uam/wmi/findmytutor/activity/UsersListActivity.java | 6 +++--- app/src/main/res/layout/users_list.xml | 3 +++ app/src/main/res/layout/users_list_main.xml | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) 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 6fe2d49..7c43a75 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 @@ -173,10 +173,10 @@ public abstract class BaseActivity setFragment(sharingFragment); } else if (itemId == R.id.nav_user_list) { - //removeFragment(sharingFragment); + removeFragment(sharingFragment); startActivity(new Intent(this, UsersListActivity.class)); } - finish(); + //finish(); }, 300); return true; 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 index 525ee06..71415ee 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -219,17 +219,17 @@ public class UsersListActivity extends BaseActivity { disposable.dispose(); } - @Override + protected int getContentViewId() { return R.layout.users_list; } - @Override + protected int getNavigationMenuItemId() { return R.id.nav_user_list; } - @Override + public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } diff --git a/app/src/main/res/layout/users_list.xml b/app/src/main/res/layout/users_list.xml index 2feba05..074de2b 100644 --- a/app/src/main/res/layout/users_list.xml +++ b/app/src/main/res/layout/users_list.xml @@ -5,12 +5,15 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".activity.UsersListActivity"> + + diff --git a/app/src/main/res/layout/users_list_main.xml b/app/src/main/res/layout/users_list_main.xml index 47b4d8e..4266a83 100644 --- a/app/src/main/res/layout/users_list_main.xml +++ b/app/src/main/res/layout/users_list_main.xml @@ -9,6 +9,7 @@ tools:context=".activity.UsersListActivity" tools:showIn="@layout/users_list_main"> + Date: Tue, 30 Oct 2018 23:55:21 +0100 Subject: [PATCH 12/16] Rewrite activity to fragment --- .../findmytutor/activity/BaseActivity.java | 10 ++- .../findmytutor/activity/ListViewAdapter.java | 5 +- .../activity/UsersListActivity.java | 70 ++++++++++++------- app/src/main/res/layout/users_list.xml | 12 +--- app/src/main/res/layout/users_list_main.xml | 1 + 5 files changed, 61 insertions(+), 37 deletions(-) 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 7c43a75..58c8e4c 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 @@ -42,6 +42,7 @@ public abstract class BaseActivity private ArrayList stringArrayList; private ListViewAdapter adapter; private SharingFragment sharingFragment; + private Fragment userListFragment; @Override @@ -52,6 +53,7 @@ public abstract class BaseActivity navigationView = findViewById(R.id.navigation); navigationView.setOnNavigationItemSelectedListener(this); sharingFragment = new SharingFragment(); + userListFragment = new UsersListActivity(); } @@ -73,7 +75,7 @@ public abstract class BaseActivity 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); @@ -165,16 +167,20 @@ public abstract class BaseActivity navigationView.postDelayed(() -> { int itemId = item.getItemId(); + 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); } else if (itemId == R.id.nav_user_list) { removeFragment(sharingFragment); - startActivity(new Intent(this, UsersListActivity.class)); + setFragment(userListFragment); + //startActivity(new Intent(this, UsersListActivity.class)); } //finish(); }, 300); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java index 51592d1..c5bbf12 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java @@ -1,6 +1,7 @@ package com.uam.wmi.findmytutor.activity; import android.app.Activity; +import android.content.Context; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; @@ -21,11 +22,11 @@ import java.util.Objects; public class ListViewAdapter extends ArrayAdapter { - private UsersListActivity activity; + private Context activity; private List friendList; private List searchList; - public ListViewAdapter(UsersListActivity context, int resource, List objects) { + public ListViewAdapter(Context context, int resource, List objects) { super(context, resource, objects); this.activity = context; this.friendList = objects; 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 index 71415ee..22012a8 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,10 +1,10 @@ package com.uam.wmi.findmytutor.activity; import android.annotation.SuppressLint; +import android.app.Fragment; import android.graphics.Color; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.RequiresApi; +import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; @@ -14,6 +14,7 @@ import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; @@ -44,7 +45,9 @@ import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; -public class UsersListActivity extends BaseActivity { +import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; + +public class UsersListActivity extends Fragment { private static final String TAG = UsersListActivity.class.getSimpleName(); @BindView(R.id.coordinator_layout) CoordinatorLayout coordinatorLayout; @@ -52,35 +55,43 @@ public class UsersListActivity extends BaseActivity { 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 tutorsList = new ArrayList<>(); - @RequiresApi(api = Build.VERSION_CODES.N) - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.users_list); - ButterKnife.bind(this); + public UsersListActivity() { + } + + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + mAdapter = new TutorsAdapter(getActivity().getApplicationContext(), tutorsList); + View view = inflater.inflate(R.layout.users_list, container, false); + view.setBackgroundColor(getResources().getColor(android.R.color.white)); + return view; + } + + public void onViewCreated(View view, Bundle savedInstanceState) { + + ButterKnife.bind(this, view); userService = ApiClient.getClient(getApplicationContext()) .create(UserService.class); - tutorTabService = ApiClient.getClient(getApplicationContext()) + tutorTabService = ApiClient.getClient(getActivity().getApplicationContext()) .create(TutorTabApi.class); - mAdapter = new TutorsAdapter(this, tutorsList); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); + + RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext()); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); - recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16)); + recyclerView.addItemDecoration(new MyDividerItemDecoration(getActivity().getApplicationContext(), LinearLayoutManager.VERTICAL, 16)); recyclerView.setAdapter(mAdapter); fetchAllTutors(); - recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, + recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity().getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() { @Override public void onClick(View view, final int position) { @@ -93,11 +104,12 @@ public class UsersListActivity extends BaseActivity { })); } + private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) { - LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); + LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext()); View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null); - AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); + AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity().getApplicationContext()); alertDialogBuilderUserInput.setView(view); alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> { @@ -128,7 +140,7 @@ public class UsersListActivity extends BaseActivity { 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 arrayAdapter = new ArrayAdapter<>(UsersListActivity.this, + final ArrayAdapter arrayAdapter = new ArrayAdapter<>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_activated_1, dutyHoursList); userDutyHours.setAdapter(arrayAdapter); @@ -172,10 +184,11 @@ public class UsersListActivity extends BaseActivity { .subscribeWith(new DisposableSingleObserver>() { @Override public void onSuccess(List users) { + toggleEmptyNotes(); tutorsList.clear(); tutorsList.addAll(users); mAdapter.notifyDataSetChanged(); - toggleEmptyNotes(); + } @Override @@ -214,21 +227,30 @@ public class UsersListActivity extends BaseActivity { } @Override - protected void onDestroy() { + public void onDestroy() { super.onDestroy(); disposable.dispose(); } - - protected int getContentViewId() { - return R.layout.users_list; + @Override + public void onResume() { + super.onResume(); + fetchAllTutors(); + Log.e(TAG,"onResume"); } + @Override + public void onPause() { + super.onPause(); + Log.e(TAG,"onPause"); - protected int getNavigationMenuItemId() { - return R.id.nav_user_list; } + @Override + public void onStop() { + super.onStop(); + Log.e(TAG,"onStop"); + } public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/app/src/main/res/layout/users_list.xml b/app/src/main/res/layout/users_list.xml index 074de2b..5cc4880 100644 --- a/app/src/main/res/layout/users_list.xml +++ b/app/src/main/res/layout/users_list.xml @@ -1,21 +1,15 @@ - + + diff --git a/app/src/main/res/layout/users_list_main.xml b/app/src/main/res/layout/users_list_main.xml index 4266a83..f8945d4 100644 --- a/app/src/main/res/layout/users_list_main.xml +++ b/app/src/main/res/layout/users_list_main.xml @@ -1,5 +1,6 @@ + Date: Thu, 1 Nov 2018 20:37:51 +0100 Subject: [PATCH 13/16] Fix loginActivity - there is possibility to use ordinary validate endpoint --- app/src/main/AndroidManifest.xml | 7 +- .../findmytutor/activity/LoginActivity.java | 479 +++++------------- .../activity/UsersListActivity.java | 9 +- .../wmi/findmytutor/utils/RestApiHelper.java | 27 +- app/src/main/res/layout/users_list_main.xml | 10 - app/src/main/res/values/strings.xml | 1 + 6 files changed, 162 insertions(+), 371 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f0599bd..1f83ca9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,11 +48,6 @@ android:label="@string/title_activity_sharing" android:launchMode="singleTop" /> - - - + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index d76c182..ef96d14 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -3,33 +3,20 @@ package com.uam.wmi.findmytutor.activity; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; -import android.app.LoaderManager.LoaderCallbacks; -import android.content.CursorLoader; import android.content.Intent; -import android.content.Loader; -import android.content.pm.PackageManager; -import android.database.Cursor; import android.net.Uri; -import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.provider.ContactsContract; -import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; -import android.util.Log; -import android.view.KeyEvent; import android.view.View; -import android.view.View.OnClickListener; import android.view.inputmethod.EditorInfo; -import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; +import android.widget.ProgressBar; import android.widget.Switch; -import android.widget.TextView; -import android.widget.ToggleButton; import com.auth0.android.jwt.Claim; import com.auth0.android.jwt.JWT; @@ -44,403 +31,197 @@ import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RestApiHelper; -import java.util.ArrayList; -import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; -import static android.Manifest.permission.READ_CONTACTS; - -/** - * A login screen that offers login via email/password. - */ -public class LoginActivity extends AppCompatActivity implements LoaderCallbacks { - - /** - * Id to identity READ_CONTACTS permission request. - */ - private static final int REQUEST_READ_CONTACTS = 0; - - /** - * A dummy authentication store containing known user names and passwords. - * TODO: remove after connecting to a real authentication system. - */ - private static final String[] DUMMY_CREDENTIALS = new String[]{ - "adam@o2.pl:adamadam", "foo@example.com:hello", "bar@example.com:world" - }; - /** - * Keep track of the login task to ensure we can cancel it if requested. - */ - private UserLoginTask mAuthTask = null; +public class LoginActivity extends AppCompatActivity { // UI references. - private AutoCompleteTextView mEmailView; + private AutoCompleteTextView mLoginNameView; private EditText mPasswordView; private View mProgressView; private View mLoginFormView; - private boolean loginOption; + private LdapService ldapService; + private UserService userService; + private CompositeDisposable disposable = new CompositeDisposable(); + private Boolean isTutor = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); - // Set up the login form. - mEmailView = (AutoCompleteTextView) findViewById(R.id.email); - populateAutoComplete(); + mLoginNameView = findViewById(R.id.email); - mPasswordView = (EditText) findViewById(R.id.password); - mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { - if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) { - attemptLogin(); - return true; - } - return false; - } - }); + ldapService = ApiClient.getClient(getApplicationContext()) + .create(LdapService.class); + userService = ApiClient.getClient(getApplicationContext()) + .create(UserService.class); - Switch tutorLogin = (Switch) findViewById(R.id.tutor_login_switch); - tutorLogin.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - loginOption = tutorLogin.isChecked(); - } - }); - - - Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); - mEmailSignInButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { + mPasswordView = findViewById(R.id.password); + mPasswordView.setOnEditorActionListener((textView, id, keyEvent) -> { + if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) { attemptLogin(); + return true; } + return false; }); + Switch tutorLogin = findViewById(R.id.tutor_login_switch); + + tutorLogin.setOnCheckedChangeListener((buttonView, isChecked) -> { + PrefUtils.storeIsTutor(getApplicationContext(), isChecked); + }); + + Button mEmailSignInButton = findViewById(R.id.email_sign_in_button); + mEmailSignInButton.setOnClickListener(view -> attemptLogin()); + mLoginFormView = findViewById(R.id.login_form); mProgressView = findViewById(R.id.login_progress); } - private void populateAutoComplete() { - if (!mayRequestContacts()) { - return; - } - getLoaderManager().initLoader(0, null, this); - } - - private boolean mayRequestContacts() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - return true; - } - if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { - return true; - } - if (shouldShowRequestPermissionRationale(READ_CONTACTS)) { - Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE) - .setAction(android.R.string.ok, new View.OnClickListener() { - @Override - @TargetApi(Build.VERSION_CODES.M) - public void onClick(View v) { - requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); - } - }); - } else { - requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); - } - return false; - } - - /** - * Callback received when a permissions request has been completed. - */ - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, - @NonNull int[] grantResults) { - if (requestCode == REQUEST_READ_CONTACTS) { - if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - populateAutoComplete(); - } - } - } - - - /** - * Attempts to sign in or register the account specified by the login form. - * If there are form errors (invalid email, missing fields, etc.), the - * errors are presented and no actual login attempt is made. - */ private void attemptLogin() { - if (mAuthTask != null) { - return; - } - // Reset errors. - mEmailView.setError(null); + mLoginNameView.setError(null); mPasswordView.setError(null); // Store values at the time of the login attempt. - String email = mEmailView.getText().toString(); + String loginName = mLoginNameView.getText().toString(); String password = mPasswordView.getText().toString(); boolean cancel = false; View focusView = null; - // Check for a valid password, if the user entered one. - if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { + // Check for a valid email address. + if (TextUtils.isEmpty(loginName)) { + mLoginNameView.setError(getString(R.string.error_field_required)); + focusView = mLoginNameView; + cancel = true; + } else if (!isEmailValid(loginName)) { + mLoginNameView.setError(getString(R.string.error_invalid_login_name)); + focusView = mLoginNameView; + cancel = true; + } + + // Check for a valid password address. + if (TextUtils.isEmpty(password)) { + mPasswordView.setError(getString(R.string.error_field_required)); + focusView = mPasswordView; + cancel = true; + } else if (!isPasswordValid(password)) { mPasswordView.setError(getString(R.string.error_invalid_password)); focusView = mPasswordView; cancel = true; } - // Check for a valid email address. - if (TextUtils.isEmpty(email)) { - mEmailView.setError(getString(R.string.error_field_required)); - focusView = mEmailView; - cancel = true; - } else if (!isEmailValid(email)) { - mEmailView.setError(getString(R.string.error_invalid_email)); - focusView = mEmailView; - cancel = true; - } - if (cancel) { - // There was an error; don't attempt login and focus the first - // form field with an error. focusView.requestFocus(); } else { - // Show a progress spinner, and kick off a background task to - // perform the user login attempt. showProgress(true); - mAuthTask = new UserLoginTask(email, password, loginOption); - mAuthTask.execute((Void) null); + loginProcess(loginName, password); + } } - private boolean isEmailValid(String email) { - //TODO: Replace this with your own logic - return email.contains("@"); + private boolean isEmailValid(String loginName) { + Pattern pattern = Pattern.compile("^s\\d+"); + Matcher matcher = pattern.matcher(loginName); + return matcher.find(); } private boolean isPasswordValid(String password) { - //TODO: Replace this with your own logic return password.length() > 4; } - /** - * Shows the progress UI and hides the login form. - */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) private void showProgress(final boolean show) { - // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow - // for very easy animations. If available, use these APIs to fade-in - // the progress spinner. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { - int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); + int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); - mLoginFormView.animate().setDuration(shortAnimTime).alpha( - show ? 0 : 1).setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); - } - }); - - mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); - mProgressView.animate().setDuration(shortAnimTime).alpha( - show ? 1 : 0).setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); - } - }); - } else { - // The ViewPropertyAnimator APIs are not available, so simply show - // and hide the relevant UI components. - mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); - } - } - - @Override - public Loader onCreateLoader(int i, Bundle bundle) { - return new CursorLoader(this, - // Retrieve data rows for the device user's 'profile' contact. - Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI, - ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, - - // Select only email addresses. - ContactsContract.Contacts.Data.MIMETYPE + - " = ?", new String[]{ContactsContract.CommonDataKinds.Email - .CONTENT_ITEM_TYPE}, - - // Show primary email addresses first. Note that there won't be - // a primary email address if the user hasn't specified one. - ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); - } - - @Override - public void onLoadFinished(Loader cursorLoader, Cursor cursor) { - List emails = new ArrayList<>(); - cursor.moveToFirst(); - while (!cursor.isAfterLast()) { - emails.add(cursor.getString(ProfileQuery.ADDRESS)); - cursor.moveToNext(); - } - - addEmailsToAutoComplete(emails); - } - - @Override - public void onLoaderReset(Loader cursorLoader) { - - } - - private void addEmailsToAutoComplete(List emailAddressCollection) { - //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list. - ArrayAdapter adapter = - new ArrayAdapter<>(LoginActivity.this, - android.R.layout.simple_dropdown_item_1line, emailAddressCollection); - - mEmailView.setAdapter(adapter); - } - - - private interface ProfileQuery { - String[] PROJECTION = { - ContactsContract.CommonDataKinds.Email.ADDRESS, - ContactsContract.CommonDataKinds.Email.IS_PRIMARY, - }; - - int ADDRESS = 0; - int IS_PRIMARY = 1; - } - - /** - * Represents an asynchronous login/registration task used to authenticate - * the user. - */ - public class UserLoginTask extends AsyncTask { - - private final String mEmail; - private final String mPassword; - private boolean isTutor; - private LdapService ldapService; - private UserService userService; - private CompositeDisposable disposable = new CompositeDisposable(); - private Boolean isAuthorizate; - - // Constructor - UserLoginTask(String email, String password, Boolean loginOption) { - mEmail = email; - mPassword = password; - isTutor = loginOption; - isAuthorizate = false; - ldapService = ApiClient.getClient(getApplicationContext()) - .create(LdapService.class); - userService = ApiClient.getClient(getApplicationContext()) - .create(UserService.class); - - PrefUtils.storeIsTutor(getApplicationContext(), this.isTutor); - } - - private void saveUserProfileToSharedPreferences(User user){ - PrefUtils.storeUserFirstName(getApplicationContext(), user.getFirstName()); - PrefUtils.storeUserLastName(getApplicationContext(), user.getLastName()); - PrefUtils.storeUserName(getApplicationContext(), user.getUserName()); - } - - private void getUserProfile(String userId) { - disposable.add( - userService - .getUserByID(userId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver() { - @Override - public void onSuccess(User user) { - Log.e("USER", String.valueOf(user)); - saveUserProfileToSharedPreferences(user); - - onPostExecute(true); - } - - public void onError(Throwable e) { - ((HttpException) e).code(); - Log.e("Login onError", e.getMessage()); - - if (e instanceof HttpException) { - ResponseBody responseBody = ((HttpException) e).response().errorBody(); - Log.e("Login onError", RestApiHelper.getErrorMessage(responseBody)); - } - - } - })); - } - - @Override - protected Boolean doInBackground(Void... params) { - LdapUser user = new LdapUser(mEmail, mPassword, "admin", (isTutor) ? "Tutor" : "Student", "string", "string", mEmail); - - disposable.add( - ldapService - .fakeValidate(user) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver() { - @Override - public void onSuccess(JwtToken jwtToken) { - String token = jwtToken.getToken(); - - //String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzY2QyMWFlYi00ZGRmLTQ0YTktOWM3OC1kNGE3MjVlN2MwNDkiLCJzdWIiOiJhc2RAYXNkc2FkYWEiLCJqdGkiOiIwMDMzYWZhMy0yNDZhLTQ1YTYtOWZmYi1lNzhiYjg3MDMzMmIiLCJleHAiOjE1NDMxMzUwNjAsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.rzks6-yjvVuYoO0pdiBwAfqDnMg8C8XrM9eA4h692m0"; - - JWT jwt = new JWT(token); - Claim role = jwt.getClaim("nameid"); - - PrefUtils.storeIsLoggedIn(getApplicationContext(), true); - PrefUtils.storeApiKey(getApplicationContext(), token); - PrefUtils.storeUserId(getApplicationContext(), role.asString()); - - getUserProfile(role.asString()); - } - - @Override - public void onError(Throwable e) { - Log.e("LoginError", "onError: " + e.getMessage()); - } - })); - - return true; - } - - @Override - protected void onPostExecute(final Boolean success) { - mAuthTask = null; - showProgress(false); - - if (success) { - Intent data = new Intent(); - String txt = "Main Activity"; - data.setData(Uri.parse(txt)); - setResult(RESULT_OK, data); - finish(); - } else { - mPasswordView.setError(getString(R.string.error_incorrect_password)); - mPasswordView.requestFocus(); + mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); + mLoginFormView.animate().setDuration(shortAnimTime).alpha( + show ? 0 : 1).setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); } + }); - } + mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); + mProgressView.animate().setDuration(shortAnimTime).alpha( + show ? 1 : 0).setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); + } + }); + } - @Override - protected void onCancelled() { - mAuthTask = null; - showProgress(false); + + private void loginProcess(String email, String password) { + LdapUser user = new LdapUser(email, password, "admin", (isTutor) ? "Tutor" : "Student", "string", "string", email); + + disposable.add(ldapService.fakeValidate(user) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::handleResponse, this::handleError)); + } + + private void getUserProfile(String userId) { + disposable.add( + userService + .getUserByID(userId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::saveUserProfileToSharedPreferences, this::handleError)); + } + + private void showSnackBarMessage(String message) { + Snackbar.make(findViewById(R.id.login_form), message, Snackbar.LENGTH_LONG) + .show(); + } + + private void handleResponse(JwtToken jwtToken) { + showProgress(false); + + String token = jwtToken.getToken(); + JWT jwt = new JWT(token); + Claim role = jwt.getClaim("nameid"); + + PrefUtils.storeIsLoggedIn(getApplicationContext(), true); + PrefUtils.storeApiKey(getApplicationContext(), token); + PrefUtils.storeUserId(getApplicationContext(), role.asString()); + + getUserProfile(role.asString()); + + Intent data = new Intent(); + String txt = "Main Activity"; + data.setData(Uri.parse(txt)); + setResult(RESULT_OK, data); + finish(); + } + + private void handleError(Throwable error) { + showProgress(false); + + if (error instanceof HttpException) { + + ResponseBody responseBody = ((HttpException) error).response().errorBody(); + showSnackBarMessage(RestApiHelper.getErrorMessage(responseBody)); + + } else { + showSnackBarMessage("Network Error !"); } } + + private void saveUserProfileToSharedPreferences(User user) { + PrefUtils.storeUserFirstName(getApplicationContext(), user.getFirstName()); + PrefUtils.storeUserLastName(getApplicationContext(), user.getLastName()); + PrefUtils.storeUserName(getApplicationContext(), user.getUserName()); + } } 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 index 22012a8..0d86a32 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -53,8 +53,7 @@ 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; @@ -184,7 +183,7 @@ public class UsersListActivity extends Fragment { .subscribeWith(new DisposableSingleObserver>() { @Override public void onSuccess(List users) { - toggleEmptyNotes(); + //toggleEmptyNotes(); tutorsList.clear(); tutorsList.addAll(users); mAdapter.notifyDataSetChanged(); @@ -218,13 +217,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() { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/RestApiHelper.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/RestApiHelper.java index ec27e2c..0a6bac4 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/RestApiHelper.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/RestApiHelper.java @@ -1,10 +1,19 @@ package com.uam.wmi.findmytutor.utils; +import android.app.Activity; +import android.graphics.Color; +import android.support.design.widget.Snackbar; +import android.view.View; +import android.widget.TextView; + +import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; +import com.uam.wmi.findmytutor.R; + import org.json.JSONObject; import okhttp3.ResponseBody; -public class RestApiHelper { +public class RestApiHelper extends Activity { public RestApiHelper() { } @@ -17,4 +26,20 @@ public class RestApiHelper { return e.getMessage(); } } + + + public void showError(Throwable e) { + String message = e.toString(); + + if (e instanceof HttpException) { + ResponseBody responseBody = ((HttpException) e).response().errorBody(); + message = RestApiHelper.getErrorMessage(responseBody); + } + + Snackbar snackbar = Snackbar.make(findViewById(R.id.activity_content), message, Snackbar.LENGTH_LONG); + View sbView = snackbar.getView(); + TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text); + textView.setTextColor(Color.BLUE); + snackbar.show(); + } } diff --git a/app/src/main/res/layout/users_list_main.xml b/app/src/main/res/layout/users_list_main.xml index f8945d4..fd7aafc 100644 --- a/app/src/main/res/layout/users_list_main.xml +++ b/app/src/main/res/layout/users_list_main.xml @@ -16,16 +16,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 258da37..1bd02fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -204,4 +204,5 @@ functionality. Notatka Dyżury: Dyżury: + Invalid format of login. Use s11111 format From aa3dbfb185fdac4cce7a6cc10b882305a8b8e10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 2 Nov 2018 15:45:18 +0100 Subject: [PATCH 14/16] Add search to list --- app/build.gradle | 1 - .../findmytutor/activity/BaseActivity.java | 65 +- .../findmytutor/activity/SharingFragment.java | 9 + .../activity/UsersListActivity.java | 46 +- .../com/uam/wmi/findmytutor/model/User.java | 1374 +++++++++-------- app/src/main/res/layout/users_list_main.xml | 11 + 6 files changed, 790 insertions(+), 716 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 054989e..72c08c7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } 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 58c8e4c..dc2e651 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 @@ -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 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); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 586fa13..03f6f2d 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -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); 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 index 0d86a32..134678f 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -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 tutorsList = new ArrayList<>(); + private List 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 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 arrayAdapter = new ArrayAdapter<>(getActivity().getApplicationContext(), + final ArrayAdapter 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>() { @Override public void onSuccess(List 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); } + + } \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/User.java b/app/src/main/java/com/uam/wmi/findmytutor/model/User.java index f16add4..4cfce36 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/User.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/User.java @@ -15,712 +15,750 @@ import io.swagger.annotations.ApiModelProperty; * User */ -public class User extends BaseResponse{ - @SerializedName("isOnline") - private Boolean isOnline = null; +public class User extends BaseResponse { + @SerializedName("isOnline") + private Boolean isOnline = null; - @SerializedName("isUsingBlacklist") - private Boolean isUsingBlacklist = null; + @SerializedName("isUsingBlacklist") + private Boolean isUsingBlacklist = null; - @SerializedName("isUsingWhitelist") - private Boolean isUsingWhitelist = null; + @SerializedName("isUsingWhitelist") + private Boolean isUsingWhitelist = null; - @SerializedName("blacklist") - private List blacklist = null; + @SerializedName("blacklist") + private List blacklist = null; - @SerializedName("whitelist") - private List whitelist = null; + @SerializedName("whitelist") + private List whitelist = null; - @SerializedName("department") - private String department = null; + @SerializedName("department") + private String department = null; - @SerializedName("ldapLogin") - private String ldapLogin = null; + @SerializedName("ldapLogin") + private String ldapLogin = null; - @SerializedName("title") - private String title = null; + @SerializedName("title") + private String title = null; - @SerializedName("firstName") - private String firstName = null; + @SerializedName("firstName") + private String firstName = null; - @SerializedName("lastName") - private String lastName = null; + @SerializedName("lastName") + private String lastName = null; - @SerializedName("isActive") - private Boolean isActive = null; + @SerializedName("isActive") + private Boolean isActive = null; - @SerializedName("tutorTab") - private TutorTab tutorTab = null; + @SerializedName("tutorTab") + private TutorTab tutorTab = null; - @SerializedName("coordinates") - private List coordinates = null; + @SerializedName("coordinates") + private List coordinates = null; - @SerializedName("id") - private String id = null; + @SerializedName("id") + private String id = null; - @SerializedName("userName") - private String userName = null; + @SerializedName("userName") + private String userName = null; - @SerializedName("normalizedUserName") - private String normalizedUserName = null; + @SerializedName("normalizedUserName") + private String normalizedUserName = null; - @SerializedName("email") - private String email = null; + @SerializedName("email") + private String email = null; - @SerializedName("normalizedEmail") - private String normalizedEmail = null; + @SerializedName("normalizedEmail") + private String normalizedEmail = null; - @SerializedName("emailConfirmed") - private Boolean emailConfirmed = null; + @SerializedName("emailConfirmed") + private Boolean emailConfirmed = null; - @SerializedName("passwordHash") - private String passwordHash = null; + @SerializedName("passwordHash") + private String passwordHash = null; - @SerializedName("securityStamp") - private String securityStamp = null; + @SerializedName("securityStamp") + private String securityStamp = null; - @SerializedName("concurrencyStamp") - private String concurrencyStamp = null; + @SerializedName("concurrencyStamp") + private String concurrencyStamp = null; - @SerializedName("phoneNumber") - private String phoneNumber = null; + @SerializedName("phoneNumber") + private String phoneNumber = null; - @SerializedName("phoneNumberConfirmed") - private Boolean phoneNumberConfirmed = null; + @SerializedName("phoneNumberConfirmed") + private Boolean phoneNumberConfirmed = null; - @SerializedName("twoFactorEnabled") - private Boolean twoFactorEnabled = null; + @SerializedName("twoFactorEnabled") + private Boolean twoFactorEnabled = null; - @SerializedName("lockoutEnd") - private OffsetDateTime lockoutEnd = null; + @SerializedName("lockoutEnd") + private OffsetDateTime lockoutEnd = null; - @SerializedName("lockoutEnabled") - private Boolean lockoutEnabled = null; + @SerializedName("lockoutEnabled") + private Boolean lockoutEnabled = null; - @SerializedName("accessFailedCount") - private Integer accessFailedCount = null; + @SerializedName("accessFailedCount") + private Integer accessFailedCount = null; - public User isOnline(Boolean isOnline) { - this.isOnline = isOnline; - return this; - } - - /** - * Get isOnline - * @return isOnline - **/ - @ApiModelProperty(value = "") - public Boolean isIsOnline() { - return isOnline; - } - - public void setIsOnline(Boolean isOnline) { - this.isOnline = isOnline; - } - - public User isUsingBlacklist(Boolean isUsingBlacklist) { - this.isUsingBlacklist = isUsingBlacklist; - return this; - } - - /** - * Get isUsingBlacklist - * @return isUsingBlacklist - **/ - @ApiModelProperty(value = "") - public Boolean isIsUsingBlacklist() { - return isUsingBlacklist; - } - - public void setIsUsingBlacklist(Boolean isUsingBlacklist) { - this.isUsingBlacklist = isUsingBlacklist; - } - - public User isUsingWhitelist(Boolean isUsingWhitelist) { - this.isUsingWhitelist = isUsingWhitelist; - return this; - } - - /** - * Get isUsingWhitelist - * @return isUsingWhitelist - **/ - @ApiModelProperty(value = "") - public Boolean isIsUsingWhitelist() { - return isUsingWhitelist; - } - - public void setIsUsingWhitelist(Boolean isUsingWhitelist) { - this.isUsingWhitelist = isUsingWhitelist; - } - - public User blacklist(List blacklist) { - this.blacklist = blacklist; - return this; - } - - public User addBlacklistItem(String blacklistItem) { - if (this.blacklist == null) { - this.blacklist = new ArrayList(); + public User isOnline(Boolean isOnline) { + this.isOnline = isOnline; + return this; } - this.blacklist.add(blacklistItem); - return this; - } - /** - * Get blacklist - * @return blacklist - **/ - @ApiModelProperty(value = "") - public List getBlacklist() { - return blacklist; - } - - public void setBlacklist(List blacklist) { - this.blacklist = blacklist; - } - - public User whitelist(List whitelist) { - this.whitelist = whitelist; - return this; - } - - public User addWhitelistItem(String whitelistItem) { - if (this.whitelist == null) { - this.whitelist = new ArrayList(); + /** + * Get isOnline + * + * @return isOnline + **/ + @ApiModelProperty(value = "") + public Boolean isIsOnline() { + return isOnline; } - this.whitelist.add(whitelistItem); - return this; - } - /** - * Get whitelist - * @return whitelist - **/ - @ApiModelProperty(value = "") - public List getWhitelist() { - return whitelist; - } - - public void setWhitelist(List whitelist) { - this.whitelist = whitelist; - } - - public User department(String department) { - this.department = department; - return this; - } - - /** - * Get department - * @return department - **/ - @ApiModelProperty(required = true, value = "") - public String getDepartment() { - return department; - } - - public void setDepartment(String department) { - this.department = department; - } - - public User ldapLogin(String ldapLogin) { - this.ldapLogin = ldapLogin; - return this; - } - - /** - * Get ldapLogin - * @return ldapLogin - **/ - @ApiModelProperty(required = true, value = "") - public String getLdapLogin() { - return ldapLogin; - } - - public void setLdapLogin(String ldapLogin) { - this.ldapLogin = ldapLogin; - } - - public User title(String title) { - this.title = title; - return this; - } - - /** - * Get title - * @return title - **/ - @ApiModelProperty(required = true, value = "") - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public User firstName(String firstName) { - this.firstName = firstName; - return this; - } - - /** - * Get firstName - * @return firstName - **/ - @ApiModelProperty(required = true, value = "") - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public User lastName(String lastName) { - this.lastName = lastName; - return this; - } - - /** - * Get lastName - * @return lastName - **/ - @ApiModelProperty(required = true, value = "") - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public User isActive(Boolean isActive) { - this.isActive = isActive; - return this; - } - - /** - * Get isActive - * @return isActive - **/ - @ApiModelProperty(required = true, value = "") - public Boolean isIsActive() { - return isActive; - } - - public void setIsActive(Boolean isActive) { - this.isActive = isActive; - } - - public User tutorTab(TutorTab tutorTab) { - this.tutorTab = tutorTab; - return this; - } - - /** - * Get tutorTab - * @return tutorTab - **/ - @ApiModelProperty(value = "") - public TutorTab getTutorTab() { - return tutorTab; - } - - public void setTutorTab(TutorTab tutorTab) { - this.tutorTab = tutorTab; - } - - public User coordinates(List coordinates) { - this.coordinates = coordinates; - return this; - } - - public User addCoordinatesItem(Coordinate coordinatesItem) { - if (this.coordinates == null) { - this.coordinates = new ArrayList(); + public void setIsOnline(Boolean isOnline) { + this.isOnline = isOnline; } - this.coordinates.add(coordinatesItem); - return this; - } - /** - * Get coordinates - * @return coordinates - **/ - @ApiModelProperty(value = "") - public List getCoordinates() { - return coordinates; - } - - public void setCoordinates(List coordinates) { - this.coordinates = coordinates; - } - - public User id(String id) { - this.id = id; - return this; - } - - /** - * Get id - * @return id - **/ - @ApiModelProperty(value = "") - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public User userName(String userName) { - this.userName = userName; - return this; - } - - /** - * Get userName - * @return userName - **/ - @ApiModelProperty(value = "") - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public User normalizedUserName(String normalizedUserName) { - this.normalizedUserName = normalizedUserName; - return this; - } - - /** - * Get normalizedUserName - * @return normalizedUserName - **/ - @ApiModelProperty(value = "") - public String getNormalizedUserName() { - return normalizedUserName; - } - - public void setNormalizedUserName(String normalizedUserName) { - this.normalizedUserName = normalizedUserName; - } - - public User email(String email) { - this.email = email; - return this; - } - - /** - * Get email - * @return email - **/ - @ApiModelProperty(value = "") - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public User normalizedEmail(String normalizedEmail) { - this.normalizedEmail = normalizedEmail; - return this; - } - - /** - * Get normalizedEmail - * @return normalizedEmail - **/ - @ApiModelProperty(value = "") - public String getNormalizedEmail() { - return normalizedEmail; - } - - public void setNormalizedEmail(String normalizedEmail) { - this.normalizedEmail = normalizedEmail; - } - - public User emailConfirmed(Boolean emailConfirmed) { - this.emailConfirmed = emailConfirmed; - return this; - } - - /** - * Get emailConfirmed - * @return emailConfirmed - **/ - @ApiModelProperty(value = "") - public Boolean isEmailConfirmed() { - return emailConfirmed; - } - - public void setEmailConfirmed(Boolean emailConfirmed) { - this.emailConfirmed = emailConfirmed; - } - - public User passwordHash(String passwordHash) { - this.passwordHash = passwordHash; - return this; - } - - /** - * Get passwordHash - * @return passwordHash - **/ - @ApiModelProperty(value = "") - public String getPasswordHash() { - return passwordHash; - } - - public void setPasswordHash(String passwordHash) { - this.passwordHash = passwordHash; - } - - public User securityStamp(String securityStamp) { - this.securityStamp = securityStamp; - return this; - } - - /** - * Get securityStamp - * @return securityStamp - **/ - @ApiModelProperty(value = "") - public String getSecurityStamp() { - return securityStamp; - } - - public void setSecurityStamp(String securityStamp) { - this.securityStamp = securityStamp; - } - - public User concurrencyStamp(String concurrencyStamp) { - this.concurrencyStamp = concurrencyStamp; - return this; - } - - /** - * Get concurrencyStamp - * @return concurrencyStamp - **/ - @ApiModelProperty(value = "") - public String getConcurrencyStamp() { - return concurrencyStamp; - } - - public void setConcurrencyStamp(String concurrencyStamp) { - this.concurrencyStamp = concurrencyStamp; - } - - public User phoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - return this; - } - - /** - * Get phoneNumber - * @return phoneNumber - **/ - @ApiModelProperty(value = "") - public String getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public User phoneNumberConfirmed(Boolean phoneNumberConfirmed) { - this.phoneNumberConfirmed = phoneNumberConfirmed; - return this; - } - - /** - * Get phoneNumberConfirmed - * @return phoneNumberConfirmed - **/ - @ApiModelProperty(value = "") - public Boolean isPhoneNumberConfirmed() { - return phoneNumberConfirmed; - } - - public void setPhoneNumberConfirmed(Boolean phoneNumberConfirmed) { - this.phoneNumberConfirmed = phoneNumberConfirmed; - } - - public User twoFactorEnabled(Boolean twoFactorEnabled) { - this.twoFactorEnabled = twoFactorEnabled; - return this; - } - - /** - * Get twoFactorEnabled - * @return twoFactorEnabled - **/ - @ApiModelProperty(value = "") - public Boolean isTwoFactorEnabled() { - return twoFactorEnabled; - } - - public void setTwoFactorEnabled(Boolean twoFactorEnabled) { - this.twoFactorEnabled = twoFactorEnabled; - } - - public User lockoutEnd(OffsetDateTime lockoutEnd) { - this.lockoutEnd = lockoutEnd; - return this; - } - - /** - * Get lockoutEnd - * @return lockoutEnd - **/ - @ApiModelProperty(value = "") - public OffsetDateTime getLockoutEnd() { - return lockoutEnd; - } - - public void setLockoutEnd(OffsetDateTime lockoutEnd) { - this.lockoutEnd = lockoutEnd; - } - - public User lockoutEnabled(Boolean lockoutEnabled) { - this.lockoutEnabled = lockoutEnabled; - return this; - } - - /** - * Get lockoutEnabled - * @return lockoutEnabled - **/ - @ApiModelProperty(value = "") - public Boolean isLockoutEnabled() { - return lockoutEnabled; - } - - public void setLockoutEnabled(Boolean lockoutEnabled) { - this.lockoutEnabled = lockoutEnabled; - } - - public User accessFailedCount(Integer accessFailedCount) { - this.accessFailedCount = accessFailedCount; - return this; - } - - /** - * Get accessFailedCount - * @return accessFailedCount - **/ - @ApiModelProperty(value = "") - public Integer getAccessFailedCount() { - return accessFailedCount; - } - - public void setAccessFailedCount(Integer accessFailedCount) { - this.accessFailedCount = accessFailedCount; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; + public User isUsingBlacklist(Boolean isUsingBlacklist) { + this.isUsingBlacklist = isUsingBlacklist; + return this; } - if (o == null || getClass() != o.getClass()) { - return false; + + /** + * Get isUsingBlacklist + * + * @return isUsingBlacklist + **/ + @ApiModelProperty(value = "") + public Boolean isIsUsingBlacklist() { + return isUsingBlacklist; } - User user = (User) o; - return Objects.equals(this.isOnline, user.isOnline) && - Objects.equals(this.isUsingBlacklist, user.isUsingBlacklist) && - Objects.equals(this.isUsingWhitelist, user.isUsingWhitelist) && - Objects.equals(this.blacklist, user.blacklist) && - Objects.equals(this.whitelist, user.whitelist) && - Objects.equals(this.department, user.department) && - Objects.equals(this.ldapLogin, user.ldapLogin) && - Objects.equals(this.title, user.title) && - Objects.equals(this.firstName, user.firstName) && - Objects.equals(this.lastName, user.lastName) && - Objects.equals(this.isActive, user.isActive) && - Objects.equals(this.tutorTab, user.tutorTab) && - Objects.equals(this.coordinates, user.coordinates) && - Objects.equals(this.id, user.id) && - Objects.equals(this.userName, user.userName) && - Objects.equals(this.normalizedUserName, user.normalizedUserName) && - Objects.equals(this.email, user.email) && - Objects.equals(this.normalizedEmail, user.normalizedEmail) && - Objects.equals(this.emailConfirmed, user.emailConfirmed) && - Objects.equals(this.passwordHash, user.passwordHash) && - Objects.equals(this.securityStamp, user.securityStamp) && - Objects.equals(this.concurrencyStamp, user.concurrencyStamp) && - Objects.equals(this.phoneNumber, user.phoneNumber) && - Objects.equals(this.phoneNumberConfirmed, user.phoneNumberConfirmed) && - Objects.equals(this.twoFactorEnabled, user.twoFactorEnabled) && - Objects.equals(this.lockoutEnd, user.lockoutEnd) && - Objects.equals(this.lockoutEnabled, user.lockoutEnabled) && - Objects.equals(this.accessFailedCount, user.accessFailedCount); - } - @Override - public int hashCode() { - return Objects.hash(isOnline, isUsingBlacklist, isUsingWhitelist, blacklist, whitelist, department, ldapLogin, title, firstName, lastName, isActive, tutorTab, coordinates, id, userName, normalizedUserName, email, normalizedEmail, emailConfirmed, passwordHash, securityStamp, concurrencyStamp, phoneNumber, phoneNumberConfirmed, twoFactorEnabled, lockoutEnd, lockoutEnabled, accessFailedCount); - } - - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class User {\n"); - - sb.append(" isOnline: ").append(toIndentedString(isOnline)).append("\n"); - sb.append(" isUsingBlacklist: ").append(toIndentedString(isUsingBlacklist)).append("\n"); - sb.append(" isUsingWhitelist: ").append(toIndentedString(isUsingWhitelist)).append("\n"); - sb.append(" blacklist: ").append(toIndentedString(blacklist)).append("\n"); - sb.append(" whitelist: ").append(toIndentedString(whitelist)).append("\n"); - sb.append(" department: ").append(toIndentedString(department)).append("\n"); - sb.append(" ldapLogin: ").append(toIndentedString(ldapLogin)).append("\n"); - sb.append(" title: ").append(toIndentedString(title)).append("\n"); - sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); - sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); - sb.append(" isActive: ").append(toIndentedString(isActive)).append("\n"); - sb.append(" tutorTab: ").append(toIndentedString(tutorTab)).append("\n"); - sb.append(" coordinates: ").append(toIndentedString(coordinates)).append("\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" userName: ").append(toIndentedString(userName)).append("\n"); - sb.append(" normalizedUserName: ").append(toIndentedString(normalizedUserName)).append("\n"); - sb.append(" email: ").append(toIndentedString(email)).append("\n"); - sb.append(" normalizedEmail: ").append(toIndentedString(normalizedEmail)).append("\n"); - sb.append(" emailConfirmed: ").append(toIndentedString(emailConfirmed)).append("\n"); - sb.append(" passwordHash: ").append(toIndentedString(passwordHash)).append("\n"); - sb.append(" securityStamp: ").append(toIndentedString(securityStamp)).append("\n"); - sb.append(" concurrencyStamp: ").append(toIndentedString(concurrencyStamp)).append("\n"); - sb.append(" phoneNumber: ").append(toIndentedString(phoneNumber)).append("\n"); - sb.append(" phoneNumberConfirmed: ").append(toIndentedString(phoneNumberConfirmed)).append("\n"); - sb.append(" twoFactorEnabled: ").append(toIndentedString(twoFactorEnabled)).append("\n"); - sb.append(" lockoutEnd: ").append(toIndentedString(lockoutEnd)).append("\n"); - sb.append(" lockoutEnabled: ").append(toIndentedString(lockoutEnabled)).append("\n"); - sb.append(" accessFailedCount: ").append(toIndentedString(accessFailedCount)).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"; + public void setIsUsingBlacklist(Boolean isUsingBlacklist) { + this.isUsingBlacklist = isUsingBlacklist; + } + + public User isUsingWhitelist(Boolean isUsingWhitelist) { + this.isUsingWhitelist = isUsingWhitelist; + return this; + } + + /** + * Get isUsingWhitelist + * + * @return isUsingWhitelist + **/ + @ApiModelProperty(value = "") + public Boolean isIsUsingWhitelist() { + return isUsingWhitelist; + } + + public void setIsUsingWhitelist(Boolean isUsingWhitelist) { + this.isUsingWhitelist = isUsingWhitelist; + } + + public User blacklist(List blacklist) { + this.blacklist = blacklist; + return this; + } + + public User addBlacklistItem(String blacklistItem) { + if (this.blacklist == null) { + this.blacklist = new ArrayList(); + } + this.blacklist.add(blacklistItem); + return this; + } + + /** + * Get blacklist + * + * @return blacklist + **/ + @ApiModelProperty(value = "") + public List getBlacklist() { + return blacklist; + } + + public void setBlacklist(List blacklist) { + this.blacklist = blacklist; + } + + public User whitelist(List whitelist) { + this.whitelist = whitelist; + return this; + } + + public User addWhitelistItem(String whitelistItem) { + if (this.whitelist == null) { + this.whitelist = new ArrayList(); + } + this.whitelist.add(whitelistItem); + return this; + } + + /** + * Get whitelist + * + * @return whitelist + **/ + @ApiModelProperty(value = "") + public List getWhitelist() { + return whitelist; + } + + public void setWhitelist(List whitelist) { + this.whitelist = whitelist; + } + + public User department(String department) { + this.department = department; + return this; + } + + /** + * Get department + * + * @return department + **/ + @ApiModelProperty(required = true, value = "") + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + + public User ldapLogin(String ldapLogin) { + this.ldapLogin = ldapLogin; + return this; + } + + /** + * Get ldapLogin + * + * @return ldapLogin + **/ + @ApiModelProperty(required = true, value = "") + public String getLdapLogin() { + return ldapLogin; + } + + public void setLdapLogin(String ldapLogin) { + this.ldapLogin = ldapLogin; + } + + public User title(String title) { + this.title = title; + return this; + } + + /** + * Get title + * + * @return title + **/ + @ApiModelProperty(required = true, value = "") + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public User firstName(String firstName) { + this.firstName = firstName; + return this; + } + + /** + * Get firstName + * + * @return firstName + **/ + @ApiModelProperty(required = true, value = "") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public User lastName(String lastName) { + this.lastName = lastName; + return this; + } + + /** + * Get lastName + * + * @return lastName + **/ + @ApiModelProperty(required = true, value = "") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public User isActive(Boolean isActive) { + this.isActive = isActive; + return this; + } + + /** + * Get isActive + * + * @return isActive + **/ + @ApiModelProperty(required = true, value = "") + public Boolean isIsActive() { + return isActive; + } + + public void setIsActive(Boolean isActive) { + this.isActive = isActive; + } + + public User tutorTab(TutorTab tutorTab) { + this.tutorTab = tutorTab; + return this; + } + + /** + * Get tutorTab + * + * @return tutorTab + **/ + @ApiModelProperty(value = "") + public TutorTab getTutorTab() { + return tutorTab; + } + + public void setTutorTab(TutorTab tutorTab) { + this.tutorTab = tutorTab; + } + + public User coordinates(List coordinates) { + this.coordinates = coordinates; + return this; + } + + public User addCoordinatesItem(Coordinate coordinatesItem) { + if (this.coordinates == null) { + this.coordinates = new ArrayList(); + } + this.coordinates.add(coordinatesItem); + return this; + } + + /** + * Get coordinates + * + * @return coordinates + **/ + @ApiModelProperty(value = "") + public List getCoordinates() { + return coordinates; + } + + public void setCoordinates(List coordinates) { + this.coordinates = coordinates; + } + + public User id(String id) { + this.id = id; + return this; + } + + /** + * Get id + * + * @return id + **/ + @ApiModelProperty(value = "") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public User userName(String userName) { + this.userName = userName; + return this; + } + + /** + * Get userName + * + * @return userName + **/ + @ApiModelProperty(value = "") + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public User normalizedUserName(String normalizedUserName) { + this.normalizedUserName = normalizedUserName; + return this; + } + + /** + * Get normalizedUserName + * + * @return normalizedUserName + **/ + @ApiModelProperty(value = "") + public String getNormalizedUserName() { + return normalizedUserName; + } + + public void setNormalizedUserName(String normalizedUserName) { + this.normalizedUserName = normalizedUserName; + } + + public User email(String email) { + this.email = email; + return this; + } + + /** + * Get email + * + * @return email + **/ + @ApiModelProperty(value = "") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public User normalizedEmail(String normalizedEmail) { + this.normalizedEmail = normalizedEmail; + return this; + } + + /** + * Get normalizedEmail + * + * @return normalizedEmail + **/ + @ApiModelProperty(value = "") + public String getNormalizedEmail() { + return normalizedEmail; + } + + public void setNormalizedEmail(String normalizedEmail) { + this.normalizedEmail = normalizedEmail; + } + + public User emailConfirmed(Boolean emailConfirmed) { + this.emailConfirmed = emailConfirmed; + return this; + } + + /** + * Get emailConfirmed + * + * @return emailConfirmed + **/ + @ApiModelProperty(value = "") + public Boolean isEmailConfirmed() { + return emailConfirmed; + } + + public void setEmailConfirmed(Boolean emailConfirmed) { + this.emailConfirmed = emailConfirmed; + } + + public User passwordHash(String passwordHash) { + this.passwordHash = passwordHash; + return this; + } + + /** + * Get passwordHash + * + * @return passwordHash + **/ + @ApiModelProperty(value = "") + public String getPasswordHash() { + return passwordHash; + } + + public void setPasswordHash(String passwordHash) { + this.passwordHash = passwordHash; + } + + public User securityStamp(String securityStamp) { + this.securityStamp = securityStamp; + return this; + } + + /** + * Get securityStamp + * + * @return securityStamp + **/ + @ApiModelProperty(value = "") + public String getSecurityStamp() { + return securityStamp; + } + + public void setSecurityStamp(String securityStamp) { + this.securityStamp = securityStamp; + } + + public User concurrencyStamp(String concurrencyStamp) { + this.concurrencyStamp = concurrencyStamp; + return this; + } + + /** + * Get concurrencyStamp + * + * @return concurrencyStamp + **/ + @ApiModelProperty(value = "") + public String getConcurrencyStamp() { + return concurrencyStamp; + } + + public void setConcurrencyStamp(String concurrencyStamp) { + this.concurrencyStamp = concurrencyStamp; + } + + public User phoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + /** + * Get phoneNumber + * + * @return phoneNumber + **/ + @ApiModelProperty(value = "") + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public User phoneNumberConfirmed(Boolean phoneNumberConfirmed) { + this.phoneNumberConfirmed = phoneNumberConfirmed; + return this; + } + + /** + * Get phoneNumberConfirmed + * + * @return phoneNumberConfirmed + **/ + @ApiModelProperty(value = "") + public Boolean isPhoneNumberConfirmed() { + return phoneNumberConfirmed; + } + + public void setPhoneNumberConfirmed(Boolean phoneNumberConfirmed) { + this.phoneNumberConfirmed = phoneNumberConfirmed; + } + + public User twoFactorEnabled(Boolean twoFactorEnabled) { + this.twoFactorEnabled = twoFactorEnabled; + return this; + } + + /** + * Get twoFactorEnabled + * + * @return twoFactorEnabled + **/ + @ApiModelProperty(value = "") + public Boolean isTwoFactorEnabled() { + return twoFactorEnabled; + } + + public void setTwoFactorEnabled(Boolean twoFactorEnabled) { + this.twoFactorEnabled = twoFactorEnabled; + } + + public User lockoutEnd(OffsetDateTime lockoutEnd) { + this.lockoutEnd = lockoutEnd; + return this; + } + + /** + * Get lockoutEnd + * + * @return lockoutEnd + **/ + @ApiModelProperty(value = "") + public OffsetDateTime getLockoutEnd() { + return lockoutEnd; + } + + public void setLockoutEnd(OffsetDateTime lockoutEnd) { + this.lockoutEnd = lockoutEnd; + } + + public User lockoutEnabled(Boolean lockoutEnabled) { + this.lockoutEnabled = lockoutEnabled; + return this; + } + + /** + * Get lockoutEnabled + * + * @return lockoutEnabled + **/ + @ApiModelProperty(value = "") + public Boolean isLockoutEnabled() { + return lockoutEnabled; + } + + public void setLockoutEnabled(Boolean lockoutEnabled) { + this.lockoutEnabled = lockoutEnabled; + } + + public User accessFailedCount(Integer accessFailedCount) { + this.accessFailedCount = accessFailedCount; + return this; + } + + /** + * Get accessFailedCount + * + * @return accessFailedCount + **/ + @ApiModelProperty(value = "") + public Integer getAccessFailedCount() { + return accessFailedCount; + } + + public void setAccessFailedCount(Integer accessFailedCount) { + this.accessFailedCount = accessFailedCount; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + User user = (User) o; + return Objects.equals(this.isOnline, user.isOnline) && + Objects.equals(this.isUsingBlacklist, user.isUsingBlacklist) && + Objects.equals(this.isUsingWhitelist, user.isUsingWhitelist) && + Objects.equals(this.blacklist, user.blacklist) && + Objects.equals(this.whitelist, user.whitelist) && + Objects.equals(this.department, user.department) && + Objects.equals(this.ldapLogin, user.ldapLogin) && + Objects.equals(this.title, user.title) && + Objects.equals(this.firstName, user.firstName) && + Objects.equals(this.lastName, user.lastName) && + Objects.equals(this.isActive, user.isActive) && + Objects.equals(this.tutorTab, user.tutorTab) && + Objects.equals(this.coordinates, user.coordinates) && + Objects.equals(this.id, user.id) && + Objects.equals(this.userName, user.userName) && + Objects.equals(this.normalizedUserName, user.normalizedUserName) && + Objects.equals(this.email, user.email) && + Objects.equals(this.normalizedEmail, user.normalizedEmail) && + Objects.equals(this.emailConfirmed, user.emailConfirmed) && + Objects.equals(this.passwordHash, user.passwordHash) && + Objects.equals(this.securityStamp, user.securityStamp) && + Objects.equals(this.concurrencyStamp, user.concurrencyStamp) && + Objects.equals(this.phoneNumber, user.phoneNumber) && + Objects.equals(this.phoneNumberConfirmed, user.phoneNumberConfirmed) && + Objects.equals(this.twoFactorEnabled, user.twoFactorEnabled) && + Objects.equals(this.lockoutEnd, user.lockoutEnd) && + Objects.equals(this.lockoutEnabled, user.lockoutEnabled) && + Objects.equals(this.accessFailedCount, user.accessFailedCount); + } + + @Override + public int hashCode() { + return Objects.hash(isOnline, isUsingBlacklist, isUsingWhitelist, blacklist, whitelist, department, ldapLogin, title, firstName, lastName, isActive, tutorTab, coordinates, id, userName, normalizedUserName, email, normalizedEmail, emailConfirmed, passwordHash, securityStamp, concurrencyStamp, phoneNumber, phoneNumberConfirmed, twoFactorEnabled, lockoutEnd, lockoutEnabled, accessFailedCount); + } + + + public String toSearchString() { + StringBuilder sb = new StringBuilder(); + sb.append(userName); + sb.append(lastName); + sb.append(department); + sb.append(email); + + return sb.toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" isOnline: ").append(toIndentedString(isOnline)).append("\n"); + sb.append(" isUsingBlacklist: ").append(toIndentedString(isUsingBlacklist)).append("\n"); + sb.append(" isUsingWhitelist: ").append(toIndentedString(isUsingWhitelist)).append("\n"); + sb.append(" blacklist: ").append(toIndentedString(blacklist)).append("\n"); + sb.append(" whitelist: ").append(toIndentedString(whitelist)).append("\n"); + sb.append(" department: ").append(toIndentedString(department)).append("\n"); + sb.append(" ldapLogin: ").append(toIndentedString(ldapLogin)).append("\n"); + sb.append(" title: ").append(toIndentedString(title)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" isActive: ").append(toIndentedString(isActive)).append("\n"); + sb.append(" tutorTab: ").append(toIndentedString(tutorTab)).append("\n"); + sb.append(" coordinates: ").append(toIndentedString(coordinates)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" userName: ").append(toIndentedString(userName)).append("\n"); + sb.append(" normalizedUserName: ").append(toIndentedString(normalizedUserName)).append("\n"); + sb.append(" email: ").append(toIndentedString(email)).append("\n"); + sb.append(" normalizedEmail: ").append(toIndentedString(normalizedEmail)).append("\n"); + sb.append(" emailConfirmed: ").append(toIndentedString(emailConfirmed)).append("\n"); + sb.append(" passwordHash: ").append(toIndentedString(passwordHash)).append("\n"); + sb.append(" securityStamp: ").append(toIndentedString(securityStamp)).append("\n"); + sb.append(" concurrencyStamp: ").append(toIndentedString(concurrencyStamp)).append("\n"); + sb.append(" phoneNumber: ").append(toIndentedString(phoneNumber)).append("\n"); + sb.append(" phoneNumberConfirmed: ").append(toIndentedString(phoneNumberConfirmed)).append("\n"); + sb.append(" twoFactorEnabled: ").append(toIndentedString(twoFactorEnabled)).append("\n"); + sb.append(" lockoutEnd: ").append(toIndentedString(lockoutEnd)).append("\n"); + sb.append(" lockoutEnabled: ").append(toIndentedString(lockoutEnabled)).append("\n"); + sb.append(" accessFailedCount: ").append(toIndentedString(accessFailedCount)).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 "); } - return o.toString().replace("\n", "\n "); - } } diff --git a/app/src/main/res/layout/users_list_main.xml b/app/src/main/res/layout/users_list_main.xml index fd7aafc..d45ea30 100644 --- a/app/src/main/res/layout/users_list_main.xml +++ b/app/src/main/res/layout/users_list_main.xml @@ -16,6 +16,17 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> + + From 44b84fef0edee5f96a81b64712e2f2333a1afe92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 2 Nov 2018 16:08:11 +0100 Subject: [PATCH 15/16] Improve searching --- .../activity/UsersListActivity.java | 29 +++++++++---------- .../com/uam/wmi/findmytutor/model/User.java | 8 ++--- app/src/main/res/layout/note_dialog.xml | 7 +++++ app/src/main/res/values/strings.xml | 5 ++-- 4 files changed, 27 insertions(+), 22 deletions(-) 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 index 134678f..b201432 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,6 +1,5 @@ package com.uam.wmi.findmytutor.activity; -import android.annotation.SuppressLint; import android.app.Fragment; import android.graphics.Color; import android.os.Bundle; @@ -63,15 +62,12 @@ public class UsersListActivity extends Fragment { private List tutorsList = new ArrayList<>(); private List tutorsFiltered = new ArrayList<>(); - public static UsersListActivity newInstance() { - - return new UsersListActivity(); - } - public UsersListActivity() { } - + public static UsersListActivity newInstance() { + return new UsersListActivity(); + } public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mAdapter = new TutorsAdapter(getActivity().getApplicationContext(), tutorsFiltered); @@ -113,11 +109,13 @@ public class UsersListActivity extends Fragment { } - public void searchUser( String textToSearch){ - Log.e("SEARCH","textToSearch"); + public void searchUser(String textToSearch) { + Log.e("SEARCH", textToSearch); + tutorsList.toString(); tutorsFiltered.clear(); - tutorsFiltered.addAll(Stream.of(tutorsList).filter(t -> t.toSearchString().contains(textToSearch)).toList()); + tutorsFiltered.addAll(Stream.of(tutorsList).filter(t -> + t.toSearchString().toLowerCase().contains(textToSearch.toLowerCase())).toList()); mAdapter.notifyDataSetChanged(); } @@ -137,6 +135,7 @@ public class UsersListActivity extends Fragment { TextView userNote = view.findViewById(R.id.userNote); TextView userRoom = view.findViewById(R.id.userRoom); TextView userEmail = view.findViewById(R.id.userEmail); + TextView department = view.findViewById(R.id.userDepartment); userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); @@ -145,18 +144,16 @@ public class UsersListActivity extends Fragment { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSingleObserver() { - @SuppressLint("SetTextI18n") @Override public void onSuccess(TutorTabViewModel tutorTabViewModel) { final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); List 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())); + department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment())); final ArrayAdapter arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_activated_1, dutyHoursList); @@ -255,20 +252,20 @@ public class UsersListActivity extends Fragment { public void onResume() { super.onResume(); fetchAllTutors(); - Log.e(TAG,"onResume"); + Log.e(TAG, "onResume"); } @Override public void onPause() { super.onPause(); - Log.e(TAG,"onPause"); + Log.e(TAG, "onPause"); } @Override public void onStop() { super.onStop(); - Log.e(TAG,"onStop"); + Log.e(TAG, "onStop"); } public void onSaveInstanceState(Bundle outState) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/User.java b/app/src/main/java/com/uam/wmi/findmytutor/model/User.java index 4cfce36..6cc363e 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/User.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/User.java @@ -704,10 +704,10 @@ public class User extends BaseResponse { public String toSearchString() { StringBuilder sb = new StringBuilder(); - sb.append(userName); - sb.append(lastName); - sb.append(department); - sb.append(email); + sb.append(getFirstName()).append(" "); + sb.append(getLastName()).append(" "); + sb.append(getDepartment()).append(" "); + sb.append(getEmail()); return sb.toString(); } diff --git a/app/src/main/res/layout/note_dialog.xml b/app/src/main/res/layout/note_dialog.xml index e0ed238..f46f130 100644 --- a/app/src/main/res/layout/note_dialog.xml +++ b/app/src/main/res/layout/note_dialog.xml @@ -19,6 +19,13 @@ android:textSize="@dimen/lbl_new_note_title" android:textStyle="normal" /> + + Pokój Email Notatka - Dyżury: - Dyżury: + Dyżury + Dyżury Invalid format of login. Use s11111 format + Zakład From e4b33da25bb50581d3b8f0caa85ae02a38259776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 2 Nov 2018 17:31:35 +0100 Subject: [PATCH 16/16] Refactor before merge to develop --- app/src/main/AndroidManifest.xml | 12 - .../uam/wmi/findmytutor/ListViewAdapter.java | 112 ----- .../findmytutor/activity/BaseActivity.java | 33 +- .../findmytutor/activity/ListViewAdapter.java | 112 ----- .../findmytutor/activity/MainActivity.java | 440 ------------------ .../wmi/findmytutor/activity/MapFragment.java | 98 ---- .../findmytutor/activity/ProfileActivity.java | 14 - .../activity/SettingsActivity.java | 121 ----- .../findmytutor/activity/SharingActivity.java | 122 ----- .../activity/UsersListActivity.java | 26 +- .../{view => adapters}/TutorsAdapter.java | 7 +- .../com/uam/wmi/findmytutor/model/User.java | 2 +- .../wmi/findmytutor/service/UserService.java | 9 +- .../wmi/findmytutor/utils/ActiveFragment.java | 8 + app/src/main/res/layout/users_list_main.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 16 files changed, 36 insertions(+), 1083 deletions(-) delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java rename app/src/main/java/com/uam/wmi/findmytutor/{view => adapters}/TutorsAdapter.java (91%) create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/utils/ActiveFragment.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1f83ca9..ce37ffb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,16 +37,6 @@ android:label="@string/title_activity_login" android:launchMode="singleTask" android:noHistory="true" /> - - - - - diff --git a/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java deleted file mode 100644 index fb0d7ee..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.uam.wmi.findmytutor; - -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.activity.MainActivity; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Objects; - -public class ListViewAdapter extends ArrayAdapter { - - - private MainActivity activity; - private List friendList; - private List searchList; - - public ListViewAdapter(MainActivity context, int resource, List 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; - - ViewHolder(View v) { - imageView = (ImageView) v.findViewById(R.id.image_view); - friendName = (TextView) 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 dc2e651..1eecf25 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 @@ -5,7 +5,6 @@ import android.app.FragmentTransaction; 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; @@ -16,12 +15,10 @@ import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.widget.FrameLayout; -import android.widget.ListView; -import com.uam.wmi.findmytutor.ListViewAdapter; import com.uam.wmi.findmytutor.R; +import com.uam.wmi.findmytutor.utils.ActiveFragment; -import java.util.ArrayList; public abstract class BaseActivity extends AppCompatActivity @@ -34,8 +31,7 @@ public abstract class BaseActivity private SharingFragment sharingFragment; private Fragment userListFragment; - private String activeFragment = ""; - + private ActiveFragment activeFragment = ActiveFragment.NONE; @Override protected void onCreate(Bundle savedInstanceState) { @@ -97,18 +93,22 @@ public abstract class BaseActivity public boolean onCreateOptionsMenu( Menu menu) { getMenuInflater().inflate( R.menu.menu_main, menu); - MenuItem myActionMenuItem = menu.findItem( R.id.action_search); + MenuItem myActionMenuItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override - public boolean onQueryTextSubmit(String query) { + public boolean onQueryTextSubmit(String input) { + if(activeFragment.equals(ActiveFragment.USER_LIST)){ + executeUserListSearch(input); + } + return false; } @Override - public boolean onQueryTextChange(String newText) { - if(activeFragment.equals("userList")){ - ((UsersListActivity) userListFragment).searchUser(newText); + public boolean onQueryTextChange(String input) { + if(activeFragment.equals(ActiveFragment.USER_LIST)){ + executeUserListSearch(input); } return true; @@ -118,6 +118,10 @@ public abstract class BaseActivity return true; } + private void executeUserListSearch(String input){ + ((UsersListActivity) userListFragment).searchUser(input); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (actionBarDrawerToggle.onOptionsItemSelected(item)) { @@ -139,7 +143,6 @@ public abstract class BaseActivity } private void removeFragment(Fragment fragment) { - activeFragment = "map"; FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.hide(fragment); fragmentTransaction.commit(); @@ -159,14 +162,14 @@ public abstract class BaseActivity } else if (itemId == R.id.nav_user_list) { loadUserListFragment(); } - //finish(); + }, 300); return true; } private void loadUserSettingsFragment() { - activeFragment = "sharedSettings"; + activeFragment = ActiveFragment.SHARED_PREFERENCES; sharingFragment = SharingFragment.newInstance(); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.activity_content, sharingFragment); @@ -174,7 +177,7 @@ public abstract class BaseActivity } private void loadUserListFragment() { - activeFragment = "userList"; + activeFragment = ActiveFragment.USER_LIST; userListFragment = UsersListActivity.newInstance(); FragmentTransaction ft = getFragmentManager().beginTransaction(); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java deleted file mode 100644 index c5bbf12..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/ListViewAdapter.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.app.Activity; -import android.content.Context; -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 { - - private Context activity; - private List friendList; - private List searchList; - - public ListViewAdapter(Context context, int resource, List 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); - } - } -} \ No newline at end of file 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 deleted file mode 100644 index 9cce13f..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java +++ /dev/null @@ -1,440 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.animation.TypeEvaluator; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.res.Configuration; -import android.graphics.Color; -import android.os.Build; -import android.os.Bundle; -import android.support.design.widget.BottomNavigationView; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.widget.DrawerLayout; -import android.content.Context; -import android.content.SharedPreferences; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -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.os.Handler; -import android.view.View; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.widget.FrameLayout; -import android.widget.ListView; -import android.widget.Toast; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import android.util.Log; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; -import com.uam.wmi.findmytutor.utils.PrefUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.uam.wmi.findmytutor.model.Coordinate; -import com.uam.wmi.findmytutor.network.RetrofitClientInstance; -import com.uam.wmi.findmytutor.service.CoordinateService; - - -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 MainActivity extends AppCompatActivity implements - OnMapReadyCallback { - - private BottomNavigationView mMainNav; - private FrameLayout mMainFrame; - private boolean isTutor; - private MapFragment mapFragment; - private SharingFragment sharingFragment; - private NotificationFragment notificationFragment; - private ProfileFragment profileFragment;; - - private static final int REQUEST_PERMISSIONS = 100; - boolean boolean_permission; - - private DrawerLayout drawerLayout; - private ActionBarDrawerToggle actionBarDrawerToggle; - - private MapView mapView; - private MapboxMap mapboxMap; - private int mInterval = 10000; - private Handler mHandler; - - private Map coordsMap = new HashMap<>(); - - private CoordinateService coordinateService; - private CompositeDisposable disposable = new CompositeDisposable(); - - private Runnable mStatusChecker; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); - final String authToken = sharedPref.getString("authToken",null); - - mStatusChecker = new Runnable() { - @Override - public void run() { - try{ - fetchTopCoords(); - } finally { - mHandler.postDelayed(mStatusChecker, mInterval); - } - } - }; - - coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); - - mHandler = new Handler(); - Bundle extras = getIntent().getExtras(); - Mapbox.getInstance(this, getString(R.string.access_token)); - - - - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this); - - configureconfigureNavigationDrawer(); - configureBottomNavigationView(); - configureLogoutButton(); - - } - - @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(); - } - }); - } - - - private void configureconfigureNavigationDrawer() { - Toolbar toolbar = findViewById(R.id.toolbar_main); - setSupportActionBar(toolbar); - - drawerLayout = findViewById(R.id.drawer_layout); - - actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawerLayout.addDrawerListener(actionBarDrawerToggle); - - ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(false); - - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); - } - } - - private void setFragment(Fragment fragment) { - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.main_frame, fragment); - fragmentTransaction.commit(); - } - - private void configureBottomNavigationView(){ - - mMainFrame = findViewById(R.id.main_frame); - mMainNav = findViewById(R.id.main_nav); - isTutor = PrefUtils.getIsTutor(getApplicationContext()); - - if (!isTutor) { - mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE); - } - - mapFragment = new MapFragment(); - sharingFragment = new SharingFragment(); - notificationFragment = new NotificationFragment(); - profileFragment = new ProfileFragment(); - - // Default frag here -// setFragment(mapFragment); - mMainNav.setSelectedItemId(R.id.nav_map); - - /* code below is resposible for changing colours of tabs in main tab menu */ - mMainNav.setOnNavigationItemSelectedListener(item -> { - - switch (item.getItemId()) { - case R.id.nav_map: -// setFragment(mapFragment); - return true; - case R.id.nav_profile: - setFragment(sharingFragment); - return true; - default: - return false; - } - }); - } - - private void configureLogoutButton(){ - // Logout button - final FloatingActionButton button = findViewById(R.id.logoutButton); - - button.setOnClickListener(view -> { - PrefUtils.cleanUserLocalStorage(getApplicationContext()); - - Intent i = getBaseContext().getPackageManager() - .getLaunchIntentForPackage(getBaseContext().getPackageName()); - if (i != null) { - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - } - startActivity(i); - finish(); - }); - } - - @Override - public boolean onCreateOptionsMenu( Menu menu) { - getMenuInflater().inflate( R.menu.menu_main, menu); - - MenuItem myActionMenuItem = menu.findItem( R.id.action_search); - final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - return false; - } - - @Override - public boolean onQueryTextChange(String newText) { - if (TextUtils.isEmpty(newText)) { -// adapter.filter(""); -// listView.clearTextFilter(); - } else { -// adapter.filter(newText); - } - - return true; - } - }); - - return true; - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - - actionBarDrawerToggle.syncState(); - - if (isTutor) { - fn_permission(); - } - - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - actionBarDrawerToggle.onConfigurationChanged(newConfig); - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (actionBarDrawerToggle.onOptionsItemSelected(item)) { - return true; - } - return super.onOptionsItemSelected(item); - - } - - - private void fn_permission() { - if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { - - if ((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) { - - } else { - ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION - - }, - REQUEST_PERMISSIONS); - } - } else { - - if (isTutor) { - Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } - - } else { - Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show(); - } - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - - switch (requestCode) { - case REQUEST_PERMISSIONS: { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - boolean_permission = true; - } else { - Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show(); - } - } - } - } - - 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; - } - } - - 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.put(id,element); - } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ - Log.d("mapper", "update"); - Log.d("mapper", " "+cord.getTimeStamp()); - Log.d("mapper", " "+element.getTimeStamp()); - coordsMap.put(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 onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @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(); - } - - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - mHandler.removeCallbacks(mStatusChecker); - disposable.dispose(); - } -} - - diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java deleted file mode 100644 index d8c1e36..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - - -import android.os.Bundle; -import android.app.Fragment; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.mapbox.mapboxsdk.maps.MapView; -import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.network.ApiClient; -import com.uam.wmi.findmytutor.service.CoordinateService; - -import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; - -/** - * A simple {@link Fragment} subclass. - */ -public class MapFragment extends Fragment { - private MapView mapView; - - - public MapFragment() { - // Required empty public constructor - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_map, container, false); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - mapView = (MapView) view.findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - CoordinateService service = ApiClient.getClient(getApplicationContext()) - .create(CoordinateService.class); - } - - @Override - public void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - public void onResume() { - super.onResume(); - mapView.onResume(); - - } - - @Override - public void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - public void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - mapView.onDestroy(); - } - -// @Override -// public void onDestroy() { -// super.onDestroy(); -// mapView.onDestroy(); -// } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - - -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java deleted file mode 100644 index 5a3d92d..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import com.uam.wmi.findmytutor.R; - -public class ProfileActivity extends BaseActivity { - - @Override - protected int getContentViewId() { return R.layout.activity_profile; } - - @Override - protected int getNavigationMenuItemId() { - return R.id.nav_profile; - } -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java deleted file mode 100644 index 13b75a1..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; -import android.preference.EditTextPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.view.MenuItem; -import com.uam.wmi.findmytutor.R; - - -public class SettingsActivity extends AppCompatPreferenceActivity { - private static final String TAG = SettingsActivity.class.getSimpleName(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - //getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - // load settings fragment - getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit(); - } - - public static class MainPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_main); - - //TODO add on change listeners for preferences - - // feedback preference click listener - Preference myPref = findPreference(getString(R.string.key_send_feedback)); - myPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference preference) { - sendFeedback(getActivity()); - return true; - } - }); - } - - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - } - return super.onOptionsItemSelected(item); - } - - private static void bindPreferenceSummaryToValue(Preference preference) { - preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - - sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } - - /** - * A preference value change listener that updates the preference's summary - * to reflect its new value. - */ - private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - String stringValue = newValue.toString(); - - if (preference instanceof ListPreference) { - // For list preferences, look up the correct display value in - // the preference's 'entries' list. - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); - - // Set the summary to reflect the new value. - preference.setSummary( - index >= 0 - ? listPreference.getEntries()[index] - : null); - - } else if (preference instanceof EditTextPreference) { - if (preference.getKey().equals("key_gallery_name")) { - // update the changed gallery name to summary filed - preference.setSummary(stringValue); - } - } else { - preference.setSummary(stringValue); - } - return true; - } - }; - - /** - * Email client intent to send support mail - * Appends the necessary device information to email body - * useful when providing support - */ - public static void sendFeedback(Context context) { - String body = null; - try { - body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; - body = "\n\n-----------------------------\nPlease don't remove this information\n Device OS: Android \n Device OS version: " + - Build.VERSION.RELEASE + "\n App Version: " + body + "\n Device Brand: " + Build.BRAND + - "\n Device Model: " + Build.MODEL + "\n Device Manufacturer: " + Build.MANUFACTURER; - } catch (PackageManager.NameNotFoundException e) { - } - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("message/rfc822"); - intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"team@findmytutor.com"}); - intent.putExtra(Intent.EXTRA_SUBJECT, "Query from android app"); - intent.putExtra(Intent.EXTRA_TEXT, body); - context.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_email_client))); - } -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java deleted file mode 100644 index a989f0e..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; -import android.preference.EditTextPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.util.Log; -import android.view.MenuItem; -import com.uam.wmi.findmytutor.R; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import static android.content.ContentValues.TAG; - - -public class SharingActivity extends AppCompatPreferenceActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit(); - } - - public static class MainPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.layout.pref_sharing); - - Preference manualStatus = findPreference("key_manual_status"); - manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { - ListPreference lp = (ListPreference) findPreference("key_status_value"); - updateListPreference(lp, newValue, "manual_statuses"); - return true; - }); - - /* Preference manualLocation = findPreference("key_sharing_enabled"); - manualLocation.setOnPreferenceChangeListener((preference, newValue) -> { - ListPreference lp = (ListPreference) findPreference("key_sharing_enabled"); - updateListPreference(lp, newValue, "sharing_enabled"); - return true; - });*/ - - Preference sharingLocation = findPreference("key_sharing_enabled"); - sharingLocation.setOnPreferenceChangeListener((preference, o) -> { - Log.e("change", "1"); - return false; - }); - } - - - protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){ - CharSequence [] entries = lp.getEntries(); - Set defaultEntries = new HashSet(Arrays.asList(entries)); - SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); - Set manualStatusSet = sharedPref.getStringSet(storageKey,defaultEntries); - manualStatusSet.add((String) newValue); - String [] manualStatusArr = manualStatusSet.toArray(new String[0]); - Arrays.sort(manualStatusArr); - setListPreferenceData(lp.getKey(),manualStatusArr); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.putStringSet(storageKey,manualStatusSet); - editor.commit(); - } - - protected ListPreference setListPreferenceData(String lp_name, String [] entries) { - ListPreference lp = (ListPreference) findPreference(lp_name); - lp.setEntries(entries); - CharSequence[] entryValues = new CharSequence [entries.length]; - - for (int i = 0; i < entries.length; i++){ - entryValues[i] = Integer.toString(i+1); - } - - lp.setDefaultValue("1"); - lp.setEntryValues(entryValues); - - return lp; - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - } - return super.onOptionsItemSelected(item); - } - - /** - * Email client intent to send support mail - * Appends the necessary device information to email body - * useful when providing support - */ -/* public static void sendFeedback(Context context) { - String body = null; - try { - body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; - body = "\n\n-----------------------------\nPlease don't remove this information\n Device OS: Android \n Device OS version: " + - Build.VERSION.RELEASE + "\n App Version: " + body + "\n Device Brand: " + Build.BRAND + - "\n Device Model: " + Build.MODEL + "\n Device Manufacturer: " + Build.MANUFACTURER; - } catch (PackageManager.NameNotFoundException e) { - } - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("message/rfc822"); - intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"team@findmytutor.com"}); - intent.putExtra(Intent.EXTRA_SUBJECT, "Query from android app"); - intent.putExtra(Intent.EXTRA_TEXT, body); - context.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_email_client))); - }*/ -} 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 index b201432..caf83e4 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListActivity.java @@ -1,7 +1,6 @@ package com.uam.wmi.findmytutor.activity; import android.app.Fragment; -import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; @@ -10,7 +9,6 @@ import android.support.v7.app.AlertDialog; 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.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,6 +19,7 @@ import android.widget.TextView; import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; +import com.uam.wmi.findmytutor.adapters.TutorsAdapter; import com.uam.wmi.findmytutor.model.DutyHourViewModel; import com.uam.wmi.findmytutor.model.TutorTabViewModel; import com.uam.wmi.findmytutor.model.User; @@ -30,7 +29,6 @@ import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration; import com.uam.wmi.findmytutor.utils.RecyclerTouchListener; import com.uam.wmi.findmytutor.utils.RestApiHelper; -import com.uam.wmi.findmytutor.view.TutorsAdapter; import java.util.ArrayList; import java.util.Collections; @@ -48,6 +46,7 @@ import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; public class UsersListActivity extends Fragment { private static final String TAG = UsersListActivity.class.getSimpleName(); + @BindView(R.id.coordinator_layout) CoordinatorLayout coordinatorLayout; @BindView(R.id.recycler_view) @@ -77,7 +76,6 @@ public class UsersListActivity extends Fragment { } public void onViewCreated(View view, Bundle savedInstanceState) { - ButterKnife.bind(this, view); userService = ApiClient.getClient(getApplicationContext()) @@ -110,12 +108,9 @@ public class UsersListActivity extends Fragment { } public void searchUser(String textToSearch) { - Log.e("SEARCH", textToSearch); - tutorsList.toString(); - tutorsFiltered.clear(); tutorsFiltered.addAll(Stream.of(tutorsList).filter(t -> - t.toSearchString().toLowerCase().contains(textToSearch.toLowerCase())).toList()); + t.toSearchAbleString().toLowerCase().contains(textToSearch.toLowerCase())).toList()); mAdapter.notifyDataSetChanged(); } @@ -169,7 +164,6 @@ public class UsersListActivity extends Fragment { })); } - private void fetchAllTutors() { disposable.add( userService.apiUsersGet() @@ -204,7 +198,6 @@ public class UsersListActivity extends Fragment { tutorsFiltered.addAll(users); mAdapter.notifyDataSetChanged(); toggleEmptyNotes(); - } @Override @@ -227,11 +220,8 @@ public class UsersListActivity extends Fragment { message = RestApiHelper.getErrorMessage(responseBody); } - Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG); - View sbView = snackbar.getView(); - TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text); - textView.setTextColor(Color.BLUE); - snackbar.show(); + Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG) + .show(); } private void toggleEmptyNotes() { @@ -252,25 +242,19 @@ public class UsersListActivity extends Fragment { public void onResume() { super.onResume(); fetchAllTutors(); - Log.e(TAG, "onResume"); } @Override public void onPause() { super.onPause(); - Log.e(TAG, "onPause"); - } @Override public void onStop() { super.onStop(); - Log.e(TAG, "onStop"); } public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } - - } \ 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/adapters/TutorsAdapter.java similarity index 91% rename from app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java rename to app/src/main/java/com/uam/wmi/findmytutor/adapters/TutorsAdapter.java index 3b623e3..070d4af 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/view/TutorsAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/adapters/TutorsAdapter.java @@ -1,11 +1,8 @@ -package com.uam.wmi.findmytutor.view; +package com.uam.wmi.findmytutor.adapters; import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Color; import android.graphics.drawable.Drawable; import android.support.v7.widget.RecyclerView; -import android.text.Html; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -13,8 +10,6 @@ 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; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/User.java b/app/src/main/java/com/uam/wmi/findmytutor/model/User.java index 6cc363e..0e5c0d5 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/User.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/User.java @@ -702,7 +702,7 @@ public class User extends BaseResponse { } - public String toSearchString() { + public String toSearchAbleString() { StringBuilder sb = new StringBuilder(); sb.append(getFirstName()).append(" "); sb.append(getLastName()).append(" "); 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 19152bf..e8f415f 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 @@ -33,15 +33,8 @@ public interface UserService { @GET("api/users/page/{pageNum}") Single getPagedUsers(@Path("pageNum") String pageNum ); - /* @GET("api/users/tutors/page/{pageNum}") - //Observable getPagedTutors(@Path("pageNum") String pageNum); - Single getPagedTutors(@Path("pageNum") String pageNum);*/ - @GET("api/users/tutors/page/{pageNum}") - Single getPagedTutors( - @retrofit2.http.Path("pageNum") Integer pageNum - ); - + Single getPagedTutors(@Path("pageNum") Integer pageNum ); @GET("api/users/students/page/{pageNum}") Single getPagedStudents(@Path("pageNum") String pageNum); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/ActiveFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/ActiveFragment.java new file mode 100644 index 0000000..bc71d2e --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/ActiveFragment.java @@ -0,0 +1,8 @@ +package com.uam.wmi.findmytutor.utils; + +public enum ActiveFragment { + USER_LIST, + SHARED_PREFERENCES, + NONE +} + diff --git a/app/src/main/res/layout/users_list_main.xml b/app/src/main/res/layout/users_list_main.xml index d45ea30..6e6b891 100644 --- a/app/src/main/res/layout/users_list_main.xml +++ b/app/src/main/res/layout/users_list_main.xml @@ -23,7 +23,7 @@ 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:text="@string/loading" android:textColor="@color/msg_no_notes" android:textSize="@dimen/msg_no_notes" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2312443..7885e42 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -206,4 +206,5 @@ functionality. Dyżury Invalid format of login. Use s11111 format Zakład + Loading ...