Skip to content

Commit

Permalink
added message to prompt resync on launch for tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
mickstar committed Jan 9, 2021
1 parent 90e05ca commit 0a184dd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
}
private var zoteroDB: ZoteroDB by zoteroDBPicker

private var performedCleanSync: Boolean = false

override fun refreshLibrary(useSmallLoadingAnimation: Boolean) {
if (!state.isUsingGroup()) {
downloadLibrary(doRefresh = true, useSmallLoadingAnimation = useSmallLoadingAnimation)
Expand Down Expand Up @@ -136,7 +138,9 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
Log.d("zotero", "not resyncing library, already have a copy.")
return
}

if (zoteroDB.getLibraryVersion() <= 0) {
this.performedCleanSync = true
}
syncManager.startCompleteSync(zoteroDB, useSmallLoadingAnimation)
}

Expand Down Expand Up @@ -337,7 +341,6 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
"MD5 Verification Error",
"The download process did not complete properly. Please retry",
{})
firebaseAnalytics.logEvent("error_downloading_file_corrupted", Bundle())
attachmentStorageManager.deleteAttachment(item)
return
} else {
Expand Down Expand Up @@ -378,10 +381,6 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
"The file does not exist on the Zotero server."
)
} else {

firebaseAnalytics.logEvent(
"error_downloading_attachment",
Bundle().apply { putString("message", "${e.message}") })
presenter.attachmentDownloadError(
"Error Message: ${e.message}"
)
Expand Down Expand Up @@ -411,7 +410,6 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
}

override fun createNote(note: Note) {
firebaseAnalytics.logEvent("create_note", Bundle())
if (state.isUsingGroup()) {
presenter.makeToastAlert("Sorry, this isn't supported in shared collections.")
return
Expand All @@ -431,9 +429,6 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
}

override fun onError(e: Throwable) {
firebaseAnalytics.logEvent(
"create_note_error",
Bundle().apply { putString("error_message", e.toString()) })
presenter.createErrorAlert(
"Error creating note",
"An error occurred while trying to create your note. Message: $e"
Expand Down Expand Up @@ -978,10 +973,10 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
}

loadCollections
.andThen(loadItems)
.andThen(db.loadTrashItemsFromDB())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.andThen(loadItems)
.andThen(db.loadTrashItemsFromDB())
.doOnComplete {
presenter.hideBasicSyncAnimation()
if (db.groupID == GroupInfo.NO_GROUP_ID) {
Expand All @@ -1005,6 +1000,21 @@ class LibraryActivityModel(private val presenter: Contract.Presenter, val contex
db.setItemsVersion(0)
}
this.checkAllAttachmentsForModification()
// TODO Remove next release.
if (preferences.firstRunForVersion42() && !performedCleanSync) {
presenter.createYesNoPrompt("Tags are now supported",
"Zoo requires a full library resync if you want to access your tags. Would you like to resync your library?",
"Resync",
"No",
{
zoteroDatabase.deleteAllItems().blockingAwait()
destroyLibrary()
refreshLibrary()
},
{}
)
}

}.doOnError {
presenter.createErrorAlert("error loading library", "got error message ${it}", {})
}.subscribe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.widget.CheckBox
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.analytics.FirebaseAnalytics
import com.mickstarify.zooforzotero.PreferenceManager
import com.mickstarify.zooforzotero.R
import com.mickstarify.zooforzotero.ZoteroAPI.Webdav
Expand All @@ -17,7 +16,7 @@ import org.jetbrains.anko.doAsync
import org.jetbrains.anko.onComplete
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.toast
import java.util.*
import java.util.Locale

class WebDAVSetup : AppCompatActivity() {
lateinit var preferenceManager: PreferenceManager
Expand Down Expand Up @@ -109,8 +108,6 @@ class WebDAVSetup : AppCompatActivity() {
} else {
// i dont want to log auth errors.
bundle.putString("exception_message", e.message)
FirebaseAnalytics.getInstance(this@WebDAVSetup)
.logEvent("webdav_connection_exception", bundle)
}
}
Log.d("zotero", "testing webdav got ${status}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ class PreferenceManager @Inject constructor(context: Context) {
return firstRun
}

fun firstRunForVersion42(): Boolean {
/*check to see if this is the first time the user is opening on version 2.9 (42)*/
val firstRun = sharedPreferences.getBoolean("firstrun_version42", true)
if (firstRun) {
val editor = sharedPreferences.edit()
editor.putBoolean("firstrun_version42", false)
editor.apply()
}
return firstRun
}

fun shouldLiveSearch(): Boolean {
/* This preference defines whether library search should update as the user types.
* This may be problematic for devices with a slow refresh rate or slow IO. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.reactivex.Completable
import io.reactivex.Maybe
import io.reactivex.Single
import io.reactivex.functions.Action
import java.util.*
import java.util.LinkedList
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -205,7 +205,12 @@ class ZoteroDatabase @Inject constructor(val context: Context) {
return db.itemDao().restoreFromTrash(groupID, itemKey)
}

fun deleteAllItems(): Completable {
return db.itemDao().deleteAllItems()
}

fun deleteEverything() {
//todo implement.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import io.reactivex.Maybe
import io.reactivex.Single
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
import java.util.*
import kotlin.collections.HashMap
import java.util.Locale

/*this code is currently inactive. Just part of my project to migrate to sQL rather than using
* json files for storage. */
Expand Down Expand Up @@ -348,4 +347,8 @@ interface ItemDao {

@Query("DELETE FROM iteminfo WHERE `group`=:groupID")
fun deleteAllForGroup(groupID: Int): Completable

@Transaction
@Query("DELETE FROM ItemInfo")
fun deleteAllItems(): Completable
}

0 comments on commit 0a184dd

Please sign in to comment.