From 0a184ddf7ecc319de2f01f56555a2756ff8add75 Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Sun, 10 Jan 2021 02:05:54 +1100 Subject: [PATCH] added message to prompt resync on launch for tags. --- .../LibraryActivity/LibraryActivityModel.kt | 34 ++++++++++++------- .../LibraryActivity/WebDAV/WebDAVSetup.kt | 5 +-- .../zooforzotero/PreferenceManager.kt | 11 ++++++ .../ZoteroStorage/Database/Database.kt | 7 +++- .../ZoteroStorage/Database/Item.kt | 7 ++-- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/LibraryActivityModel.kt b/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/LibraryActivityModel.kt index 7b6ecff3..8b52b4ea 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/LibraryActivityModel.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/LibraryActivityModel.kt @@ -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) @@ -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) } @@ -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 { @@ -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}" ) @@ -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 @@ -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" @@ -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) { @@ -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() diff --git a/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/WebDAV/WebDAVSetup.kt b/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/WebDAV/WebDAVSetup.kt index 5bf49569..96fd05c1 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/WebDAV/WebDAVSetup.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/LibraryActivity/WebDAV/WebDAVSetup.kt @@ -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 @@ -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 @@ -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}") diff --git a/app/src/main/java/com/mickstarify/zooforzotero/PreferenceManager.kt b/app/src/main/java/com/mickstarify/zooforzotero/PreferenceManager.kt index 3de9fe85..d47c3e2d 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/PreferenceManager.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/PreferenceManager.kt @@ -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. */ diff --git a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Database.kt b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Database.kt index 033e58a5..2bce68e2 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Database.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Database.kt @@ -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 @@ -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. } } diff --git a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt index aae61031..a3cdf697 100644 --- a/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt +++ b/app/src/main/java/com/mickstarify/zooforzotero/ZoteroStorage/Database/Item.kt @@ -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. */ @@ -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 } \ No newline at end of file