Skip to content

Commit

Permalink
fix: disable CSV import for older android versions
Browse files Browse the repository at this point in the history
Related to #4155
  • Loading branch information
VaiTon committed Aug 13, 2021
1 parent 924a9dc commit c06c049
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -18,12 +18,14 @@ package openfoodfacts.github.scrachx.openfood.features.productlists
import android.app.ProgressDialog
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.DialogAction
Expand Down Expand Up @@ -183,6 +185,7 @@ class ProductListsActivity : BaseActivity(), SwipeController.Actions {
}
}

@RequiresApi(Build.VERSION_CODES.KITKAT)
private val chooseFileContract = registerForActivityResult(ActivityResultContracts.OpenDocument())
{ uri ->
if (uri != null) {
Expand Down Expand Up @@ -223,7 +226,13 @@ class ProductListsActivity : BaseActivity(), SwipeController.Actions {
else -> super.onOptionsItemSelected(item)
}

private fun openCSVToImport() = chooseFileContract.launch(arrayOf("text/csv"))
private fun openCSVToImport() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
chooseFileContract.launch(arrayOf("text/csv"))
} else {
Toast.makeText(this, "Feature disabled for your android version.", Toast.LENGTH_LONG).show()
}
}

public override fun onResume() {
super.onResume()
Expand Down

0 comments on commit c06c049

Please sign in to comment.