allow setting default event type at importing ics

This commit is contained in:
tibbi 2017-03-05 13:01:46 +01:00
parent 6838ce626a
commit c43275c7ff
18 changed files with 73 additions and 5 deletions

View File

@ -3,19 +3,32 @@ package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.ViewGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.IcsParser
import com.simplemobiletools.calendar.helpers.IcsParser.ImportResult.*
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast
import kotlinx.android.synthetic.main.dialog_import_events.view.*
class ImportEventsDialog(val activity: Activity, val path: String, val callback: (refreshView: Boolean) -> Unit) : AlertDialog.Builder(activity) {
var currEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply {
val view = (LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null) as ViewGroup).apply {
import_events_filename.text = activity.humanizePath(path)
updateEventType(this)
import_event_type_holder.setOnClickListener {
SelectEventTypeDialog(activity, currEventTypeId) {
currEventTypeId = it
updateEventType(this)
}
}
}
AlertDialog.Builder(activity)
@ -25,7 +38,7 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
activity.setupDialogStuff(view, this, R.string.import_events)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
Thread({
val result = IcsParser().parseIcs(context, path)
val result = IcsParser().parseIcs(context, path, currEventTypeId)
handleParseResult(result)
dismiss()
}).start()
@ -33,6 +46,12 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
}
}
private fun updateEventType(view: ViewGroup) {
val eventType = DBHelper.newInstance(context).getEventType(currEventTypeId)
view.import_event_type_title.text = eventType!!.title
view.import_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
}
private fun handleParseResult(result: IcsParser.ImportResult) {
activity.runOnUiThread {
activity.toast(when (result) {

View File

@ -55,7 +55,7 @@ class IcsParser {
var eventsImported = 0
var eventsFailed = 0
fun parseIcs(context: Context, path: String): ImportResult {
fun parseIcs(context: Context, path: String, defaultEventType: Int): ImportResult {
try {
val dbHelper = DBHelper.newInstance(context)
val importIDs = dbHelper.getImportIds()
@ -74,6 +74,7 @@ class IcsParser {
if (line == BEGIN_EVENT) {
resetValues()
curEventType = defaultEventType
} else if (line.startsWith(DTSTART)) {
curStart = getTimestamp(line.substring(DTSTART.length))
} else if (line.startsWith(DTEND)) {

View File

@ -10,7 +10,7 @@
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_label"
android:id="@+id/import_events_filename_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filename"
@ -26,4 +26,37 @@
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_event_type_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/default_event_type"
android:textSize="@dimen/smaller_text_size"/>
<RelativeLayout
android:id="@+id/import_event_type_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/small_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_event_type_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"/>
<ImageView
android:id="@+id/import_event_type_color"
android:layout_width="@dimen/color_sample_size"
android:layout_height="@dimen/color_sample_size"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/medium_margin"
android:layout_marginRight="@dimen/medium_margin"
android:clickable="false"/>
</RelativeLayout>
</LinearLayout>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Título</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">ungültiges Dateiformat</string>
<string name="export_raw_database">exportiere raw Datenbank</string>
<string name="database_exported_successfully">Datenbank erfolgreich exportiert</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Titel</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Título</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Titre</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Título</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">शीर्षक</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Név</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Titolo</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">כותרת</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">タイトル</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Formato de ficheiro inválido</string>
<string name="export_raw_database">Exportar base de dados raw</string>
<string name="database_exported_successfully">Base de dados exportada com sucesso</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Título</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Неправильный формат файла</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Заголовок</string>

View File

@ -104,7 +104,8 @@
<string name="importing_some_events_failed">Importovanie niektorých udalostí zlyhalo</string>
<string name="invalid_file_format">Nesprávny formát súboru</string>
<string name="export_raw_database">Exportovať surovú databázu</string>
<string name="database_exported_successfully">Databáza bola úspešne exportovaná</string>
<string name="database_exported_successfully">Databáza bola úspešne exportovaná
<string name="default_event_type">Predvolený typ udalosti</string></string>
<!-- Event details -->
<string name="title">Názov</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Titel</string>

View File

@ -98,6 +98,7 @@
<string name="invalid_file_format">Invalid file format</string>
<string name="export_raw_database">Export raw database</string>
<string name="database_exported_successfully">Database exported successfully</string>
<string name="default_event_type">Default event type</string>
<!-- Event details -->
<string name="title">Title</string>