Add duty hours to user information modal

This commit is contained in:
Mieszko Wrzeszczyński 2018-10-28 12:18:49 +01:00
parent 299e25d0f9
commit 4701387d48
7 changed files with 48 additions and 16 deletions

View File

@ -57,5 +57,6 @@ dependencies {
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.auth0.android:jwtdecode:1.1.1' implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.annimon:stream:1.2.1' implementation 'com.annimon:stream:1.2.1'
implementation 'com.facebook.shimmer:shimmer:0.3.0'
} }

View File

@ -1,5 +1,7 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -18,6 +20,7 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import com.facebook.shimmer.ShimmerFrameLayout;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.DutyHour; import com.uam.wmi.findmytutor.model.DutyHour;
@ -44,6 +47,8 @@ import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import static java.util.stream.Collectors.toList;
public class UsersListActivity extends BaseActivity { public class UsersListActivity extends BaseActivity {
private static final String TAG = UsersListActivity.class.getSimpleName(); private static final String TAG = UsersListActivity.class.getSimpleName();
@BindView(R.id.coordinator_layout) @BindView(R.id.coordinator_layout)
@ -120,8 +125,12 @@ public class UsersListActivity extends BaseActivity {
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this);
alertDialogBuilderUserInput.setView(view); alertDialogBuilderUserInput.setView(view);
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
// User cancelled the dialog
});
TextView userName = view.findViewById(R.id.userName); 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 userNote = view.findViewById(R.id.userNote);
TextView userRoom = view.findViewById(R.id.userRoom); TextView userRoom = view.findViewById(R.id.userRoom);
TextView userEmail = view.findViewById(R.id.userEmail); TextView userEmail = view.findViewById(R.id.userEmail);
@ -133,19 +142,22 @@ public class UsersListActivity extends BaseActivity {
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() { .subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
@SuppressLint("SetTextI18n")
@Override @Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) { public void onSuccess(TutorTabViewModel tutorTabViewModel) {
Log.e("TUTOR_TAB",tutorTabViewModel.toString()); Log.e("TUTOR_TAB",tutorTabViewModel.toString());
List<String> dutyHourslist = Stream.of(tutorTabViewModel.getDutyHours()) List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
.map(DutyHourViewModel::toString).toList(); .map(DutyHourViewModel::getSummary).toList();
userRoom.setText(tutorTabViewModel.getRoom()); userRoom.setText(getString(R.string.userRoom) + ": " + tutorTabViewModel.getRoom());
userEmail.setText(tutorTabViewModel.getEmailTutorTab()); userEmail.setText(getString(R.string.userEmail) + ": " + tutorTabViewModel.getEmailTutorTab());
userNote.setText(tutorTabViewModel.getNote()); userNote.setText(getString(R.string.userNote) + ": " + tutorTabViewModel.getNote());
if(dutyHourslist.size() > 0) final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(UsersListActivity.this,
userDutyHours.setText(dutyHourslist.get(0)); 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(); final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
alertDialog.show(); alertDialog.show();
} }
private void fetchAllTutors() { private void fetchAllTutors() {
@ -202,8 +214,6 @@ public class UsersListActivity extends BaseActivity {
showError(e); showError(e);
} }
})); }));
} }
private void showError(Throwable e) { private void showError(Throwable e) {

View File

@ -94,6 +94,11 @@ public class DutyHourViewModel {
return Objects.hash(day, start, end); return Objects.hash(day, start, end);
} }
public String getSummary() {
return this.getDay() + " " + this.getStart() + " " + this.getEnd();
}
@Override @Override
public String toString() { public String toString() {

View File

@ -22,13 +22,13 @@ public class TutorTabViewModel {
private String userId = null; private String userId = null;
@SerializedName("room") @SerializedName("room")
private String room = null; private String room = "";
@SerializedName("emailTutorTab") @SerializedName("emailTutorTab")
private String emailTutorTab = null; private String emailTutorTab = "";
@SerializedName("note") @SerializedName("note")
private String note = null; private String note = "";
@SerializedName("dutyHours") @SerializedName("dutyHours")
private List<DutyHourViewModel> dutyHours = null; private List<DutyHourViewModel> dutyHours = null;
@ -112,6 +112,9 @@ public class TutorTabViewModel {
public String getNote() { public String getNote() {
if(note == null)
return "";
return note; return note;
} }

View File

@ -8,6 +8,7 @@
android:paddingRight="@dimen/activity_margin" android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"> android:paddingTop="@dimen/activity_margin">
<TextView android:id="@+id/userName" <TextView android:id="@+id/userName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -33,6 +34,14 @@
android:textColor="@color/note_list_text" /> android:textColor="@color/note_list_text" />
<TextView <TextView
android:id="@+id/userDutyHoursTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/userDutyHoursHeader"
android:textColor="@color/note_list_text"
tools:text="Dyżury:" />
<ListView
android:id="@+id/userDutyHours" android:id="@+id/userDutyHours"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -44,5 +53,4 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/note_list_text" /> android:textColor="@color/note_list_text" />
</LinearLayout> </LinearLayout>

View File

@ -2,7 +2,7 @@
<resources> <resources>
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#9ef13f</color> <color name="colorAccent">#dc0004</color>
<color name="msg_no_notes">#999</color> <color name="msg_no_notes">#999</color>
<color name="hint_enter_note">#89c3c3c3</color> <color name="hint_enter_note">#89c3c3c3</color>
<color name="timestamp">#858585</color> <color name="timestamp">#858585</color>

View File

@ -198,4 +198,9 @@ functionality.</string>
<string name="title_activity_main2">Main2Activity</string> <string name="title_activity_main2">Main2Activity</string>
<string name="there_is_no_users_in_system">There is no users in system</string> <string name="there_is_no_users_in_system">There is no users in system</string>
<string name="cancel">Close</string>
<string name="userRoom">Pokój</string>
<string name="userEmail">Email</string>
<string name="userNote">Notatka</string>
<string name="userDutyHoursHeader">Dyżury:</string>
</resources> </resources>