From abbd887db7a939fa1a0424dd7867aeca81884153 Mon Sep 17 00:00:00 2001 From: "marcin.jedynski" Date: Tue, 27 Nov 2018 06:51:49 +0100 Subject: [PATCH 1/4] added basic layout and fetching of profile activity, but save note not implemented yet, got some problems --- app/src/main/AndroidManifest.xml | 4 + .../findmytutor/activity/BaseActivity.java | 4 +- .../findmytutor/activity/LoginActivity.java | 5 +- .../wmi/findmytutor/activity/TutorTab.java | 198 +++++++++++++++--- .../main/res/layout/activity_tutor_tab.xml | 64 +++--- app/src/main/res/layout/content_tutor_tab.xml | 95 ++++++++- app/src/main/res/values/strings.xml | 4 + 7 files changed, 296 insertions(+), 78 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ed85fed..2eb11da 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -54,6 +54,10 @@ android:exported="false" android:launchMode="singleTop" /> + \ 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 c347afc..b8d5ea3 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 @@ -92,8 +92,8 @@ public abstract class BaseActivity } else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) { - /* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class); - startActivity(launchIntent);*/ + launchIntent = new Intent(getApplicationContext(), TutorTab.class); + startActivity(launchIntent); } else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) { launchIntent = new Intent(getApplicationContext(), SettingsActivity.class); startActivity(launchIntent); 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 06f1c5f..70a3809 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 @@ -154,8 +154,9 @@ public class LoginActivity extends AppCompatActivity { private void loginProcess(String email, String password) { ValidateUser user = new ValidateUser(email, password); - - disposable.add(ldapService.validate(user) + LdapUser fuser = new LdapUser(email,password,"wmi","tutor","marek","nocny","marek@wmi.pl"); +// disposable.add(ldapService.validate(user) + disposable.add(ldapService.fakeValidate(fuser) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::handleResponse, this::handleError)); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java index 566a4a8..6822528 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java @@ -1,31 +1,167 @@ -package com.uam.wmi.findmytutor.activity; - -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; - -import com.uam.wmi.findmytutor.R; - -public class TutorTab extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_tutor_tab); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); - } - }); - } - -} +package com.uam.wmi.findmytutor.activity; + +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +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.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.PrefUtils; +import com.uam.wmi.findmytutor.utils.RestApiHelper; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import io.reactivex.Single; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.disposables.Disposable; +import io.reactivex.observers.DisposableSingleObserver; +import io.reactivex.schedulers.Schedulers; +import okhttp3.ResponseBody; +import retrofit2.Response; + +import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; + +public class TutorTab extends AppCompatActivity { + private TutorTabApi tutorTabService; + private UserService userService; + private CompositeDisposable disposable = new CompositeDisposable(); + private TextView userName; + private TextView userDutyHours; + private TextView userNote; + private TextView userRoom; + private TextView userEmail; + private TextView department; + private Button saveButon; + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + tutorTabService = ApiClient.getClient(getApplicationContext()) + .create(TutorTabApi.class); + userService = ApiClient.getClient(getApplicationContext()) + .create(UserService.class); + setContentView(R.layout.content_tutor_tab); + TextView userName = findViewById(R.id.userName); + TextView userDutyHours = findViewById(R.id.userDutyHours); + TextView userNote = findViewById(R.id.userNote); + TextView userRoom = findViewById(R.id.userRoom); + TextView userEmail = findViewById(R.id.userEmail); + TextView department = findViewById(R.id.userDepartment); + Button saveButon = findViewById(R.id.saveButon); + userName.setText(String.format("%s %s", PrefUtils.getUserFirstName(getApplicationContext()), PrefUtils.getUserLastName(getApplicationContext()))); + disposable.add( + tutorTabService.apiUsersTutorTabByTutorIdGet("91fc76b3-bc82-455d-af5a-2209c9e4e1b3") + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver() { + @Override + public void onSuccess(TutorTabViewModel tutorTabViewModel) { + List dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours()) + .map(DutyHourViewModel::getSummary).toList(); + Log.d("TUTORTAB",Arrays.toString(dutyHoursList.toArray())); + userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom())); + userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab())); + if (!tutorTabViewModel.getNote().equals("")) { + userNote.setText(String.format("%s", tutorTabViewModel.getNote())); + } + userDutyHours.setText(String.format("%s: %s", getString(R.string.userDutyHoursHeader),Arrays.toString(dutyHoursList.toArray()))); + + } + + @Override + public void onError(Throwable e) { + showError(e); + } + })); + disposable.add( + +// userService.getUserById(PrefUtils.getUserId(getApplicationContext())) + userService.getUserById("91fc76b3-bc82-455d-af5a-2209c9e4e1b3") + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver () { + @Override + public void onSuccess(User user) { + department.setText(user.getDepartment()); + Log.d("TUTORTAB",(user.getDepartment())); + + } + + @Override + public void onError(Throwable e) { + showError(e); + } + })); +// setUpSaveListener(); + +// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); +// setSupportActionBar(toolbar); + + } + +// private void setUpSaveListener(){ +// saveButon.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// TutorTabViewModel newTab = new TutorTabViewModel(); +// disposable.add(tutorTabService.apiUsersTutorTabByTutorIdPut(PrefUtils.getUserId(getApplicationContext()),newTab) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(this::handleResponse, this::handleError)); +// } +// }); +// } + private void handleResponse(Response resp) { + Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.modal_feedback_thankyou), Toast.LENGTH_SHORT).show(); + } + + private void handleError(Throwable error) { + if (error instanceof HttpException) { + + ResponseBody responseBody = ((HttpException) error).response().errorBody(); + Toast.makeText(getApplicationContext(), + RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show(); + + } else { + Toast.makeText(getApplicationContext(), + "Network error " + error.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d("FEEDBACK",error.getMessage()); + } + } + 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 !"; + } + +// Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG) +// .show(); + Toast.makeText(getApplicationContext(),message,Toast.LENGTH_SHORT).show(); + } + +} diff --git a/app/src/main/res/layout/activity_tutor_tab.xml b/app/src/main/res/layout/activity_tutor_tab.xml index 72feb63..5c5d96f 100644 --- a/app/src/main/res/layout/activity_tutor_tab.xml +++ b/app/src/main/res/layout/activity_tutor_tab.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_tutor_tab.xml b/app/src/main/res/layout/content_tutor_tab.xml index e83904e..8bfd4bf 100644 --- a/app/src/main/res/layout/content_tutor_tab.xml +++ b/app/src/main/res/layout/content_tutor_tab.xml @@ -1,11 +1,84 @@ - - - - \ No newline at end of file + + + + + + + + + + + + + + + + +