add a dialog related to importing events

This commit is contained in:
tibbi 2017-01-25 22:32:48 +01:00
parent 74e1c36e1e
commit 326015c03a
15 changed files with 169 additions and 18 deletions

View File

@ -18,6 +18,7 @@ import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
import com.simplemobiletools.calendar.dialogs.ImportEventsDialog
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.fragments.EventListFragment
import com.simplemobiletools.calendar.fragments.WeekFragment
@ -101,7 +102,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.change_view -> showViewDialog()
R.id.import_file -> tryImportFile()
R.id.import_events -> tryImportEvents()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item)
@ -146,19 +147,21 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
mWeekScrollY = 0
}
private fun tryImportFile() {
private fun tryImportEvents() {
if (hasReadStoragePermission()) {
importFile()
importEvents()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), STORAGE_PERMISSION)
}
}
private fun importFile() {
private fun importEvents() {
FilePickerDialog(this) {
ImportEventsDialog(this, it) {
}
}
}
private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java))
@ -363,7 +366,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
if (requestCode == STORAGE_PERMISSION) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
tryImportFile()
tryImportEvents()
}
}
}

View File

@ -0,0 +1,24 @@
package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import com.simplemobiletools.calendar.R
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_import_events.view.*
class ImportEventsDialog(val activity: Activity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply {
import_events_filename.text = activity.humanizePath(path)
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.import_events)
}
}
}

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/import_events_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filename"
android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_filename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:paddingBottom="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_reminder_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event_reminder"
android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyAppCompatSpinner
android:id="@+id/import_events_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:entries="@array/reminders"/>
<LinearLayout
android:id="@+id/import_events_custom_reminder_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/activity_margin"
android:orientation="horizontal"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/import_events_custom_reminder_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginStart="@dimen/activity_margin"
android:digits="0123456789"
android:inputType="number"
android:maxLength="10"
android:minEms="3"
android:textCursorDrawable="@null"
android:textSize="@dimen/day_text_size"/>
<com.simplemobiletools.commons.views.MyAppCompatSpinner
android:id="@+id/import_events_custom_reminder_other_period"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:entries="@array/custom_reminders"
android:gravity="center"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_custom_reminder_other_val"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/before"/>
</LinearLayout>
</LinearLayout>

View File

@ -7,8 +7,8 @@
android:title="@string/change_view"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/import_file"
android:title="@string/import_ics_file"
android:id="@+id/import_events"
android:title="@string/import_events"
app:showAsAction="never"/>
<item
android:id="@+id/settings"

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Einfache Termin Liste</string>
<string name="no_upcoming_events">Sieht aus als wäre dein Kalender leer.</string>
<string name="add_some_events">Du kannst neue Termine mit dem Plus Button unten rechts erstellen.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Monats Kalender</string>
@ -43,6 +42,11 @@
<string name="hours">Stunden</string>
<string name="days">Tage</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Details</string>
<string name="title">Titel</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Lista de eventos simples</string>
<string name="no_upcoming_events">Seems like you don\'t have any upcoming events.</string>
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Calendar monthly</string>
@ -43,6 +42,11 @@
<string name="hours">horas</string>
<string name="days">días</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Detalles</string>
<string name="title">Título</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Liste simple d\'événements</string>
<string name="no_upcoming_events">Il semblerait que vous n\'ayez aucun événement à venir.</string>
<string name="add_some_events">Vous pouvez ajouter des évènements avec le bouton Plus en bas.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Calendrier mensuel</string>
@ -43,6 +42,11 @@
<string name="hours">heures</string>
<string name="days">jours</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Détails</string>
<string name="title">Titre</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">सरल इवेंट सूची</string>
<string name="no_upcoming_events">Seems like you don\'t have any upcoming events.</string>
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Calendar monthly</string>
@ -43,6 +42,11 @@
<string name="hours">hours</string>
<string name="days">days</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">विवरण</string>
<string name="title">शीर्षक</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Egyszerű bejegyzéslista</string>
<string name="no_upcoming_events">Seems like you don\'t have any upcoming events.</string>
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Havi naptár</string>
@ -43,6 +42,11 @@
<string name="hours">órával</string>
<string name="days">nappal</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Részletek</string>
<string name="title">Név</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Simple event list</string>
<string name="no_upcoming_events">Seems like you don\'t have any upcoming events.</string>
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Calendar monthly</string>
@ -43,6 +42,11 @@
<string name="hours">hours</string>
<string name="days">days</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Dettagli</string>
<string name="title">Titolo</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">シンプル イベント リスト</string>
<string name="no_upcoming_events">Seems like you don\'t have any upcoming events.</string>
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">カレンダー月</string>
@ -43,6 +42,11 @@
<string name="hours">時間</string>
<string name="days"></string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">詳細</string>
<string name="title">タイトル</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Lista de eventos</string>
<string name="no_upcoming_events">Parece que você não tem eventos para breve.</string>
<string name="add_some_events">Pode adicionar um evento através do botão existente na base do ecrã.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Calendário mensal</string>
@ -43,6 +42,11 @@
<string name="hours">horas</string>
<string name="days">dias</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Detalhes</string>
<string name="title">Título</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Простой список событий</string>
<string name="no_upcoming_events">Похоже у вас нет пердстоящих событий.</string>
<string name="add_some_events">Вы можете их добавить, нажав на кнопку с плюсом внизу.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Календарь на месяц</string>
@ -43,6 +42,11 @@
<string name="hours">часов</string>
<string name="days">дней</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Подробности</string>
<string name="title">Заголовок</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Händelselista</string>
<string name="no_upcoming_events">Det ser ut som att du inte har några kommandechändelser.</string>
<string name="add_some_events">Du kan lägga till händelser via plus-knappen som du ser längst ner.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Kalender månadsvis</string>
@ -43,6 +42,11 @@
<string name="hours">timmar</string>
<string name="days">dagar</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Detaljer</string>
<string name="title">Titel</string>

View File

@ -9,7 +9,6 @@
<string name="simple_event_list">Simple event list</string>
<string name="no_upcoming_events">Seems like you don\'t have any upcoming events.</string>
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
<string name="import_ics_file">Import events from .ics file</string>
<!-- Widget titles -->
<string name="widget_monthly">Calendar monthly</string>
@ -43,6 +42,11 @@
<string name="hours">hours</string>
<string name="days">days</string>
<!-- Importing -->
<string name="import_events">Import events</string>
<string name="event_reminder">Event reminder</string>
<string name="events_imported_successfully">Events imported successfully</string>
<!-- Day details -->
<string name="details">Details</string>
<string name="title">Title</string>