package p000.p001.p002.p008.p009.p010;

import android.os.Build;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import androidx.lifecycle.LiveData;
import ar.tvplayer.core.data.prefs.ރ;
import ar.tvplayer.core.domain.ލ;
import ar.tvplayer.core.util.CommonUtilsKt;
import java.io.Closeable;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import kotlin.TypeCastException;
import p000.p001.p002.p008.C0915;
import p000.p001.p021.C1255;
import p025.p026.C1340;
import p025.p026.InterfaceC1327;
import p037.p041.p042.LayoutInflaterFactory2C1494;
import p037.p065.p068.C1850;
import p037.p099.AbstractC2245;
import p037.p099.C2229;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p329.p342.EnumC6159;
import p138.p329.p342.p343.C6175;
import p138.p329.p362.C6339;
import p138.p329.p362.p363.C6343;
import p138.p329.p362.p365.C6354;
import p138.p329.p362.p370.C6391;
import p138.p329.p362.p370.C6406;
import p138.p377.p378.p379.p384.C6443;
import p138.p377.p378.p379.p384.p385.C6446;
import p138.p377.p378.p379.p390.EnumC6466;
import p402.C6549;
import p402.InterfaceC6540;
import p402.p403.C6560;
import p402.p403.C6563;
import p402.p405.InterfaceC6575;
import p402.p405.p406.EnumC6586;
import p402.p405.p407.p408.AbstractC6597;
import p402.p405.p407.p408.InterfaceC6593;
import p402.p411.p412.InterfaceC6618;
import p402.p411.p413.C6635;
import p402.p420.C6703;

/* JADX INFO: renamed from: ނ.֏.֏.ހ.֏.ހ.ބ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C0769 extends AbstractC2245 {

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final LiveData<List<C0767>> f3285;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public List<C0767> f3286;

    /* JADX INFO: renamed from: ނ.֏.֏.ހ.֏.ހ.ބ$֏, reason: contains not printable characters */
    @InterfaceC6593(c = "ar.tvplayer.tv.base.ui.filepicker.FilePickerViewModel$listFiles$1", f = "FilePickerViewModel.kt", l = {}, m = "invokeSuspend")
    public static final class C0770 extends AbstractC6597 implements InterfaceC6618<InterfaceC1327, InterfaceC6575<? super C6549>, Object> {

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public InterfaceC1327 f3287;

        /* JADX INFO: renamed from: މ, reason: contains not printable characters */
        public final /* synthetic */ String f3289;

        /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
        public final /* synthetic */ boolean f3290;

        /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
        public final /* synthetic */ List f3291;

        /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
        public final /* synthetic */ boolean f3292;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C0770(String str, boolean z, List list, boolean z2, InterfaceC6575 interfaceC6575) {
            super(2, interfaceC6575);
            this.f3289 = str;
            this.f3290 = z;
            this.f3291 = list;
            this.f3292 = z2;
        }

        @Override // p402.p405.p407.p408.AbstractC6589
        /* JADX INFO: renamed from: ֏ */
        public final InterfaceC6575<C6549> mo837(Object obj, InterfaceC6575<?> interfaceC6575) {
            if (interfaceC6575 == null) {
                C6635.m9824("completion");
                throw null;
            }
            C0770 c0770 = C0769.this.new C0770(this.f3289, this.f3290, this.f3291, this.f3292, interfaceC6575);
            c0770.f3287 = (InterfaceC1327) obj;
            return c0770;
        }

        @Override // p402.p411.p412.InterfaceC6618
        /* JADX INFO: renamed from: ؠ */
        public final Object mo838(InterfaceC1327 interfaceC1327, InterfaceC6575<? super C6549> interfaceC6575) {
            return ((C0770) mo837(interfaceC1327, interfaceC6575)).mo839(C6549.f19328);
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference failed for: r3v11, types: [java.util.ArrayList] */
        /* JADX WARN: Type inference failed for: r3v12, types: [java.util.List<ނ.֏.֏.ހ.֏.ހ.ނ>] */
        /* JADX WARN: Type inference failed for: r3v22, types: [ގ.ފ.ޅ] */
        /* JADX WARN: Type inference failed for: r3v23, types: [java.util.ArrayList] */
        @Override // p402.p405.p407.p408.AbstractC6589
        /* JADX INFO: renamed from: ށ */
        public final Object mo839(Object obj) {
            List<C0767> listM9778;
            boolean z;
            ?? arrayList;
            List<StorageVolume> storageVolumes;
            EnumC6586 enumC6586 = EnumC6586.COROUTINE_SUSPENDED;
            C4303.m7198(obj);
            C0769 c0769 = C0769.this;
            String str = this.f3289;
            boolean z2 = this.f3290;
            List list = this.f3291;
            boolean z3 = this.f3292;
            C0767 c0767 = null;
            if (c0769 == null) {
                throw null;
            }
            if (str.length() == 0) {
                if (Build.VERSION.SDK_INT >= 24) {
                    StorageManager storageManager = (StorageManager) C1850.m3648(C1255.m2551(), StorageManager.class);
                    if (storageManager == null || (storageVolumes = storageManager.getStorageVolumes()) == null) {
                        arrayList = C6563.f19343;
                    } else {
                        arrayList = new ArrayList(C4303.m6985(storageVolumes, 10));
                        for (StorageVolume storageVolume : storageVolumes) {
                            String description = storageVolume.getDescription(C1255.m2551());
                            C6635.m9823((Object) description, "it.getDescription(appContext)");
                            C6635.m9823((Object) storageVolume, "it");
                            String str2 = CommonUtilsKt.֏(storageVolume);
                            if (str2 == null) {
                                str2 = "";
                            }
                            arrayList.add(new C0767(description, str2, true, true));
                        }
                    }
                } else {
                    arrayList = new ArrayList();
                    File[] externalFilesDirs = C1255.m2551().getExternalFilesDirs(null);
                    if (externalFilesDirs != null) {
                        for (File file : externalFilesDirs) {
                            if (file != null) {
                                String path = file.getPath();
                                C6635.m9823((Object) path, "it.path");
                                String strM9903 = C6703.m9903(path, "/Android/data/", (String) null, 2);
                                String string = C6703.m9881((CharSequence) strM9903, (CharSequence) "emulated", false, 2) ? C1255.m2551().getString(C0915.file_picker_storage) : C6703.m9892(strM9903, "/", (String) null, 2);
                                C6635.m9823((Object) string, "if (path.contains(\"emula…                        }");
                                arrayList.add(new C0767(string, strM9903, true, true));
                            }
                        }
                    }
                }
                c0769.f3286 = arrayList;
                if (z3) {
                    if (ރ.ߠ.ʺ().length() > 0) {
                        String strM2073 = c0769.m2073();
                        c0767 = new C0767(ރ.ߠ.ʰ().length() > 0 ? ރ.ߠ.ʰ() : strM2073, C2803.m4879("smb://", strM2073), true, true);
                    }
                    if (c0767 != null) {
                        ArrayList arrayList2 = new ArrayList(c0769.f3286);
                        arrayList2.add(c0767);
                        c0769.f3286 = arrayList2;
                    }
                }
                listM9778 = c0769.f3286;
            } else if (CommonUtilsKt.ރ(str)) {
                try {
                } catch (Exception unused) {
                    listM9778 = null;
                }
                if (c0769.m2072(str)) {
                    C6354 c6354M9559 = new C6339().m9559(c0769.m2073());
                    try {
                        String str3 = ރ.ߠ.ʶ();
                        String str4 = ރ.ߠ.ʲ();
                        if (str4 == null) {
                            throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
                        }
                        char[] charArray = str4.toCharArray();
                        C6635.m9823((Object) charArray, "(this as java.lang.String).toCharArray()");
                        List<C6446> listM9664 = new C6443(EnumC6466.SRVSVC.m9669(c6354M9559.m9576(new C6343(str3, charArray, "")))).m9664();
                        C6635.m9823((Object) listM9664, "ServerService(transport).shares1");
                        ArrayList<C6446> arrayList3 = new ArrayList();
                        for (Object obj2 : listM9664) {
                            C6446 c6446 = (C6446) obj2;
                            C6635.m9823((Object) c6446, "it");
                            if (c6446.f19063 == 0) {
                                arrayList3.add(obj2);
                            }
                        }
                        ArrayList arrayList4 = new ArrayList(C4303.m6985(arrayList3, 10));
                        for (C6446 c64462 : arrayList3) {
                            C6635.m9823((Object) c64462, "it");
                            String str5 = c64462.f19065;
                            C6635.m9823((Object) str5, "it.netName");
                            arrayList4.add(new C0767(str5, str + '/' + c64462.f19065, true, false));
                        }
                        C4303.m7088((Closeable) c6354M9559, (Throwable) null);
                        listM9778 = arrayList4;
                    } finally {
                    }
                } else {
                    C6354 c6354M95592 = new C6339().m9559(c0769.m2073());
                    try {
                        String str6 = ރ.ߠ.ʶ();
                        String str7 = ރ.ߠ.ʲ();
                        if (str7 == null) {
                            throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
                        }
                        char[] charArray2 = str7.toCharArray();
                        C6635.m9823((Object) charArray2, "(this as java.lang.String).toCharArray()");
                        C6406 c6406M9610 = c6354M95592.m9576(new C6343(str6, charArray2, "")).m9610(C6703.m9903(C6703.m9870(C6703.m9870(str, "://", (String) null, 2), "/", (String) null, 2), "/", (String) null, 2));
                        if (c6406M9610 == null) {
                            throw new TypeCastException("null cannot be cast to non-null type com.hierynomus.smbj.share.DiskShare");
                        }
                        C6391 c6391 = (C6391) c6406M9610;
                        try {
                            List<C6175> listM9618 = c6391.m9618(C6703.m9869(C6703.m9870(C6703.m9870(str, "://", (String) null, 2), "/", (String) null, 2), "/", ""), "*");
                            C6635.m9823((Object) listM9618, "share.list(path, \"*\")");
                            ArrayList<C6175> arrayList5 = new ArrayList();
                            for (Object obj3 : listM9618) {
                                C6175 c6175 = (C6175) obj3;
                                C6635.m9823((Object) c6175, "it");
                                if (!C4303.m7122(c6175.f17312, EnumC6159.FILE_ATTRIBUTE_HIDDEN) && (!C6635.m9825((Object) c6175.f17309, (Object) ".")) && (!C6635.m9825((Object) c6175.f17309, (Object) ".."))) {
                                    if (!C4303.m7122(c6175.f17312, EnumC6159.FILE_ATTRIBUTE_DIRECTORY)) {
                                        if (!z2) {
                                            String str8 = c6175.f17309;
                                            C6635.m9823((Object) str8, "it.fileName");
                                            if (ލ.֏(str8, list)) {
                                            }
                                        }
                                        z = false;
                                    }
                                    z = true;
                                } else {
                                    z = false;
                                }
                                if (z) {
                                    arrayList5.add(obj3);
                                }
                            }
                            ArrayList arrayList6 = new ArrayList(C4303.m6985(arrayList5, 10));
                            for (C6175 c61752 : arrayList5) {
                                C6635.m9823((Object) c61752, "it");
                                String str9 = c61752.f17309;
                                C6635.m9823((Object) str9, "it.fileName");
                                arrayList6.add(new C0767(str9, str + '/' + c61752.f17309, C4303.m7122(c61752.f17312, EnumC6159.FILE_ATTRIBUTE_DIRECTORY), false));
                            }
                            List<C0767> listM97782 = C6560.m9778((Iterable) arrayList6, (Comparator) C0771.f3293);
                            C4303.m7090((AutoCloseable) c6391, (Throwable) null);
                            C4303.m7088((Closeable) c6354M95592, (Throwable) null);
                            listM9778 = listM97782;
                        } finally {
                        }
                    } finally {
                        try {
                            throw th;
                        } finally {
                        }
                    }
                    listM9778 = null;
                }
            } else {
                File[] fileArrListFiles = new File(str).listFiles(new C0768(z2, list));
                if (fileArrListFiles == null) {
                    fileArrListFiles = new File[0];
                }
                ArrayList arrayList7 = new ArrayList(fileArrListFiles.length);
                for (File file2 : fileArrListFiles) {
                    C6635.m9823((Object) file2, "it");
                    String name = file2.getName();
                    C6635.m9823((Object) name, "it.name");
                    String path2 = file2.getPath();
                    C6635.m9823((Object) path2, "it.path");
                    arrayList7.add(new C0767(name, path2, file2.isDirectory(), false));
                }
                listM9778 = C6560.m9778((Iterable) arrayList7, (Comparator) C0771.f3293);
            }
            LiveData<List<C0767>> liveData = C0769.this.f3285;
            if (liveData == null) {
                throw new TypeCastException("null cannot be cast to non-null type androidx.lifecycle.MutableLiveData<kotlin.collections.List<ar.tvplayer.tv.base.ui.filepicker.FilePickerItem>?>");
            }
            ((C2229) liveData).mo341(listM9778);
            return C6549.f19328;
        }
    }

    public C0769(String str, boolean z, List<String> list, boolean z2) {
        if (str == null) {
            C6635.m9824("folderPath");
            throw null;
        }
        if (list == null) {
            C6635.m9824("fileExts");
            throw null;
        }
        this.f3285 = new C2229();
        this.f3286 = C6563.f19343;
        m2071(str, z, list, z2);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m2071(String str, boolean z, List<String> list, boolean z2) {
        if (str == null) {
            C6635.m9824("folderPath");
            throw null;
        }
        if (list != null) {
            C4303.m7160(LayoutInflaterFactory2C1494.C1505.m2925((AbstractC2245) this), C1340.f4488, null, new C0770(str, z, list, z2, null), 2, null);
        } else {
            C6635.m9824("fileExts");
            throw null;
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean m2072(String str) {
        if (str == null) {
            C6635.m9824("folderPath");
            throw null;
        }
        List<C0767> list = this.f3286;
        if ((list instanceof Collection) && list.isEmpty()) {
            return false;
        }
        Iterator<T> it = list.iterator();
        while (it.hasNext()) {
            if (C6635.m9825((Object) ((C0767) it.next()).f3280, (Object) str)) {
                return true;
            }
        }
        return false;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final String m2073() {
        return C6703.m9903(C6703.m9870(ރ.ߠ.ʺ(), "//", (String) null, 2), "/", (String) null, 2);
    }
}
