Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updates UserInfo #16

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/src/main/java/com/onelogin/oidc/demo/UserInfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import com.onelogin.oidc.Callback
import com.onelogin.oidc.OneLoginOIDC.getClient
import com.onelogin.oidc.userInfo.UserInfo
import com.onelogin.oidc.userInfo.UserInfoError
import java.text.SimpleDateFormat
import java.util.*

class UserInfoFragment : Fragment() {

Expand All @@ -21,6 +23,7 @@ class UserInfoFragment : Fragment() {
private val preferredName: TextView by lazy { requireView().findViewById<TextView>(R.id.username) }
private val updatedAt: TextView by lazy { requireView().findViewById<TextView>(R.id.updated_at) }
private val animator: ViewAnimator by lazy { requireView() as ViewAnimator }
private val format = SimpleDateFormat("EEE, MMM d, ''yy", Locale.getDefault())

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -43,7 +46,12 @@ class UserInfoFragment : Fragment() {
email.text = success.email
preferredName.text =
if (success.preferredUsername != null) success.preferredUsername else "Empty"
updatedAt.text = if (success.updatedAt != null) success.updatedAt else "Empty"
val lastUpdateTimestamp = success.updatedAt
updatedAt.text = if (lastUpdateTimestamp != null) {
format.format(Date(lastUpdateTimestamp * 1000))
} else {
"Empty"
}
animator.displayedChild = 1
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onelogin.oidc.appjava;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -20,13 +21,18 @@

import static com.onelogin.oidc.appjava.OIDCDemoApp.LOG_TAG;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class UserInfoFragment extends Fragment {

private TextView userId;
private TextView email;
private TextView preferredName;
private TextView updatedAt;
private ViewAnimator animator;
private final SimpleDateFormat format = new SimpleDateFormat("EEE, MMM d, ''yy", Locale.getDefault());

@Nullable
@Override
Expand All @@ -45,12 +51,18 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

animator.setDisplayedChild(0);
OneLoginOIDC.getClient().getUserInfo(new Callback<UserInfo, UserInfoError>() {
@SuppressLint("SetTextI18n")
@Override
public void onSuccess(UserInfo userInfo) {
userId.setText(userInfo.getSub());
email.setText(userInfo.getEmail());
preferredName.setText(userInfo.getPreferredUsername() != null ? userInfo.getPreferredUsername() : "Empty");
updatedAt.setText(userInfo.getUpdatedAt() != null ? userInfo.getUpdatedAt() : "Empty");
if (userInfo.getUpdatedAt() != null) {
updatedAt.setText(format.format(new Date(userInfo.getUpdatedAt() * 1000)));
} else {
updatedAt.setText("Empty");
}

animator.setDisplayedChild(1);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package com.onelogin.oidc.userInfo

import com.google.gson.annotations.SerializedName

data class UserInfo(
@SerializedName("sub")
val sub: String,
@SerializedName("email")
val email: String,
@SerializedName("preferred_username")
val preferredUsername: String?,
@SerializedName("name")
val name: String?,
val updatedAt: String?,
@SerializedName("updated_at")
val updatedAt: Long?,
@SerializedName("given_name")
val givenName: String?,
@SerializedName("family_name")
val familyName: String?,
@SerializedName("groups")
val groups: List<String>?
)