From bc893388df9983a93784fd977762ef10b608834f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 12 Jul 2024 10:16:46 +0200 Subject: [PATCH] solve git conflicts Signed-off-by: alperozturk --- .../nextcloud/model/SearchResultEntryType.kt | 25 +++++++++ .../nextcloud/utils/CalendarEventManager.kt | 32 +++++------ .../com/nextcloud/utils/ContactManager.kt | 18 +++--- .../extensions/SearchResultEntryExtensions.kt | 18 ++++++ .../ui/activity/FileDisplayActivity.java | 13 ----- .../ui/adapter/UnifiedSearchItemViewHolder.kt | 55 +++++++++++-------- 6 files changed, 100 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/model/SearchResultEntryType.kt diff --git a/app/src/main/java/com/nextcloud/model/SearchResultEntryType.kt b/app/src/main/java/com/nextcloud/model/SearchResultEntryType.kt new file mode 100644 index 0000000000..6d9e56c165 --- /dev/null +++ b/app/src/main/java/com/nextcloud/model/SearchResultEntryType.kt @@ -0,0 +1,25 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.model + +import com.owncloud.android.R + +enum class SearchResultEntryType { + CalendarEvent, Folder, Note, Contact, Deck, Unknown; + + fun getIconId(): 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 + } + } +} diff --git a/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt b/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt index b723db0660..8bcb1977ff 100644 --- a/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt +++ b/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt @@ -19,8 +19,15 @@ import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface class CalendarEventManager(private val context: Context) { fun openCalendarEvent(searchResult: SearchResultEntry, listInterface: UnifiedSearchListInterface) { - val eventStartDate = searchResult.parseDateTimeRange()!! + val eventStartDate = searchResult.parseDateTimeRange() + + if (eventStartDate == null) { + listInterface.onSearchResultClicked(searchResult) + return + } + val eventId: Long? = getCalendarEventId(searchResult.title, eventStartDate) + if (eventId == null) { listInterface.onSearchResultClicked(searchResult) } else { @@ -37,31 +44,24 @@ class CalendarEventManager(private val context: Context) { CalendarContract.Events.DTSTART, ) + val selection = "${CalendarContract.Events.TITLE} = ? AND ${CalendarContract.Events.DTSTART} = ?" + val selectionArgs = arrayOf(eventTitle, eventStartDate.toString()) + val cursor = context.contentResolver.query( CalendarContract.Events.CONTENT_URI, projection, - null, - null, + selection, + selectionArgs, "${CalendarContract.Events.DTSTART} ASC" ) cursor?.use { - val idIndex = cursor.getColumnIndex(CalendarContract.Events._ID) - val titleIndex = cursor.getColumnIndex(CalendarContract.Events.TITLE) - val dtstartIndex = cursor.getColumnIndex(CalendarContract.Events.DTEND) - - while (cursor.moveToNext()) { - val title = cursor.getString(titleIndex) - val startDate = cursor.getLong(dtstartIndex) - - // Jun 19, 2024 9:30 AM - 10:00 AM - if (eventTitle == title && startDate == eventStartDate) { - return cursor.getLong(idIndex) - } + if (cursor.moveToFirst()) { + val idIndex = cursor.getColumnIndex(CalendarContract.Events._ID) + return cursor.getLong(idIndex) } } return null } - } diff --git a/app/src/main/java/com/nextcloud/utils/ContactManager.kt b/app/src/main/java/com/nextcloud/utils/ContactManager.kt index 63a713d043..6691595391 100644 --- a/app/src/main/java/com/nextcloud/utils/ContactManager.kt +++ b/app/src/main/java/com/nextcloud/utils/ContactManager.kt @@ -1,7 +1,7 @@ /* * Nextcloud - Android Client * - * SPDX-FileCopyrightText: 2024 Your Name + * SPDX-FileCopyrightText: 2024 Alper Ozturk * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -37,28 +37,26 @@ class ContactManager(private val context: Context) { ContactsContract.Contacts.DISPLAY_NAME ) + val selection = "${ContactsContract.Contacts.DISPLAY_NAME} = ?" + val selectionArgs = arrayOf(contactName) + val cursor = context.contentResolver.query( ContactsContract.Contacts.CONTENT_URI, projection, - null, - null, + selection, + selectionArgs, null ) cursor?.use { val idIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID) - val nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME) while (cursor.moveToNext()) { val id = cursor.getLong(idIndex) - val title = cursor.getString(nameIndex) - - if (title == contactName) { - result.add(id) - } + result.add(id) } } return result } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nextcloud/utils/extensions/SearchResultEntryExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/SearchResultEntryExtensions.kt index 888c48a876..0081b83b3a 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/SearchResultEntryExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/SearchResultEntryExtensions.kt @@ -8,11 +8,29 @@ package com.nextcloud.utils.extensions import android.annotation.SuppressLint +import com.nextcloud.model.SearchResultEntryType import com.owncloud.android.lib.common.SearchResultEntry import java.text.ParseException import java.text.SimpleDateFormat import java.util.TimeZone +fun SearchResultEntry.getType(): SearchResultEntryType { + return if (icon == "icon-folder") { + SearchResultEntryType.Folder + } else if (icon.startsWith("icon-note")) { + SearchResultEntryType.Note + } else if (icon.startsWith("icon-contacts")) { + SearchResultEntryType.Contact + } else if (icon.startsWith("icon-calendar")) { + SearchResultEntryType.CalendarEvent + } else if (icon.startsWith("icon-deck")) { + SearchResultEntryType.Deck + } else { + SearchResultEntryType.Unknown + } +} + +// FIXME @SuppressLint("SimpleDateFormat") fun SearchResultEntry.parseDateTimeRange(): Long? { // Define the input and output date formats diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 7f118f7214..71fb8d8df6 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -287,19 +287,6 @@ public class FileDisplayActivity extends FileActivity initSyncBroadcastReceiver(); observeWorkerState(); registerRefreshFolderEventReceiver(); - - String aa = "Jun 19, 2024 9:30 AM - 10:00 AM"; - SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm a - HH:mm a"); - try { - Date date = formatter.parse(aa); - formatter.setTimeZone(TimeZone.getTimeZone("UTC")); - - Log_OC.d("TAGGGGG", "UTC time: " + date.getTime()); - - } catch (ParseException e) { - throw new RuntimeException(e); - } - } @SuppressWarnings("unchecked") diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt b/app/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt index a52eb8838f..09bc0625b2 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt @@ -16,9 +16,10 @@ import com.afollestad.sectionedrecyclerview.SectionedViewHolder import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target +import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.client.account.User import com.nextcloud.client.network.ClientFactory -import com.owncloud.android.R +import com.nextcloud.model.SearchResultEntryType import com.owncloud.android.databinding.UnifiedSearchItemBinding import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.lib.common.SearchResultEntry @@ -26,6 +27,7 @@ import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface import com.owncloud.android.utils.BitmapUtils import com.nextcloud.utils.CalendarEventManager import com.nextcloud.utils.ContactManager +import com.nextcloud.utils.extensions.getType import com.owncloud.android.utils.MimeTypeUtil import com.owncloud.android.utils.glide.CustomGlideStreamLoader import com.owncloud.android.utils.theme.ViewThemeUtils @@ -61,7 +63,8 @@ class UnifiedSearchItemViewHolder( val mimetype = MimeTypeUtil.getBestMimeTypeByFilename(entry.title) - val placeholder = getPlaceholder(entry, mimetype) + val entryType = entry.getType() + val placeholder = getPlaceholder(entry, entryType, mimetype) Glide.with(context).using(CustomGlideStreamLoader(user, clientFactory)) .load(entry.thumbnailUrl) @@ -82,34 +85,42 @@ class UnifiedSearchItemViewHolder( } binding.unifiedSearchItemLayout.setOnClickListener { - if (entry.icon.startsWith("icon-contacts")) { + searchEntryOnClick(entry, entryType) + } + } + + private fun searchEntryOnClick(entry: SearchResultEntry, entryType: SearchResultEntryType) { + when (entryType) { + SearchResultEntryType.Contact -> { contactManager.openContact(entry, listInterface) - } else if (entry.icon.startsWith("icon-calendar")) { + } + SearchResultEntryType.CalendarEvent -> { calendarEventManager.openCalendarEvent(entry, listInterface) - } else { + } + else -> { listInterface.onSearchResultClicked(entry) } } } - private fun getPlaceholder(entry: SearchResultEntry, mimetype: String?): Drawable { - val drawable = with(entry.icon) { - when { - equals("icon-folder") -> - ResourcesCompat.getDrawable(context.resources, R.drawable.folder, null) - startsWith("icon-note") -> - ResourcesCompat.getDrawable(context.resources, R.drawable.ic_edit, null) - startsWith("icon-contacts") -> - ResourcesCompat.getDrawable(context.resources, R.drawable.file_vcard, null) - startsWith("icon-calendar") -> - ResourcesCompat.getDrawable(context.resources, R.drawable.file_calendar, null) - startsWith("icon-deck") -> - ResourcesCompat.getDrawable(context.resources, R.drawable.ic_deck, null) - else -> - MimeTypeUtil.getFileTypeIcon(mimetype, entry.title, context, viewThemeUtils) - } + private fun getPlaceholder( + entry: SearchResultEntry, + entryType: SearchResultEntryType, + mimetype: String? + ): Drawable { + val iconId = entryType.run { + getIconId() } - return viewThemeUtils.platform.tintPrimaryDrawable(context, drawable)!! + + val defaultDrawable = MimeTypeUtil.getFileTypeIcon(mimetype, entry.title, context, viewThemeUtils) + + val drawable: Drawable = if (iconId == null) { + defaultDrawable + } else { + ResourcesCompat.getDrawable(context.resources, iconId, null) ?: defaultDrawable + } + + return viewThemeUtils.platform.tintDrawable(context, drawable, ColorRole.PRIMARY) } private inner class RoundIfNeededListener(private val entry: SearchResultEntry) :