Skip to content

Commit

Permalink
reformat kt code for ktlin check compliance
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Dec 4, 2023
1 parent 6bb0858 commit c8ad798
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ import org.junit.Test

class MainActivityTest {
@get:Rule
val activityRule: IntentsTestRule<MainActivity> = IntentsTestRule(
MainActivity::class.java,
true,
false
)
val activityRule: IntentsTestRule<MainActivity> =
IntentsTestRule(MainActivity::class.java, true, false)

@Test
fun login() {
val sut = activityRule.launchActivity(null)

val user = sut.userManager.storeProfile(
"test",
UserManager.UserAttributes(
null,
serverUrl = "http://server/nc",
currentUser = true,
userId = "test",
token = "test",
displayName = "Test Name",
pushConfigurationState = null,
capabilities = null,
certificateAlias = null,
externalSignalingServer = null
)
).blockingGet()
val user =
sut
.userManager
.storeProfile(
"test",
UserManager.UserAttributes(
null,
serverUrl = "http://server/nc",
currentUser = true,
userId = "test",
token = "test",
displayName = "Test Name",
pushConfigurationState = null,
capabilities = null,
certificateAlias = null,
externalSignalingServer = null,
),
)
.blockingGet()

assertNotNull("Error creating user", user)
}
Expand Down
16 changes: 10 additions & 6 deletions app/src/androidTest/java/com/nextcloud/talk/utils/ShareUtilsIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class ShareUtilsIT {

private fun parseDate2(dateStr: String): Date {
return DateUtils.parseDate(
dateStr, Locale.US,
dateStr,
Locale.US,
HttpUtils.httpDateFormatStr,
"EEE, dd MMM yyyy HH:mm:ss zzz", // RFC 822, updated by RFC 1123 with any TZ
"EEEE, dd-MMM-yy HH:mm:ss zzz", // RFC 850, obsoleted by RFC 1036 with any TZ.
"EEE MMM d HH:mm:ss yyyy", // ANSI C's asctime() format
// RFC 822, updated by RFC 1123 with any TZ
"EEE, dd MMM yyyy HH:mm:ss zzz",
// RFC 850, obsoleted by RFC 1036 with any TZ.
"EEEE, dd-MMM-yy HH:mm:ss zzz",
// ANSI C's asctime() format
"EEE MMM d HH:mm:ss yyyy",
// Alternative formats.
"EEE, dd-MMM-yyyy HH:mm:ss z",
"EEE, dd-MMM-yyyy HH-mm-ss z",
Expand All @@ -34,9 +38,9 @@ class ShareUtilsIT {
"EEE dd MMM yy HH:mm:ss z",
"EEE,dd-MMM-yy HH:mm:ss z",
"EEE,dd-MMM-yyyy HH:mm:ss z",
// RI bug 6641315 claims a cookie of this format was once served by www.yahoo.com
"EEE, dd-MM-yyyy HH:mm:ss z",
/* RI bug 6641315 claims a cookie of this format was once served by www.yahoo.com */
"EEE MMM d yyyy HH:mm:ss z"
"EEE MMM d yyyy HH:mm:ss z",
)
}

Expand Down
53 changes: 26 additions & 27 deletions app/src/androidTest/java/com/nextcloud/talk/utils/UriUtilsIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import junit.framework.TestCase.assertTrue
import org.junit.Test

class UriUtilsIT {

@Test
fun testHasHttpProtocolPrefixed() {
val uriHttp = "http://www.example.com"
Expand All @@ -46,16 +45,16 @@ class UriUtilsIT {
assertEquals(
"42",
UriUtils.extractInstanceInternalFileFileId(
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=42"
)
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=42",
),
)
}

@Test
fun testExtractInstanceInternalFileShareFileId() {
assertEquals(
"42",
UriUtils.extractInstanceInternalFileShareFileId("https://cloud.nextcloud.com/f/42")
UriUtils.extractInstanceInternalFileShareFileId("https://cloud.nextcloud.com/f/42"),
)
}

Expand All @@ -64,29 +63,29 @@ class UriUtilsIT {
assertTrue(
UriUtils.isInstanceInternalFileShareUrl(
"https://cloud.nextcloud.com",
"https://cloud.nextcloud.com/f/42"
)
"https://cloud.nextcloud.com/f/42",
),
)

assertFalse(
UriUtils.isInstanceInternalFileShareUrl(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/f/42"
)
"https://cloud.nextcloud.com/f/42",
),
)

assertFalse(
UriUtils.isInstanceInternalFileShareUrl(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/f/"
)
"https://cloud.nextcloud.com/f/",
),
)

assertFalse(
UriUtils.isInstanceInternalFileShareUrl(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/f/test123"
)
"https://cloud.nextcloud.com/f/test123",
),
)
}

Expand All @@ -95,36 +94,36 @@ class UriUtilsIT {
assertTrue(
UriUtils.isInstanceInternalFileUrl(
"https://cloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41"
)
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41",
),
)

assertFalse(
UriUtils.isInstanceInternalFileUrl(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41"
)
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41",
),
)

assertFalse(
UriUtils.isInstanceInternalFileUrl(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=test123"
)
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=test123",
),
)

assertFalse(
UriUtils.isInstanceInternalFileUrl(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid="
)
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=",
),
)

assertFalse(
UriUtils.isInstanceInternalFileUrl(
"https://cloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering"
)
"https://cloud.nextcloud.com/apps/files/?dir=/Engineering",
),
)
}

Expand All @@ -133,23 +132,23 @@ class UriUtilsIT {
assertTrue(
UriUtils.isInstanceInternalFileUrlNew(
"https://cloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/files/41?dir=/"
)
"https://cloud.nextcloud.com/apps/files/files/41?dir=/",
),
)

assertFalse(
UriUtils.isInstanceInternalFileUrlNew(
"https://nextcloud.nextcloud.com",
"https://cloud.nextcloud.com/apps/files/files/41?dir=/"
)
"https://cloud.nextcloud.com/apps/files/files/41?dir=/",
),
)
}

@Test
fun testExtractInstanceInternalFileFileIdNew() {
assertEquals(
"42",
UriUtils.extractInstanceInternalFileFileIdNew("https://cloud.nextcloud.com/apps/files/files/42?dir=/")
UriUtils.extractInstanceInternalFileFileIdNew("https://cloud.nextcloud.com/apps/files/files/42?dir=/"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
class VibrationUtilsTest {

@Mock
private lateinit var mockContext: Context

Expand All @@ -49,13 +48,10 @@ class VibrationUtilsTest {
VibrationUtils.vibrateShort(mockContext)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Mockito.verify(mockVibrator)
Mockito
.verify(mockVibrator)
.vibrate(
VibrationEffect
.createOneShot(
VibrationUtils.SHORT_VIBRATE,
VibrationEffect.DEFAULT_AMPLITUDE
)
VibrationEffect.createOneShot(VibrationUtils.SHORT_VIBRATE, VibrationEffect.DEFAULT_AMPLITUDE),
)
} else {
Mockito.verify(mockVibrator).vibrate(VibrationUtils.SHORT_VIBRATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
class GetFirebasePushTokenWorker(val context: Context, workerParameters: WorkerParameters) :
Worker(context, workerParameters) {

@Inject
lateinit var appPreferences: AppPreferences

Expand All @@ -60,11 +59,13 @@ class GetFirebasePushTokenWorker(val context: Context, workerParameters: WorkerP

val data: Data =
Data.Builder().putString(PushRegistrationWorker.ORIGIN, "GetFirebasePushTokenWorker").build()
val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java)
.setInputData(data)
.build()
val pushRegistrationWork =
OneTimeWorkRequest
.Builder(PushRegistrationWorker::class.java)
.setInputData(data)
.build()
WorkManager.getInstance(context).enqueue(pushRegistrationWork)
}
},
)

return Result.success()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import javax.inject.Inject

@AutoInjector(NextcloudTalkApplication::class)
class NCFirebaseMessagingService : FirebaseMessagingService() {

@Inject
lateinit var appPreferences: AppPreferences

Expand All @@ -62,12 +61,16 @@ class NCFirebaseMessagingService : FirebaseMessagingService() {
val signature = data[KEY_NOTIFICATION_SIGNATURE]

if (!subject.isNullOrEmpty() && !signature.isNullOrEmpty()) {
val messageData = Data.Builder()
.putString(BundleKeys.KEY_NOTIFICATION_SUBJECT, subject)
.putString(BundleKeys.KEY_NOTIFICATION_SIGNATURE, signature)
.build()
val messageData =
Data
.Builder()
.putString(BundleKeys.KEY_NOTIFICATION_SUBJECT, subject)
.putString(BundleKeys.KEY_NOTIFICATION_SIGNATURE, signature)
.build()
val notificationWork =
OneTimeWorkRequest.Builder(NotificationWorker::class.java).setInputData(messageData)
OneTimeWorkRequest
.Builder(NotificationWorker::class.java)
.setInputData(messageData)
.build()
WorkManager.getInstance().enqueue(notificationWork)
}
Expand All @@ -81,9 +84,11 @@ class NCFirebaseMessagingService : FirebaseMessagingService() {

val data: Data =
Data.Builder().putString(PushRegistrationWorker.ORIGIN, "NCFirebaseMessagingService#onNewToken").build()
val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java)
.setInputData(data)
.build()
val pushRegistrationWork =
OneTimeWorkRequest
.Builder(PushRegistrationWorker::class.java)
.setInputData(data)
.build()
WorkManager.getInstance().enqueue(pushRegistrationWork)
}

Expand Down
33 changes: 18 additions & 15 deletions app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,22 @@ import java.util.concurrent.TimeUnit

@AutoInjector(NextcloudTalkApplication::class)
class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallListener {

override val isGooglePlayServicesAvailable: Boolean = isGPlayServicesAvailable()

override fun providerInstallerInstallIfNeededAsync() {
NextcloudTalkApplication.sharedApplication?.let {
ProviderInstaller.installIfNeededAsync(
it.applicationContext,
this
)
ProviderInstaller.installIfNeededAsync(it.applicationContext, this)
}
}

override fun onProviderInstalled() {
// unused atm
}

override fun onProviderInstallFailed(p0: Int, p1: Intent?) {
override fun onProviderInstallFailed(
p0: Int,
p1: Intent?,
) {
// unused atm
}

Expand All @@ -82,19 +81,23 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi
}

private fun setUpPeriodicTokenRefreshFromFCM() {
val periodicTokenRefreshFromFCM = PeriodicWorkRequest.Builder(
GetFirebasePushTokenWorker::class.java,
DAILY,
TimeUnit.HOURS,
FLEX_INTERVAL,
TimeUnit.HOURS
).build()
val periodicTokenRefreshFromFCM =
PeriodicWorkRequest
.Builder(
GetFirebasePushTokenWorker::class.java,
DAILY,
TimeUnit.HOURS,
FLEX_INTERVAL,
TimeUnit.HOURS,
)
.build()

WorkManager.getInstance()
WorkManager
.getInstance()
.enqueueUniquePeriodicWork(
"periodicTokenRefreshFromFCM",
ExistingPeriodicWorkPolicy.UPDATE,
periodicTokenRefreshFromFCM
periodicTokenRefreshFromFCM,
)
}

Expand Down

0 comments on commit c8ad798

Please sign in to comment.