Skip to content

Commit

Permalink
fix: use setDataAndType instead of data and type in Intent creations
Browse files Browse the repository at this point in the history
refactor: use logcat in FileUtils
  • Loading branch information
VaiTon committed Mar 31, 2023
1 parent 770d9c2 commit bfe78a9
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -16,10 +16,11 @@ import android.widget.Toast
import androidx.annotation.CheckResult
import androidx.core.app.NotificationCompat
import androidx.core.content.getSystemService
import logcat.asLog
import logcat.logcat
import openfoodfacts.github.scrachx.openfood.AppFlavor
import openfoodfacts.github.scrachx.openfood.R
import openfoodfacts.github.scrachx.openfood.features.productlist.ProductListActivity
import openfoodfacts.github.scrachx.openfood.features.scanhistory.ScanHistoryActivity
import openfoodfacts.github.scrachx.openfood.models.HistoryProduct
import openfoodfacts.github.scrachx.openfood.models.entities.ProductLists
import org.apache.commons.csv.CSVFormat
Expand All @@ -28,6 +29,9 @@ import org.jetbrains.annotations.Contract
import java.io.IOException


private const val LOG_TAG = "FileUtils"
const val LOCALE_FILE_SCHEME = "file://"

fun isLocaleFile(url: String?) = url?.startsWith(LOCALE_FILE_SCHEME) ?: false

fun isAbsoluteUrl(url: String?) = url?.startsWith("/") ?: false
Expand All @@ -39,7 +43,6 @@ fun getCsvFolderName() = when (AppFlavor.currentFlavor) {
AppFlavor.OPF -> "Open Products Facts"
AppFlavor.OBF -> "Open Beauty Facts"
AppFlavor.OFF -> "Open Food Facts"
else -> "Open Food Facts"
}

fun writeListToFile(context: Context, productList: ProductLists, csvUri: Uri) {
Expand Down Expand Up @@ -90,12 +93,11 @@ fun writeHistoryToFile(context: Context, productList: List<HistoryProduct>, csvU
Toast.makeText(context, R.string.txt_history_exported, Toast.LENGTH_LONG).show()
success = true
} catch (e: IOException) {
Log.e(ScanHistoryActivity.LOG_TAG, "Can't export to $csvUri.", e)
logcat(LOG_TAG) { "Can't export to $csvUri: " + e.asLog() }
}
val downloadIntent = Intent(ACTION_VIEW).apply {
flags = FLAG_ACTIVITY_CLEAR_TOP or FLAG_ACTIVITY_NEW_TASK or FLAG_GRANT_READ_URI_PERMISSION
data = csvUri
type = "text/csv"
setDataAndType(csvUri, "text/csv")
}
val notificationManager = createNotificationManager(context)
if (success) {
Expand All @@ -108,7 +110,6 @@ fun writeHistoryToFile(context: Context, productList: List<HistoryProduct>, csvU
}
}

const val LOCALE_FILE_SCHEME = "file://"

// TODO: Use constants and refactor
fun createNotificationManager(context: Context): NotificationManager {
Expand Down

0 comments on commit bfe78a9

Please sign in to comment.