Skip to content

Commit

Permalink
v1.5.3-46-GE-sdk26
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandros committed Nov 25, 2021
1 parent bd9f64e commit 7d69018
Show file tree
Hide file tree
Showing 44 changed files with 741 additions and 138 deletions.
38 changes: 12 additions & 26 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
apply plugin: 'com.android.application'
apply plugin: 'com.jaredsburrows.license'
//apply plugin: 'com.jaredsburrows.license'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
apply from: '../env/env.gradle'
apply from: '../utils.gradle'
apply plugin: 'birdflightupload'

licenseReport {
// To generate the report, run the gradle task 'licenseDevDebugReport'.
generateHtmlReport = true
generateJsonReport = false
}
//licenseReport {
// // To generate the report, run the gradle task 'licenseDevDebugReport'.
// generateHtmlReport = true
// generateJsonReport = false
//}

def getGithubSourceCodeZipURL = { ->
def gitRef = System.getenv("CI_COMMIT_REF_NAME")
if(!gitRef){
if(!gitRef) {
gitRef = gitBranch()
}
def githubUrl = "https://github.com/telekom/syncplus/archive/" + gitRef + ".zip"
Expand Down Expand Up @@ -59,10 +59,10 @@ android {

defaultConfig {
applicationId "de.telekom.sync.plus"
minSdkVersion 21 // Android 5
minSdkVersion 26 // Android 8
targetSdkVersion 30 // Android 11
versionCode 36
versionName "1.5.1"
versionCode 46
versionName "1.5.3"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -139,6 +139,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation 'androidx.multidex:multidex:2.0.1'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"

implementation 'com.google.android.material:material:1.1.0'
implementation 'com.github.AppIntro:AppIntro:5.1.0'
Expand All @@ -154,18 +155,3 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}


// Configure the extension
birdflightuploadExtension {
apiKey = birdflightApiKey
appKey = birdflightAppKey
id = "syncplus-aos-cicd-" + System.getenv("CI_PIPELINE_ID") + "-" + System.getenv("CI_JOB_ID")
appVersion = gitBranch()
compatiblity = "Android"
notes = System.getenv("CI_COMMIT_REF_NAME") + "\n" + System.getenv("CI_COMMIT_MESSAGE")+ "\n" + System.getenv("CI_COMMIT_SHORT_SHA")
isPublic = "true"
httpProxyHost = "proxy.infrastruktur.aul.t-online.de"
httpProxyPort = 3128
}

21 changes: 20 additions & 1 deletion app/src/main/java/de/telekom/syncplus/AccountsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,37 @@ package de.telekom.syncplus
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import de.telekom.dtagsyncpluskit.davx5.log.Logger
import de.telekom.dtagsyncpluskit.extraNotNull
import de.telekom.dtagsyncpluskit.ui.BaseActivity
import de.telekom.syncplus.ui.main.AccountDeletedDialog
import de.telekom.syncplus.ui.main.AccountsFragment
import de.telekom.syncplus.ui.main.EnergySaverDialog
import kotlinx.android.synthetic.main.activity_accounts.*

class AccountsActivity : BaseActivity() {
companion object {
private const val ARG_NEW = "ARG_NEW"
fun newIntent(context: Context, newAccountCreated: Boolean): Intent {
private const val ARG_ENERGY_SAVING = "ARG_ENERGY_SAVING"
private const val ARG_ACCOUNT_DELETED = "ARG_ACCOUNT_DELETED"
fun newIntent(
context: Context,
newAccountCreated: Boolean,
energySaving: Boolean = false,
accountDeleted: Boolean = false
): Intent {
val intent = Intent(context, AccountsActivity::class.java)
intent.putExtra(ARG_NEW, newAccountCreated)
intent.putExtra(ARG_ENERGY_SAVING, energySaving)
intent.putExtra(ARG_ACCOUNT_DELETED, accountDeleted)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
return intent
}
}

private val mNewAccountCreated by extraNotNull(ARG_NEW, false)
private val mAccountDeleted by extraNotNull(ARG_ACCOUNT_DELETED, false)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -64,5 +78,10 @@ class AccountsActivity : BaseActivity() {
helpButton.setOnClickListener {
startActivity(HelpActivity.newIntent(this))
}

if (mAccountDeleted) {
val dialog = AccountDeletedDialog(this)
dialog.show(supportFragmentManager, "AccountDeleted")
}
}
}
17 changes: 14 additions & 3 deletions app/src/main/java/de/telekom/syncplus/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ import androidx.multidex.MultiDexApplication
import de.telekom.dtagsyncpluskit.api.APIFactory
import de.telekom.dtagsyncpluskit.api.IDMEnv
import de.telekom.dtagsyncpluskit.api.ServiceEnvironments
import de.telekom.dtagsyncpluskit.awaitResponseOrNull
import de.telekom.dtagsyncpluskit.awaitResponse
import de.telekom.dtagsyncpluskit.davx5.log.Logger
import de.telekom.dtagsyncpluskit.davx5.ui.NotificationUtils
import de.telekom.dtagsyncpluskit.model.idm.WellKnownInfo
import de.telekom.dtagsyncpluskit.model.spica.Contact
import de.telekom.dtagsyncpluskit.model.spica.Duplicate
import de.telekom.dtagsyncpluskit.utils.Err
import de.telekom.dtagsyncpluskit.utils.Ok
import de.telekom.syncplus.dav.DavNotificationUtils
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -73,8 +75,10 @@ class App : MultiDexApplication() {

val env = IDMEnv.fromBuildConfig(BuildConfig.ENVIRON[BuildConfig.FLAVOR]!!)
val idm = APIFactory.idmAPI(env)
val wellKnownResults = idm.wellKnown().awaitResponseOrNull()
_wellKnownInfo = wellKnownResults?.body()
when (val wellKnownResults = idm.wellKnown().awaitResponse()) {
is Ok -> _wellKnownInfo = wellKnownResults.value.body();
is Err -> Logger.log.severe("Error: WellKnownResults: ${wellKnownResults.error}");
}
return _wellKnownInfo!!
}

Expand Down Expand Up @@ -123,6 +127,13 @@ class App : MultiDexApplication() {

DavNotificationUtils.createChannels(this)

/*val notificationManager = NotificationManagerCompat.from(this)
notificationManager.notify(
"test",
NotificationUtils.NOTIFY_SYNC_ERROR,
DavNotificationUtils.energySavingNotification(this)
)*/

/*
// !!! DEBUG !!!
val serviceEnvironments = serviceEnvironments(this)
Expand Down
48 changes: 39 additions & 9 deletions app/src/main/java/de/telekom/syncplus/WelcomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@

package de.telekom.syncplus

import android.accounts.AccountManagerFuture
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import de.telekom.dtagsyncpluskit.davx5.log.Logger
import de.telekom.dtagsyncpluskit.extraNotNull
import de.telekom.dtagsyncpluskit.ui.BaseActivity
import de.telekom.dtagsyncpluskit.utils.IDMAccountManager
import de.telekom.syncplus.dav.DavNotificationUtils
import de.telekom.syncplus.ui.main.WelcomeFragment
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

class WelcomeActivity : BaseActivity() {
companion object {
Expand All @@ -52,16 +56,42 @@ class WelcomeActivity : BaseActivity() {

val accountManager =
IDMAccountManager(this, DavNotificationUtils.reloginCallback(this, "authority"))
if (!mNoRedirect && accountManager.getAccounts().count() > 0) {
startActivity(AccountsActivity.newIntent(this, false))
} else {
setContentView(R.layout.activity_container)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.container, WelcomeFragment.newInstance())
.commitNow()

// Verify that all accounts have been setup completely.
val futures = ArrayList<AccountManagerFuture<Bundle>>()
for (account in accountManager.getAccounts()) {
if (!accountManager.isSetupCompleted(account)) {
Logger.log.info("Account deleted: $account")
futures.add(accountManager.removeAccountAsync(account, this))
}
}

val accountsDeleted = futures.size > 0
val next = {
Logger.log.info("Accounts: ${accountManager.getAccounts().map { it.name }}")
if (!mNoRedirect && accountManager.getAccounts().count() > 0) {
startActivity(
AccountsActivity.newIntent(
this,
newAccountCreated = false,
energySaving = false,
accountDeleted = accountsDeleted
)
)
} else {
setContentView(R.layout.activity_container)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.container, WelcomeFragment.newInstance(accountsDeleted))
.commitNow()
}
}
}

GlobalScope.launch {
futures.forEach { it.result }
runOnUiThread(next)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
package de.telekom.syncplus.dav

import android.accounts.Account
import android.content.ContentProviderClient
import android.content.SyncResult
import android.os.Bundle
import androidx.core.app.NotificationManagerCompat
import de.telekom.dtagsyncpluskit.api.ServiceEnvironments
import de.telekom.dtagsyncpluskit.davx5.settings.AccountSettings
import de.telekom.dtagsyncpluskit.davx5.syncadapter.AddressBooksSyncAdapterService
import de.telekom.dtagsyncpluskit.davx5.ui.NotificationUtils
import de.telekom.syncplus.App
import de.telekom.syncplus.util.Prefs

class AddressBooksSyncAdapterService : AddressBooksSyncAdapterService() {
private val notificationManager by lazy { NotificationManagerCompat.from(this) }
private val prefs by lazy { Prefs(this.applicationContext) }

override fun onSecurityException(account: Account, syncResult: SyncResult) {
if ((this.applicationContext as? App)?.inSetup == true) return
Expand All @@ -45,4 +51,40 @@ class AddressBooksSyncAdapterService : AddressBooksSyncAdapterService() {
DavNotificationUtils.buildReloginNotification(this, account)
)
}

override fun onSyncWillRun(
serviceEnvironments: ServiceEnvironments,
account: Account,
extras: Bundle,
authority: String,
provider: ContentProviderClient,
syncResult: SyncResult
) {
}

override fun onSyncDidRun(
serviceEnvironments: ServiceEnvironments,
account: Account,
extras: Bundle,
authority: String,
provider: ContentProviderClient,
syncResult: SyncResult
) {
val accountSettings = AccountSettings(this, serviceEnvironments, account) {
onLoginException(authority, it)
}
val lastSyncs = prefs.lastSyncs
val currentSync = System.currentTimeMillis()
val lastSync = lastSyncs.lastSyncs.put("AddressBooks.$authority", currentSync)
val i = accountSettings.getSyncInterval(authority)
val interval = if (i == null) Long.MAX_VALUE else i * 1000
if (lastSync != null && (currentSync - lastSync) > (interval * 2)) {
notificationManager.notify(
NotificationUtils.notificationTag(authority, account),
NotificationUtils.NOTIFY_SYNC_ERROR,
DavNotificationUtils.energySavingNotification(this)
)
}
prefs.lastSyncs = lastSyncs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
package de.telekom.syncplus.dav

import android.accounts.Account
import android.content.ContentProviderClient
import android.content.SyncResult
import android.os.Bundle
import androidx.core.app.NotificationManagerCompat
import de.telekom.dtagsyncpluskit.api.ServiceEnvironments
import de.telekom.dtagsyncpluskit.davx5.settings.AccountSettings
import de.telekom.dtagsyncpluskit.davx5.syncadapter.CalendarsSyncAdapterService
import de.telekom.dtagsyncpluskit.davx5.ui.NotificationUtils
import de.telekom.syncplus.App
import de.telekom.syncplus.util.Prefs

class CalendarsSyncAdapterService : CalendarsSyncAdapterService() {
private val notificationManager by lazy { NotificationManagerCompat.from(this) }
private val prefs by lazy { Prefs(this.applicationContext) }

override fun onSecurityException(account: Account, syncResult: SyncResult) {
if ((this.applicationContext as? App)?.inSetup == true) return
Expand All @@ -45,4 +51,40 @@ class CalendarsSyncAdapterService : CalendarsSyncAdapterService() {
DavNotificationUtils.buildReloginNotification(this, account)
)
}

override fun onSyncWillRun(
serviceEnvironments: ServiceEnvironments,
account: Account,
extras: Bundle,
authority: String,
provider: ContentProviderClient,
syncResult: SyncResult
) {
}

override fun onSyncDidRun(
serviceEnvironments: ServiceEnvironments,
account: Account,
extras: Bundle,
authority: String,
provider: ContentProviderClient,
syncResult: SyncResult
) {
val accountSettings = AccountSettings(this, serviceEnvironments, account) {
onLoginException(authority, it)
}
val lastSyncs = prefs.lastSyncs
val currentSync = System.currentTimeMillis()
val lastSync = lastSyncs.lastSyncs.put("Calendars.$authority", currentSync)
val i = accountSettings.getSyncInterval(authority)
val interval = if (i == null) Long.MAX_VALUE else i * 1000
if (lastSync != null && (currentSync - lastSync) > (interval * 2)) {
notificationManager.notify(
NotificationUtils.notificationTag(authority, account),
NotificationUtils.NOTIFY_SYNC_ERROR,
DavNotificationUtils.energySavingNotification(this)
)
}
prefs.lastSyncs = lastSyncs
}
}
Loading

0 comments on commit 7d69018

Please sign in to comment.