added basic layout and fetching of profile activity, but save note not implemented yet, got some problems

This commit is contained in:
marcin.jedynski 2018-11-27 06:51:49 +01:00
parent 6684274488
commit abbd887db7
7 changed files with 296 additions and 78 deletions

View File

@ -54,6 +54,10 @@
android:exported="false" android:exported="false"
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<activity
android:name=".activity.TutorTab"
android:label="@string/title_activity_tutor_tab"
android:theme="@style/AppTheme"></activity>
</application> </application>
</manifest> </manifest>

View File

@ -92,8 +92,8 @@ public abstract class BaseActivity
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) { } else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class); launchIntent = new Intent(getApplicationContext(), TutorTab.class);
startActivity(launchIntent);*/ startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) { } else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
launchIntent = new Intent(getApplicationContext(), SettingsActivity.class); launchIntent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(launchIntent); startActivity(launchIntent);

View File

@ -154,8 +154,9 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) { private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, password); ValidateUser user = new ValidateUser(email, password);
LdapUser fuser = new LdapUser(email,password,"wmi","tutor","marek","nocny","marek@wmi.pl");
disposable.add(ldapService.validate(user) // disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(fuser)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));

View File

@ -1,31 +1,167 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.os.Bundle; import android.os.Bundle;
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.AppCompatActivity; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.support.v7.widget.Toolbar;
import android.util.Log;
import com.uam.wmi.findmytutor.R; import android.view.View;
import android.widget.ArrayAdapter;
public class TutorTab extends AppCompatActivity { import android.widget.Button;
import android.widget.ListView;
@Override import android.widget.TextView;
protected void onCreate(Bundle savedInstanceState) { import android.widget.Toast;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tutor_tab); import com.annimon.stream.Stream;
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
setSupportActionBar(toolbar); import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); import com.uam.wmi.findmytutor.model.TutorTabViewModel;
fab.setOnClickListener(new View.OnClickListener() { import com.uam.wmi.findmytutor.model.User;
@Override import com.uam.wmi.findmytutor.network.ApiClient;
public void onClick(View view) { import com.uam.wmi.findmytutor.service.TutorTabApi;
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) import com.uam.wmi.findmytutor.service.UserService;
.setAction("Action", null).show(); 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<TutorTabViewModel>() {
@Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
List<String> 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 <User>() {
@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<Void> 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();
}
}

View File

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".activity.TutorTab"> tools:context=".activity.TutorTab">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" /> app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<include layout="@layout/content_tutor_tab" /> <include layout="@layout/content_tutor_tab" />
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" /> app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

View File

@ -1,11 +1,84 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="match_parent" android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" android:paddingLeft="@dimen/activity_margin"
tools:context=".activity.TutorTab" android:paddingRight="@dimen/activity_margin"
tools:showIn="@layout/activity_tutor_tab"> android:paddingTop="@dimen/activity_margin">
</android.support.constraint.ConstraintLayout> <TextView android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<TextView
android:id="@+id/userDepartment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text"
/>
<TextView
android:id="@+id/userRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text"
/>
<TextView
android:id="@+id/userEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text" />
<TextView
android:id="@+id/userDutyHours"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text"
tools:text="@string/dutyHours" />
<TextView
android:id="@+id/userNoteTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:paddingStart="@dimen/activity_margin"
android:textColor="@color/note_list_text" />
<EditText
android:id="@+id/userNote"
android:layout_width="match_parent"
android:layout_height="150dp"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text"
android:hint="@string/tutorTabHint"
android:inputType="textMultiLine"
android:maxLength="1000"
android:maxLines="7"
android:requiresFadingEdge="vertical"
android:scrollbars="vertical"/>
<Button
android:id="@+id/saveButon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/saveButton" />
</LinearLayout>

View File

@ -82,6 +82,9 @@
<string name="settings_description">Descrition</string> <string name="settings_description">Descrition</string>
<string name="saveButton">Save</string>
<string name="tutorTabHint">Here you can add your note.\nIt will be visible to the other users.</string>
<string name="key_description">key_description</string> <string name="key_description">key_description</string>
@ -213,6 +216,7 @@
<string name="map_activity_label" translatable="false">MapActivity</string> <string name="map_activity_label" translatable="false">MapActivity</string>
<string name="nav_profile">User profile</string> <string name="nav_profile">User profile</string>
<string name="remove_manual_location">Remove Manual location</string> <string name="remove_manual_location">Remove Manual location</string>
<string name="title_activity_tutor_tab">TutorTab</string>
</resources> </resources>