Commit e27c6fde authored by Ricki Hirner's avatar Ricki Hirner 🐑

Update to support library 27.1.0 and use it wherever possible

* Fragment transactions can now be done in onLoadFinished().
parent 3135af78
......@@ -77,10 +77,10 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.android.support:preference-v14:27.0.2'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
compile 'com.android.support:design:27.1.0'
compile 'com.android.support:preference-v14:27.1.0'
compile 'com.github.yukuku:ambilwarna:2.0.1'
......
......@@ -104,8 +104,8 @@ class AboutActivity: AppCompatActivity() {
class ComponentFragment: Fragment(), LoaderManager.LoaderCallbacks<Spanned> {
companion object {
val KEY_POSITION = "position"
val KEY_FILE_NAME = "fileName"
const val KEY_POSITION = "position"
const val KEY_FILE_NAME = "fileName"
fun instantiate(position: Int): ComponentFragment {
val frag = ComponentFragment()
......@@ -165,8 +165,8 @@ class AboutActivity: AppCompatActivity() {
return v
}
override fun onCreateLoader(id: Int, args: Bundle) =
LicenseLoader(activity!!, args.getString(KEY_FILE_NAME))
override fun onCreateLoader(id: Int, args: Bundle?) =
LicenseLoader(activity!!, args!!.getString(KEY_FILE_NAME))
override fun onLoadFinished(loader: Loader<Spanned>, license: Spanned?) {
view?.let { v ->
......
......@@ -9,22 +9,22 @@
package at.bitfire.davdroid.ui
import android.accounts.Account
import android.app.DialogFragment
import android.app.LoaderManager
import android.content.*
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.SyncStatusObserver
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.CalendarContract
import android.security.KeyChain
import android.support.v14.preference.PreferenceFragment
import android.support.v4.app.DialogFragment
import android.support.v4.app.LoaderManager
import android.support.v4.app.NavUtils
import android.support.v4.content.Loader
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.support.v7.preference.EditTextPreference
import android.support.v7.preference.ListPreference
import android.support.v7.preference.Preference
import android.support.v7.preference.SwitchPreferenceCompat
import android.support.v7.preference.*
import android.view.MenuItem
import at.bitfire.davdroid.AccountSettings
import at.bitfire.davdroid.InvalidAccountException
......@@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils
class AccountSettingsActivity: AppCompatActivity() {
companion object {
val EXTRA_ACCOUNT = "account"
const val EXTRA_ACCOUNT = "account"
}
private lateinit var account: Account
......@@ -53,7 +53,7 @@ class AccountSettingsActivity: AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
if (savedInstanceState == null)
fragmentManager.beginTransaction()
supportFragmentManager.beginTransaction()
.replace(android.R.id.content, DialogFragment.instantiate(this, AccountSettingsFragment::class.java.name, intent.extras))
.commit()
}
......@@ -68,13 +68,13 @@ class AccountSettingsActivity: AppCompatActivity() {
false
class AccountSettingsFragment: PreferenceFragment(), LoaderManager.LoaderCallbacks<Pair<ISettings, AccountSettings>?> {
class AccountSettingsFragment: PreferenceFragmentCompat(), LoaderManager.LoaderCallbacks<Pair<ISettings, AccountSettings>> {
lateinit var account: Account
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
account = arguments.getParcelable(EXTRA_ACCOUNT)
account = arguments!!.getParcelable(EXTRA_ACCOUNT)
loaderManager.initLoader(0, arguments, this)
}
......@@ -82,10 +82,10 @@ class AccountSettingsActivity: AppCompatActivity() {
addPreferencesFromResource(R.xml.settings_account)
}
override fun onCreateLoader(id: Int, args: Bundle) =
AccountSettingsLoader(activity, args.getParcelable(EXTRA_ACCOUNT))
override fun onCreateLoader(id: Int, args: Bundle?) =
AccountSettingsLoader(requireActivity(), args!!.getParcelable(EXTRA_ACCOUNT))
override fun onLoadFinished(loader: Loader<Pair<ISettings, AccountSettings>?>, result: Pair<ISettings, AccountSettings>?) {
override fun onLoadFinished(loader: Loader<Pair<ISettings, AccountSettings>>, result: Pair<ISettings, AccountSettings>?) {
val (settings, accountSettings) = result ?: return
// preference group: authentication
......@@ -222,7 +222,7 @@ class AccountSettingsActivity: AppCompatActivity() {
else {
it.isEnabled = true
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, groupMethod ->
AlertDialog.Builder(activity)
AlertDialog.Builder(requireActivity())
.setIcon(R.drawable.ic_error_dark)
.setTitle(R.string.settings_contact_group_method_change)
.setMessage(R.string.settings_contact_group_method_change_reload_contacts)
......@@ -258,11 +258,10 @@ class AccountSettingsActivity: AppCompatActivity() {
it.setSummary(R.string.settings_sync_time_range_past_none)
}
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
var days: Int
try {
days = (newValue as String).toInt()
} catch(ignored: NumberFormatException) {
days = -1
val days = try {
(newValue as String).toInt()
} catch(e: NumberFormatException) {
-1
}
accountSettings.setTimeRangePastDays(if (days < 0) null else days)
loaderManager.restartLoader(0, arguments, this)
......@@ -296,7 +295,7 @@ class AccountSettingsActivity: AppCompatActivity() {
accountSettings.setEventColors(true)
loaderManager.restartLoader(0, arguments, this)
} else
AlertDialog.Builder(activity)
AlertDialog.Builder(requireActivity())
.setIcon(R.drawable.ic_error_dark)
.setTitle(R.string.settings_event_colors)
.setMessage(R.string.settings_event_colors_off_confirm)
......@@ -313,7 +312,7 @@ class AccountSettingsActivity: AppCompatActivity() {
}
}
override fun onLoaderReset(loader: Loader<Pair<ISettings, AccountSettings>?>) {
override fun onLoaderReset(loader: Loader<Pair<ISettings, AccountSettings>>) {
}
}
......@@ -330,7 +329,7 @@ class AccountSettingsActivity: AppCompatActivity() {
super.onStartLoading()
if (listenerHandle == null)
listenerHandle = ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this@AccountSettingsLoader)
listenerHandle = ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this)
}
override fun onReset() {
......
......@@ -10,35 +10,32 @@ package at.bitfire.davdroid.ui
import android.accounts.AccountManager
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.SyncStatusObserver
import android.net.Uri
import android.app.LoaderManager
import android.content.*
import android.os.Bundle
import android.support.design.widget.NavigationView
import android.support.design.widget.Snackbar
import android.support.v4.app.LoaderManager
import android.support.v4.content.Loader
import android.support.v4.view.GravityCompat
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import at.bitfire.davdroid.App
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.R
import at.bitfire.davdroid.settings.ISettings
import at.bitfire.davdroid.ui.setup.LoginActivity
import kotlinx.android.synthetic.main.accounts_content.*
import kotlinx.android.synthetic.main.activity_accounts.*
import java.util.*
class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, LoaderManager.LoaderCallbacks<AccountsActivity.Settings>, SyncStatusObserver {
companion object {
private val EXTRA_CREATE_STARTUP_FRAGMENTS = "createStartupFragments"
val accountsDrawerHandler = DefaultAccountsDrawerHandler()
private val BETA_FEEDBACK_URI = "mailto:support@davdroid.com?subject=${BuildConfig.APPLICATION_ID} beta feedback ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
private const val fragTagStartup = "startup"
}
private var syncStatusSnackbar: Snackbar? = null
......@@ -52,7 +49,7 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
setSupportActionBar(toolbar)
fab.setOnClickListener({
startActivity(Intent(this@AccountsActivity, LoginActivity::class.java))
startActivity(Intent(this, LoginActivity::class.java))
})
val toggle = ActionBarDrawerToggle(
......@@ -62,8 +59,6 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
nav_view.setNavigationItemSelectedListener(this)
nav_view.itemIconTintList = null
if (BuildConfig.VERSION_NAME.contains("-beta") || BuildConfig.VERSION_NAME.contains("-rc"))
nav_view.menu.findItem(R.id.nav_beta_feedback).isVisible = true
/* When the DAVdroid main activity is started, start a Settings service that stays in memory
for better performance. The service stops itself when memory is trimmed. */
......@@ -71,24 +66,30 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
startService(settingsIntent)
val args = Bundle(1)
args.putBoolean(EXTRA_CREATE_STARTUP_FRAGMENTS, savedInstanceState == null && packageName != callingPackage)
loaderManager.initLoader(0, args, this)
supportLoaderManager.initLoader(0, args, this)
}
override fun onCreateLoader(code: Int, args: Bundle) =
SettingsLoader(this, args.getBoolean(EXTRA_CREATE_STARTUP_FRAGMENTS))
override fun onCreateLoader(code: Int, args: Bundle?) =
SettingsLoader(this)
override fun onLoadFinished(loader: Loader<Settings>?, result: Settings?) {
override fun onLoadFinished(loader: Loader<Settings>, result: Settings?) {
val result = result ?: return
if (result.createStartupFragments) {
val ft = fragmentManager.beginTransaction()
StartupDialogFragment.getStartupDialogs(this, result.settings).forEach { ft.add(it, null) }
ft.commitAllowingStateLoss()
if (supportFragmentManager.findFragmentByTag(fragTagStartup) == null) {
val ft = supportFragmentManager.beginTransaction()
StartupDialogFragment.getStartupDialogs(this, result.settings).forEach { ft.add(it, fragTagStartup) }
ft.commit()
}
nav_view?.menu?.let {
accountsDrawerHandler.onSettingsChanged(result.settings, it)
}
}
override fun onLoaderReset(loader: Loader<Settings>?) {
override fun onLoaderReset(loader: Loader<Settings>) {
nav_view?.menu?.let {
accountsDrawerHandler.onSettingsChanged(null, it)
}
}
override fun onResume() {
......@@ -133,50 +134,18 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
var processed = true
when (item.itemId) {
R.id.nav_about ->
startActivity(Intent(this, AboutActivity::class.java))
R.id.nav_app_settings ->
startActivity(Intent(this, AppSettingsActivity::class.java))
R.id.nav_beta_feedback -> {
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse(BETA_FEEDBACK_URI))
if (packageManager.resolveActivity(intent, 0) != null)
startActivity(intent)
}
R.id.nav_twitter ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/davdroidapp")))
R.id.nav_website ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.homepage_url))))
R.id.nav_manual ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("manual/").build()))
R.id.nav_faq ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("faq/").build()))
R.id.nav_forums ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("forums/").build()))
R.id.nav_donate ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("donate/").build()))
else ->
processed = false
}
val processed = accountsDrawerHandler.onNavigationItemSelected(this, item)
drawer_layout.closeDrawer(GravityCompat.START)
return processed
}
class Settings(
val settings: ISettings,
val createStartupFragments: Boolean
val settings: ISettings
)
class SettingsLoader(
context: Context,
private val createStartupFragments: Boolean
context: Context
): at.bitfire.davdroid.ui.SettingsLoader<Settings>(context) {
override fun loadInBackground(): Settings? {
......@@ -185,8 +154,7 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
val accounts = accountManager.getAccountsByType(context.getString(R.string.account_type))
return Settings(
it,
createStartupFragments
it
)
}
return null
......
......@@ -36,7 +36,7 @@ import java.net.URISyntaxException
class AppSettingsActivity: AppCompatActivity() {
companion object {
val EXTRA_SCROLL_TO = "scrollTo"
const val EXTRA_SCROLL_TO = "scrollTo"
}
override fun onCreate(savedInstanceState: Bundle?) {
......
......@@ -31,7 +31,7 @@ import java.util.*
class CreateAddressBookActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks<CreateAddressBookActivity.AccountInfo> {
companion object {
val EXTRA_ACCOUNT = "account"
const val EXTRA_ACCOUNT = "account"
}
private lateinit var account: Account
......
......@@ -35,7 +35,7 @@ import java.util.*
class CreateCalendarActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks<CreateCalendarActivity.AccountInfo> {
companion object {
val EXTRA_ACCOUNT = "account"
const val EXTRA_ACCOUNT = "account"
}
private lateinit var account: Account
......
......@@ -37,8 +37,8 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
companion object {
val ARG_ACCOUNT = "account"
val ARG_COLLECTION_INFO = "collectionInfo"
const val ARG_ACCOUNT = "account"
const val ARG_COLLECTION_INFO = "collectionInfo"
fun newInstance(account: Account, info: CollectionInfo): CreateCollectionFragment {
val frag = CreateCollectionFragment()
......@@ -57,8 +57,9 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
account = arguments!!.getParcelable(ARG_ACCOUNT)
info = arguments!!.getSerializable(ARG_COLLECTION_INFO) as CollectionInfo
val args = requireNotNull(arguments)
account = args.getParcelable(ARG_ACCOUNT)
info = args.getSerializable(ARG_COLLECTION_INFO) as CollectionInfo
loaderManager.initLoader(0, null, this)
}
......@@ -74,16 +75,16 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
}
override fun onCreateLoader(id: Int, args: Bundle?) = CreateCollectionLoader(activity!!, account, info)
override fun onCreateLoader(id: Int, args: Bundle?) = CreateCollectionLoader(requireActivity(), account, info)
override fun onLoadFinished(loader: Loader<Exception>, exception: Exception?) {
dismissAllowingStateLoss()
activity?.let { parent ->
if (exception != null)
fragmentManager!!.beginTransaction()
requireFragmentManager().beginTransaction()
.add(ExceptionInfoFragment.newInstance(exception, account), null)
.commitAllowingStateLoss()
.commit()
else
parent.finish()
}
......
......@@ -11,8 +11,9 @@ package at.bitfire.davdroid.ui
import android.Manifest
import android.accounts.Account
import android.accounts.AccountManager
import android.app.LoaderManager
import android.content.*
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.os.Build
......@@ -20,8 +21,11 @@ import android.os.Bundle
import android.os.PowerManager
import android.provider.CalendarContract
import android.provider.ContactsContract
import android.support.v4.app.LoaderManager
import android.support.v4.content.AsyncTaskLoader
import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import android.support.v4.content.Loader
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu
......@@ -47,13 +51,13 @@ import java.util.logging.Level
class DebugInfoActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks<String> {
companion object {
@JvmField val KEY_THROWABLE = "throwable"
@JvmField val KEY_LOGS = "logs"
@JvmField val KEY_ACCOUNT = "account"
@JvmField val KEY_AUTHORITY = "authority"
@JvmField val KEY_PHASE = "phase"
@JvmField val KEY_LOCAL_RESOURCE = "localResource"
@JvmField val KEY_REMOTE_RESOURCE = "remoteResource"
const val KEY_THROWABLE = "throwable"
const val KEY_LOGS = "logs"
const val KEY_ACCOUNT = "account"
const val KEY_AUTHORITY = "authority"
const val KEY_PHASE = "phase"
const val KEY_LOCAL_RESOURCE = "localResource"
const val KEY_REMOTE_RESOURCE = "remoteResource"
}
private var report: String? = null
......@@ -62,7 +66,7 @@ class DebugInfoActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks<Stri
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_debug_info)
loaderManager.initLoader(0, intent.extras, this)
supportLoaderManager.initLoader(0, intent.extras, this)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
......
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.view.Menu
import android.view.MenuItem
import at.bitfire.davdroid.App
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.R
import at.bitfire.davdroid.settings.ISettings
class DefaultAccountsDrawerHandler: IAccountsDrawerHandler {
companion object {
private const val BETA_FEEDBACK_URI = "mailto:support@davdroid.com?subject=${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME} feedback (${BuildConfig.VERSION_CODE})"
}
override fun onSettingsChanged(settings: ISettings?, menu: Menu) {
if (BuildConfig.VERSION_NAME.contains("-beta") || BuildConfig.VERSION_NAME.contains("-rc"))
menu.findItem(R.id.nav_beta_feedback).isVisible = true
}
override fun onNavigationItemSelected(activity: Activity, item: MenuItem): Boolean {
when (item.itemId) {
R.id.nav_about ->
activity.startActivity(Intent(activity, AboutActivity::class.java))
R.id.nav_app_settings ->
activity.startActivity(Intent(activity, AppSettingsActivity::class.java))
R.id.nav_beta_feedback -> {
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse(BETA_FEEDBACK_URI))
if (activity.packageManager.resolveActivity(intent, 0) != null)
activity.startActivity(intent)
}
R.id.nav_twitter ->
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/davdroidapp")))
R.id.nav_website ->
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.homepage_url))))
R.id.nav_manual ->
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("manual/").build()))
R.id.nav_faq ->
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("faq/").build()))
R.id.nav_forums ->
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("forums/").build()))
R.id.nav_donate ->
if (BuildConfig.FLAVOR != App.FLAVOR_GOOGLE_PLAY)
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.homepage_url))
.buildUpon().appendEncodedPath("donate/").build()))
else ->
return false
}
return true
}
}
\ No newline at end of file
......@@ -31,8 +31,8 @@ import okhttp3.HttpUrl
class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<Exception> {
companion object {
val ARG_ACCOUNT = "account"
val ARG_COLLECTION_INFO = "collectionInfo"
const val ARG_ACCOUNT = "account"
const val ARG_COLLECTION_INFO = "collectionInfo"
}
private lateinit var account: Account
......@@ -65,9 +65,9 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
dismissAllowingStateLoss()
if (exception != null)
fragmentManager!!.beginTransaction()
requireFragmentManager().beginTransaction()
.add(ExceptionInfoFragment.newInstance(exception, account), null)
.commitAllowingStateLoss()
.commit()
else
(activity as? AccountActivity)?.reload()
}
......
......@@ -21,8 +21,8 @@ import java.io.IOException
class ExceptionInfoFragment: DialogFragment() {
companion object {
val ARG_ACCOUNT = "account"
val ARG_EXCEPTION = "exception"
const val ARG_ACCOUNT = "account"
const val ARG_EXCEPTION = "exception"
fun newInstance(exception: Exception, account: Account?): ExceptionInfoFragment {
val frag = ExceptionInfoFragment()
......@@ -35,8 +35,9 @@ class ExceptionInfoFragment: DialogFragment() {
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val exception = arguments!!.getSerializable(ARG_EXCEPTION) as Exception
val account: Account? = arguments!!.getParcelable(ARG_ACCOUNT)
val args = requireNotNull(arguments)
val exception = args.getSerializable(ARG_EXCEPTION) as Exception
val account: Account? = args.getParcelable(ARG_ACCOUNT)
val title = when (exception) {
is HttpException -> R.string.exception_httpexception
......@@ -44,7 +45,7 @@ class ExceptionInfoFragment: DialogFragment() {
else -> R.string.exception
}
val dialog = AlertDialog.Builder(activity!!)
val dialog = AlertDialog.Builder(requireActivity())
.setIcon(R.drawable.ic_error_dark)
.setTitle(title)
.setMessage(exception::class.java.name + "\n" + exception.localizedMessage)
......
......@@ -8,9 +8,13 @@
package at.bitfire.davdroid.ui
import android.content.*
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Handler
import android.os.IBinder
import android.support.v4.content.AsyncTaskLoader
import at.bitfire.davdroid.settings.ISettings
import at.bitfire.davdroid.settings.ISettingsObserver
import at.bitfire.davdroid.settings.Settings
......
......@@ -11,18 +11,18 @@ package at.bitfire.davdroid.ui
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.Dialog
import android.app.DialogFragment
import android.app.LoaderManager
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.Loader
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.support.v4.app.DialogFragment
import android.support.v4.app.LoaderManager
import android.support.v4.content.Loader
import android.support.v7.app.AlertDialog
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.R
......@@ -32,7 +32,7 @@ import at.bitfire.davdroid.settings.ISettings
import java.util.*
import java.util.logging.Level
class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISettings?> {
class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISettings> {
enum class Mode {
BATTERY_OPTIMIZATIONS,
......@@ -43,13 +43,13 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
companion object {
private val SETTING_NEXT_DONATION_POPUP = "time_nextDonationPopup"
private const val SETTING_NEXT_DONATION_POPUP = "time_nextDonationPopup"
@JvmField val HINT_BATTERY_OPTIMIZATIONS = "hint_BatteryOptimizations"
@JvmField val HINT_GOOGLE_PLAY_ACCOUNTS_REMOVED = "hint_GooglePlayAccountsRemoved"
@JvmField val HINT_OPENTASKS_NOT_INSTALLED = "hint_OpenTasksNotInstalled"
const val HINT_BATTERY_OPTIMIZATIONS = "hint_BatteryOptimizations"
const val HINT_GOOGLE_PLAY_ACCOUNTS_REMOVED = "hint_GooglePlayAccountsRemoved"
const val HINT_OPENTASKS_NOT_INSTALLED = "hint_OpenTasksNotInstalled"
val ARGS_MODE = "mode"
const val ARGS_MODE = "mode"
fun getStartupDialogs(context: Context, settings: ISettings): List<StartupDialogFragment> {
val dialogs = LinkedList<StartupDialogFragment>()
......@@ -97,14 +97,14 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
loaderManager.initLoader(0, null, this)
}
override fun onCreateLoader(code: Int, args: Bundle?): Loader<ISettings?> =
SettingsLoader(activity)
override fun onCreateLoader(code: Int, args: Bundle?) =
SettingsLoader(requireActivity())
override fun onLoadFinished(loader: Loader<ISettings?>?, result: ISettings?) {
override fun onLoadFinished(loader: Loader<ISettings>, result: ISettings?) {
settings = result
}
override fun onLoaderReset(loader: Loader<ISettings?>?) {
override fun onLoaderReset(loader: Loader<ISettings>) {
settings = null
}
......@@ -113,7 +113,8 @@ class StartupDialogFragment: DialogFragment(), LoaderManager.LoaderCallbacks<ISe
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
isCancelable = false
val mode = Mode.valueOf(arguments.getString(ARGS_MODE))
val activity = requireActivity()
val mode = Mode.valueOf(arguments!!.getString(ARGS_MODE))
return when (mode) {
Mode.BATTERY_OPTIMIZATIONS ->
AlertDialog.Builder(activity)
......
......@@ -11,13 +11,17 @@ package at.bitfire.davdroid.ui.setup
import android.accounts.Account
import android.accounts.AccountManager
import android.app.Activity
import android.app.Fragment
import android.app.LoaderManager
import android.content.*
import android.content.ContentResolver
import android.content.ContentValues
import android.content.Context