Skip to content

Commit

Permalink
Merge branch 'dev-ose' into 445-refactor-hiltviewmodels-applicationco…
Browse files Browse the repository at this point in the history
…ntext

# Conflicts:
#	app/src/main/kotlin/at/bitfire/davdroid/ui/intro/BatteryOptimizationsFragment.kt
#	app/src/main/kotlin/at/bitfire/davdroid/ui/webdav/AddWebdavMountActivity.kt
  • Loading branch information
ArnyminerZ committed Oct 18, 2023
2 parents 11307ba + f8330e8 commit 9ade2bb
Show file tree
Hide file tree
Showing 31 changed files with 598 additions and 256 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
defaultConfig {
applicationId "at.bitfire.davdroid"

versionCode 403080000
versionName '4.3.8'
versionCode 403090000
versionName '4.3.9-beta.1'

buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"

Expand Down
4 changes: 4 additions & 0 deletions app/proguard-rules-release.pro
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
# Additional rules which are now required since missing classes can't be ignored in R8 anymore.
# [https://developer.android.com/build/releases/past-releases/agp-7-0-0-release-notes#r8-missing-class-warning]
-dontwarn com.android.org.conscrypt.SSLParametersImpl
-dontwarn com.sun.jna.** # dnsjava
-dontwarn groovy.**
-dontwarn java.beans.Transient
-dontwarn javax.naming.NamingException # dnsjava
-dontwarn javax.naming.directory.** # dnsjava
-dontwarn junit.textui.TestRunner
-dontwarn lombok.** # dnsjava
-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
-dontwarn org.bouncycastle.jsse.**
-dontwarn org.codehaus.groovy.**
Expand Down
21 changes: 16 additions & 5 deletions app/src/main/kotlin/at/bitfire/davdroid/ui/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.core.text.HtmlCompat
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
Expand Down Expand Up @@ -81,14 +82,24 @@ class AboutActivity: AppCompatActivity() {

binding.viewpager.adapter = TabsAdapter(supportFragmentManager)
binding.tabs.setupWithViewPager(binding.viewpager, false)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.activity_about, menu)
return true
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.activity_about, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem) =
when (menuItem.itemId) {
R.id.show_website -> {
showWebsite()
true
}
else -> false
}
})
}

fun showWebsite(item: MenuItem) {
fun showWebsite() {
UiUtils.launchUri(this, App.homepageUrl(this))
}

Expand Down
33 changes: 23 additions & 10 deletions app/src/main/kotlin/at/bitfire/davdroid/ui/AccountListFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import android.provider.Settings
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.annotation.AnyThread
import androidx.core.content.ContextCompat
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.AndroidViewModel
Expand Down Expand Up @@ -58,8 +61,6 @@ class AccountListFragment: Fragment() {
private var syncStatusSnackbar: Snackbar? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
setHasOptionsMenu(true)

_binding = AccountListBinding.inflate(inflater, container, false)
return binding.root
}
Expand Down Expand Up @@ -132,16 +133,28 @@ class AccountListFragment: Fragment() {
accountAdapter.submitList(accounts)
requireActivity().invalidateOptionsMenu()
}
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) =
inflater.inflate(R.menu.activity_accounts, menu)
requireActivity().addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.activity_accounts, menu)
}

override fun onPrepareOptionsMenu(menu: Menu) {
// Show "Sync all" only when there is at least one account
model.accounts.value?.let { accounts ->
menu.findItem(R.id.syncAll).setVisible(accounts.isNotEmpty())
}
override fun onMenuItemSelected(menuItem: MenuItem) =
when (menuItem.itemId) {
R.id.syncAll -> {
(activity as AccountsActivity).syncAllAccounts()
true
}
else -> false
}

override fun onPrepareMenu(menu: Menu) {
// Show "Sync all" only when there is at least one account
model.accounts.value?.let { accounts ->
menu.findItem(R.id.syncAll).setVisible(accounts.isNotEmpty())
}
}
})
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
super.onCreate(savedInstanceState)

if (savedInstanceState == null) {
// use a separate thread to check whether IntroActivity should be shown
CoroutineScope(Dispatchers.Default).launch {
// use a separate thread to check whether IntroActivity should be shown
if (IntroActivity.shouldShowIntroActivity(this@AccountsActivity)) {
if (IntroActivity.shouldShowIntroActivity(this@AccountsActivity))
introActivityLauncher.launch(null)
}
}
}

Expand Down Expand Up @@ -109,7 +108,7 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
private fun allAccounts() =
AccountManager.get(this).getAccountsByType(getString(R.string.account_type))

fun syncAllAccounts(item: MenuItem? = null) {
fun syncAllAccounts() {
if (Build.VERSION.SDK_INT >= 25)
getSystemService<ShortcutManager>()?.reportShortcutUsed(UiUtils.SHORTCUT_SYNC_ALL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.MenuProvider
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.*
import androidx.viewpager2.adapter.FragmentStateAdapter
Expand Down Expand Up @@ -105,27 +107,45 @@ class AccountActivity: AppCompatActivity() {
SyncWorker.enqueueAllAuthorities(this, model.account)
}
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.activity_account, menu)
return true
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.activity_account, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem) =
when (menuItem.itemId) {
R.id.settings -> {
openAccountSettings()
true
}
R.id.rename_account -> {
renameAccount()
true
}
R.id.delete_account -> {
deleteAccountDialog()
true
}
else -> false
}
})
}


// menu actions

fun openAccountSettings(menuItem: MenuItem) {
fun openAccountSettings() {
val intent = Intent(this, SettingsActivity::class.java)
intent.putExtra(SettingsActivity.EXTRA_ACCOUNT, model.account)
startActivity(intent, null)
}

fun renameAccount(menuItem: MenuItem) {
fun renameAccount() {
RenameAccountFragment.newInstance(model.account).show(supportFragmentManager, null)
}

fun deleteAccount(menuItem: MenuItem) {
fun deleteAccountDialog() {
MaterialAlertDialogBuilder(this)
.setIcon(R.drawable.ic_error)
.setTitle(R.string.account_delete_confirmation_title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
package at.bitfire.davdroid.ui.account

import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.FragmentManager
import at.bitfire.davdroid.util.PermissionUtils
import at.bitfire.davdroid.R
Expand All @@ -22,26 +25,39 @@ class AddressBooksFragment: CollectionsFragment() {

override val noCollectionsStringId = R.string.account_no_address_books

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) =
inflater.inflate(R.menu.carddav_actions, menu)
private val menuProvider = object : CollectionsMenuProvider() {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.carddav_actions, menu)
}

override fun onPrepareOptionsMenu(menu: Menu) {
menu.findItem(R.id.create_address_book).isVisible = model.hasWriteableCollections.value ?: false
super.onPrepareOptionsMenu(menu)
}
override fun onPrepareMenu(menu: Menu) {
super.onPrepareMenu(menu)
menu.findItem(R.id.create_address_book).isVisible = model.hasWriteableCollections.value ?: false
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
if (super.onMenuItemSelected(menuItem))
return true

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (super.onOptionsItemSelected(item))
return true
if (menuItem.itemId == R.id.create_address_book) {
val intent = Intent(requireActivity(), CreateAddressBookActivity::class.java)
intent.putExtra(CreateAddressBookActivity.EXTRA_ACCOUNT, accountModel.account)
startActivity(intent)
return true
}

if (item.itemId == R.id.create_address_book) {
val intent = Intent(requireActivity(), CreateAddressBookActivity::class.java)
intent.putExtra(CreateAddressBookActivity.EXTRA_ACCOUNT, accountModel.account)
startActivity(intent)
return true
return false
}
}

override fun onResume() {
super.onResume()
requireActivity().addMenuProvider(menuProvider)
}

return false
override fun onPause() {
super.onPause()
requireActivity().removeMenuProvider(menuProvider)
}

override fun checkPermissions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
package at.bitfire.davdroid.ui.account

import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.FragmentManager
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.util.PermissionUtils
Expand All @@ -18,26 +21,40 @@ class CalendarsFragment: CollectionsFragment() {

override val noCollectionsStringId = R.string.account_no_calendars

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) =
inflater.inflate(R.menu.caldav_actions, menu)
private val menuProvider = object : CollectionsMenuProvider() {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.caldav_actions, menu)
}

override fun onPrepareOptionsMenu(menu: Menu) {
menu.findItem(R.id.create_calendar).isVisible = model.hasWriteableCollections.value ?: false
super.onPrepareOptionsMenu(menu)
}
override fun onPrepareMenu(menu: Menu) {
super.onPrepareMenu(menu)
menu.findItem(R.id.create_calendar).isVisible = model.hasWriteableCollections.value ?: false
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (super.onOptionsItemSelected(item))
return true
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
if (super.onMenuItemSelected(menuItem)) {
return true
}

if (item.itemId == R.id.create_calendar) {
val intent = Intent(requireActivity(), CreateCalendarActivity::class.java)
intent.putExtra(CreateCalendarActivity.EXTRA_ACCOUNT, accountModel.account)
startActivity(intent)
return true
if (menuItem.itemId == R.id.create_calendar) {
val intent = Intent(requireActivity(), CreateCalendarActivity::class.java)
intent.putExtra(CreateCalendarActivity.EXTRA_ACCOUNT, accountModel.account)
startActivity(intent)
return true
}

return false
}
}

override fun onResume() {
super.onResume()
requireActivity().addMenuProvider(menuProvider)
}

return false
override fun onPause() {
super.onPause()
requireActivity().removeMenuProvider(menuProvider)
}


Expand Down
Loading

0 comments on commit 9ade2bb

Please sign in to comment.