Skip to content

Commit

Permalink
[fix] fix bug when opening .1list files from file managers using cont…
Browse files Browse the repository at this point in the history
…entresolver
  • Loading branch information
lolo-io committed Dec 4, 2019
1 parent 645f481 commit b35bd5c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.lolo.io.onelist"
minSdkVersion 16
targetSdkVersion 28
versionCode 7
versionName "1.2.0"
versionCode 9
versionName "1.2.1"
vectorDrawables.useSupportLibrary = true
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/lolo/io/onelist/OneListFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ class OneListFragment : Fragment(), ListsCallbacks, ItemsCallbacks, MainActivity
}
}

override fun onStart() {
super.onStart()
// in case things have changed while stopped
persistence.refreshAndFetchNewLists(allLists)
listsAdapter.notifyDataSetChanged()
itemsAdapter.notifyDataSetChanged()
}

private fun setupListsRecyclerView() {

listsRecyclerView.adapter = listsAdapter
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/lolo/io/onelist/PersistenceHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ class PersistenceHelper(private val app: Activity) {
}
}


fun refreshAndFetchNewLists(lists: MutableList<ItemList>) {
runBlocking {
val newIds = getListIdsTable()
newIds.forEach { fetchedId ->
if (!listsIds.keys.contains(fetchedId.key)) {
lists.add(getListAsync(fetchedId.key).await())
}
}
listsIds = newIds
refreshAllLists(lists)
}
}

fun refreshAllLists(lists: List<ItemList>) {
runBlocking {
lists.forEach {
Expand Down Expand Up @@ -101,7 +115,6 @@ class PersistenceHelper(private val app: Activity) {
val content = app.contentResolver.openInputStream(uri)?.bufferedReader()?.use { it.readText() }
val list = gson.fromJson(content, ItemList::class.java)
list.path = ""
if (uri.path?.startsWith("/tree/") == true) list.path = uri.toString()
require(!listsIds.containsKey(list.stableId)) { app.getString(R.string.list_already_in_your_lists) }
return list
} catch (e: IllegalArgumentException) {
Expand Down

0 comments on commit b35bd5c

Please sign in to comment.