mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
solve git conflicts
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
485a859ca2
commit
bc893388df
6 changed files with 100 additions and 61 deletions
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
@ -37,25 +37,23 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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) :
|
||||
|
|
Loading…
Reference in a new issue