Skip to content

Commit 77e3a6d

Browse files
Afridi Hasansamiurprapon
authored andcommitted
Android: Refactor codebase and integrate sign in endpoint only
1 parent 1c4cc54 commit 77e3a6d

File tree

20 files changed

+376
-96
lines changed

20 files changed

+376
-96
lines changed

android/app/build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ plugins {
1010
}
1111

1212
android {
13-
compileSdkVersion 30
13+
compileSdkVersion 33
1414
buildToolsVersion "30.0.3"
1515

1616
defaultConfig {
1717
applicationId "life.nsu.aether"
1818
minSdkVersion 23
19-
targetSdkVersion 30
19+
targetSdkVersion 33
2020
versionCode 1
21-
versionName "1.0"
21+
versionName "0.1.0"
2222

2323
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2424
}
@@ -47,9 +47,9 @@ dependencies {
4747
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
4848

4949
// UI components
50-
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
51-
implementation 'androidx.appcompat:appcompat:1.3.1'
52-
implementation 'com.google.android.material:material:1.4.0'
50+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
51+
implementation 'androidx.appcompat:appcompat:1.5.1'
52+
implementation 'com.google.android.material:material:1.7.0'
5353
implementation 'androidx.cardview:cardview:1.0.0'
5454
implementation 'androidx.recyclerview:recyclerview:1.2.1'
5555

@@ -61,12 +61,15 @@ dependencies {
6161

6262
// image cache library
6363
implementation 'com.github.bumptech.glide:glide:4.12.0'
64-
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
64+
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
6565

6666
// Networking Components
6767
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
6868
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
6969

70+
// serialization/deserialization library to convert Java Objects into JSON
71+
implementation 'com.google.code.gson:gson:2.9.1'
72+
7073
// Runtime permission
7174
implementation 'com.karumi:dexter:6.2.2'
7275

android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<activity android:name=".views.authentication.RegistrationActivity" />
2222
<activity
2323
android:name=".SplashActivity"
24-
android:launchMode="singleTask">
24+
android:launchMode="singleTask"
25+
android:exported="true">
2526
<intent-filter>
2627
<action android:name="android.intent.action.MAIN" />
2728

android/app/src/main/java/life/nsu/aether/SplashActivity.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88

99
package life.nsu.aether;
1010

11+
import android.annotation.SuppressLint;
1112
import android.os.Bundle;
13+
import android.util.Log;
1214

1315
import androidx.appcompat.app.AppCompatActivity;
1416
import androidx.lifecycle.ViewModelProvider;
1517

1618
import life.nsu.aether.viewModels.SplashViewModel;
1719

20+
@SuppressLint("CustomSplashScreen")
1821
public class SplashActivity extends AppCompatActivity {
1922

2023
SplashViewModel viewModel;
@@ -27,13 +30,8 @@ protected void onCreate(Bundle savedInstanceState) {
2730
viewModel = new ViewModelProvider(this).get(SplashViewModel.class);
2831

2932
viewModel.getRefreshResponseMutableLiveData().observe(this, refreshResponse -> {
30-
if(!refreshResponse.isSuccess()){
33+
Log.d("SplashActivity:refreshResponse", refreshResponse.getMessage());
3134
viewModel.switchActivity(refreshResponse);
32-
}else{
33-
viewModel.getProfileValidityResponseMutableLiveData().observe(this, profileValidityResponse -> {
34-
viewModel.switchActivity(profileValidityResponse);
35-
});
36-
}
3735
});
3836
}
3937

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Token Created by Samiur Prapon
3+
* Last modified 10/23/22, 3:39 PM
4+
* Copyright (c) 2022. All rights reserved.
5+
*
6+
*/
7+
8+
package life.nsu.aether.models;
9+
10+
import com.google.gson.annotations.Expose;
11+
import com.google.gson.annotations.SerializedName;
12+
13+
public class Token {
14+
@SerializedName("accessToken")
15+
@Expose()
16+
private final String accessToken;
17+
18+
@SerializedName("refreshToken")
19+
@Expose()
20+
private final String refreshToken;
21+
22+
public Token(String accessToken, String refreshToken) {
23+
this.accessToken = accessToken;
24+
this.refreshToken = refreshToken;
25+
}
26+
27+
public String getAccessToken() {
28+
return this.accessToken;
29+
}
30+
31+
public String getRefreshToken() {
32+
return refreshToken;
33+
}
34+
35+
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* TokenData Created by Samiur Prapon
3+
* Last modified 10/23/22, 5:35 PM
4+
* Copyright (c) 2022. All rights reserved.
5+
*
6+
*/
7+
8+
package life.nsu.aether.models;
9+
10+
import life.nsu.aether.models.tokenDecode.Details;
11+
import life.nsu.aether.models.tokenDecode.Permissions;
12+
import life.nsu.aether.models.tokenDecode.User;
13+
14+
public class TokenData {
15+
private Details details;
16+
private Permissions permissions;
17+
private User user;
18+
19+
public TokenData() {
20+
}
21+
22+
public Permissions getPermissions() {
23+
return permissions;
24+
}
25+
26+
public Details getDetails() {
27+
return details;
28+
}
29+
30+
public User getUser() {
31+
return user;
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Details Created by Samiur Prapon
3+
* Last modified 10/23/22, 4:29 PM
4+
* Copyright (c) 2022. All rights reserved.
5+
*
6+
*/
7+
8+
package life.nsu.aether.models.tokenDecode;
9+
10+
import com.google.gson.annotations.Expose;
11+
import com.google.gson.annotations.SerializedName;
12+
13+
public class Details {
14+
@SerializedName("id")
15+
@Expose
16+
private String id;
17+
18+
@SerializedName("studentID")
19+
@Expose
20+
private Object studentID;
21+
22+
@SerializedName("school")
23+
@Expose
24+
private Object school;
25+
26+
public String getId() {
27+
return id;
28+
}
29+
30+
public Object getStudentID() {
31+
return studentID;
32+
}
33+
34+
public Object getSchool() {
35+
return school;
36+
}
37+
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Role Created by Samiur Prapon
3+
* Last modified 10/23/22, 4:30 PM
4+
* Copyright (c) 2022. All rights reserved.
5+
*
6+
*/
7+
8+
package life.nsu.aether.models.tokenDecode;
9+
10+
import com.google.gson.annotations.Expose;
11+
import com.google.gson.annotations.SerializedName;
12+
13+
public class Permissions {
14+
@SerializedName("id")
15+
@Expose
16+
private String id;
17+
18+
@SerializedName("type")
19+
@Expose
20+
private final String type;
21+
22+
public Permissions(String id, String type) {
23+
this.id = id;
24+
this.type = type;
25+
}
26+
27+
public String getId() {
28+
return id;
29+
}
30+
31+
public void setId(String id) {
32+
this.id = id;
33+
}
34+
35+
public String getType() {
36+
return type;
37+
}
38+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* User Created by Samiur Prapon
3+
* Last modified 10/23/22, 4:34 PM
4+
* Copyright (c) 2022. All rights reserved.
5+
*
6+
*/
7+
8+
package life.nsu.aether.models.tokenDecode;
9+
10+
import com.google.gson.annotations.Expose;
11+
import com.google.gson.annotations.SerializedName;
12+
13+
public class User {
14+
@SerializedName("id")
15+
@Expose
16+
private String id;
17+
18+
@SerializedName("email")
19+
@Expose
20+
private String email;
21+
22+
@SerializedName("name")
23+
@Expose
24+
private Object name;
25+
26+
@SerializedName("sex")
27+
@Expose
28+
private String sex;
29+
30+
@SerializedName("isBan")
31+
@Expose
32+
private Boolean isBan;
33+
34+
@SerializedName("cid")
35+
@Expose
36+
private String cid;
37+
38+
public String getId() {
39+
return id;
40+
}
41+
42+
public String getEmail() {
43+
return email;
44+
}
45+
public Object getName() {
46+
return name;
47+
}
48+
public String getSex() {
49+
return sex;
50+
}
51+
public Boolean getIsBan() {
52+
return isBan;
53+
}
54+
public String getCid() {
55+
return cid;
56+
}
57+
58+
}

android/app/src/main/java/life/nsu/aether/repositories/RefreshRepository.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class RefreshRepository {
2727
Application application;
2828
MutableLiveData<RefreshResponse> refreshResponseMutableLiveData;
2929

30-
3130
private static RefreshRepository refreshRepository = null;
3231

3332
public synchronized static RefreshRepository getInstance(Application application) {
@@ -55,7 +54,7 @@ public MutableLiveData<RefreshResponse> getRefreshResponseMutableLiveData(String
5554
public void onResponse(@NonNull Call<RefreshResponse> call, @NonNull Response<RefreshResponse> response) {
5655
if (response.body() != null) {
5756
refreshResponseMutableLiveData.postValue(response.body());
58-
// Log.d("refreshResponse", response.body().getMessage() + " " + response.body().isSuccess() + " " + response.body().getAccessToken());
57+
// Log.d("refreshResponse", response.body().getMessage() + " " + response.body().isError() + " " + response.body().getAccessToken());
5958
}
6059

6160
if (response.errorBody() != null) {
@@ -74,7 +73,7 @@ public void onResponse(@NonNull Call<RefreshResponse> call, @NonNull Response<Re
7473
@Override
7574
public void onFailure(@NonNull Call<RefreshResponse> call, @NonNull Throwable t) {
7675
// Log.d("refreshResponse", t.getMessage());
77-
refreshResponseMutableLiveData.postValue(new RefreshResponse(false, t.getMessage(), ""));
76+
refreshResponseMutableLiveData.postValue(new RefreshResponse(true, t.getMessage(), ""));
7877
}
7978
});
8079

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* DecodeJwt Created by Samiur Prapon
3+
* Last modified 10/23/22, 5:41 PM
4+
* Copyright (c) 2022. All rights reserved.
5+
*
6+
*/
7+
8+
package life.nsu.aether.utils;
9+
10+
import com.google.gson.Gson;
11+
12+
import java.nio.charset.StandardCharsets;
13+
14+
import life.nsu.aether.models.TokenData;
15+
16+
public class DecodeJwt {
17+
18+
TokenData data;
19+
20+
public DecodeJwt(String token) {
21+
// split bearer + token
22+
String[] splitData = token.split(" ");
23+
24+
// Log.d("DecodeJwt", splitData[1]);
25+
26+
// decode token and store as a String
27+
String onlyToken = getDecodedJwt(splitData[1]);
28+
29+
// Log.d("DecodeJwt", onlyToken);
30+
31+
// Convert string to object
32+
this.data = new Gson().fromJson(onlyToken, TokenData.class);
33+
}
34+
35+
public String getDecodedJwt(String jwt) {
36+
StringBuilder result = new StringBuilder();
37+
38+
String[] parts = jwt.split("[.]");
39+
40+
try {
41+
byte[] partAsBytes = parts[1].getBytes(StandardCharsets.UTF_8);
42+
String decodedPart = null;
43+
44+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
45+
decodedPart = new String(java.util.Base64.getUrlDecoder().decode(partAsBytes), StandardCharsets.UTF_8);
46+
}
47+
48+
result.append(decodedPart);
49+
} catch (Exception e) {
50+
throw new RuntimeException("Couldn't decode jwt", e);
51+
}
52+
53+
return result.toString();
54+
}
55+
56+
public TokenData getData() {
57+
return data;
58+
}
59+
}

0 commit comments

Comments
 (0)