Skip to content

Commit

Permalink
Wraps the authority in an object
Browse files Browse the repository at this point in the history
  • Loading branch information
florina-muntenescu committed Oct 23, 2018
1 parent 2462e51 commit 7098b7c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
22 changes: 22 additions & 0 deletions core/src/main/java/io/plaidapp/core/util/FileAuthority.kt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions core/src/main/java/io/plaidapp/core/util/ImageUriProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit 7098b7c

Please sign in to comment.