Skip to content
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())
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimpleDateFormat is not thread-safe. While Kotlin's lazy initialization helps, if this fragment is accessed by multiple threads, thread-safety issues could occur. Consider using DateTimeFormatter or create a new SimpleDateFormat instance when needed.

Copilot uses AI. Check for mistakes.

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());
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimpleDateFormat is not thread-safe and should not be stored as an instance field. If this fragment is accessed concurrently or reused, this could cause issues. Consider using ThreadLocal or DateTimeFormatter (API 26+) instead.

Copilot uses AI. Check for mistakes.

@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>?
)