mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1451 App | Tech | Remove legacy related to 'Space debug' option on 'Profile' screen (#198)
This commit is contained in:
parent
5058a2b2ed
commit
9396ae88b0
9 changed files with 35 additions and 187 deletions
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -64,8 +64,22 @@ inline fun <T> List<T>.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))
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Job>()
|
||||
|
||||
val isDebugSpaceReportInProgress = MutableStateFlow(false)
|
||||
val isLoggingOut = MutableStateFlow(false)
|
||||
val debugSyncReportUri = MutableStateFlow<Uri?>(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 <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return ProfileViewModel(
|
||||
deleteAccount = deleteAccount,
|
||||
debugSpaceShareDownloader = debugSpaceShareDownloader,
|
||||
analytics = analytics,
|
||||
storelessSubscriptionContainer = storelessSubscriptionContainer,
|
||||
setObjectDetails = setObjectDetails,
|
||||
|
|
|
@ -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<DebugSpaceFileContentSaver.Params, File>(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"
|
||||
}
|
||||
}
|
|
@ -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<Unit, Uri>(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"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue