Skip to content

Commit

Permalink
NF: Move sync files to their own subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur-Milchior committed Dec 11, 2024
1 parent f93096a commit be10887
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 32 deletions.
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ import com.ichi2.anki.servicelayer.ScopedStorageService
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
import com.ichi2.anki.snackbar.SnackbarBuilder
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.SyncActionProvider
import com.ichi2.anki.sync.SyncCompletion
import com.ichi2.anki.sync.SyncCompletionListener
import com.ichi2.anki.sync.SyncHandler
import com.ichi2.anki.sync.SyncHandlerDelegate
import com.ichi2.anki.ui.windows.reviewer.ReviewerFragment
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
import com.ichi2.anki.utils.ext.showDialogFragment
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.ichi2.anki.dialogs.DialogHandlerMessage
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.servicelayer.ScopedStorageService
import com.ichi2.anki.services.ReminderService
import com.ichi2.anki.sync.millisecondsSinceLastSync
import com.ichi2.anki.ui.windows.reviewer.ReviewerFragment
import com.ichi2.anki.worker.SyncWorker
import com.ichi2.annotations.NeedsTest
Expand Down
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/MyAccount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.dialogs.help.HelpDialog
import com.ichi2.anki.pages.RemoveAccountFragment
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.sync.cancelSync
import com.ichi2.anki.sync.getEndpoint
import com.ichi2.anki.sync.isLoggedIn
import com.ichi2.anki.sync.syncLogout
import com.ichi2.anki.sync.updateLogin
import com.ichi2.anki.utils.ext.removeFragmentFromContainer
import com.ichi2.anki.utils.ext.showDialogFragment
import com.ichi2.libanki.syncLogin
Expand Down
3 changes: 3 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ import com.ichi2.anki.scheduling.registerOnForgetHandler
import com.ichi2.anki.servicelayer.NoteService.isMarked
import com.ichi2.anki.servicelayer.NoteService.toggleMark
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.SyncActionProvider
import com.ichi2.anki.sync.SyncHandler
import com.ichi2.anki.sync.SyncHandlerDelegate
import com.ichi2.anki.ui.internationalization.toSentenceCase
import com.ichi2.anki.utils.ext.showDialogFragment
import com.ichi2.anki.utils.navBarNeedsScrim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.core.os.bundleOf
import androidx.fragment.app.commit
import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.isLoggedIn
import com.ichi2.annotations.NeedsTest
import com.ichi2.ui.AccessibleSearchView
import com.ichi2.utils.FileNameAndExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.CrashReportService
import com.ichi2.anki.DeckPicker
import com.ichi2.anki.R
import com.ichi2.anki.isLoggedIn
import com.ichi2.anki.millisecondsSinceLastSync
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.servicelayer.ScopedStorageService.collectionWillBeMadeInaccessibleAfterUninstall
import com.ichi2.anki.servicelayer.ScopedStorageService.userIsPromptedToDeleteCollectionOnUninstall
import com.ichi2.anki.sync.isLoggedIn
import com.ichi2.anki.sync.millisecondsSinceLastSync
import com.ichi2.compat.CompatHelper.Companion.getPackageInfoCompat
import com.ichi2.compat.PackageInfoFlagsCompat
import com.ichi2.libanki.utils.TimeManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.BackupManager
import com.ichi2.anki.CollectionHelper
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.ConflictResolution
import com.ichi2.anki.DatabaseRestorationListener
import com.ichi2.anki.DeckPicker
import com.ichi2.anki.LocalizedUnambiguousBackupTimeFormatter
Expand All @@ -54,11 +53,12 @@ import com.ichi2.anki.dialogs.DatabaseErrorDialog.DatabaseErrorDialogType.DIALOG
import com.ichi2.anki.dialogs.DatabaseErrorDialog.DatabaseErrorDialogType.DIALOG_STORAGE_UNAVAILABLE_AFTER_UNINSTALL
import com.ichi2.anki.dialogs.DatabaseErrorDialog.DatabaseErrorDialogType.INCOMPATIBLE_DB_VERSION
import com.ichi2.anki.dialogs.ImportFileSelectionFragment.ImportOptions
import com.ichi2.anki.isLoggedIn
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.requireAnkiActivity
import com.ichi2.anki.servicelayer.DebugInfoService
import com.ichi2.anki.showImportDialog
import com.ichi2.anki.sync.ConflictResolution
import com.ichi2.anki.sync.isLoggedIn
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
import com.ichi2.libanki.Consts
import com.ichi2.libanki.utils.TimeManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.os.bundleOf
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.ConflictResolution
import com.ichi2.anki.DeckPicker
import com.ichi2.anki.R
import com.ichi2.anki.joinSyncMessages
import com.ichi2.anki.showError
import com.ichi2.anki.sync.ConflictResolution
import com.ichi2.anki.sync.joinSyncMessages
import com.ichi2.anki.utils.ext.dismissAllDialogFragments

class SyncErrorDialog : AsyncDialogFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.R
import com.ichi2.anki.SyncPreferences
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.SyncPreferences
import com.ichi2.preferences.VersatileTextPreference
import com.ichi2.utils.show
import okhttp3.HttpUrl.Companion.toHttpUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import com.google.android.material.snackbar.Snackbar
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.customSyncBase
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.customSyncBase
import com.ichi2.anki.utils.ext.sharedPrefs
import com.ichi2.utils.show

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/

package com.ichi2.anki
package com.ichi2.anki.sync

import android.content.Context
import android.content.SharedPreferences
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCallback
import androidx.core.content.edit
import anki.sync.SyncAuth
import com.ichi2.anki.AnkiDroidApp
import com.ichi2.anki.BackupManager
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.DeckPicker
import com.ichi2.anki.ProgressContext
import com.ichi2.anki.R
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.withProgress
import com.ichi2.anki.worker.SyncMediaWorker
import com.ichi2.libanki.MediaCheckResult
import com.ichi2.libanki.createBackup
Expand Down Expand Up @@ -117,10 +123,7 @@ suspend fun syncLogout(context: Context) {
* or even that the ankiweb account is still valid.
*/
fun isLoggedIn() =
AnkiDroidApp.instance
.sharedPrefs()
.getString(SyncPreferences.HKEY, "")!!
.isNotEmpty()
AnkiDroidApp.Companion.instance.sharedPrefs().getString(SyncPreferences.HKEY, "")!!.isNotEmpty()

fun millisecondsSinceLastSync(preferences: SharedPreferences) = TimeManager.time.intTimeMS() - preferences.getLong("lastSyncTime", 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ichi2.anki
package com.ichi2.anki.sync

import android.app.Activity
import android.content.Context
Expand All @@ -24,6 +24,8 @@ import android.view.View
import androidx.appcompat.widget.AppCompatImageButton
import androidx.core.view.isVisible
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.ichi2.anki.ActionProviderCompat
import com.ichi2.anki.R
import com.ichi2.compat.setTooltipTextCompat
import com.ichi2.ui.RtlCompliantActionProvider.Companion.unwrapContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/

package com.ichi2.anki
package com.ichi2.anki.sync

import android.app.Activity.RESULT_OK
import android.content.Intent
Expand All @@ -41,16 +41,28 @@ import anki.sync.SyncCollectionResponse
import anki.sync.SyncStatusResponse
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.AnkiDroidApp
import com.ichi2.anki.BackupManager
import com.ichi2.anki.Channel
import com.ichi2.anki.CollectionIntegrityStorageCheck
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.MyAccount
import com.ichi2.anki.ProgressContext
import com.ichi2.anki.R
import com.ichi2.anki.dialogs.AsyncDialogFragment
import com.ichi2.anki.dialogs.MediaCheckDialog
import com.ichi2.anki.dialogs.SyncErrorDialog
import com.ichi2.anki.dialogs.SyncErrorDialog.Companion.newInstance
import com.ichi2.anki.dialogs.SyncErrorDialog.SyncErrorDialogListener
import com.ichi2.anki.handleDatabaseCheck
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.servicelayer.checkMedia
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.withProgress
import com.ichi2.anki.worker.SyncMediaWorker
import com.ichi2.anki.worker.SyncWorker
import com.ichi2.anki.worker.UniqueWorkNames
Expand Down Expand Up @@ -336,7 +348,7 @@ class SyncHandler(
override fun integrityCheck() {
// #5852 - We were having issues with integrity checks where the users had run out of space.
// display a dialog box if we don't have the space
val status = CollectionIntegrityStorageCheck.createInstance(activity)
val status = CollectionIntegrityStorageCheck.Companion.createInstance(activity)
if (status.shouldWarnOnIntegrityCheck()) {
Timber.d("Displaying File Size confirmation")
AlertDialog.Builder(activity).show {
Expand Down Expand Up @@ -376,7 +388,7 @@ class SyncHandler(
return
}

MyAccount.checkNotificationPermission(activity, notificationPermissionLauncher)
MyAccount.Companion.checkNotificationPermission(activity, notificationPermissionLauncher)

/** Nested private function that makes the connection to
* the sync server and starts syncing the data */
Expand Down Expand Up @@ -547,7 +559,7 @@ class SyncHandler(
withCol {
try {
createBackup(
BackupManager.getBackupDirectoryFromCollection(path),
BackupManager.Companion.getBackupDirectoryFromCollection(path),
force = true,
waitForCompletion = true,
)
Expand Down Expand Up @@ -669,7 +681,7 @@ class SyncHandler(
syncMessage: String?,
) {
if (delegate.activityPaused()) {
val res = AnkiDroidApp.appResources
val res = AnkiDroidApp.Companion.appResources
activity.showSimpleNotification(
res.getString(R.string.app_name),
res.getString(messageResource),
Expand All @@ -679,7 +691,7 @@ class SyncHandler(
if (syncMessage.isNullOrEmpty()) {
activity.showSnackbar(messageResource)
} else {
val res = AnkiDroidApp.appResources
val res = AnkiDroidApp.Companion.appResources
activity.showSimpleMessageDialog(title = res.getString(messageResource), message = syncMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ import com.ichi2.anki.Flag
import com.ichi2.anki.NoteEditor
import com.ichi2.anki.R
import com.ichi2.anki.Reviewer.Companion.ENABLE_SYNC
import com.ichi2.anki.SyncActionProvider
import com.ichi2.anki.SyncHandler
import com.ichi2.anki.SyncHandlerDelegate
import com.ichi2.anki.cardviewer.CardMediaPlayer
import com.ichi2.anki.dialogs.MediaCheckDialog
import com.ichi2.anki.dialogs.SyncErrorDialog
Expand All @@ -64,6 +61,9 @@ import com.ichi2.anki.requireAnkiActivity
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
import com.ichi2.anki.snackbar.SnackbarBuilder
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.SyncActionProvider
import com.ichi2.anki.sync.SyncHandler
import com.ichi2.anki.sync.SyncHandlerDelegate
import com.ichi2.anki.utils.ext.collectIn
import com.ichi2.anki.utils.ext.collectLatestIn
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import anki.sync.syncAuth
import com.ichi2.anki.Channel
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.R
import com.ichi2.anki.cancelMediaSync
import com.ichi2.anki.notifications.NotificationId
import com.ichi2.anki.sync.cancelMediaSync
import com.ichi2.anki.utils.ext.trySetForeground
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay
Expand Down
6 changes: 3 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/worker/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.SyncPreferences
import com.ichi2.anki.cancelSync
import com.ichi2.anki.notifications.NotificationId
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.setLastSyncTimeToNow
import com.ichi2.anki.sync.SyncPreferences
import com.ichi2.anki.sync.cancelSync
import com.ichi2.anki.sync.setLastSyncTimeToNow
import com.ichi2.anki.utils.ext.trySetForeground
import com.ichi2.libanki.syncCollection
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.content.Context
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.ichi2.anki.R
import com.ichi2.anki.SyncActionProvider
import com.ichi2.anki.sync.SyncActionProvider
import timber.log.Timber

class BadgeDrawableBuilder(
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/layout/sync_progress_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".SyncActionProvider">
tools:context=".sync.SyncActionProvider">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/button"
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/menu-xlarge/deck_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:id="@+id/action_sync"
android:icon="@drawable/ic_sync"
android:title="@string/button_sync"
app:actionProviderClass="com.ichi2.anki.SyncActionProvider"
app:actionProviderClass="com.ichi2.anki.sync.SyncActionProvider"
app:showAsAction="always"/>
<item
android:id="@+id/action_deck_rename"
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/menu/deck_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:id="@+id/action_sync"
android:icon="@drawable/ic_sync"
android:title="@string/button_sync"
ankidroid:actionProviderClass="com.ichi2.anki.SyncActionProvider"
ankidroid:actionProviderClass="com.ichi2.anki.sync.SyncActionProvider"
ankidroid:showAsAction="always"/>
<item
android:id="@+id/action_undo"
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/menu/reviewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:id="@+id/action_sync"
android:icon="@drawable/ic_sync"
android:title="@string/button_sync"
ankidroid:actionProviderClass="com.ichi2.anki.SyncActionProvider"
ankidroid:actionProviderClass="com.ichi2.anki.sync.SyncActionProvider"
ankidroid:showAsAction="always"/>
<item
android:id="@+id/action_undo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario.launchActivityForResult
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.sync.SyncPreferences
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals
Expand Down

0 comments on commit be10887

Please sign in to comment.