Skip to content

Commit

Permalink
Show toast message for fallback scenario
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <alper_ozturk@proton.me>
  • Loading branch information
alperozturk96 committed Jun 19, 2024
1 parent f45f932 commit 4d0a851
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
25 changes: 12 additions & 13 deletions app/src/main/java/com/nextcloud/utils/CalendarEventManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,13 +24,15 @@ 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
}

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)
Expand All @@ -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)
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/nextcloud/utils/ContactManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ 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

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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@
<string name="default_credentials_wrong">Incorrect credentials</string>
<string name="credentials_disabled">Credentials disabled</string>

<string name="unified_search_fragment_calendar_event_cannot_be_found_on_device">The calendar event cannot be found on your device. Redirecting to web…</string>
<string name="unified_search_fragment_contact_cannot_be_found_on_device">Contact cannot be found on your device. Redirecting to web…</string>

<string name="pass_code_configure_your_pass_code">Enter your passcode</string>
<string name="pass_code_configure_your_pass_code_explanation">The passcode will be requested every time the app is started</string>
<string name="pass_code_reenter_your_pass_code">Please reenter your passcode</string>
Expand Down

0 comments on commit 4d0a851

Please sign in to comment.