Skip to content

Commit

Permalink
Merge pull request #14 from Goooler/ktlint-111
Browse files Browse the repository at this point in the history
Spotless 6.24.0 + Ktlint 1.1.1 + Fixing styes
  • Loading branch information
SigmanZero authored Feb 14, 2024
2 parents a97e0fb + f208058 commit 02bbded
Show file tree
Hide file tree
Showing 28 changed files with 176 additions and 139 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_imports_layout = *
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ktlint_code_style = intellij_idea
ktlint_function_naming_ignore_when_annotated_with = Composable

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
12 changes: 6 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ dependencies {
implementation(libs.camera.lifecycle)
implementation(libs.camera.view)

implementation (libs.media3.common)
implementation (libs.media3.effect)
implementation (libs.media3.exoplayer)
implementation (libs.media3.transformer)
implementation (libs.media3.ui)
implementation(libs.media3.common)
implementation(libs.media3.effect)
implementation(libs.media3.exoplayer)
implementation(libs.media3.transformer)
implementation(libs.media3.ui)

implementation(libs.hilt.android)
implementation(libs.hilt.navigation.compose)
Expand All @@ -131,7 +131,7 @@ dependencies {

androidTestImplementation(libs.turbine)

//For photopicker feature
// For photopicker feature
implementation(libs.activity)

implementation(libs.coil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class AppDatabaseTest {

private lateinit var _db: AppDatabase
private var _contactsSize = Contact.CONTACTS.size + 1
private lateinit var db: AppDatabase
private var contactsSize = Contact.CONTACTS.size + 1

@Before
fun setup() {
_db = createTestDatabase()
db = createTestDatabase()
}

@Test
fun populateInitialData_AssureDataIsInitialized() = runBlocking {
val contacts = _db.contactDao().loadAll()
val chatDetails = _db.chatDao().loadAllDetails()
val contacts = db.contactDao().loadAll()
val chatDetails = db.chatDao().loadAllDetails()

// Assert
assertThat(contacts).hasSize(_contactsSize)
assertThat(contacts).hasSize(contactsSize)
assertThat(chatDetails).hasSize(4)
for (detail in chatDetails) {
assertThat(detail.attendees).hasSize(1)
val messages = _db.messageDao().loadAll(detail.chatWithLastMessage.id)
val messages = db.messageDao().loadAll(detail.chatWithLastMessage.id)
assertThat(messages).hasSize(2)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ fun createTestRepository(): ChatRepository {
contactDao = database.contactDao(),
messageDao = database.messageDao(),
notificationHelper = NotificationHelper(context),
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import android.content.Context
import android.content.Intent
import com.google.android.samples.socialite.repository.ChatRepository
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
* Handles the "Reply" action in the chat notification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.Executors
import javax.inject.Qualifier
import javax.inject.Singleton

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher

@Qualifier
annotation class AppCoroutineScope
Expand Down Expand Up @@ -69,7 +68,7 @@ object DatabaseModule {
@Singleton
@AppCoroutineScope
fun providesApplicationCoroutineScope(): CoroutineScope = CoroutineScope(
Executors.newSingleThreadExecutor().asCoroutineDispatcher()
Executors.newSingleThreadExecutor().asCoroutineDispatcher(),
)
}

Expand All @@ -78,5 +77,5 @@ object DatabaseModule {
interface DatabaseBindingModule {

@Binds
fun bindDatabaseManager(manager: RoomDatabaseManager) : DatabaseManager
fun bindDatabaseManager(manager: RoomDatabaseManager): DatabaseManager
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import com.google.android.samples.socialite.data.MessageDao
import com.google.android.samples.socialite.di.AppCoroutineScope
import com.google.android.samples.socialite.model.ChatDetail
import com.google.android.samples.socialite.model.Message
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ChatRepository @Inject internal constructor(
Expand Down Expand Up @@ -67,7 +67,8 @@ class ChatRepository @Inject internal constructor(
Message(
id = 0L,
chatId = chatId,
senderId = 0L, // User
// User
senderId = 0L,
text = text,
mediaUri = mediaUri,
mediaMimeType = mediaMimeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ fun Bubble(chatId: Long) {
chatId = chatId,
foreground = false,
onBackPressed = null,
onCameraClick = {}, // TODO (donovanfm): Hook up camera button in the Bubble composable
onVideoClick = {}, // TODO (jolandaverhoef): Hook up play video button in the Bubble composable
onPhotoPickerClick = {}, // TODO (mayurikhin): Hook up camera button in the Bubble composable
// TODO (donovanfm): Hook up camera button in the Bubble composable
onCameraClick = {},
// TODO (jolandaverhoef): Hook up play video button in the Bubble composable
onVideoClick = {},
// TODO (mayurikhin): Hook up camera button in the Bubble composable
onPhotoPickerClick = {},
modifier = Modifier.fillMaxSize(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import kotlinx.coroutines.flow.stateIn
* use in UI.
*/
context(ViewModel)
fun <T> Flow<T>.stateInUi(initialValue: T): StateFlow<T> {
fun <T> Flow<T>.stateInUi(
initialValue: T,
): StateFlow<T> {
return stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), initialValue)
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ data class ShortcutParams(
)

object AnimationConstants {
private const val enterMillis = 250
private const val exitMillis = 250
private const val ENTER_MILLIS = 250
private const val EXIT_MILLIS = 250

val enterTransition = fadeIn(
animationSpec = tween(
durationMillis = enterMillis,
durationMillis = ENTER_MILLIS,
easing = FastOutLinearInEasing,
),
)

val exitTransition = fadeOut(
animationSpec = tween(
durationMillis = exitMillis,
durationMillis = EXIT_MILLIS,
easing = FastOutSlowInEasing,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ import androidx.window.layout.FoldingFeature
import androidx.window.layout.WindowInfoTracker
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import kotlin.reflect.KFunction1
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlin.reflect.KFunction1

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun Camera(chatId: Long,
onMediaCaptured: (Media?) -> Unit,
viewModel: CameraViewModel = hiltViewModel(),
) {
fun Camera(
chatId: Long,
onMediaCaptured: (Media?) -> Unit,
viewModel: CameraViewModel = hiltViewModel(),
) {
var surfaceProvider by remember { mutableStateOf<Preview.SurfaceProvider?>(null) }
var cameraSelector by remember { mutableStateOf(CameraSelector.DEFAULT_BACK_CAMERA) }
var captureMode by remember { mutableStateOf(CaptureMode.PHOTO) }
Expand All @@ -98,12 +99,11 @@ fun Camera(chatId: Long,
val foldingFeature = newLayoutInfo?.displayFeatures
?.firstOrNull { it is FoldingFeature } as FoldingFeature
isLayoutUnfolded = (foldingFeature != null)
} catch (e: Exception){
} catch (e: Exception) {
// If there was an issue detecting a foldable in the open position, default
// to isLayoutUnfolded being false.
isLayoutUnfolded = false
}

}
}

Expand Down Expand Up @@ -199,7 +199,7 @@ fun Camera(chatId: Long,
if (isLayoutUnfolded != null) {
if (isLayoutUnfolded as Boolean) {
Row(
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
) {
Column(
modifier = Modifier
Expand All @@ -216,7 +216,7 @@ fun Camera(chatId: Long,
CameraControls(
captureMode,
{ setCaptureMode(CaptureMode.PHOTO) },
{ setCaptureMode(CaptureMode.VIDEO_READY) }
{ setCaptureMode(CaptureMode.VIDEO_READY) },
)
}
Row(
Expand All @@ -228,10 +228,12 @@ fun Camera(chatId: Long,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
) {
ShutterButton(captureMode,
ShutterButton(
captureMode,
{ viewModel.capturePhoto(onMediaCaptured) },
{ onVideoRecordingStart() },
{ onVideoRecordingFinish() })
{ onVideoRecordingFinish() },
)
}
Row(
modifier = Modifier,
Expand Down Expand Up @@ -281,7 +283,7 @@ fun Camera(chatId: Long,
CameraControls(
captureMode,
{ setCaptureMode(CaptureMode.PHOTO) },
{ setCaptureMode(CaptureMode.VIDEO_READY) }
{ setCaptureMode(CaptureMode.VIDEO_READY) },
)
}
Row(
Expand All @@ -294,10 +296,12 @@ fun Camera(chatId: Long,
horizontalArrangement = Arrangement.Center,
) {
Spacer(modifier = Modifier.size(50.dp))
ShutterButton(captureMode,
ShutterButton(
captureMode,
{ viewModel.capturePhoto(onMediaCaptured) },
{ onVideoRecordingStart() },
{ onVideoRecordingFinish() })
{ onVideoRecordingFinish() },
)
CameraSwitcher(captureMode, cameraSelector, ::setCameraSelector)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ interface CameraProviderManager {
class CameraXProcessCameraProviderManager @Inject constructor(@ApplicationContext context: Context) : CameraProviderManager {
private val cameraFuture = ProcessCameraProvider.getInstance(context)
override suspend fun getCameraProvider() = cameraFuture.await()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.camera.core.resolutionselector.AspectRatioStrategy
import androidx.camera.core.resolutionselector.ResolutionSelector
import androidx.camera.extensions.ExtensionMode
import androidx.camera.extensions.ExtensionsManager
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.video.MediaStoreOutputOptions
import androidx.camera.video.Quality
import androidx.camera.video.QualitySelector
Expand All @@ -53,14 +52,13 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.samples.socialite.repository.ChatRepository
import com.google.common.util.concurrent.ListenableFuture
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.Locale
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

@HiltViewModel
class CameraViewModel @Inject constructor(
Expand Down Expand Up @@ -250,7 +248,7 @@ class CameraViewModel @Inject constructor(
chatId = chatId,
text = "",
mediaUri = photoUri,
mediaMimeType = "image/jpeg"
mediaMimeType = "image/jpeg",
)
}
}
Expand Down Expand Up @@ -333,5 +331,7 @@ enum class CameraState {
}

enum class CaptureMode {
PHOTO, VIDEO_READY, VIDEO_RECORDING
PHOTO,
VIDEO_READY,
VIDEO_RECORDING,
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ import android.net.Uri
data class Media(var uri: Uri, var mediaType: MediaType)

enum class MediaType {
PHOTO, VIDEO
PHOTO,
VIDEO,
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ import dagger.hilt.components.SingletonComponent
interface CameraProviderBindingModule {

@Binds
fun bindCameraProviderManager(manager: CameraXProcessCameraProviderManager) : CameraProviderManager
fun bindCameraProviderManager(manager: CameraXProcessCameraProviderManager): CameraProviderManager
}
Loading

0 comments on commit 02bbded

Please sign in to comment.