make sure the file exists before trying to read it at the read activity

This commit is contained in:
tibbi 2018-03-31 10:38:13 +02:00
parent 90a0d6a663
commit 308755c5ba
3 changed files with 11 additions and 5 deletions

View File

@ -80,7 +80,13 @@ class ReadTextActivity : SimpleActivity() {
val text = if (uri.scheme == "file") {
filePath = uri.path
File(uri.path).readText()
val file = File(filePath)
if (file.exists()) {
file.readText()
} else {
toast(R.string.unknown_error_occurred)
""
}
} else {
try {
contentResolver.openInputStream(uri).bufferedReader().use { it.readText() }

View File

@ -95,7 +95,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
override fun getSelectableItemCount() = fileDirItems.size
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = createViewHolder(R.layout.list_item, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.list_item, parent)
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val fileDirItem = fileDirItems[position]
@ -461,10 +461,10 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
}
}
override fun onViewRecycled(holder: ViewHolder?) {
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) {
Glide.with(activity).clear(holder?.itemView?.item_icon!!)
Glide.with(activity).clear(holder.itemView?.item_icon!!)
}
}

View File

@ -34,7 +34,7 @@ class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayL
override fun getSelectableItemCount() = favorites.size
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = createViewHolder(R.layout.item_manage_favorite, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_favorite, parent)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val favorite = favorites[position]