allow selecting which event type events should be exported

This commit is contained in:
tibbi 2017-05-18 22:01:27 +02:00
parent 537afc2f05
commit 25e22a67e6
2 changed files with 102 additions and 45 deletions

View File

@ -1,18 +1,36 @@
package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import android.widget.LinearLayout
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.FilterEventTypeAdapter
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_export_events.view.*
import java.io.File
class ExportEventsDialog(val activity: Activity, val path: String, val callback: (exportPastEvents: Boolean, file: File) -> Unit) : AlertDialog.Builder(activity) {
class ExportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (exportPastEvents: Boolean, file: File) -> Unit) : AlertDialog.Builder(activity) {
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply {
export_events_folder.text = activity.humanizePath(path)
export_events_filename.setText("events_${System.currentTimeMillis() / 1000}")
activity.dbHelper.getEventTypes {
val eventTypes = HashSet<String>()
it.mapTo(eventTypes, { it.id.toString() })
activity.runOnUiThread {
if (it.size > 1) {
export_events_pick_types.beVisible()
export_events_types_list.adapter = FilterEventTypeAdapter(activity, it, eventTypes)
val margin = activity.resources.getDimension(R.dimen.normal_margin).toInt()
(export_events_checkbox.layoutParams as LinearLayout.LayoutParams).leftMargin = margin
}
}
}
}
AlertDialog.Builder(activity)

View File

@ -1,9 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/export_events_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/export_events_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
@ -50,4 +56,37 @@
android:paddingTop="@dimen/small_margin"
android:text="@string/export_past_events_too"/>
<LinearLayout
android:id="@+id/export_events_pick_types"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/export_events_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:background="@color/darker_divider"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_events_pick_types_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/include_event_types"
android:textSize="@dimen/smaller_text_size"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/export_events_types_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingTop="@dimen/medium_margin"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</LinearLayout>
</ScrollView>