almost working button, need to handle response

This commit is contained in:
Domagalski 2018-12-17 16:20:58 +01:00
parent 2d9c8aa6cc
commit 8fdcdf4f80
7 changed files with 134 additions and 3 deletions

Binary file not shown.

View File

@ -1,10 +1,12 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
@ -12,20 +14,30 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.adapters.BlackListAdapter; import com.uam.wmi.findmytutor.adapters.BlackListAdapter;
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.model.StudentIdModel;
import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.model.UserResponseModel;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration; import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener; import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.SharingLevel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -49,6 +61,9 @@ public class BlackList extends AppCompatActivity {
@BindView(R.id.black_list_empty_text_view) @BindView(R.id.black_list_empty_text_view)
TextView noNotesView; TextView noNotesView;
@BindView(R.id.add_to_black_list_fab)
FloatingActionButton addToBlackListFab;
private BlackListAdapter mAdapter; private BlackListAdapter mAdapter;
private List<User> blacklistedUsers = new ArrayList<>(); private List<User> blacklistedUsers = new ArrayList<>();
@ -92,6 +107,8 @@ public class BlackList extends AppCompatActivity {
})); }));
addToBlackListFab.setOnClickListener(this::showFabDialog);
fetchBlackListedUsers(PrefUtils.getUserId(getApplicationContext())); fetchBlackListedUsers(PrefUtils.getUserId(getApplicationContext()));
} }
@ -103,9 +120,12 @@ public class BlackList extends AppCompatActivity {
.subscribeWith(new DisposableSingleObserver<List<User>>() { .subscribeWith(new DisposableSingleObserver<List<User>>() {
@Override @Override
public void onSuccess(List<User> users) { public void onSuccess(List<User> users) {
blacklistedUsers.addAll(users);
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
Log.e("BLACKLIST","fetch success"); Log.e("BLACKLIST","fetch success");
Snackbar.make(getWindow().getDecorView().getRootView(), "fetch success", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
toggleEmptyNotes(); toggleEmptyNotes();
} }
@ -117,6 +137,61 @@ public class BlackList extends AppCompatActivity {
); );
} }
private void showFabDialog(View v){
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.black_list_fab_modal, null);
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.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();
EditText modalUserInput = view.findViewById(R.id.black_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(), "Co tu napisac?", Toast.LENGTH_SHORT).show();
modalUserInput.requestFocus();
} else {
// send4Location(body, latLng);
sendUserToBlacklist(body);
alertDialog.dismiss();
}
});
});
alertDialog.show();
}
private void sendUserToBlacklist(String body) {
UserService userService = ApiClient.getClient(getApplicationContext()).create(UserService.class);
StudentIdModel studentIdModel = new StudentIdModel(body);
Toast.makeText(getApplicationContext(), body, Toast.LENGTH_SHORT).show();
//TODO subscribe Completable #how to do that?
// disposable.add(
// userService.addStudentToBlacklist(PrefUtils.getUserId(getApplicationContext()), studentIdModel)
// .observeOn(AndroidSchedulers.mainThread())
//
//
// );
}
private void showError(Throwable e) { private void showError(Throwable e) {
String message; String message;

View File

@ -18,6 +18,14 @@ public class StudentIdModel extends BaseResponse{
@SerializedName("ldapLogin") @SerializedName("ldapLogin")
private String ldapLogin = null; private String ldapLogin = null;
/**
*
* @param studentId
*/
public StudentIdModel(String studentId){
this.studentId = studentId;
}
public StudentIdModel studentId(String studentId) { public StudentIdModel studentId(String studentId) {
this.studentId = studentId; this.studentId = studentId;
return this; return this;

View File

@ -67,7 +67,7 @@
<include layout="@layout/content_black_list" /> <include layout="@layout/content_black_list" />
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/add_to_black_list_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/lato_regular"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/black_list_modal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/black_list_modal_input"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="@string/black_list_title"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<EditText
android:id="@+id/black_list_modal_input"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="@string/index_user"
android:maxLength="30"
android:maxLines="1"
android:requiresFadingEdge="vertical"
android:scrollbars="vertical"
android:textColor="@color/note_list_text" />
</RelativeLayout>

View File

@ -206,12 +206,15 @@
<string name="info_icon_sharing_tab_p7">Zarówno manualne lokalizacje jak i statusy możesz dodać do listy, które potem możesz wybrać w wygodny sposób.</string> <string name="info_icon_sharing_tab_p7">Zarówno manualne lokalizacje jak i statusy możesz dodać do listy, które potem możesz wybrać w wygodny sposób.</string>
<!--(PL) Userlist Tab info helper--> <!--(PL) Userlist Tab info helper-->
<string name="info_icon_userlist_tab_p1">W tym panelu znajduje się listę profesorów.</string> <string name="info_icon_userlist_tab_p1">W tym panelu znajduje się lista profesorów.</string>
<string name="info_icon_userlist_tab_p2">Ich status symbolizowany jest przez kolorowe kropki:</string> <string name="info_icon_userlist_tab_p2">Ich status symbolizowany jest przez kolorowe kropki:</string>
<string name="info_icon_userlist_tab_level_status_online">- użytkownik jest obecnie online</string> <string name="info_icon_userlist_tab_level_status_online">- użytkownik jest obecnie online</string>
<string name="info_icon_userlist_tab_level_status_offline">- użytkownik jest obecnie offline</string> <string name="info_icon_userlist_tab_level_status_offline">- użytkownik jest obecnie offline</string>
<string name="info_icon_userlist_tab_level_status_inactive">- użytkownik jest nieaktywny</string> <string name="info_icon_userlist_tab_level_status_inactive">- użytkownik jest nieaktywny</string>
<string name="info_icon_userlist_tab_level_status_inactive_tip">(nie udostępnił żadnych danych o lokalizacji od conajmniej tygodnia)</string> <string name="info_icon_userlist_tab_level_status_inactive_tip">(nie udostępnił żadnych danych o lokalizacji od conajmniej tygodnia)</string>
<string name="add">Dodaj</string>
<string name="index_user">Index użytkownika</string>
<string name="black_list_title">Dodaj użytkownika do Blacklsi</string>
</resources> </resources>

View File

@ -294,6 +294,8 @@
<string name="info_icon_userlist_tab_level_status_inactive">- user is inactive </string> <string name="info_icon_userlist_tab_level_status_inactive">- user is inactive </string>
<string name="info_icon_userlist_tab_level_status_inactive_tip">(didnt share any localization data since 7 days)</string> <string name="info_icon_userlist_tab_level_status_inactive_tip">(didnt share any localization data since 7 days)</string>
<string name="title_activity_black_list">BlackList</string> <string name="title_activity_black_list">BlackList</string>
<string name="index_user">User index</string>
<string name="black_list_title">Add user to Blacklist</string>
<string name="large_text"> <string name="large_text">
"Material is the metaphor.\n\n" "Material is the metaphor.\n\n"
@ -383,5 +385,6 @@
"For example, position the FAB to one side of stream of a cards so the FAB wont interfere " "For example, position the FAB to one side of stream of a cards so the FAB wont interfere "
"when a user tries to pick up one of cards.\n\n" "when a user tries to pick up one of cards.\n\n"
</string> </string>
<string name="add">Add</string>
</resources> </resources>