forked from samiurprapon/Aether
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from obboy/master
android: minimal student profile feature added.
- Loading branch information
Showing
24 changed files
with
863 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
android/app/src/main/java/life/nsu/aether/models/Student.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Student Created by Samiur Prapon | ||
* Last modified 24/8/21, 12:51 am | ||
* Copyright (c) 2021. All rights reserved. | ||
* | ||
*/ | ||
|
||
package life.nsu.aether.models; | ||
public class Student { | ||
|
||
private String id; | ||
private String name; | ||
private String studentID; | ||
private String sex; | ||
private String uid; | ||
private String status; | ||
private String createdAt; | ||
private String updatedAt; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getStudentID() { | ||
return studentID; | ||
} | ||
|
||
public void setStudentID(String studentID) { | ||
this.studentID = studentID; | ||
} | ||
|
||
public String getSex() { | ||
return sex; | ||
} | ||
|
||
public void setSex(String sex) { | ||
this.sex = sex; | ||
} | ||
|
||
public String getUid() { | ||
return uid; | ||
} | ||
|
||
public void setUid(String uid) { | ||
this.uid = uid; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(String status) { | ||
this.status = status; | ||
} | ||
|
||
public String getCreatedAt() { | ||
return createdAt; | ||
} | ||
|
||
public void setCreatedAt(String createdAt) { | ||
this.createdAt = createdAt; | ||
} | ||
|
||
public String getUpdatedAt() { | ||
return updatedAt; | ||
} | ||
|
||
public void setUpdatedAt(String updatedAt) { | ||
this.updatedAt = updatedAt; | ||
} | ||
|
||
} |
142 changes: 142 additions & 0 deletions
142
android/app/src/main/java/life/nsu/aether/repositories/ProfileRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* ProfileRepository Created by Samiur Prapon | ||
* Last modified 24/8/21, 12:51 am | ||
* Copyright (c) 2021. All rights reserved. | ||
* | ||
*/ | ||
|
||
package life.nsu.aether.repositories; | ||
|
||
import android.app.Application; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.lifecycle.LiveData; | ||
import androidx.lifecycle.MutableLiveData; | ||
|
||
import java.io.IOException; | ||
import java.lang.annotation.Annotation; | ||
|
||
import life.nsu.aether.models.Student; | ||
import life.nsu.aether.utils.networking.NetworkingService; | ||
import life.nsu.aether.utils.networking.requests.ProfileUpdateRequest; | ||
import life.nsu.aether.utils.networking.responses.ProfileValidityResponse; | ||
import life.nsu.aether.utils.networking.responses.StudentProfileDetailsResponse; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Converter; | ||
import retrofit2.Response; | ||
|
||
public class ProfileRepository { | ||
Application application; | ||
MutableLiveData<ProfileValidityResponse> profileValidityResponseMutableLiveData; | ||
MutableLiveData<StudentProfileDetailsResponse> studentProfileDetailsResponseMutableLiveData; | ||
MutableLiveData<StudentProfileDetailsResponse> studentProfileUpdateDetailsResponseMutableLiveData; | ||
|
||
|
||
private static ProfileRepository profileRepository = null; | ||
|
||
public synchronized static ProfileRepository getInstance(Application application) { | ||
if (profileRepository == null) { | ||
profileRepository = new ProfileRepository(application); | ||
} | ||
|
||
return profileRepository; | ||
} | ||
|
||
private ProfileRepository(Application application) { | ||
this.application = application; | ||
|
||
profileValidityResponseMutableLiveData = new MutableLiveData<>(); | ||
studentProfileDetailsResponseMutableLiveData = new MutableLiveData<>(); | ||
studentProfileUpdateDetailsResponseMutableLiveData = new MutableLiveData<>(); | ||
|
||
} | ||
|
||
public MutableLiveData<ProfileValidityResponse> getProfileValidityResponseMutableLiveData(String refreshToken) { | ||
Call<ProfileValidityResponse> call = NetworkingService.getInstance() | ||
.getRoute() | ||
.validateStudentProfile(refreshToken); | ||
|
||
call.enqueue(new Callback<ProfileValidityResponse>() { | ||
@Override | ||
public void onResponse(@NonNull Call<ProfileValidityResponse> call, @NonNull Response<ProfileValidityResponse> response) { | ||
if (response.body() != null) { | ||
profileValidityResponseMutableLiveData.postValue(response.body()); | ||
} | ||
|
||
if (response.errorBody() != null) { | ||
profileValidityResponseMutableLiveData.postValue(new ProfileValidityResponse(false, response.message(), false)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(@NonNull Call<ProfileValidityResponse> call, @NonNull Throwable t) { | ||
profileValidityResponseMutableLiveData.postValue(new ProfileValidityResponse(false, t.getMessage(), false)); | ||
} | ||
}); | ||
|
||
return profileValidityResponseMutableLiveData; | ||
} | ||
|
||
public MutableLiveData<StudentProfileDetailsResponse> getStudentProfileDetailsResponseMutableLiveData(String refreshToken) { | ||
Call<StudentProfileDetailsResponse> call = NetworkingService.getInstance() | ||
.getRoute() | ||
.getStudentProfile(refreshToken); | ||
|
||
call.enqueue(new Callback<StudentProfileDetailsResponse>() { | ||
@Override | ||
public void onResponse(@NonNull Call<StudentProfileDetailsResponse> call, @NonNull Response<StudentProfileDetailsResponse> response) { | ||
if (response.body() != null) { | ||
studentProfileDetailsResponseMutableLiveData.postValue(response.body()); | ||
} | ||
|
||
if (response.errorBody() != null) { | ||
studentProfileDetailsResponseMutableLiveData.postValue(new StudentProfileDetailsResponse(false, response.message(), new Student())); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(@NonNull Call<StudentProfileDetailsResponse> call, @NonNull Throwable t) { | ||
studentProfileDetailsResponseMutableLiveData.postValue(new StudentProfileDetailsResponse(false, t.getMessage(), new Student())); | ||
} | ||
}); | ||
|
||
return studentProfileDetailsResponseMutableLiveData; | ||
} | ||
|
||
public LiveData<StudentProfileDetailsResponse> getStudentProfileUpdateResponseLiveData(String refreshToken, String name, String gender, String studentId) { | ||
Call<StudentProfileDetailsResponse> call = NetworkingService.getInstance() | ||
.getRoute() | ||
.updateProfile(refreshToken, new ProfileUpdateRequest(Integer.parseInt(studentId), name, gender)); | ||
|
||
call.enqueue(new Callback<StudentProfileDetailsResponse>() { | ||
@Override | ||
public void onResponse(@NonNull Call<StudentProfileDetailsResponse> call, @NonNull Response<StudentProfileDetailsResponse> response) { | ||
|
||
if (response.body() != null) { | ||
studentProfileUpdateDetailsResponseMutableLiveData.postValue(response.body()); | ||
} | ||
|
||
if (response.errorBody() != null) { | ||
Log.e("Error", String.valueOf(response.code())); | ||
try { | ||
Log.e("Error", response.errorBody().string()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
studentProfileUpdateDetailsResponseMutableLiveData.postValue(new StudentProfileDetailsResponse(false, response.message(), new Student())); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(@NonNull Call<StudentProfileDetailsResponse> call, @NonNull Throwable t) { | ||
studentProfileUpdateDetailsResponseMutableLiveData.postValue(new StudentProfileDetailsResponse(false, t.getMessage(), new Student())); | ||
} | ||
}); | ||
|
||
return studentProfileUpdateDetailsResponseMutableLiveData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...oid/app/src/main/java/life/nsu/aether/utils/networking/requests/ProfileUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* ProfileUpdateRequest Created by Samiur Prapon | ||
* Last modified 24/8/21, 12:51 am | ||
* Copyright (c) 2021. All rights reserved. | ||
* | ||
*/ | ||
|
||
package life.nsu.aether.utils.networking.requests; | ||
|
||
public class ProfileUpdateRequest { | ||
private int studentID; | ||
private String name; | ||
private String sex; | ||
|
||
public ProfileUpdateRequest(){ | ||
// Default Constructor | ||
} | ||
|
||
public ProfileUpdateRequest(int studentID, String name, String sex) { | ||
this.studentID = studentID; | ||
this.name = name; | ||
this.sex = sex; | ||
} | ||
|
||
public int getStudentID() { | ||
return studentID; | ||
} | ||
|
||
public void setStudentID(int studentID) { | ||
this.studentID = studentID; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getSex() { | ||
return sex; | ||
} | ||
|
||
public void setSex(String sex) { | ||
this.sex = sex; | ||
} | ||
} |
Oops, something went wrong.