Skip to content

Commit

Permalink
Merge pull request #14 from SharifRafid/master
Browse files Browse the repository at this point in the history
android : Student Profile Update And Edit Feature Added ⚡
  • Loading branch information
samiurprapon authored Aug 24, 2021
2 parents 7f0ba33 + 444d61d commit f8db439
Show file tree
Hide file tree
Showing 24 changed files with 863 additions and 31 deletions.
14 changes: 5 additions & 9 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ AndroidManifest.xml Created by Samiur Prapon
~ Last modified 7/30/21, 6:23 PM
~ Copyright (c) 2021. All rights reserved.
~
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="life.nsu.aether">
Expand All @@ -17,10 +10,13 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.Aether"
android:usesCleartextTraffic="true"
tools:ignore="AllowBackup">
<activity android:name=".views.student.StudentHomeActivity"/>
<activity
android:name=".views.student.profile.EditProfileActivity"
android:exported="true" />
<activity android:name=".views.student.StudentHomeActivity" />
<activity android:name=".views.authentication.LoginActivity" />
<activity android:name=".views.authentication.RegistrationActivity" />
<activity
Expand Down
13 changes: 7 additions & 6 deletions android/app/src/main/java/life/nsu/aether/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ protected void onCreate(Bundle savedInstanceState) {
viewModel = new ViewModelProvider(this).get(SplashViewModel.class);

viewModel.getRefreshResponseMutableLiveData().observe(this, refreshResponse -> {
// Log.d("refreshResponse", refreshResponse.getMessage() +" " + refreshResponse.isSuccess() + " " + refreshResponse.getAccessToken());
viewModel.switchActivity(refreshResponse);
if(!refreshResponse.isSuccess()){
viewModel.switchActivity(refreshResponse);
}else{
viewModel.getProfileValidityResponseMutableLiveData().observe(this, profileValidityResponse -> {
viewModel.switchActivity(profileValidityResponse);
});
}
});
}

@Override
protected void onDestroy() {
super.onDestroy();

if(viewModel.getRefreshResponseMutableLiveData().hasActiveObservers()) {
viewModel.getRefreshResponseMutableLiveData().removeObservers(this);
}
}
}
84 changes: 84 additions & 0 deletions android/app/src/main/java/life/nsu/aether/models/Student.java
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;
}

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void onResponse(@NonNull Call<RefreshResponse> call, @NonNull Response<Re
e.printStackTrace();
}
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void onResponse(@NonNull Call<MessageResponse> call, @NonNull Response<Me
MessageResponse errorResponse = converter.convert(response.errorBody());
mutableMessage.postValue(errorResponse);
} catch (IOException e) {
mutableMessage.postValue(new MessageResponse(false, e.getMessage()));
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

public class NetworkCredentials {

public static String SERVER_BASE_URL = "http://103.198.139.224:3100/api/";
public static String SERVER_BASE_URL = "http://103.198.139.224:3101/api/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
package life.nsu.aether.utils.networking;

import life.nsu.aether.utils.networking.requests.LoginRequest;
import life.nsu.aether.utils.networking.requests.ProfileUpdateRequest;
import life.nsu.aether.utils.networking.requests.RegistrationRequest;
import life.nsu.aether.utils.networking.responses.LoginResponse;
import life.nsu.aether.utils.networking.responses.MessageResponse;
import life.nsu.aether.utils.networking.responses.ProfileValidityResponse;
import life.nsu.aether.utils.networking.responses.RefreshResponse;
import life.nsu.aether.utils.networking.responses.StudentProfileDetailsResponse;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;

Expand All @@ -31,4 +35,13 @@ public interface ServerEndpoints {
@POST("auth/logout")
Call<MessageResponse> deAuthentication(@Header("Authorization") String accessToken);

@GET("student/valid")
Call<ProfileValidityResponse> validateStudentProfile(@Header("Authorization") String accessToken);

@POST("student")
Call<StudentProfileDetailsResponse> updateProfile(@Header("Authorization") String accessToken, @Body ProfileUpdateRequest request);

@GET("student")
Call<StudentProfileDetailsResponse> getStudentProfile(@Header("Authorization") String accessToken);

}
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;
}
}
Loading

0 comments on commit f8db439

Please sign in to comment.