add a dialog for choosing an .ics file

This commit is contained in:
tibbi 2017-01-25 22:07:36 +01:00
parent 1b024d3596
commit 74e1c36e1e
4 changed files with 37 additions and 1 deletions

View File

@ -32,7 +32,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.5.3'
compile 'com.simplemobiletools:commons:2.5.4'
compile 'joda-time:joda-time:2.9.1'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -4,6 +4,7 @@
package="com.simplemobiletools.calendar">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<application

View File

@ -1,9 +1,12 @@
package com.simplemobiletools.calendar.activities
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.app.ActivityCompat
import android.support.v4.view.ViewPager
import android.view.Menu
import android.view.MenuItem
@ -21,7 +24,9 @@ import com.simplemobiletools.calendar.fragments.WeekFragment
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.views.MyScrollView
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.checkWhatsNew
import com.simplemobiletools.commons.extensions.hasReadStoragePermission
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.LICENSE_JODA
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
@ -36,6 +41,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
private val PREFILLED_MONTHS = 73
private val PREFILLED_YEARS = 21
private val PREFILLED_WEEKS = 41
private val STORAGE_PERMISSION = 1
private var mIsMonthSelected = false
private var mSnackbar: Snackbar? = null
@ -95,6 +101,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.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item)
@ -139,6 +146,20 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
mWeekScrollY = 0
}
private fun tryImportFile() {
if (hasReadStoragePermission()) {
importFile()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), STORAGE_PERMISSION)
}
}
private fun importFile() {
FilePickerDialog(this) {
}
}
private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java))
}
@ -337,6 +358,16 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
mIsMonthSelected = true
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == STORAGE_PERMISSION) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
tryImportFile()
}
}
}
override fun notifyDeletion(cnt: Int) {
val msg = resources.getQuantityString(R.plurals.events_deleted, cnt, cnt)
mSnackbar = Snackbar.make(calendar_coordinator, msg, Snackbar.LENGTH_LONG)

View File

@ -6,6 +6,10 @@
android:icon="@drawable/ic_change_view"
android:title="@string/change_view"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/import_file"
android:title="@string/import_ics_file"
app:showAsAction="never"/>
<item
android:id="@+id/settings"
android:title="@string/settings"