make sure the file exists before trying to read it at the read activity
This commit is contained in:
parent
90a0d6a663
commit
308755c5ba
|
@ -80,7 +80,13 @@ class ReadTextActivity : SimpleActivity() {
|
||||||
|
|
||||||
val text = if (uri.scheme == "file") {
|
val text = if (uri.scheme == "file") {
|
||||||
filePath = uri.path
|
filePath = uri.path
|
||||||
File(uri.path).readText()
|
val file = File(filePath)
|
||||||
|
if (file.exists()) {
|
||||||
|
file.readText()
|
||||||
|
} else {
|
||||||
|
toast(R.string.unknown_error_occurred)
|
||||||
|
""
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
contentResolver.openInputStream(uri).bufferedReader().use { it.readText() }
|
contentResolver.openInputStream(uri).bufferedReader().use { it.readText() }
|
||||||
|
|
|
@ -95,7 +95,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||||
|
|
||||||
override fun getSelectableItemCount() = fileDirItems.size
|
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) {
|
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||||
val fileDirItem = fileDirItems[position]
|
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)
|
super.onViewRecycled(holder)
|
||||||
if (!activity.isActivityDestroyed()) {
|
if (!activity.isActivityDestroyed()) {
|
||||||
Glide.with(activity).clear(holder?.itemView?.item_icon!!)
|
Glide.with(activity).clear(holder.itemView?.item_icon!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayL
|
||||||
|
|
||||||
override fun getSelectableItemCount() = favorites.size
|
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) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val favorite = favorites[position]
|
val favorite = favorites[position]
|
||||||
|
|
Loading…
Reference in New Issue