mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added clear cache files menu in help
This commit is contained in:
parent
770e816468
commit
ace9e02133
7 changed files with 72 additions and 3 deletions
|
|
@ -228,6 +228,11 @@ class ContactsManager @UiThread constructor() {
|
|||
coreContext.contactsManager.notifyContactsListChanged()
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun areContactsAvailable(): Boolean {
|
||||
return nativeContactsLoaded || knownContactsAvatarsMap.isNotEmpty()
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun onNativeContactsLoaded() {
|
||||
nativeContactsLoaded = true
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.navGraphViewModels
|
||||
import kotlinx.coroutines.launch
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.HelpFragmentBinding
|
||||
|
|
@ -36,6 +38,7 @@ import org.linphone.ui.main.fragment.GenericFragment
|
|||
import org.linphone.ui.main.help.viewmodel.HelpViewModel
|
||||
import org.linphone.ui.main.history.model.ConfirmationDialogModel
|
||||
import org.linphone.utils.DialogUtils
|
||||
import org.linphone.utils.FileUtils
|
||||
|
||||
@UiThread
|
||||
class HelpFragment : GenericFragment() {
|
||||
|
|
@ -108,6 +111,17 @@ class HelpFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
binding.setClearCacheCLickListener {
|
||||
lifecycleScope.launch {
|
||||
Log.w("$TAG User requested we clear the cache folder, doing it")
|
||||
FileUtils.clearCacheDirectory()
|
||||
(requireActivity() as GenericActivity).showGreenToast(
|
||||
getString(R.string.help_cache_directory_cleared_toast_message),
|
||||
R.drawable.info
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.newVersionAvailableEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { pair ->
|
||||
val version = pair.first
|
||||
|
|
|
|||
|
|
@ -424,6 +424,7 @@ class FileUtils {
|
|||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
suspend fun clearExistingPlainFiles(path: String) {
|
||||
val dir = File(path)
|
||||
if (dir.exists()) {
|
||||
|
|
@ -436,6 +437,19 @@ class FileUtils {
|
|||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
suspend fun clearCacheDirectory() {
|
||||
val dir = coreContext.context.cacheDir
|
||||
var count = 0
|
||||
if (dir.exists()) {
|
||||
for (file in dir.listFiles().orEmpty()) {
|
||||
deleteFile(file.path)
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
Log.w("$TAG Deleted [$count] cache files")
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun countFilesInDirectory(path: String): Int {
|
||||
val dir = File(path)
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class ImageUtils {
|
|||
list.add(picture)
|
||||
}
|
||||
}
|
||||
if (list.isNotEmpty()) {
|
||||
if (list.isNotEmpty() && coreContext.contactsManager.areContactsAvailable()) {
|
||||
Log.i(
|
||||
"$TAG Found at [${list.size}] participant(s) with a picture for conversation [$id]($hash), creating avatar"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
<variable
|
||||
name="translateClickListener"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="clearCacheCLickListener"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="debugClickListener"
|
||||
type="View.OnClickListener" />
|
||||
|
|
@ -285,12 +288,41 @@
|
|||
android:drawableEnd="@drawable/caret_right"
|
||||
android:drawablePadding="8dp"
|
||||
app:drawableTint="?attr/color_main2_500"
|
||||
app:layout_constraintVertical_bias="0"
|
||||
app:layout_constraintTop_toBottomOf="@id/advanced_title"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/clear_cache_icon"
|
||||
app:layout_constraintStart_toEndOf="@id/debug_icon"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{clearCacheCLickListener}"
|
||||
android:id="@+id/clear_cache_icon"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:src="@drawable/file"
|
||||
app:tint="?attr/color_main1_500"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/clear_cache_title"
|
||||
app:layout_constraintTop_toTopOf="@id/clear_cache_title"
|
||||
app:layout_constraintBottom_toBottomOf="@id/clear_cache_title" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/header_style"
|
||||
android:onClick="@{clearCacheCLickListener}"
|
||||
android:id="@+id/clear_cache_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginBottom="@dimen/screen_bottom_margin"
|
||||
android:text="@string/help_clear_cache_directory"
|
||||
app:layout_constraintVertical_bias="0"
|
||||
app:layout_constraintTop_toBottomOf="@id/debug_title"
|
||||
app:layout_constraintStart_toEndOf="@id/clear_cache_icon"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
|
|
|||
|
|
@ -187,6 +187,8 @@
|
|||
<string name="help_error_checking_version_toast_message">Une erreur est survenue</string>
|
||||
<string name="help_dialog_update_available_title">Mise à jour disponible</string>
|
||||
<string name="help_dialog_update_available_message">Une nouvelle version %s est disponible. Voulez-vous mettre à jour ?</string>
|
||||
<string name="help_clear_cache_directory">Vider le dossier de cache</string>
|
||||
<string name="help_cache_directory_cleared_toast_message">Cache directory has been cleared</string>
|
||||
<string name="help_troubleshooting_title">Dépannage</string>
|
||||
<string name="help_troubleshooting_debug_title">Activer/désactiver les messages dans ADB</string>
|
||||
<string name="help_troubleshooting_debug_subtitle">Blah blah blah?</string> <!-- TODO -->
|
||||
|
|
|
|||
|
|
@ -222,6 +222,8 @@
|
|||
<string name="help_error_checking_version_toast_message">An error occurred while checking for update</string>
|
||||
<string name="help_dialog_update_available_title">Update available</string>
|
||||
<string name="help_dialog_update_available_message">A new version %s is available. Do you want to update?</string>
|
||||
<string name="help_clear_cache_directory">Clear cache directory</string>
|
||||
<string name="help_cache_directory_cleared_toast_message">Cache directory has been cleared</string>
|
||||
<string name="help_troubleshooting_title">Troubleshooting</string>
|
||||
<string name="help_troubleshooting_debug_title">Enable/disable printing logs in ADB</string>
|
||||
<string name="help_troubleshooting_debug_subtitle">Blah blah blah?</string> <!-- TODO -->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue