Make null-ness possibility explicit. Improve fallback of displayname
This commit is contained in:
parent
5be0f1f773
commit
2c1fef2a0a
|
@ -35,7 +35,7 @@ class FollowsActivity : AppCompatActivity() {
|
|||
val user = db.userDao().getActiveUser()!!
|
||||
startFragment(user.user_id, user.display_name, followers)
|
||||
} else {
|
||||
startFragment(account.id, account.display_name, followers)
|
||||
startFragment(account.id!!, account.getDisplayName(), followers)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ class MainActivity : AppCompatActivity() {
|
|||
if (response.body() != null && response.isSuccessful) {
|
||||
val account = response.body() as Account
|
||||
DBUtils.addUser(db, account, domain, accessToken = accessToken)
|
||||
fillDrawerAccountInfo(account.id)
|
||||
fillDrawerAccountInfo(account.id!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,17 +248,16 @@ class MainActivity : AppCompatActivity() {
|
|||
iconUrl = user.avatar_static
|
||||
isNameShown = true
|
||||
identifier = user.user_id.toLong()
|
||||
descriptionText = "${user.username}@${user.instance_uri.removePrefix("https://")}"
|
||||
descriptionText = "@${user.username}@${user.instance_uri.removePrefix("https://")}"
|
||||
}
|
||||
}.toMutableList()
|
||||
|
||||
// reuse the already existing "add account" item
|
||||
for (profile in header.profiles.orEmpty()) {
|
||||
if (profile.identifier == ADD_ACCOUNT_IDENTIFIER) {
|
||||
profiles.add(profile)
|
||||
break
|
||||
}
|
||||
}
|
||||
header.profiles.orEmpty()
|
||||
.filter { it.identifier == ADD_ACCOUNT_IDENTIFIER }
|
||||
.take(1)
|
||||
.map { profiles.add(it) }
|
||||
|
||||
header.clear()
|
||||
header.profiles = profiles
|
||||
header.setActiveProfile(account.toLong())
|
||||
|
|
|
@ -86,7 +86,7 @@ class PostActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun initializeFragment(arguments: Bundle, status: Status?){
|
||||
supportActionBar?.title = getString(R.string.post_title).format(status!!.account?.display_name)
|
||||
supportActionBar?.title = getString(R.string.post_title).format(status!!.account?.getDisplayName())
|
||||
arguments.putSerializable(POST_TAG, status)
|
||||
postFragment.arguments = arguments
|
||||
supportFragmentManager.beginTransaction()
|
||||
|
|
|
@ -123,15 +123,16 @@ class ProfileActivity : AppCompatActivity() {
|
|||
|
||||
val description = findViewById<TextView>(R.id.descriptionTextView)
|
||||
description.text = parseHTMLText(
|
||||
account!!.note, emptyList(), pixelfedAPI,
|
||||
account!!.note ?: "", emptyList(), pixelfedAPI,
|
||||
applicationContext, "Bearer $accessToken"
|
||||
)
|
||||
|
||||
val accountName = findViewById<TextView>(R.id.accountNameTextView)
|
||||
accountName.text = account!!.display_name
|
||||
accountName.text = account!!.getDisplayName()
|
||||
|
||||
supportActionBar?.title = account!!.display_name
|
||||
if(account!!.display_name != account!!.acct){
|
||||
val displayName = account!!.getDisplayName()
|
||||
supportActionBar?.title = displayName
|
||||
if(displayName != "@${account!!.acct}"){
|
||||
supportActionBar?.subtitle = "@${account!!.acct}"
|
||||
}
|
||||
|
||||
|
@ -215,7 +216,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
*/
|
||||
private fun activateFollow() {
|
||||
// Get relationship between the two users (credential and this) and set followButton accordingly
|
||||
pixelfedAPI.checkRelationships("Bearer $accessToken", listOf(account!!.id))
|
||||
pixelfedAPI.checkRelationships("Bearer $accessToken", listOf(account!!.id.orEmpty()))
|
||||
.enqueue(object : Callback<List<Relationship>> {
|
||||
|
||||
override fun onFailure(call: Call<List<Relationship>>, t: Throwable) {
|
||||
|
@ -257,7 +258,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
followButton.setText(R.string.follow)
|
||||
|
||||
followButton.setOnClickListener {
|
||||
pixelfedAPI.follow(account!!.id, "Bearer $accessToken")
|
||||
pixelfedAPI.follow(account!!.id.orEmpty(), "Bearer $accessToken")
|
||||
.enqueue(object : Callback<Relationship> {
|
||||
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {
|
||||
|
@ -291,7 +292,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
followButton.setText(R.string.unfollow)
|
||||
|
||||
followButton.setOnClickListener {
|
||||
pixelfedAPI.unfollow(account!!.id, "Bearer $accessToken")
|
||||
pixelfedAPI.unfollow(account!!.id.orEmpty(), "Bearer $accessToken")
|
||||
.enqueue(object : Callback<Relationship> {
|
||||
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {
|
||||
|
|
|
@ -107,8 +107,6 @@ class CameraFragment : Fragment() {
|
|||
|
||||
// Shut down our background executor
|
||||
cameraExecutor.shutdown()
|
||||
|
||||
// Unregister the broadcast receivers and listeners
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
|
@ -198,7 +198,7 @@ class NotificationsFragment : FeedFragment() {
|
|||
holder.photoThumbnail.visibility = View.GONE
|
||||
}
|
||||
|
||||
setNotificationType(notification.type, notification.account.username, holder.notificationType)
|
||||
setNotificationType(notification.type, notification.account.username!!, holder.notificationType)
|
||||
setTextViewFromISO8601(notification.created_at, holder.notificationTime, false, context)
|
||||
|
||||
//Convert HTML to clickable text
|
||||
|
|
|
@ -18,29 +18,29 @@ https://docs.joinmastodon.org/entities/account/
|
|||
|
||||
data class Account(
|
||||
//Base attributes
|
||||
override val id: String,
|
||||
val username: String,
|
||||
val acct: String = "",
|
||||
val url: String = "", //HTTPS URL
|
||||
override val id: String?,
|
||||
val username: String?,
|
||||
val acct: String? = "",
|
||||
val url: String? = "", //HTTPS URL
|
||||
//Display attributes
|
||||
val display_name: String = "",
|
||||
val note: String = "", //HTML
|
||||
val avatar: String = "", //URL
|
||||
val avatar_static: String = "", //URL
|
||||
val header: String = "", //URL
|
||||
val header_static: String = "", //URL
|
||||
val locked: Boolean = false,
|
||||
val display_name: String? = "",
|
||||
val note: String? = "", //HTML
|
||||
val avatar: String? = "", //URL
|
||||
val avatar_static: String? = "", //URL
|
||||
val header: String? = "", //URL
|
||||
val header_static: String? = "", //URL
|
||||
val locked: Boolean? = false,
|
||||
val emojis: List<Emoji>? = null,
|
||||
val discoverable: Boolean = true,
|
||||
val discoverable: Boolean? = true,
|
||||
//Statistical attributes
|
||||
val created_at: String = "", //ISO 8601 Datetime (maybe can use a date type)
|
||||
val statuses_count: Int = 0,
|
||||
val followers_count: Int = 0,
|
||||
val following_count: Int = 0,
|
||||
val created_at: String? = "", //ISO 8601 Datetime (maybe can use a date type)
|
||||
val statuses_count: Int? = 0,
|
||||
val followers_count: Int? = 0,
|
||||
val following_count: Int? = 0,
|
||||
//Optional attributes
|
||||
val moved: Account? = null,
|
||||
val fields: List<Field>? = emptyList(),
|
||||
val bot: Boolean = false,
|
||||
val bot: Boolean? = false,
|
||||
val source: Source? = null
|
||||
) : Serializable, FeedContent() {
|
||||
companion object {
|
||||
|
@ -48,6 +48,7 @@ data class Account(
|
|||
const val ACCOUNT_ID_TAG = "AccountIdTag"
|
||||
const val FOLLOWERS_TAG = "FollowingTag"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an activity of the profile with the given id
|
||||
*/
|
||||
|
@ -76,6 +77,12 @@ data class Account(
|
|||
}
|
||||
}
|
||||
|
||||
fun getDisplayName() : String = when {
|
||||
username.isNullOrBlank() && display_name.isNullOrBlank() -> ""
|
||||
username.isNullOrBlank() -> "@${display_name.orEmpty()}"
|
||||
else -> "@$username"
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open profile activity with given account
|
||||
*/
|
||||
|
|
|
@ -109,12 +109,6 @@ data class Status(
|
|||
private fun getDescription(api: PixelfedAPI, context: Context, credential: String) : Spanned =
|
||||
parseHTMLText(content ?: "", mentions, api, context, credential)
|
||||
|
||||
fun getUsername() : CharSequence = when {
|
||||
account?.username.isNullOrBlank() && account?.display_name.isNullOrBlank() -> "No Name"
|
||||
account!!.username.isNullOrBlank() -> account.display_name as CharSequence
|
||||
else -> account.username as CharSequence
|
||||
}
|
||||
|
||||
fun getNLikes(context: Context) : CharSequence {
|
||||
return context.getString(R.string.likes).format(favourites_count.toString())
|
||||
}
|
||||
|
@ -229,13 +223,13 @@ data class Status(
|
|||
) {
|
||||
//Setup username as a button that opens the profile
|
||||
rootView.findViewById<TextView>(R.id.username).apply {
|
||||
text = this@Status.getUsername()
|
||||
text = this@Status.account?.getDisplayName() ?: ""
|
||||
setTypeface(null, Typeface.BOLD)
|
||||
setOnClickListener { account?.openProfile(rootView.context) }
|
||||
}
|
||||
|
||||
rootView.findViewById<TextView>(R.id.usernameDesc).apply {
|
||||
text = this@Status.getUsername()
|
||||
text = this@Status.account?.getDisplayName() ?: ""
|
||||
setTypeface(null, Typeface.BOLD)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,12 @@ class DBUtils {
|
|||
fun addUser(db: AppDatabase, account: Account, instance_uri: String, activeUser: Boolean = true, accessToken: String) {
|
||||
db.userDao().insertUser(
|
||||
UserDatabaseEntity(
|
||||
user_id = account.id,
|
||||
user_id = account.id!!,
|
||||
//make sure not to normalize to https when localhost, to allow testing
|
||||
instance_uri = normalizeOrNot(instance_uri),
|
||||
username = account.username,
|
||||
display_name = account.display_name,
|
||||
avatar_static = account.avatar_static,
|
||||
username = account.username!!,
|
||||
display_name = account.getDisplayName(),
|
||||
avatar_static = account.avatar_static.orEmpty(),
|
||||
isActive = activeUser,
|
||||
accessToken = accessToken
|
||||
)
|
||||
|
@ -68,7 +68,7 @@ class DBUtils {
|
|||
instance_uri = user.instance_uri,
|
||||
uri = post.uri ?: "",
|
||||
account_profile_picture = post.getProfilePicUrl() ?: "",
|
||||
account_name = post.getUsername().toString(),
|
||||
account_name = (post.account?.getDisplayName() ?: "").toString(),
|
||||
media_urls = post.media_attachments.map {
|
||||
attachment -> attachment.url ?: ""
|
||||
},
|
||||
|
|
|
@ -177,7 +177,7 @@ abstract class PostUtils {
|
|||
holder.commentIn.visibility = View.GONE
|
||||
|
||||
//Add the comment to the comment section
|
||||
addComment(holder.context, holder.commentCont, resp.account!!.username,
|
||||
addComment(holder.context, holder.commentCont, resp.account!!.username!!,
|
||||
resp.content!!
|
||||
)
|
||||
|
||||
|
@ -222,7 +222,7 @@ abstract class PostUtils {
|
|||
|
||||
//Create the new views for each comment
|
||||
for (status in statuses) {
|
||||
addComment(holder.context, holder.commentCont, status.account!!.username,
|
||||
addComment(holder.context, holder.commentCont, status.account!!.username!!,
|
||||
status.content!!
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue