diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/settings/ProfileDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/settings/ProfileDI.kt index 805aacdf83..ed357c545d 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/settings/ProfileDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/settings/ProfileDI.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.di.feature.settings -import android.content.Context import com.anytypeio.anytype.analytics.base.Analytics import com.anytypeio.anytype.core_utils.di.scope.PerScreen import com.anytypeio.anytype.domain.account.DeleteAccount @@ -17,13 +16,8 @@ import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.`object`.SetObjectDetails import com.anytypeio.anytype.domain.search.SubscriptionEventChannel import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider -import com.anytypeio.anytype.presentation.util.downloader.UriFileProvider -import com.anytypeio.anytype.providers.DefaultUriFileProvider import com.anytypeio.anytype.ui.settings.ProfileFragment import com.anytypeio.anytype.ui_settings.account.ProfileViewModel -import com.anytypeio.anytype.ui_settings.account.repo.DebugSpaceFileContentSaver -import com.anytypeio.anytype.ui_settings.account.repo.DebugSpaceShareDownloader -import dagger.Binds import dagger.Module import dagger.Provides import dagger.Subcomponent @@ -49,7 +43,6 @@ object ProfileModule { @PerScreen fun provideViewModelFactory( deleteAccount: DeleteAccount, - debugSpaceShareDownloader: DebugSpaceShareDownloader, analytics: Analytics, storelessSubscriptionContainer: StorelessSubscriptionContainer, setObjectDetails: SetObjectDetails, @@ -59,7 +52,6 @@ object ProfileModule { spaceGradientProvider: SpaceGradientProvider ): ProfileViewModel.Factory = ProfileViewModel.Factory( deleteAccount = deleteAccount, - debugSpaceShareDownloader = debugSpaceShareDownloader, analytics = analytics, storelessSubscriptionContainer = storelessSubscriptionContainer, setObjectDetails = setObjectDetails, @@ -80,30 +72,6 @@ object ProfileModule { dispatchers: AppCoroutineDispatchers ): DebugSpace = DebugSpace(repo = repo, dispatchers = dispatchers) - @Provides - @PerScreen - fun provideFileSaver( - context: Context, - dispatchers: AppCoroutineDispatchers, - ): DebugSpaceFileContentSaver = DebugSpaceFileContentSaver( - context = context, - dispatchers = dispatchers - ) - - @Provides - @PerScreen - fun providesDebugSyncShareDownloader( - debugSpace: DebugSpace, - fileSaver: DebugSpaceFileContentSaver, - dispatchers: AppCoroutineDispatchers, - uriFileProvider: UriFileProvider - ): DebugSpaceShareDownloader = DebugSpaceShareDownloader( - debugSpace = debugSpace, - fileSaver = fileSaver, - dispatchers = dispatchers, - uriFileProvider = uriFileProvider - ) - @JvmStatic @PerScreen @Provides @@ -157,11 +125,6 @@ object ProfileModule { @Module interface Bindings { - - @PerScreen - @Binds - fun bindUriFileProvider( - defaultProvider: DefaultUriFileProvider - ): UriFileProvider + // Add bindings if needed } } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/ui/settings/MainSettingFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/settings/MainSettingFragment.kt index 7576839616..42446abde5 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/settings/MainSettingFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/settings/MainSettingFragment.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast import androidx.compose.material.MaterialTheme import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.core.os.bundleOf @@ -146,7 +147,13 @@ class MainSettingFragment : BaseBottomSheetComposeFragment() { safeNavigate(R.id.actionOpenFilesStorageScreen) } is Command.Toast -> { - toast(msg = command.msg) + toast( + msg = command.msg, + duration = if (command.isLongDuration) + Toast.LENGTH_LONG + else + Toast.LENGTH_SHORT + ) } is Command.ShareSpaceDebug -> { try { diff --git a/app/src/main/java/com/anytypeio/anytype/ui/settings/ProfileFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/settings/ProfileFragment.kt index eb91732c59..f8fbe577cd 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/settings/ProfileFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/settings/ProfileFragment.kt @@ -76,10 +76,7 @@ class ProfileFragment : BaseBottomSheetComposeFragment() { onKeychainPhraseClicked = onKeychainPhraseClicked, onDeleteAccountClicked = { throttle { proceedWithAccountDeletion() } }, onLogoutClicked = onLogoutClicked, - onSpaceDebugClicked = { throttle { vm.onSpaceDebugClicked() } }, isLogoutInProgress = vm.isLoggingOut.collectAsState().value, - isDebugSpaceReportInProgress = vm.isDebugSpaceReportInProgress.collectAsState().value, - isShowDebug = false, onNameChange = { vm.onNameChange(it) }, onProfileIconClick = { proceedWithIconClick() }, account = vm.profileData.collectAsStateWithLifecycle().value, diff --git a/core-utils/src/main/java/com/anytypeio/anytype/core_utils/ext/Extensions.kt b/core-utils/src/main/java/com/anytypeio/anytype/core_utils/ext/Extensions.kt index d3be54d454..077d5feebb 100644 --- a/core-utils/src/main/java/com/anytypeio/anytype/core_utils/ext/Extensions.kt +++ b/core-utils/src/main/java/com/anytypeio/anytype/core_utils/ext/Extensions.kt @@ -64,8 +64,22 @@ inline fun List.replace(replacement: (T) -> T, target: (T) -> Boolean): L return map { if (target(it)) replacement(it) else it } } -fun Context.toast(msg: CharSequence) = Toast.makeText(this, msg, Toast.LENGTH_SHORT).show() -fun Fragment.toast(msg: CharSequence) = requireActivity().toast(msg) +fun Context.toast( + msg: CharSequence, + duration: Int = Toast.LENGTH_SHORT +) = Toast.makeText( + this, + msg, + duration +).show() + +fun Fragment.toast( + msg: CharSequence, + duration: Int = Toast.LENGTH_SHORT +) = requireActivity().toast( + msg = msg, + duration = duration +) fun Fragment.toast(@StringRes msgId: Int) = requireActivity().toast(requireActivity().getString(msgId)) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/settings/MainSettingsViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/settings/MainSettingsViewModel.kt index db8f5b2456..662933fbef 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/settings/MainSettingsViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/settings/MainSettingsViewModel.kt @@ -120,6 +120,11 @@ class MainSettingsViewModel( .stream(Unit) .collect { result -> result.fold( + onLoading = { + commands.emit( + Command.Toast(SPACE_DEBUG_MSG, isLongDuration = true) + ) + }, onSuccess = { path -> commands.emit( Command.ShareSpaceDebug(path) @@ -232,7 +237,7 @@ class MainSettingsViewModel( object OpenDebugScreen : Command() class OpenSpaceImageSet(val id: Id) : Command() object OpenFilesStorageScreen : Command() - data class Toast(val msg: String) : Command() + data class Toast(val msg: String, val isLongDuration: Boolean = false) : Command() data class ShareSpaceDebug(val path: Filepath): Command() } @@ -253,6 +258,10 @@ class MainSettingsViewModel( val icon: ProfileIconView, ) } + + companion object { + const val SPACE_DEBUG_MSG = "Kindly share this debug logs with Anytype developers." + } } const val SPACE_STORAGE_SUBSCRIPTION_ID = "settings_space_storage_subscription" diff --git a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileScreen.kt b/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileScreen.kt index 426544e80f..39d0a066b4 100644 --- a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileScreen.kt +++ b/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileScreen.kt @@ -67,10 +67,7 @@ fun ProfileScreen( onKeychainPhraseClicked: () -> Unit, onDeleteAccountClicked: () -> Unit, onLogoutClicked: () -> Unit, - onSpaceDebugClicked: () -> Unit, isLogoutInProgress: Boolean, - isDebugSpaceReportInProgress: Boolean, - isShowDebug: Boolean, onNameChange: (String) -> Unit, onProfileIconClick: () -> Unit, account: ProfileViewModel.AccountProfile @@ -108,15 +105,6 @@ fun ProfileScreen( onClick = onLogoutClicked, isInProgress = isLogoutInProgress ) - Divider() - if (isShowDebug) { - ActionWithProgressBar( - name = stringResource(R.string.space_debug), - color = colorResource(R.color.text_primary), - onClick = onSpaceDebugClicked, - isInProgress = isDebugSpaceReportInProgress - ) - } Box(Modifier.height(54.dp)) } } diff --git a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileViewModel.kt b/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileViewModel.kt index 52bb94512f..962a926c3a 100644 --- a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileViewModel.kt +++ b/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/ProfileViewModel.kt @@ -23,11 +23,9 @@ import com.anytypeio.anytype.presentation.extension.sendScreenSettingsDeleteEven import com.anytypeio.anytype.presentation.profile.ProfileIconView import com.anytypeio.anytype.presentation.profile.profileIcon import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider -import com.anytypeio.anytype.ui_settings.account.repo.DebugSpaceShareDownloader import kotlinx.coroutines.Job import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -36,7 +34,6 @@ import timber.log.Timber class ProfileViewModel( private val analytics: Analytics, private val deleteAccount: DeleteAccount, - private val debugSpaceShareDownloader: DebugSpaceShareDownloader, private val storelessSubscriptionContainer: StorelessSubscriptionContainer, private val setObjectDetails: SetObjectDetails, private val configStorage: ConfigStorage, @@ -47,7 +44,6 @@ class ProfileViewModel( private val jobs = mutableListOf() - val isDebugSpaceReportInProgress = MutableStateFlow(false) val isLoggingOut = MutableStateFlow(false) val debugSyncReportUri = MutableStateFlow(null) @@ -114,26 +110,6 @@ class ProfileViewModel( } } - fun onSpaceDebugClicked() { - Timber.d("onDebugSyncReportClicked, ") - jobs += viewModelScope.launch { - debugSpaceShareDownloader.stream(Unit).collect { result -> - result.fold( - onSuccess = { report -> - isDebugSpaceReportInProgress.value = false - debugSyncReportUri.value = report - Timber.d(report.toString()) - }, - onLoading = { isDebugSpaceReportInProgress.value = true }, - onFailure = { e -> - isDebugSpaceReportInProgress.value = false - Timber.e(e, "Error while creating a debug sync report") - } - ) - } - } - } - fun onStop() { Timber.d("onStop, ") jobs.apply { @@ -179,7 +155,6 @@ class ProfileViewModel( class Factory( private val deleteAccount: DeleteAccount, - private val debugSpaceShareDownloader: DebugSpaceShareDownloader, private val analytics: Analytics, private val storelessSubscriptionContainer: StorelessSubscriptionContainer, private val setObjectDetails: SetObjectDetails, @@ -192,7 +167,6 @@ class ProfileViewModel( override fun create(modelClass: Class): T { return ProfileViewModel( deleteAccount = deleteAccount, - debugSpaceShareDownloader = debugSpaceShareDownloader, analytics = analytics, storelessSubscriptionContainer = storelessSubscriptionContainer, setObjectDetails = setObjectDetails, diff --git a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/repo/DebugSpaceFileContentSaver.kt b/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/repo/DebugSpaceFileContentSaver.kt deleted file mode 100644 index 1e5e8d4d79..0000000000 --- a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/repo/DebugSpaceFileContentSaver.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.anytypeio.anytype.ui_settings.account.repo - -import android.content.Context -import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers -import com.anytypeio.anytype.domain.base.ResultInteractor -import java.io.File -import java.io.FileOutputStream - -@Deprecated("To be deleted") -class DebugSpaceFileContentSaver( - private val context: Context, - dispatchers: AppCoroutineDispatchers, -) : ResultInteractor(dispatchers.io) { - - data class Params( - val content: String, - val filename: String, - val folderName: String = DEFAULT_FOLDER_NAME - ) - - override suspend fun doWork(params: Params): File { - val cacheDir = context.cacheDir - - require(cacheDir != null) { "Impossible to cache files!" } - - // Creating folder - - val downloadFolder = File("${cacheDir.path}/${params.folderName}/").apply { - mkdirs() - } - - val resultFilePath = "${cacheDir.path}/${params.folderName}/${params.filename}" - val resultFile = File(resultFilePath) - - // Writing content - - val tempFileFolderPath = "${downloadFolder.absolutePath}/${TEMP_FOLDER_NAME}" - val tempDir = File(tempFileFolderPath) - if (tempDir.exists()) tempDir.deleteRecursively() - tempDir.mkdirs() - - val tempResult = File(tempFileFolderPath, params.filename) - - FileOutputStream(tempResult).use { stream -> - stream.write(params.content.toByteArray()) - } - - tempResult.renameTo(resultFile) - - // Clearing - - tempDir.deleteRecursively() - - // Sending file - - return resultFile - } - - companion object { - const val DEFAULT_FOLDER_NAME = "debug_space" - const val TEMP_FOLDER_NAME = "tmp" - } -} \ No newline at end of file diff --git a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/repo/DebugSpaceShareDownloader.kt b/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/repo/DebugSpaceShareDownloader.kt deleted file mode 100644 index 3a9bd5c959..0000000000 --- a/ui-settings/src/main/java/com/anytypeio/anytype/ui_settings/account/repo/DebugSpaceShareDownloader.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.anytypeio.anytype.ui_settings.account.repo - -import android.net.Uri -import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers -import com.anytypeio.anytype.domain.base.ResultInteractor -import com.anytypeio.anytype.domain.debugging.DebugSpace -import com.anytypeio.anytype.presentation.util.downloader.UriFileProvider -import java.text.SimpleDateFormat -import java.util.Calendar -import java.util.Locale - -@Deprecated("To be deleted") -class DebugSpaceShareDownloader( - private val debugSpace: DebugSpace, - private val fileSaver: DebugSpaceFileContentSaver, - private val uriFileProvider: UriFileProvider, - dispatchers: AppCoroutineDispatchers, -) : ResultInteractor(dispatchers.io) { - - private fun getFileName(): String { - val date = Calendar.getInstance().time - val dateFormat = SimpleDateFormat(DATE_FORMAT, Locale.getDefault()) - val formattedDate = dateFormat.format(date) - return "DebugSpace$formattedDate.txt" - } - - override suspend fun doWork(params: Unit): Uri { - val content = debugSpace.run(Unit) - val file = fileSaver.run( - DebugSpaceFileContentSaver.Params( - content = content, - filename = getFileName() - ) - ) - return uriFileProvider.getUriForFile(file) - } - - companion object { - const val DATE_FORMAT = "dd-MM-yyyy-HH:mm:ss" - } -} \ No newline at end of file