From d9ada9319bb553e3ff491fa8199d2b3fe2ab02f5 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Thu, 3 Jan 2019 21:07:32 +0100 Subject: [PATCH 1/4] white list finished, toogle on/off related to blacklsits --- app/src/main/AndroidManifest.xml | 5 + app/src/main/assets/wmi1floor.geojson | 727 ++++++++++++++++++ .../findmytutor/activity/BaseActivity.java | 4 +- .../wmi/findmytutor/activity/BlackList.java | 20 +- .../wmi/findmytutor/activity/MapActivity.java | 1 + .../wmi/findmytutor/activity/WhiteList.java | 332 ++++++++ .../adapters/WhiteListAdapter.java | 132 ++++ .../wmi/findmytutor/service/UserService.java | 7 +- .../uam/wmi/findmytutor/utils/PrefUtils.java | 20 + .../main/res/layout/activity_black_list.xml | 1 - .../main/res/layout/activity_white_list.xml | 83 ++ .../main/res/layout/content_black_list.xml | 2 +- .../main/res/layout/content_white_list.xml | 33 + .../main/res/layout/info_popup_whitelist.xml | 39 + .../main/res/layout/white_list_fab_modal.xml | 42 + app/src/main/res/layout/white_list_row.xml | 59 ++ .../main/res/menu/activity_main_drawer.xml | 4 +- app/src/main/res/menu/menu_white_list.xml | 11 + app/src/main/res/values-pl/strings.xml | 4 + app/src/main/res/values/strings.xml | 6 +- 20 files changed, 1517 insertions(+), 15 deletions(-) create mode 100644 app/src/main/assets/wmi1floor.geojson create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java create mode 100644 app/src/main/res/layout/activity_white_list.xml create mode 100644 app/src/main/res/layout/content_white_list.xml create mode 100644 app/src/main/res/layout/info_popup_whitelist.xml create mode 100644 app/src/main/res/layout/white_list_fab_modal.xml create mode 100644 app/src/main/res/layout/white_list_row.xml create mode 100644 app/src/main/res/menu/menu_white_list.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index da2d313..d209b5a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -65,6 +65,11 @@ android:configChanges="keyboardHidden|orientation|screenSize" android:screenOrientation="portrait" android:theme="@style/AppTheme" /> + whitelistedUsers = new ArrayList<>(); + private HashSet whitelistedUsersIDs = new HashSet<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + setContentView(R.layout.activity_white_list); + ButterKnife.bind(this); + tutorId = PrefUtils.getUserId(getApplicationContext()); + userService = ApiClient.getClient(getApplicationContext()) + .create(UserService.class); + + if (PrefUtils.isWhiteListing(this)){ + aSwitch.setText(getString(R.string.action_white_list) +" ON"); + aSwitch.setChecked(true); + handleChangeRequest(true); + }else{ + aSwitch.setText(getString(R.string.action_white_list) +" OFF"); + aSwitch.setChecked(false); + handleChangeRequest(false); + } + + Toolbar toolbar = findViewById(R.id.toolbar); + toolbar.setTitle(getString(R.string.activity_title_whitelist)); + setSupportActionBar(toolbar); + + mAdapter = new WhiteListAdapter(this, whitelistedUsers); + RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); + recyclerView.setLayoutManager(mLayoutManager); + recyclerView.setItemAnimator(new DefaultItemAnimator()); + recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16)); + recyclerView.setAdapter(mAdapter); + + /** + * On long press on RecyclerView item, open alert dialog + * with options to choose + * Edit and Delete + * */ + 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) { + } + })); + + addToWhiteListFab.setOnClickListener(this::showFabDialog); + + fetchWhiteListedUsersIDs(PrefUtils.getUserId(getApplicationContext())); + handleSwitch(); + } + + private void fetchWhiteListedUsersIDs(String userId) { + disposable.add( + userService.getTutorWhitelistedByID(userId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver>() { + @Override + public void onSuccess(List users) { + whitelistedUsersIDs.addAll(users); + didFetched = true; + fetchWhiteListedUsers(); + toggleEmptyNotes(); + } + + @Override + public void onError(Throwable e) { + showError(e); + } + }) + ); + } + + private void fetchWhiteListedUsers() { + for (String GUID : whitelistedUsersIDs){ + disposable.add( + userService.getUserById(GUID) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver() { + @Override + public void onSuccess(User user) { + whitelistedUsers.add(user); + Snackbar.make(getWindow().getDecorView().getRootView(), "user fetch OK! success", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + toggleEmptyNotes(); + if (whitelistedUsers.size() == whitelistedUsersIDs.size()) { + mAdapter.notifyDataSetChanged(); + } + } + + @Override + public void onError(Throwable e) { + showError(e); + } + }) + ); + } + } + + + private void showFabDialog(View v){ + LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); + @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.white_list_fab_modal, null); + AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); + + alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null); + + alertDialogBuilderUserInput + .setPositiveButton(R.string.add, null) + .setNegativeButton(R.string.cancel, null); + + final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + + EditText modalUserInput = view.findViewById(R.id.white_list_modal_input); + + alertDialog.setOnShowListener(dialogInterface -> { + Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); + + Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); + + dismissButton.setOnClickListener(view1 -> alertDialog.dismiss()); + + sendButton.setOnClickListener(view1 -> { + String body = modalUserInput.getText().toString(); + + if (TextUtils.isEmpty(body)) { + Toast.makeText(getApplicationContext(), R.string.can_not_be_empty, Toast.LENGTH_SHORT).show(); + modalUserInput.requestFocus(); + } else { + sendUserToWhitelist(body); + alertDialog.dismiss(); + } + }); + }); + + alertDialog.show(); + } + + private void sendUserToWhitelist(String body) { + StudentIdModel studentIdModel = new StudentIdModel(body); + disposable.add( + userService.addStudentToWhitelist(PrefUtils.getUserId(getApplicationContext()), studentIdModel) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(()->{ + fetchWhiteListedUsersIDs(PrefUtils.getUserId(getApplicationContext())); + Toast.makeText(getApplicationContext(), R.string.user_added, Toast.LENGTH_SHORT).show(); + },this::showError) + ); + } + + private void showError(Throwable e) { + String message; + + if (e instanceof HttpException) { + ResponseBody responseBody = ((HttpException) e).response().errorBody(); + message = RestApiHelper.getErrorMessage(responseBody); + } else { + message = "Network Error !"; + } + Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show(); + + + Snackbar.make(getWindow().getDecorView().getRootView(), message, Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + + private void toggleEmptyNotes() { + + if (didFetched && whitelistedUsers.size() == 0) { + noNotesView.setText(R.string.list_is_empty); + noNotesView.setVisibility(View.VISIBLE); + }else if (whitelistedUsers.size() > 0) { + noNotesView.setVisibility(View.GONE); + } else { + noNotesView.setText(getString(R.string.loading)); + noNotesView.setVisibility(View.VISIBLE); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + disposable.dispose(); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + } + + @Override + public void onStop() { + super.onStop(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_white_list, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + if (item.getItemId()==R.id.action_whitelist_info_popup){ + int layoutID = R.layout.info_popup_whitelist; + + View popupView = getLayoutInflater().inflate(layoutID,null); + + PopupWindow popupWindow = new PopupWindow(popupView, + LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); + // If the PopupWindow should be focusable + popupWindow.setFocusable(true); + // If you need the PopupWindow to dismiss when when touched outside + popupWindow.setBackgroundDrawable(new ColorDrawable()); + // Get the View's(the one that was clicked in the Fragment) location + View anchorView= getWindow().getDecorView().findViewById(android.R.id.content); + popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0); + } + + return super.onOptionsItemSelected(item); + } + + private void handleSwitch(){ + aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { + if (isChecked){ + aSwitch.setText(getString(R.string.action_white_list) + " "+ getString(R.string.on)); + handleChangeRequest(true); + PrefUtils.useWhitelist(this, true); + }else { + aSwitch.setText(getString(R.string.action_white_list) + " "+getString(R.string.off)); + handleChangeRequest(false); + PrefUtils.useWhitelist(this, false); + } + }); + } + + private void handleChangeRequest(boolean value){ + IsUsingListBool isUsingListBool = new IsUsingListBool(); + isUsingListBool.setIsUsing(value); + disposable.add( + userService.setTutorWhitelist(tutorId, isUsingListBool) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(()->{ + },this::showError) + ); + } +} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java new file mode 100644 index 0000000..45d2671 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java @@ -0,0 +1,132 @@ +package com.uam.wmi.findmytutor.adapters; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.TextView; +import android.widget.Toast; + +import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; +import com.uam.wmi.findmytutor.R; +import com.uam.wmi.findmytutor.model.StudentIdModel; +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.PrefUtils; +import com.uam.wmi.findmytutor.utils.RestApiHelper; + +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.schedulers.Schedulers; +import okhttp3.ResponseBody; + +import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; + + +public class WhiteListAdapter extends RecyclerView.Adapter { + + private Context context; + private List tutorsList; + private CompositeDisposable disposable = new CompositeDisposable(); + private UserService userService; + + + public WhiteListAdapter(Context context, List tutors) { + this.context = context; + this.tutorsList = tutors; + } + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + userService = ApiClient.getClient(getApplicationContext()) + .create(UserService.class); + View itemView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.white_list_row, parent, false); + + return new MyViewHolder(itemView); + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + Drawable image = null; + User tutor = tutorsList.get(position); + + holder.firstName.setText(tutor.getFirstName() + " " + tutor.getLastName()); + holder.lastName.setText("Index: " + tutor.getLdapLogin() + " Email: " + tutor.getEmail()); +//"s416196" + holder.imageButton.setOnClickListener(l ->{ + StudentIdModel studentIdModel = new StudentIdModel(tutor.getLdapLogin()); + String tutorId = PrefUtils.getUserId(getApplicationContext()); + disposable.add( + userService.removeStudentFromWhitelist(tutorId, studentIdModel) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(()->{ + Toast.makeText(getApplicationContext(), "User removed", Toast.LENGTH_SHORT).show(); + tutorsList.remove(position); + notifyDataSetChanged(); + },this::showError) + ); + }); +// +// if (tutor.isIsOnline()) { +// image = context.getResources().getDrawable(R.drawable.user_list_online); +// } else { +// image = context.getResources().getDrawable(R.drawable.user_list_offline); +// } +// +// if (!tutor.isIsActive()) { +// image = context.getResources().getDrawable(R.drawable.user_list_off); +// } + +// image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); +// holder.isOnline.setCompoundDrawables(image, null, null, null); + } + + @Override + public int getItemCount() { + return tutorsList.size(); + } + + class MyViewHolder extends RecyclerView.ViewHolder { + + @BindView(R.id.firstName) + TextView firstName; + + @BindView(R.id.lastName) + TextView lastName; + +// @BindView(R.id.isOnline) +// TextView isOnline; + @BindView(R.id.removeUserImageButton) + ImageButton imageButton; + + MyViewHolder(View view) { + super(view); + ButterKnife.bind(this, view); + } + } + + private void showError(Throwable e) { + String message; + + if (e instanceof HttpException) { + ResponseBody responseBody = ((HttpException) e).response().errorBody(); + message = RestApiHelper.getErrorMessage(responseBody); + } else { + message = "Network Error !"; + } + Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); + + } + +} \ 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 8915cfa..393e20d 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 @@ -81,14 +81,15 @@ public interface UserService { Completable removeStudentFromBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student); @GET("api/users/whitelist/{tutorID}") - Single> getTutorwhitelistedByID(@Path("tutorID") String tutorID); + Single> getTutorWhitelistedByID(@Path("tutorID") String tutorID); @PUT("api/users/whitelist/{tutorID}") Completable setTutorWhitelist(@Path("tutorID") String tutorID, @Body IsUsingListBool isUsing); @POST("api/users/whitelist/{tutorID}") - Completable addStudentTowhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student); + Completable addStudentToWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student); - @DELETE("api/users/whitelist/{tutorID}") +// @DELETE("api/users/whitelist/{tutorID}") + @HTTP(method = "DELETE", path = "api/users/whitelist/{tutorID}", hasBody = true) Completable removeStudentFromWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student); } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java index a630b83..be3e350 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java @@ -207,5 +207,25 @@ public class PrefUtils { return getSharedPreferences(context).getBoolean("show_only_online_users_in_list", true); } + public static void useBlacklist(Context context, Boolean flag) { + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); + editor.putBoolean("blacklisting", flag); + editor.putBoolean("whitelisting", false); + editor.apply(); + } + + public static void useWhitelist(Context context, Boolean flag) { + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); + editor.putBoolean("whitelisting", flag); + editor.putBoolean("blacklisting", false); + editor.apply(); + } + + public static Boolean isBlackListing(Context context) { + return getSharedPreferences(context).getBoolean("blacklisting", false); + } + public static Boolean isWhiteListing(Context context) { + return getSharedPreferences(context).getBoolean("whitelisting", false); + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_black_list.xml b/app/src/main/res/layout/activity_black_list.xml index 7b69662..903ec62 100644 --- a/app/src/main/res/layout/activity_black_list.xml +++ b/app/src/main/res/layout/activity_black_list.xml @@ -48,7 +48,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:thumbTextPadding="45dp" - android:checked="true" android:text="BLACKLIST TEXT SWITCH" /> diff --git a/app/src/main/res/layout/activity_white_list.xml b/app/src/main/res/layout/activity_white_list.xml new file mode 100644 index 0000000..0654405 --- /dev/null +++ b/app/src/main/res/layout/activity_white_list.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_black_list.xml b/app/src/main/res/layout/content_black_list.xml index a252726..e7cc148 100644 --- a/app/src/main/res/layout/content_black_list.xml +++ b/app/src/main/res/layout/content_black_list.xml @@ -13,7 +13,7 @@ diff --git a/app/src/main/res/layout/content_white_list.xml b/app/src/main/res/layout/content_white_list.xml new file mode 100644 index 0000000..3ac2670 --- /dev/null +++ b/app/src/main/res/layout/content_white_list.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/info_popup_whitelist.xml b/app/src/main/res/layout/info_popup_whitelist.xml new file mode 100644 index 0000000..b61cb8f --- /dev/null +++ b/app/src/main/res/layout/info_popup_whitelist.xml @@ -0,0 +1,39 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/white_list_fab_modal.xml b/app/src/main/res/layout/white_list_fab_modal.xml new file mode 100644 index 0000000..f0380e6 --- /dev/null +++ b/app/src/main/res/layout/white_list_fab_modal.xml @@ -0,0 +1,42 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/white_list_row.xml b/app/src/main/res/layout/white_list_row.xml new file mode 100644 index 0000000..d2efd45 --- /dev/null +++ b/app/src/main/res/layout/white_list_row.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index c149fc1..90a85ef 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -1,10 +1,10 @@ - + android:title="@string/navigation_item_whitelist" /> + + diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 07e6ed9..65df81d 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -256,6 +256,10 @@ Brak użytkowników online. Brak użytkowników offline. Tylko użytkownicy online + Czarna lista + Biała lista + Biała lista + Dodaj użytkownika do białej listy diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7f42f4d..69d392b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,6 +33,7 @@ Settings Blacklist + Whitelist Password Sign in or register Sign out @@ -298,9 +299,12 @@ - user is inactive (didn’t share any localization data since 7 days) BlackList + Whitelist User index Add user to Blacklist - + Add user to Whitelist + + "Material is the metaphor.\n\n" "A material metaphor is the unifying theory of a rationalized space and a system of motion." From 3a6f20d12e6987a9683ecfb189a2a5b9da481739 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Thu, 3 Jan 2019 21:30:43 +0100 Subject: [PATCH 2/4] strings fixes and toast removed --- .../java/com/uam/wmi/findmytutor/activity/BlackList.java | 5 +++-- .../java/com/uam/wmi/findmytutor/activity/MapActivity.java | 1 - .../java/com/uam/wmi/findmytutor/activity/WhiteList.java | 7 +++---- app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java index a381e41..89b5004 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java @@ -168,8 +168,6 @@ public class BlackList extends AppCompatActivity { @Override public void onSuccess(User user) { blacklistedUsers.add(user); - Snackbar.make(getWindow().getDecorView().getRootView(), "user fetch OK! success", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); toggleEmptyNotes(); if (blacklistedUsers.size() == blacklistedUsersIDs.size()) { mAdapter.notifyDataSetChanged(); @@ -244,6 +242,9 @@ public class BlackList extends AppCompatActivity { if (e instanceof HttpException) { ResponseBody responseBody = ((HttpException) e).response().errorBody(); message = RestApiHelper.getErrorMessage(responseBody); + if (((HttpException) e).response().code() == 404) { + message = getString(R.string.no_such_a_user); + } } else { message = "Network Error !"; } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index 6124dd0..b1e9a32 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -199,7 +199,6 @@ public class MapActivity extends BaseActivity private void createMarkerModalView(User user) { String cordStatus = coordsMap.get(user.getId()).getLabel(); String sharingLevel = coordsMap.get(user.getId()).getDisplayMode(); - user.statu LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.marker_modal, null); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java index 04a698e..8ad8ea8 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java @@ -155,8 +155,6 @@ public class WhiteList extends AppCompatActivity { @Override public void onSuccess(User user) { whitelistedUsers.add(user); - Snackbar.make(getWindow().getDecorView().getRootView(), "user fetch OK! success", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); toggleEmptyNotes(); if (whitelistedUsers.size() == whitelistedUsersIDs.size()) { mAdapter.notifyDataSetChanged(); @@ -231,11 +229,12 @@ public class WhiteList extends AppCompatActivity { if (e instanceof HttpException) { ResponseBody responseBody = ((HttpException) e).response().errorBody(); message = RestApiHelper.getErrorMessage(responseBody); + if (((HttpException) e).response().code() == 404) { + message = getString(R.string.no_such_a_user); + } } else { message = "Network Error !"; } - Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show(); - Snackbar.make(getWindow().getDecorView().getRootView(), message, Snackbar.LENGTH_LONG) .setAction("Action", null).show(); diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 65df81d..c79d468 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -260,6 +260,7 @@ Biała lista Biała lista Dodaj użytkownika do białej listy + Nie ma takiego użytkownika diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 69d392b..f47f95f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -427,5 +427,6 @@ Currently, there are no\nonline users. Currently, there are no\noffline users. Only online users + No such a user From af1e1a53b4ffd960047d9b5dafb53b7ae9cafb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Thu, 3 Jan 2019 21:32:28 +0100 Subject: [PATCH 3/4] Add proper search --- .../findmytutor/activity/BaseActivity.java | 8 +------ .../activity/UsersListFragment.java | 22 +++++-------------- .../wmi/findmytutor/service/UserService.java | 8 +++++-- .../main/res/layout/info_popup_userlist.xml | 2 ++ app/src/main/res/values-pl/strings.xml | 5 +++-- app/src/main/res/values/strings.xml | 13 ++++++----- 6 files changed, 25 insertions(+), 33 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 36f212a..18d1955 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 @@ -220,17 +220,12 @@ public abstract class BaseActivity } public void handleBackgroundTaskLifeCycle() { - Log.e("Localization", String.valueOf(PrefUtils.isEnableSharingLocalization(getApplicationContext()))); Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) && isTutor; - Log.e("Localization", String.valueOf(shouldServiceRun)); if (shouldServiceRun) { startBackgroundLocalizationTask(); - Log.e("Localization", "JEstem i odpalam"); - } else { stopBackgroundLocalizationTask(); - Log.e("Localization", "JEstem i nie odpalam"); } } @@ -304,11 +299,10 @@ public abstract class BaseActivity } }); - - RxSearchObservable.fromView(searchView) .skip(0) .map(String::toLowerCase) + .filter(t -> !t.isEmpty()) .debounce(250, TimeUnit.MILLISECONDS) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java index 9b89791..eb15075 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java @@ -229,7 +229,7 @@ public class UsersListFragment extends Fragment { private void fetchAllTutors() { disposable.add( (fetchOnlyOnlineUsers ? - userService.getAllOnlineTutors() : + userService.getAllActiveTutors() : userService.getAllOfflineTutors()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -313,12 +313,7 @@ public class UsersListFragment extends Fragment { message = getString(R.string.network_err); } - Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG); - View view = snackbar.getView(); - CoordinatorLayout.LayoutParams params=(CoordinatorLayout.LayoutParams)view.getLayoutParams(); - params.gravity = Gravity.TOP; - view.setLayoutParams(params); - snackbar.show(); + createSnackbar(message); } private void showSearchError(Throwable e) { @@ -332,23 +327,18 @@ public class UsersListFragment extends Fragment { message = getString(R.string.search_null); } - /* Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG) - .show(); -*/ + createSnackbar(message); + } - - - Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG); + private void createSnackbar(String msg){ + Snackbar snackbar = Snackbar.make(coordinatorLayout, msg, Snackbar.LENGTH_LONG); View view = snackbar.getView(); CoordinatorLayout.LayoutParams params=(CoordinatorLayout.LayoutParams)view.getLayoutParams(); params.gravity = Gravity.TOP; view.setLayoutParams(params); snackbar.show(); - - } - private void toggleEmptyNotes() { if (tutorsList.size() > 0) { noNotesView.setVisibility(View.GONE); 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 1399068..a393017 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 @@ -19,6 +19,7 @@ import retrofit2.http.HTTP; import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; +import retrofit2.http.Query; public interface UserService { @@ -34,11 +35,14 @@ public interface UserService { @GET("api/users/tutors/online") Single > getAllOnlineTutors(); + @GET("api/users/tutors/active") + Single > getAllActiveTutors(); + @GET("api/users/tutors/offline") Single > getAllOfflineTutors(); - @GET("api/users/tutors/search/{searchString}") - Single > searchUser(@Path("searchString") String searchString ); + @GET("api/users/tutors/search") + Single > searchUser(@Query(value = "searchString", encoded = true) String searchString); @POST("api/users") Completable createUser(@Body User user); diff --git a/app/src/main/res/layout/info_popup_userlist.xml b/app/src/main/res/layout/info_popup_userlist.xml index afd1c17..19761d7 100644 --- a/app/src/main/res/layout/info_popup_userlist.xml +++ b/app/src/main/res/layout/info_popup_userlist.xml @@ -72,4 +72,6 @@ android:text="@string/info_icon_userlist_summary" android:textColor="@color/half_black"/> + + \ No newline at end of file diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 77ef3d5..e3fa57b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -253,9 +253,10 @@ Pobierz dane z WMI Dane zostały zaktualizwane! - Brak użytkowników online. + + Brak aktywnych użytkowników. Brak użytkowników offline. - Tylko użytkownicy online + Tylko aktywni użytkownicy Błąd sieci! Brak wyników! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6860e0d..f9e86bc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -260,7 +260,6 @@ exact localization (from mobile GPS) approximated localization manual localization (manually picked) - You can search for any tutor on the map by entering his name and surname in the search field. In this panel you can add users to your blacklist. Users from the blacklist can’t see any data that you share - localization, online status, or information about presence. @@ -298,9 +297,7 @@ - user is currently offline - user is inactive (didn’t share any localization data since 7 days) - After clicking on a name, the tutor tab will pop up, containing details about selected tutor. - By default, only active users are shown. You can change that in menu (three dots icon). - You can also search for a tutor directly, by entering name and surname of person that you look for. + After clicking on a name, the tutor tab will pop up, containing details about selected tutor.\n\nYou can search for any tutor on the map by entering his name and surname in the search field.\n\nBy default, only active users are shown. You can change that in menu (three dots icon).\n\nYou can also search for a tutor directly, by entering name and surname of person that you look for. Blacklist @@ -335,9 +332,13 @@ OFF Scrap! Data updated! - Currently, there are no\nonline users. + + + Currently, there are no\nactive users. Currently, there are no\noffline users. - Only online users + Only active users + + Network Error ! Search response is empty! Insert a name for this localization. From 2338e484f87660c3b68a34ec1d6f898739ee93e9 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Thu, 3 Jan 2019 21:53:15 +0100 Subject: [PATCH 4/4] Merge confict --- app/src/main/res/values/strings.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fcf3230..a5fc583 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -298,11 +298,8 @@ - user is currently offline - user is inactive (didn’t share any localization data since 7 days) -<<<<<<< HEAD BlackList Whitelist - User index - Add user to Blacklist Add user to Whitelist @@ -394,14 +391,12 @@ "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere " "when a user tries to pick up one of cards.\n\n" -======= + After clicking on a name, the tutor tab will pop up, containing details about selected tutor.\n\nYou can search for any tutor on the map by entering his name and surname in the search field.\n\nBy default, only active users are shown. You can change that in menu (three dots icon).\n\nYou can also search for a tutor directly, by entering name and surname of person that you look for. - Blacklist User index Add user to blacklist ->>>>>>> develop Add Yes