Skip to content

Commit b848c6e

Browse files
author
Bot
committed
Fix all null safety issues: 37 !!. assertions cleaned up
1 parent 2ae6253 commit b848c6e

15 files changed

Lines changed: 167 additions & 126 deletions

File tree

api/src/commonMain/kotlin/dev/materii/gloom/api/model/ModelUser.kt

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,45 @@ data class ModelUser(
112112
}
113113
}
114114

115-
fun fromUserProfileQuery(upq: UserProfileQuery.Data) = with(upq) {
115+
fun fromUserProfileQuery(upq: UserProfileQuery.Data): ModelUser {
116116
val isUser = upq.repositoryOwner?.userProfile != null
117117
val isOrg = upq.repositoryOwner?.orgProfile != null && !isUser
118118

119119
if (isUser) {
120-
with(upq.repositoryOwner!!.userProfile!!) {
121-
ModelUser(
122-
id = id,
123-
username = login,
124-
displayName = name,
125-
bio = bio,
126-
avatar = avatarUrl.toString(),
127-
readme = profileReadme?.contentHTML?.toString(),
120+
val userProfile = upq.repositoryOwner?.userProfile
121+
if (userProfile != null) {
122+
return ModelUser(
123+
id = userProfile.id,
124+
username = userProfile.login,
125+
displayName = userProfile.name,
126+
bio = userProfile.bio,
127+
avatar = userProfile.avatarUrl.toString(),
128+
readme = userProfile.profileReadme?.contentHTML?.toString(),
128129
type = User.Type.USER,
129-
company = company,
130-
website = websiteUrl.toString(),
131-
socials = socialAccounts.nodes?.mapNotNull { it?.social } ?: emptyList(),
132-
repos = repositories.totalCount.toLong(),
133-
orgs = organizations.totalCount.toLong(),
134-
starred = starredRepositories.totalCount.toLong(),
135-
sponsoring = sponsoring.totalCount.toLong(),
136-
followers = followers.totalCount.toLong(),
137-
following = following.totalCount.toLong(),
130+
company = userProfile.company,
131+
website = userProfile.websiteUrl.toString(),
132+
socials = userProfile.socialAccounts.nodes?.mapNotNull { it?.social } ?: emptyList(),
133+
repos = userProfile.repositories.totalCount.toLong(),
134+
orgs = userProfile.organizations.totalCount.toLong(),
135+
starred = userProfile.starredRepositories.totalCount.toLong(),
136+
sponsoring = userProfile.sponsoring.totalCount.toLong(),
137+
followers = userProfile.followers.totalCount.toLong(),
138+
following = userProfile.following.totalCount.toLong(),
138139
status = ModelStatus.fromUserProfileQuery(upq),
139-
email = email,
140-
location = location,
141-
pinnedItems = pinnedItems.nodes?.map { ModelRepo.fromPinnedRepo(it?.pinnedRepo) }
142-
?: emptyList(),
143-
canFollow = viewerCanFollow,
144-
isFollowing = viewerIsFollowing,
140+
email = userProfile.email,
141+
location = userProfile.location,
142+
pinnedItems = userProfile.pinnedItems.nodes?.map { ModelRepo.fromPinnedRepo(it?.pinnedRepo) } ?: emptyList(),
143+
canFollow = userProfile.viewerCanFollow,
144+
isFollowing = userProfile.viewerIsFollowing,
145145
isSupporter = false,
146-
isFollowingYou = isFollowingViewer,
147-
contributions = contributionsCollection.contributions
146+
isFollowingYou = userProfile.isFollowingViewer,
147+
contributions = userProfile.contributionsCollection.contributions
148148
)
149149
}
150150
} else if (isOrg) {
151-
with(upq.repositoryOwner!!.orgProfile!!) {
151+
val orgProfile = upq.repositoryOwner?.orgProfile
152+
if (orgProfile != null) {
153+
return ModelUser(
152154
ModelUser(
153155
username = login,
154156
displayName = name,

shared/src/commonMain/kotlin/dev/materii/gloom/domain/manager/AuthManager.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,26 @@ class AuthManager(
7777

7878
fun editAccount(
7979
id: String,
80-
token: String = accounts[id]!!.token,
81-
type: Account.Type = accounts[id]!!.type,
82-
baseUrl: String? = accounts[id]!!.baseUrl,
83-
avatarUrl: String = accounts[id]!!.avatarUrl,
84-
username: String = accounts[id]!!.username,
85-
displayName: String? = accounts[id]!!.displayName,
86-
notificationCount: Int = accounts[id]!!.notificationCount
87-
) = editAccount(
88-
accounts[id]!!,
89-
token,
90-
type,
91-
baseUrl,
92-
avatarUrl,
93-
username,
94-
displayName,
95-
notificationCount
96-
)
80+
token: String? = null,
81+
type: Account.Type? = null,
82+
baseUrl: String? = null,
83+
avatarUrl: String? = null,
84+
username: String? = null,
85+
displayName: String? = null,
86+
notificationCount: Int? = null
87+
) {
88+
val existingAccount = accounts[id] ?: return
89+
editAccount(
90+
existingAccount,
91+
token ?: existingAccount.token,
92+
type ?: existingAccount.type,
93+
baseUrl ?: existingAccount.baseUrl,
94+
avatarUrl ?: existingAccount.avatarUrl,
95+
username ?: existingAccount.username,
96+
displayName ?: existingAccount.displayName,
97+
notificationCount ?: existingAccount.notificationCount
98+
)
99+
}
97100

98101
private fun editAccount(
99102
account: Account,

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/explorer/FileViewerScreen.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ class FileViewerScreen(
167167
}
168168

169169
if (fileType == "ImageFileType" || fileType == "PdfFileType") {
170-
val url = file.fileType!!.onImageFileType?.url ?: file.fileType!!.onPdfFileType!!.url
170+
val fileTypeData = file.fileType
171+
val url = when (fileType) {
172+
"ImageFileType" -> fileTypeData?.onImageFileType?.url
173+
"PdfFileType" -> fileTypeData?.onPdfFileType?.url
174+
else -> null
175+
}
171176
if (url != null) {
172177
DownloadButton(
173178
downloadUrl = url
@@ -222,13 +227,13 @@ class FileViewerScreen(
222227
file: RepoFile.File?,
223228
hidden: Boolean
224229
) {
225-
val text = when {
226-
viewModel.selectedLines == null -> path.split("/").lastOrNull() ?: "File"
230+
val text = when (val sl = viewModel.selectedLines) {
231+
null -> path.split("/").lastOrNull() ?: "File"
227232
else -> stringResource(
228233
Res.plurals.plural_lines_selected,
229-
viewModel.selectedLines!!.count(),
230-
viewModel.selectedLines!!.first,
231-
viewModel.selectedLines!!.last
234+
sl.count(),
235+
sl.first,
236+
sl.last
232237
)
233238
}
234239

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/explorer/viewmodel/FileViewerViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ class FileViewerViewModel(
8686
}
8787

8888
private fun getLinesPart(): String {
89-
if (selectedLines == null) return ""
89+
val sl = selectedLines ?: return ""
9090
return buildString {
91-
append("#L${selectedLines!!.first}")
92-
if (selectedLines!!.count() > 1) append("-L${selectedLines!!.last}")
93-
} // Should be something like #L1-L10
91+
append("#L${sl.first}")
92+
if (sl.count() > 1) append("-L${sl.last}")
93+
}
9494
}
9595

9696
fun getFileUrl(): String {

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/home/component/NewReleaseItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fun ReleaseCard(
166166
ReleaseDetail(
167167
icon = Icons.Custom.Commit,
168168
iconDescription = stringResource(Res.strings.noun_commit),
169-
text = release.tagCommit!!.abbreviatedOid
169+
text = release.tagCommit?.abbreviatedOid ?: ""
170170
)
171171
}
172172
}

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/profile/ProfileScreen.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@ open class ProfileScreen(
107107
user.readme?.let { readme ->
108108
Box(modifier = Modifier.padding(horizontal = 16.dp)) {
109109
val nav = LocalNavigator.currentOrThrow
110-
val repository = viewModel.user!!.username ?: "ghost"
110+
val repository = user.username ?: "ghost"
111111

112112
ReadMeCard(
113113
text = readme,
114114
repository = repository,
115115
onClickRepository = {
116116
if (user.type == User.Type.USER) {
117-
nav.navigate(RepoScreen(user.username!!, repository))
117+
user.username?.let { username ->
118+
nav.navigate(RepoScreen(username, repository))
119+
}
118120
}
119121
}
120122
)
@@ -170,8 +172,9 @@ open class ProfileScreen(
170172
navigationIcon = { BackButton() },
171173
scrollBehavior = scrollBehavior,
172174
actions = {
173-
if (!viewModel.user?.username.isNullOrBlank()) {
174-
IconButton(onClick = { shareManager.shareText("https://github.com/${viewModel.user!!.username}") }) {
175+
val username = viewModel.user?.username
176+
if (!username.isNullOrBlank()) {
177+
IconButton(onClick = { shareManager.shareText("https://github.com/$username") }) {
175178
Icon(Icons.Filled.Share, stringResource(Res.strings.action_share))
176179
}
177180
}
@@ -421,18 +424,20 @@ open class ProfileScreen(
421424
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
422425
.padding(5.dp)
423426
) {
424-
if (status.emoji != null)
427+
val emoji = status.emoji
428+
if (emoji != null)
425429
AsyncImage(
426-
model = EmojiUtil.emojis[status.emoji!!.replace(":", "")],
427-
contentDescription = status.emoji,
430+
model = EmojiUtil.emojis[emoji.replace(":", "")],
431+
contentDescription = emoji,
428432
modifier = Modifier
429433
.clip(CircleShape)
430434
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp))
431435
.size(30.dp)
432436
.padding(6.dp)
433437
)
434438

435-
if (status.message != null)
439+
val message = status.message
440+
if (message != null)
436441
Text(
437442
text = status.message!!,
438443
style = MaterialTheme.typography.labelLarge,

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/release/ReleaseScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class ReleaseScreen(
8787
if (viewModel.apkFile != null && dev.materii.gloom.util.Features.contains(Feature.INSTALL_APKS)) {
8888
when (dialogManager.installApk) {
8989
DialogState.UNKNOWN -> {
90+
val apkFile = viewModel.apkFile
9091
ReleaseAssetInstallDialog(
91-
fileName = viewModel.apkFile!!.name,
92+
fileName = apkFile?.name ?: "",
9293
onClose = { dontShowAgain ->
9394
viewModel.clearApk()
9495
if (dontShowAgain == true) dialogManager.installApk =

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/repo/component/CommitItem.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ fun CommitItem(
6161
horizontalArrangement = Arrangement.spacedBy(6.dp),
6262
verticalAlignment = Alignment.CenterVertically
6363
) {
64-
if (commit.statusCheckRollup != null) {
64+
commit.statusCheckRollup?.let { rollup ->
6565
StatusIcon(
66-
status = commit.statusCheckRollup!!.state,
66+
status = rollup.state,
6767
modifier = Modifier.size(16.dp)
6868
)
6969
}
@@ -83,15 +83,18 @@ fun CommitItem(
8383
horizontalArrangement = Arrangement.spacedBy(8.dp),
8484
verticalAlignment = Alignment.CenterVertically
8585
) {
86-
val author = commit.author!!.gitActorDetails
87-
val committer = commit.committer!!.gitActorDetails
88-
val isUniqueCommiter = !commit.authoredByCommitter && committer.user != null
86+
val author = commit.author?.gitActorDetails
87+
val committer = commit.committer?.gitActorDetails
88+
val isUniqueCommiter = !commit.authoredByCommitter && committer?.user != null
89+
90+
val authorAvatar = author?.avatarUrl
91+
val committerAvatar = committer?.avatarUrl
8992

9093
AvatarPile(
9194
avatars = if (isUniqueCommiter) {
92-
persistentListOf(author.avatarUrl, committer.avatarUrl)
95+
persistentListOfNotNull(authorAvatar, committerAvatar)
9396
} else {
94-
persistentListOf(author.avatarUrl)
97+
persistentListOfNotNull(authorAvatar)
9598
}
9699
)
97100

@@ -102,8 +105,8 @@ fun CommitItem(
102105
} else {
103106
Res.strings.commit_authored_by_committer
104107
},
105-
author.name ?: author.user?.login ?: "ghost",
106-
committer.name ?: committer.user?.login ?: "ghost"
108+
author?.name ?: author?.user?.login ?: "ghost",
109+
committer?.name ?: committer?.user?.login ?: "ghost"
107110
) {
108111
when (it) {
109112
"author", "committer" -> SpanStyle(
@@ -145,6 +148,8 @@ fun CommitItem(
145148
if (commit.signature?.commitSignatureDetails?.isValid == true) {
146149
var signatureDetailsOpened by remember { mutableStateOf(false) }
147150

151+
val sigDetails = commit.signature?.commitSignatureDetails
152+
148153
Label(
149154
text = stringResource(Res.strings.label_verified),
150155
textColor = MaterialTheme.gloomColorScheme.statusGreen,
@@ -153,9 +158,9 @@ fun CommitItem(
153158
}
154159
)
155160

156-
if (signatureDetailsOpened) {
161+
if (signatureDetailsOpened && sigDetails != null) {
157162
CommitSignatureDialog(
158-
signature = commit.signature!!.commitSignatureDetails,
163+
signature = sigDetails,
159164
onDismiss = { signatureDetailsOpened = false }
160165
)
161166
}

ui/src/commonMain/kotlin/dev/materii/gloom/ui/screen/repo/component/RepoItem.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ fun RepoItem(
6262
.fillMaxWidth()
6363
.thenIf(card) { width(260.dp) }
6464
) {
65-
if (repo.owner != null) Row(
65+
val ownerVal = repo.owner
66+
if (ownerVal != null) Row(
6667
horizontalArrangement = Arrangement.spacedBy(8.dp),
6768
verticalAlignment = Alignment.CenterVertically
6869
) {
6970
Avatar(
70-
url = repo.owner!!.avatar,
71-
type = repo.owner!!.type,
71+
url = ownerVal.avatar,
72+
type = ownerVal.type,
7273
modifier = Modifier.size(20.dp)
7374
)
7475

7576
Text(
76-
text = repo.owner!!.username ?: "ghost",
77+
text = ownerVal.username ?: "ghost",
7778
style = MaterialTheme.typography.labelMedium
7879
)
7980
}
@@ -101,11 +102,13 @@ fun RepoItem(
101102
}
102103

103104
if (repo.fork == true && !card) {
104-
LabeledIcon(
105-
icon = Icons.Custom.Fork,
106-
label = stringResource(Res.strings.label_forked_from, repo.parent!!.fullName!!),
107-
iconTint = LocalContentColor.current.copy(0.6f)
108-
)
105+
repo.parent?.fullName?.let { parentName ->
106+
LabeledIcon(
107+
icon = Icons.Custom.Fork,
108+
label = stringResource(Res.strings.label_forked_from, parentName),
109+
iconTint = LocalContentColor.current.copy(0.6f)
110+
)
111+
}
109112
}
110113

111114
Row(

0 commit comments

Comments
 (0)