From 7098b7cc3f51dd65b3192886822e6334134c435c Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Mon, 22 Oct 2018 11:05:01 +0100 Subject: [PATCH] Wraps the authority in an object --- .../io/plaidapp/core/util/FileAuthority.kt | 22 +++++++++++++++++++ .../io/plaidapp/core/util/ImageUriProvider.kt | 4 ++-- .../dribbble/dagger/DribbbleModule.kt | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/io/plaidapp/core/util/FileAuthority.kt diff --git a/core/src/main/java/io/plaidapp/core/util/FileAuthority.kt b/core/src/main/java/io/plaidapp/core/util/FileAuthority.kt new file mode 100644 index 000000000..95617ed0f --- /dev/null +++ b/core/src/main/java/io/plaidapp/core/util/FileAuthority.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2018 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.plaidapp.core.util + +/** + * Wrapping the file authority value in a data class, to make it more type safe. + */ +data class FileAuthority(val authority: String) \ No newline at end of file diff --git a/core/src/main/java/io/plaidapp/core/util/ImageUriProvider.kt b/core/src/main/java/io/plaidapp/core/util/ImageUriProvider.kt index f61d4a7cf..ce80a183b 100644 --- a/core/src/main/java/io/plaidapp/core/util/ImageUriProvider.kt +++ b/core/src/main/java/io/plaidapp/core/util/ImageUriProvider.kt @@ -28,7 +28,7 @@ import javax.inject.Inject */ class ImageUriProvider @Inject constructor( context: Context, - private val fileAuthority: String + private val fileAuthority: FileAuthority ) { // Only hold the app context to avoid leaks @@ -52,6 +52,6 @@ class ImageUriProvider @Inject constructor( val fileName = url.substring(url.lastIndexOf('/') + 1) val renamed = File(file.parent, fileName) file.renameTo(renamed) - return FileProvider.getUriForFile(appContext, fileAuthority, renamed) + return FileProvider.getUriForFile(appContext, fileAuthority.authority, renamed) } } diff --git a/dribbble/src/main/java/io/plaidapp/dribbble/dagger/DribbbleModule.kt b/dribbble/src/main/java/io/plaidapp/dribbble/dagger/DribbbleModule.kt index c9d030bf5..ea367a6e5 100644 --- a/dribbble/src/main/java/io/plaidapp/dribbble/dagger/DribbbleModule.kt +++ b/dribbble/src/main/java/io/plaidapp/dribbble/dagger/DribbbleModule.kt @@ -24,6 +24,7 @@ import io.plaidapp.core.dagger.dribbble.DribbbleDataModule import io.plaidapp.core.data.CoroutinesContextProvider import io.plaidapp.core.dribbble.data.ShotsRepository import io.plaidapp.core.ui.widget.ElasticDragDismissFrameLayout +import io.plaidapp.core.util.FileAuthority import io.plaidapp.dribbble.BuildConfig import io.plaidapp.dribbble.domain.GetShareShotInfoUseCase import io.plaidapp.dribbble.ui.shot.ShotActivity @@ -68,5 +69,5 @@ class DribbbleModule(private val activity: ShotActivity, private val shotId: Lon } @Provides - fun fileAuthority() = BuildConfig.FILES_AUTHORITY + fun fileAuthority() = FileAuthority(BuildConfig.FILES_AUTHORITY) }