Skip to content

Commit

Permalink
Add fallback icon for events, make SearchResultEntry extensions private
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <alper_ozturk@proton.me>
  • Loading branch information
alperozturk96 committed Jul 26, 2024
1 parent a7aa4fe commit 433ee4d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ enum class SearchResultEntryType {
Deck,
Unknown;

fun getIconId(): Int? {
fun iconId(): Int {
return when (this) {
Folder -> R.drawable.folder
Note -> R.drawable.ic_edit
Contact -> R.drawable.file_vcard
CalendarEvent -> R.drawable.file_calendar
Deck -> R.drawable.ic_deck
else -> null
else -> R.drawable.ic_find_in_page
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.CalendarContract
import com.nextcloud.utils.extensions.createdAt
import com.nextcloud.utils.extensions.showToast
import com.owncloud.android.R
import com.owncloud.android.lib.common.SearchResultEntry
Expand Down Expand Up @@ -74,3 +73,6 @@ class CalendarEventManager(private val context: Context) {
return null
}
}

@Suppress("MagicNumber")
private fun SearchResultEntry.createdAt(): Long? = attributes["createdAt"]?.toLongOrNull()?.times(1000L)
9 changes: 6 additions & 3 deletions app/src/main/java/com/nextcloud/utils/ContactManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.ContactsContract
import com.nextcloud.utils.extensions.displayName
import com.nextcloud.utils.extensions.email
import com.nextcloud.utils.extensions.phoneNumber
import com.nextcloud.utils.extensions.showToast
import com.owncloud.android.R
import com.owncloud.android.lib.common.SearchResultEntry
Expand Down Expand Up @@ -139,3 +136,9 @@ class ContactManager(private val context: Context) {
return result
}
}

private fun SearchResultEntry.displayName(): String? = attributes["displayName"]

private fun SearchResultEntry.email(): String? = attributes["email"]

private fun SearchResultEntry.phoneNumber(): String? = attributes["phoneNumber"]
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,3 @@ fun SearchResultEntry.getType(): SearchResultEntryType {
SearchResultEntryType.Unknown
}
}

@Suppress("MagicNumber")
fun SearchResultEntry.createdAt(): Long? = attributes["createdAt"]?.toLongOrNull()?.times(1000L)

fun SearchResultEntry.displayName(): String? = attributes["displayName"]

fun SearchResultEntry.email(): String? = attributes["email"]

fun SearchResultEntry.phoneNumber(): String? = attributes["phoneNumber"]
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils

@Suppress("LongParameterList")
class UnifiedSearchItemViewHolder(
private val isServerVersionThirtyOrAbove: Boolean,
private val supportsOpeningCalendarContactsLocally: Boolean,
val binding: UnifiedSearchItemBinding,
val user: User,
val clientFactory: ClientFactory,
Expand Down Expand Up @@ -91,14 +91,16 @@ class UnifiedSearchItemViewHolder(
}

private fun searchEntryOnClick(entry: SearchResultEntry, entryType: SearchResultEntryType) {
if (isServerVersionThirtyOrAbove) {
if (supportsOpeningCalendarContactsLocally) {
when (entryType) {
SearchResultEntryType.Contact -> {
contactManager.openContact(entry, listInterface)
}

SearchResultEntryType.CalendarEvent -> {
calendarEventManager.openCalendarEvent(entry, listInterface)
}

else -> {
listInterface.onSearchResultClicked(entry)
}
Expand All @@ -114,17 +116,11 @@ class UnifiedSearchItemViewHolder(
mimetype: String?
): Drawable {
val iconId = entryType.run {
getIconId()
iconId()
}

val defaultDrawable = MimeTypeUtil.getFileTypeIcon(mimetype, entry.title, context, viewThemeUtils)

val drawable: Drawable = if (iconId == null) {
defaultDrawable
} else {
ResourcesCompat.getDrawable(context.resources, iconId, null) ?: defaultDrawable
}

val drawable: Drawable = ResourcesCompat.getDrawable(context.resources, iconId, null) ?: defaultDrawable
return viewThemeUtils.platform.tintDrawable(context, drawable, ColorRole.PRIMARY)
}

Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/ic_find_in_page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
~ SPDX-License-Identifier: AGPL-3.0-or-later
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FF969696"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M20,19.59V8l-6,-6H6c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2H18c0.45,0 0.85,-0.15 1.19,-0.4l-4.43,-4.43c-0.8,0.52 -1.74,0.83 -2.76,0.83 -2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5c0,1.02 -0.31,1.96 -0.83,2.75L20,19.59zM9,13c0,1.66 1.34,3 3,3s3,-1.34 3,-3 -1.34,-3 -3,-3 -3,1.34 -3,3z" />

</vector>

0 comments on commit 433ee4d

Please sign in to comment.