From 4d0a851527bc1570c8bf518721a69ea6a6499c73 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 19 Jun 2024 10:23:28 +0200 Subject: [PATCH] Show toast message for fallback scenario Signed-off-by: alperozturk --- .../nextcloud/utils/CalendarEventManager.kt | 25 +++++++++---------- .../com/nextcloud/utils/ContactManager.kt | 4 +++ .../ui/activity/FileDisplayActivity.java | 9 ------- app/src/main/res/values/strings.xml | 3 +++ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt b/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt index 3c2869a4328f..5788af00fc10 100644 --- a/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt +++ b/app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt @@ -13,6 +13,8 @@ import android.content.Intent import android.net.Uri import android.provider.CalendarContract import com.nextcloud.utils.extensions.parseDateTimeRange +import com.nextcloud.utils.extensions.showToast +import com.owncloud.android.R import com.owncloud.android.lib.common.SearchResultEntry import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface @@ -22,6 +24,7 @@ class CalendarEventManager(private val context: Context) { val eventStartDate = searchResult.parseDateTimeRange() if (eventStartDate == null) { + context.showToast(R.string.unified_search_fragment_calendar_event_cannot_be_found_on_device) listInterface.onSearchResultClicked(searchResult) return } @@ -29,6 +32,7 @@ class CalendarEventManager(private val context: Context) { val eventId: Long? = getCalendarEventId(searchResult.title, eventStartDate) if (eventId == null) { + context.showToast(R.string.unified_search_fragment_calendar_event_cannot_be_found_on_device) listInterface.onSearchResultClicked(searchResult) } else { val uri: Uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId) @@ -44,26 +48,21 @@ 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 startDateIndex = cursor.getColumnIndex(CalendarContract.Events.DTSTART) - - while (cursor.moveToNext()) { - val title = cursor.getString(titleIndex) - val startDate = cursor.getLong(startDateIndex) - - if (eventTitle == title && startDate == eventStartDate) { - return cursor.getLong(idIndex) - } + if (cursor.moveToFirst()) { + val idIndex = cursor.getColumnIndex(CalendarContract.Events._ID) + return cursor.getLong(idIndex) } } diff --git a/app/src/main/java/com/nextcloud/utils/ContactManager.kt b/app/src/main/java/com/nextcloud/utils/ContactManager.kt index 66915953912f..38b7a66b0562 100644 --- a/app/src/main/java/com/nextcloud/utils/ContactManager.kt +++ b/app/src/main/java/com/nextcloud/utils/ContactManager.kt @@ -11,6 +11,8 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.provider.ContactsContract +import com.nextcloud.utils.extensions.showToast +import com.owncloud.android.R import com.owncloud.android.lib.common.SearchResultEntry import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface @@ -18,7 +20,9 @@ class ContactManager(private val context: Context) { fun openContact(searchResult: SearchResultEntry, listInterface: UnifiedSearchListInterface) { val contactIds = getContactIds(searchResult.title) + if (contactIds.isEmpty()) { + context.showToast(R.string.unified_search_fragment_contact_cannot_be_found_on_device) listInterface.onSearchResultClicked(searchResult) } else { val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactIds.first().toString()) 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 d2fadaf4f82a..17eaa3c75b79 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 @@ -20,7 +20,6 @@ import android.app.Dialog; import android.content.BroadcastReceiver; import android.content.ComponentName; -import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -29,7 +28,6 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources.NotFoundException; -import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -38,7 +36,6 @@ import android.os.IBinder; import android.os.Looper; import android.os.Parcelable; -import android.provider.ContactsContract; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; @@ -133,21 +130,15 @@ import com.owncloud.android.utils.StringUtils; import com.owncloud.android.utils.theme.CapabilityUtils; -import net.fortuna.ical4j.model.property.Contact; - import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.io.File; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Optional; -import java.util.TimeZone; import javax.inject.Inject; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d3bcdc8e5459..453a6527edfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -298,6 +298,9 @@ Incorrect credentials Credentials disabled + The calendar event cannot be found on your device. Redirecting to web… + Contact cannot be found on your device. Redirecting to web… + Enter your passcode The passcode will be requested every time the app is started Please reenter your passcode