Merge branch 'add-scrap-button' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2018-12-18 17:41:49 +00:00 committed by Gogs
commit d80b83f2b5
8 changed files with 109 additions and 79 deletions

View File

@ -29,7 +29,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -10,7 +10,7 @@ android {
applicationId "com.uam.wmi.findmytutor" applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 27 targetSdkVersion 27
versionCode 19 versionCode 20
versionName "0.9.5-beta" versionName "0.9.5-beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true

Binary file not shown.

View File

@ -8,18 +8,13 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Adapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.annimon.stream.Stream;
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.adapters.DutyHoursAdapter; import com.uam.wmi.findmytutor.adapters.DutyHoursAdapter;
import com.uam.wmi.findmytutor.model.DutyHour;
import com.uam.wmi.findmytutor.model.DutyHourViewModel; import com.uam.wmi.findmytutor.model.DutyHourViewModel;
import com.uam.wmi.findmytutor.model.TutorTabViewModel; import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.User;
@ -36,11 +31,14 @@ import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableCompletableObserver;
import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Response; import retrofit2.Response;
import static java.lang.String.valueOf;
public class TutorTab extends AppCompatActivity { public class TutorTab extends AppCompatActivity {
private TutorTabApi tutorTabService; private TutorTabApi tutorTabService;
private UserService userService; private UserService userService;
@ -53,6 +51,7 @@ public class TutorTab extends AppCompatActivity {
private TextView department; private TextView department;
private Button addDutyButton; private Button addDutyButton;
private Button saveButon; private Button saveButon;
private Button scrapButton;
private Boolean ifTutorTabExists = true; private Boolean ifTutorTabExists = true;
private List<DutyHourViewModel> dutyHourList; private List<DutyHourViewModel> dutyHourList;
private RecyclerView dutyHoursRecycller; private RecyclerView dutyHoursRecycller;
@ -72,69 +71,24 @@ public class TutorTab extends AppCompatActivity {
userEmail = findViewById(R.id.userEmail); userEmail = findViewById(R.id.userEmail);
department = findViewById(R.id.userDepartment); department = findViewById(R.id.userDepartment);
saveButon = findViewById(R.id.saveButon); saveButon = findViewById(R.id.saveButon);
scrapButton = findViewById(R.id.scrapTutorTab);
addDutyButton = findViewById(R.id.addDuty); addDutyButton = findViewById(R.id.addDuty);
dutyHoursRecycller = (RecyclerView) findViewById(R.id.dutyHourView); dutyHoursRecycller = findViewById(R.id.dutyHourView);
dutyHoursLayoutManager = new LinearLayoutManager(this); dutyHoursLayoutManager = new LinearLayoutManager(this);
dutyHoursRecycller.setLayoutManager(dutyHoursLayoutManager); dutyHoursRecycller.setLayoutManager(dutyHoursLayoutManager);
tutorTabService = ApiClient.getClient(getApplicationContext()) tutorTabService = ApiClient.getClient(getApplicationContext())
.create(TutorTabApi.class); .create(TutorTabApi.class);
userService = ApiClient.getClient(getApplicationContext()) userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class); .create(UserService.class);
disposable.add(
tutorTabService.apiUsersTutorTabByTutorIdGet(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
@Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
dutyHourList = tutorTabViewModel.getDutyHours();
if(dutyHourList == null){
}else{
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),dutyHourList);
dutyHoursRecycller.setAdapter(dutyHoursAdapter);
addDutyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addEmptyDuty(dutyHoursAdapter);
}
});
}
userRoom.setText(String.format("%s", tutorTabViewModel.getRoom()));
userEmail.setText(String.format("%s", tutorTabViewModel.getEmailTutorTab()));
if (!tutorTabViewModel.getNote().equals("")) {
userNote.setText(String.format("%s", tutorTabViewModel.getNote()));
}
}
@Override
public void onError(Throwable e) {
int code = ((HttpException) e).response().code();
if( code == 404){
ifTutorTabExists = false;
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),new ArrayList<DutyHourViewModel>());
dutyHoursRecycller.setAdapter(dutyHoursAdapter);
addDutyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addEmptyDuty(dutyHoursAdapter);
}
});
}
showError(e);
}
}));
getTutorTab();
findViewById(R.id.contentTutorTabInfoImageButton).setOnClickListener(v-> InfoHelperUtils.infoPopUp(v,R.layout.info_popup_tutor_tab)); findViewById(R.id.contentTutorTabInfoImageButton).setOnClickListener(v-> InfoHelperUtils.infoPopUp(v,R.layout.info_popup_tutor_tab));
userName.setText(String.format("%s %s", PrefUtils.getUserFirstName(getApplicationContext()), PrefUtils.getUserLastName(getApplicationContext()))); userName.setText(String.format("%s %s", PrefUtils.getUserFirstName(getApplicationContext()), PrefUtils.getUserLastName(getApplicationContext())));
disposable.add( disposable.add(
userService.getUserById(PrefUtils.getUserId(getApplicationContext())) userService.getUserById(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -153,7 +107,46 @@ public class TutorTab extends AppCompatActivity {
} }
})); }));
setUpSaveListener(saveButon); setUpSaveListener(saveButon);
scrapButton.setOnClickListener(view -> scrapTutorTab());
} }
private void getTutorTab(){
disposable.add(
tutorTabService.apiUsersTutorTabByTutorIdGet(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
@Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
dutyHourList = tutorTabViewModel.getDutyHours();
if(dutyHourList != null){
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),dutyHourList);
dutyHoursRecycller.setAdapter(dutyHoursAdapter);
addDutyButton.setOnClickListener(v -> addEmptyDuty(dutyHoursAdapter));
}
userRoom.setText(String.format("%s", tutorTabViewModel.getRoom()));
userEmail.setText(String.format("%s", tutorTabViewModel.getEmailTutorTab()));
if (!tutorTabViewModel.getNote().equals("")) {
userNote.setText(String.format("%s", tutorTabViewModel.getNote()));
}
}
@Override
public void onError(Throwable e) {
int code = ((HttpException) e).response().code();
if( code == 404){
ifTutorTabExists = false;
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),new ArrayList<DutyHourViewModel>());
dutyHoursRecycller.setAdapter(dutyHoursAdapter);
addDutyButton.setOnClickListener(v -> addEmptyDuty(dutyHoursAdapter));
}
showError(e);
}
}));
}
private void addEmptyDuty(DutyHoursAdapter adapter){ private void addEmptyDuty(DutyHoursAdapter adapter){
adapter.addDuty(new DutyHourViewModel()); adapter.addDuty(new DutyHourViewModel());
adapter.notifyItemInserted(adapter.getItemCount()); adapter.notifyItemInserted(adapter.getItemCount());
@ -161,20 +154,17 @@ public class TutorTab extends AppCompatActivity {
} }
private void setUpSaveListener(Button button) { private void setUpSaveListener(Button button) {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(view -> {
@Override newTab = new TutorTabViewModel(PrefUtils.getUserId(getApplicationContext()),
public void onClick(View view) { userRoom.getText().toString(),
newTab = new TutorTabViewModel(PrefUtils.getUserId(getApplicationContext()), userEmail.getText().toString(),
userRoom.getText().toString(), userNote.getText().toString(),
userEmail.getText().toString(), dutyHoursAdapter.getDutyList());
userNote.getText().toString(), if(ifTutorTabExists){
dutyHoursAdapter.getDutyList()); putUserTab(newTab);
if(ifTutorTabExists){ }else{
putUserTab(newTab); postUserTab(newTab);
}else{ ifTutorTabExists=true;
postUserTab(newTab);
ifTutorTabExists=true;
}
} }
}); });
} }
@ -185,23 +175,35 @@ public class TutorTab extends AppCompatActivity {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponsePut, this::handleError)); .subscribe(this::handleResponsePut, this::handleError));
} }
private void postUserTab(TutorTabViewModel tutorTabViewModel) { private void postUserTab(TutorTabViewModel tutorTabViewModel) {
disposable.add(tutorTabService.apiUsersTutorTabByTutorIdPost(PrefUtils.getUserId(getApplicationContext()), tutorTabViewModel) disposable.add(tutorTabService.apiUsersTutorTabByTutorIdPost(PrefUtils.getUserId(getApplicationContext()), tutorTabViewModel)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponsePost, this::handleError)); .subscribe(this::handleResponsePost, this::handleError));
} }
private void scrapTutorTab() {
disposable.add(tutorTabService.apiUsersScrapTutorTabByTutorIdPost(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponseScrap, this::handleError));
}
private void handleResponseScrap() {
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.scrap_tutor_msg), Toast.LENGTH_SHORT).show();
getTutorTab();
}
private void handleResponsePut(Response<Void> resp) { private void handleResponsePut(Response<Void> resp) {
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.updateToast), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.updateToast), Toast.LENGTH_SHORT).show();
} }
private void handleResponsePost(TutorTabViewModel tutorTabViewModel ) { private void handleResponsePost(TutorTabViewModel tutorTabViewModel ) {
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.updateToast), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.updateToast), Toast.LENGTH_SHORT).show();
} }
private void handleError(Throwable error) { private void handleError(Throwable error) {
if (error instanceof HttpException) { if (error instanceof HttpException) {
@ -212,6 +214,10 @@ public class TutorTab extends AppCompatActivity {
} else { } else {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show(); "Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.e("WMI SUCC", String.valueOf(error));
} }
} }

View File

@ -3,6 +3,7 @@ package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.TutorTabViewModel; import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import io.reactivex.Completable;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.Single; import io.reactivex.Single;
import retrofit2.Response; import retrofit2.Response;
@ -17,7 +18,7 @@ public interface TutorTabApi {
* @return Call&lt;Void&gt; * @return Call&lt;Void&gt;
*/ */
@POST("api/users/scrapTutorTab/{tutorId}") @POST("api/users/scrapTutorTab/{tutorId}")
Observable<Void> apiUsersScrapTutorTabByTutorIdPost( Completable apiUsersScrapTutorTabByTutorIdPost(
@retrofit2.http.Path("tutorId") String tutorId @retrofit2.http.Path("tutorId") String tutorId
); );
@ -27,7 +28,7 @@ public interface TutorTabApi {
* @return Call&lt;Void&gt; * @return Call&lt;Void&gt;
*/ */
@POST("api/users/scrapTutorTab") @POST("api/users/scrapTutorTab")
Observable<Void> apiUsersScrapTutorTabPost(); Single<Void> apiUsersScrapTutorTabPost();
/** /**

View File

@ -7,6 +7,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout <LinearLayout
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -16,14 +18,24 @@
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin" android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"> android:paddingTop="@dimen/activity_margin">
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/linearLayout1" android:layout_height="wrap_content">
<Button
android:id="@+id/scrapTutorTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="@string/scrap_tutor_tab" />
<ImageButton <ImageButton
android:id="@+id/contentTutorTabInfoImageButton" android:id="@+id/contentTutorTabInfoImageButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="end"
mapbox:srcCompat="@drawable/outline_info_24"/> mapbox:srcCompat="@drawable/outline_info_24"/>
</LinearLayout>
<TextView <TextView
android:id="@+id/userName" android:id="@+id/userName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -122,14 +134,19 @@
android:layout_height="100dp" android:layout_height="100dp"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/linearLayout1" android:layout_height="wrap_content">
<Button <Button
android:id="@+id/addDuty" android:id="@+id/addDuty"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/addDuty"
android:layout_gravity="end"/> android:layout_gravity="end"
android:text="@string/addDuty" />
</LinearLayout>
<TextView <TextView
android:textSize="16sp" android:textSize="16sp"

View File

@ -239,6 +239,9 @@
<string name="negative_dialog_button">Nie</string> <string name="negative_dialog_button">Nie</string>
<string name="enable_sharing_question">Aby skorzystać z tej funkcji musisz pozwolić na udostępnianie lokalizacji. Zgadzasz sie?</string> <string name="enable_sharing_question">Aby skorzystać z tej funkcji musisz pozwolić na udostępnianie lokalizacji. Zgadzasz sie?</string>
<string name="sharing_modal_title">Udostępnianie</string> <string name="sharing_modal_title">Udostępnianie</string>
<string name="scrap_tutor_tab">Pobierz dane z WMI</string>
<string name="scrap_tutor_msg">Dane zostały zaktualizwane!</string>
</resources> </resources>

View File

@ -319,4 +319,7 @@
<string name="enable_sharing_question">In order to use this function, you have to enable localization sharing. May I do it for you?</string> <string name="enable_sharing_question">In order to use this function, you have to enable localization sharing. May I do it for you?</string>
<string name="sharing_modal_title">Sharing</string> <string name="sharing_modal_title">Sharing</string>
<string name="lack_of_status">The user hasn\'t defined a status.</string> <string name="lack_of_status">The user hasn\'t defined a status.</string>
<string name="scrap_tutor_tab">Scrap!</string>
<string name="scrap_tutor_msg">Thank you for scraping your tab!</string>
</resources> </resources>