1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Mostly fix email sending for events with attendees.

We need to correctly set the organizer (and for that we need the email
address of the account).
This commit is contained in:
Tom Hacohen 2020-09-10 16:34:01 +03:00
parent 21d6459cd9
commit 16f7187a77
2 changed files with 25 additions and 14 deletions

View File

@ -157,7 +157,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
private fun createInviteAttendeesNotification(event: Event, icsContent: String) { private fun createInviteAttendeesNotification(event: Event, icsContent: String) {
val intent = EventEmailInvitation(context, account).createIntent(event, icsContent) val intent = EventEmailInvitation(context, account).createIntent(event, icsContent)
if (intent != null) { if (intent != null) {
val notificationHelper = SyncNotification(context, event.uid!!, event.uid!!.hashCode()) val notificationHelper = SyncNotification(context, icsContent, event.hashCode())
notificationHelper.notify( notificationHelper.notify(
context.getString( context.getString(
R.string.sync_calendar_attendees_notification_title, event.summary), R.string.sync_calendar_attendees_notification_title, event.summary),

View File

@ -25,6 +25,7 @@ import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.R import com.etesync.syncadapter.R
import com.etesync.syncadapter.resource.* import com.etesync.syncadapter.resource.*
import com.etesync.syncadapter.ui.BaseActivity import com.etesync.syncadapter.ui.BaseActivity
import com.etesync.syncadapter.utils.EventEmailInvitation
import com.etesync.syncadapter.utils.TaskProviderHandling import com.etesync.syncadapter.utils.TaskProviderHandling
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import ezvcard.util.PartialDate import ezvcard.util.PartialDate
@ -40,6 +41,9 @@ class CollectionItemFragment(private val cachedItem: CachedItem) : Fragment() {
private val model: AccountViewModel by activityViewModels() private val model: AccountViewModel by activityViewModels()
private val collectionModel: CollectionViewModel by activityViewModels() private val collectionModel: CollectionViewModel by activityViewModels()
private var emailInvitationEvent: Event? = null
private var emailInvitationEventString: String? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val ret = inflater.inflate(R.layout.journal_item_activity, container, false) val ret = inflater.inflate(R.layout.journal_item_activity, container, false)
setHasOptionsMenu(true) setHasOptionsMenu(true)
@ -58,7 +62,7 @@ class CollectionItemFragment(private val cachedItem: CachedItem) : Fragment() {
private fun initUi(inflater: LayoutInflater, v: View, cachedCollection: CachedCollection) { private fun initUi(inflater: LayoutInflater, v: View, cachedCollection: CachedCollection) {
val viewPager = v.findViewById<ViewPager>(R.id.viewpager) val viewPager = v.findViewById<ViewPager>(R.id.viewpager)
viewPager.adapter = TabsAdapter(childFragmentManager, requireContext(), cachedCollection, cachedItem) viewPager.adapter = TabsAdapter(childFragmentManager, this, requireContext(), cachedCollection, cachedItem)
val tabLayout = v.findViewById<TabLayout>(R.id.tabs) val tabLayout = v.findViewById<TabLayout>(R.id.tabs)
tabLayout.setupWithViewPager(viewPager) tabLayout.setupWithViewPager(viewPager)
@ -66,27 +70,35 @@ class CollectionItemFragment(private val cachedItem: CachedItem) : Fragment() {
v.findViewById<View>(R.id.journal_list_item).visibility = View.GONE v.findViewById<View>(R.id.journal_list_item).visibility = View.GONE
} }
fun allowSendEmail(event: Event?, icsContent: String) {
emailInvitationEvent = event
emailInvitationEventString = icsContent
activity?.invalidateOptionsMenu()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.collection_item_fragment, menu) inflater.inflate(R.menu.collection_item_fragment, menu)
// FIXME menu.setGroupVisible(R.id.journal_item_menu_event_invite, emailInvitationEvent != null) menu.setGroupVisible(R.id.journal_item_menu_event_invite, emailInvitationEvent != null)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
val accountHolder = model.value!!
when (item.itemId) { when (item.itemId) {
R.id.on_send_event_invite -> { R.id.on_send_event_invite -> {
// FIXME val account = accountHolder.account
val intent = EventEmailInvitation(requireContext(), account).createIntent(emailInvitationEvent!!, emailInvitationEventString!!)
startActivity(intent)
} }
R.id.on_restore_item -> { R.id.on_restore_item -> {
restoreItem() restoreItem(accountHolder)
} }
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
fun restoreItem() { fun restoreItem(accountHolder: AccountHolder) {
// FIXME: This code makes the assumption that providers are all available. May not be true for tasks, and potentially others too. // FIXME: This code makes the assumption that providers are all available. May not be true for tasks, and potentially others too.
val context = requireContext() val context = requireContext()
val accountHolder = model.value!!
val account = accountHolder.account val account = accountHolder.account
val cachedCol = collectionModel.value!! val cachedCol = collectionModel.value!!
when (cachedCol.meta.collectionType) { when (cachedCol.meta.collectionType) {
@ -146,7 +158,7 @@ class CollectionItemFragment(private val cachedItem: CachedItem) : Fragment() {
} }
} }
private class TabsAdapter(fm: FragmentManager, private val context: Context, private val cachedCollection: CachedCollection, private val cachedItem: CachedItem) : FragmentPagerAdapter(fm) { private class TabsAdapter(fm: FragmentManager, private val mainFragment: CollectionItemFragment, private val context: Context, private val cachedCollection: CachedCollection, private val cachedItem: CachedItem) : FragmentPagerAdapter(fm) {
override fun getCount(): Int { override fun getCount(): Int {
// FIXME: Make it depend on info enumType (only have non-raw for known types) // FIXME: Make it depend on info enumType (only have non-raw for known types)
@ -165,7 +177,7 @@ private class TabsAdapter(fm: FragmentManager, private val context: Context, pri
override fun getItem(position: Int): Fragment { override fun getItem(position: Int): Fragment {
return if (position == 0) { return if (position == 0) {
PrettyFragment(cachedCollection, cachedItem.content) PrettyFragment(mainFragment, cachedCollection, cachedItem.content)
} else if (position == 1) { } else if (position == 1) {
TextFragment(cachedItem.content) TextFragment(cachedItem.content)
} else { } else {
@ -187,7 +199,7 @@ class TextFragment(private val content: String) : Fragment() {
} }
} }
class PrettyFragment(private val cachedCollection: CachedCollection, private val content: String) : Fragment() { class PrettyFragment(private val mainFragment: CollectionItemFragment, private val cachedCollection: CachedCollection, private val content: String) : Fragment() {
private var asyncTask: Future<Unit>? = null private var asyncTask: Future<Unit>? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -280,11 +292,10 @@ class PrettyFragment(private val cachedCollection: CachedCollection, private val
} }
setTextViewText(view, R.id.reminders, sb.toString()) setTextViewText(view, R.id.reminders, sb.toString())
/* FIXME: if (event.attendees.isNotEmpty()) {
if (event.attendees.isNotEmpty() && activity != null) { mainFragment.allowSendEmail(event, content)
(activity as JournalItemActivity).allowSendEmail(event, syncEntry.content)
} }
*/
} }
} }
} }