Search in sources :

Example 1 with FileUtils

use of org.thoughtcrime.securesms.util.FileUtils in project Signal-Android by WhisperSystems.

the class DownloadLatestEmojiDataJob method clearOldEmojiData.

private static void clearOldEmojiData(@NonNull Context context, @Nullable EmojiFiles.Version newVersion) {
    EmojiFiles.Version version = EmojiFiles.Version.readVersion(context);
    final String currentDirectoryName;
    final String newVersionDirectoryName;
    if (version != null) {
        currentDirectoryName = version.getUuid().toString();
    } else {
        currentDirectoryName = "";
    }
    if (newVersion != null) {
        newVersionDirectoryName = newVersion.getUuid().toString();
    } else {
        newVersionDirectoryName = "";
    }
    File emojiDirectory = EmojiFiles.getBaseDirectory(context);
    File[] files = emojiDirectory.listFiles();
    if (files == null) {
        Log.d(TAG, "No emoji data to delete.");
        return;
    }
    Log.d(TAG, "Deleting old folders of emoji data");
    Stream.of(files).filter(File::isDirectory).filterNot(file -> file.getName().equals(currentDirectoryName)).filterNot(file -> file.getName().equals(newVersionDirectoryName)).forEach(FileUtils::deleteDirectory);
    EmojiPageCache.INSTANCE.clear();
    if (version != null) {
        SignalStore.emojiValues().clearJumboEmojiSheets(version.getVersion());
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Okio(okio.Okio) Arrays(java.util.Arrays) Hex(com.mobilecoin.lib.util.Hex) Stream(com.annimon.stream.Stream) Source(okio.Source) ScreenDensity(org.thoughtcrime.securesms.util.ScreenDensity) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) Uri(android.net.Uri) AutoDownloadEmojiConstraint(org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint) EmojiFiles(org.thoughtcrime.securesms.emoji.EmojiFiles) Sink(okio.Sink) Matcher(java.util.regex.Matcher) EmojiPageCache(org.thoughtcrime.securesms.emoji.EmojiPageCache) Response(okhttp3.Response) IntPair(com.annimon.stream.IntPair) FileUtils(org.thoughtcrime.securesms.util.FileUtils) EmojiJsonRequest(org.thoughtcrime.securesms.emoji.EmojiJsonRequest) EmojiSource(org.thoughtcrime.securesms.emoji.EmojiSource) ResponseBody(okhttp3.ResponseBody) JumboEmoji(org.thoughtcrime.securesms.emoji.JumboEmoji) OutputStream(java.io.OutputStream) EmojiData(org.thoughtcrime.securesms.emoji.EmojiData) EmojiImageRequest(org.thoughtcrime.securesms.emoji.EmojiImageRequest) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) IOException(java.io.IOException) UUID(java.util.UUID) File(java.io.File) EmojiDownloader(org.thoughtcrime.securesms.emoji.EmojiDownloader) EmojiPageModel(org.thoughtcrime.securesms.components.emoji.EmojiPageModel) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Job(org.thoughtcrime.securesms.jobmanager.Job) EmojiRemote(org.thoughtcrime.securesms.emoji.EmojiRemote) Pattern(java.util.regex.Pattern) FileUtils(org.thoughtcrime.securesms.util.FileUtils) File(java.io.File) EmojiFiles(org.thoughtcrime.securesms.emoji.EmojiFiles)

Aggregations

Context (android.content.Context)1 Uri (android.net.Uri)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 IntPair (com.annimon.stream.IntPair)1 Stream (com.annimon.stream.Stream)1 Hex (com.mobilecoin.lib.util.Hex)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Arrays (java.util.Arrays)1 List (java.util.List)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Response (okhttp3.Response)1 ResponseBody (okhttp3.ResponseBody)1 Okio (okio.Okio)1 Sink (okio.Sink)1