导航菜单

页面标题

页面副标题

Plus 12 v10.13.1.1 - ThemingActivity.java 源代码

正在查看: Plus 12 v10.13.1.1 应用的 ThemingActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.telegram.ui;

import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.SendMessagesHelper;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.INavigationLayout;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextColorCell;
import org.telegram.ui.Cells.TextDetailSettingsCell;
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Components.ColorSelectorDialog;
import org.telegram.ui.Components.EditTextBoldCursor;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.DocumentSelectActivity;

public class ThemingActivity extends BaseFragment {
    public int applyThemeRow;
    public int chatRow;
    public int chatsRow;
    public int contactsRow;
    public int convertThemesRow;
    public int currentAccount;
    public int dialogBGColorRow;
    public int dialogColorRow;
    public int dialogSection2Row;
    public int dialogSectionRow;
    public int dialogTextColorRow;
    public int drawerRow;
    public int generalSection2Row;
    public ListAdapter listAdapter;
    public ListView listView;
    public int profileRow;
    public int resetThemeRow;
    public boolean reseting;
    public int rowCount;
    public int saveThemeRow;
    public boolean saving;
    public int screensSection2Row;
    public int screensSectionRow;
    public int scrollToPosition;
    public int settingsRow;
    public boolean showPrefix;
    public int themeColorRow;
    public int themesSection2Row;
    public int themesSectionRow;
    public int usePlusThemeRow;

    public ThemingActivity(Bundle args) {
        super(args);
        this.reseting = false;
        this.saving = false;
        this.currentAccount = UserConfig.selectedAccount;
    }

    public boolean onFragmentCreate() {
        super.onFragmentCreate();
        this.rowCount = 0;
        int i = 0 + 1;
        this.rowCount = i;
        this.usePlusThemeRow = 0;
        int i2 = i + 1;
        this.rowCount = i2;
        this.generalSection2Row = i;
        int i3 = i2 + 1;
        this.rowCount = i3;
        this.themeColorRow = i2;
        int i4 = i3 + 1;
        this.rowCount = i4;
        this.screensSectionRow = i3;
        int i5 = i4 + 1;
        this.rowCount = i5;
        this.screensSection2Row = i4;
        int i6 = i5 + 1;
        this.rowCount = i6;
        this.chatsRow = i5;
        int i7 = i6 + 1;
        this.rowCount = i7;
        this.chatRow = i6;
        int i8 = i7 + 1;
        this.rowCount = i8;
        this.contactsRow = i7;
        int i9 = i8 + 1;
        this.rowCount = i9;
        this.drawerRow = i8;
        int i10 = i9 + 1;
        this.rowCount = i10;
        this.profileRow = i9;
        int i11 = i10 + 1;
        this.rowCount = i11;
        this.settingsRow = i10;
        int i12 = i11 + 1;
        this.rowCount = i12;
        this.dialogSectionRow = i11;
        int i13 = i12 + 1;
        this.rowCount = i13;
        this.dialogSection2Row = i12;
        int i14 = i13 + 1;
        this.rowCount = i14;
        this.dialogColorRow = i13;
        int i15 = i14 + 1;
        this.rowCount = i15;
        this.dialogBGColorRow = i14;
        int i16 = i15 + 1;
        this.rowCount = i16;
        this.dialogTextColorRow = i15;
        int i17 = i16 + 1;
        this.rowCount = i17;
        this.themesSectionRow = i16;
        int i18 = i17 + 1;
        this.rowCount = i18;
        this.themesSection2Row = i17;
        int i19 = i18 + 1;
        this.rowCount = i19;
        this.saveThemeRow = i18;
        int i20 = i19 + 1;
        this.rowCount = i20;
        this.applyThemeRow = i19;
        int i21 = i20 + 1;
        this.rowCount = i21;
        this.resetThemeRow = i20;
        if (BuildVars.BETA) {
            this.rowCount = i21 + 1;
        } else {
            i21 = -1;
        }
        this.convertThemesRow = i21;
        this.showPrefix = ApplicationLoader.applicationContext.getSharedPreferences("plusconfig", 0).getBoolean("showPrefix", true);
        Bundle bundle = ((BaseFragment) this).arguments;
        if (bundle != null) {
            this.scrollToPosition = bundle.getInt("scroll_to_position", 0);
        }
        return true;
    }

    public final void clickItem(final int position) {
        try {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    ThemingActivity.this.lambda$clickItem$1(position);
                }
            }, 300L);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public void lambda$clickItem$1(int i) {
        ListView listView = this.listView;
        listView.performItemClick(listView, i, listView.getItemIdAtPosition(i));
        View viewByPosition = getViewByPosition(i);
        if (viewByPosition == null || !(viewByPosition instanceof TextCheckCell)) {
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                ThemingActivity.this.lambda$clickItem$0();
            }
        }, 200L);
    }

    public void lambda$clickItem$0() {
        this.listAdapter.notifyDataSetChanged();
    }

    public final View getViewByPosition(int pos) {
        int firstVisiblePosition = this.listView.getFirstVisiblePosition();
        int childCount = (this.listView.getChildCount() + firstVisiblePosition) - 1;
        if (pos < firstVisiblePosition || pos > childCount) {
            return this.listView.getAdapter().getView(pos, null, this.listView);
        }
        return this.listView.getChildAt(pos - firstVisiblePosition);
    }

    public View createView(Context context) {
        int i;
        View view = ((BaseFragment) this).fragmentView;
        if (view == null) {
            ((BaseFragment) this).actionBar.setBackButtonImage(R.drawable.ic_ab_back);
            if (AndroidUtilities.isTablet()) {
                ((BaseFragment) this).actionBar.setOccupyStatusBar(false);
            }
            ((BaseFragment) this).actionBar.setTitle(LocaleController.getString("Theming", R.string.Theming));
            ((BaseFragment) this).actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
                @Override
                public void onItemClick(int id) {
                    if (id == -1) {
                        ThemingActivity.this.finishFragment();
                    }
                }
            });
            ((BaseFragment) this).actionBar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ThemingActivity.this.showPrefix = !r3.showPrefix;
                    ApplicationLoader.applicationContext.getSharedPreferences("plusconfig", 0).edit().putBoolean("showPrefix", ThemingActivity.this.showPrefix).apply();
                    if (ThemingActivity.this.listAdapter != null) {
                        ThemingActivity.this.listAdapter.notifyDataSetChanged();
                    }
                }
            });
            this.listAdapter = new ListAdapter(context);
            FrameLayout frameLayout = new FrameLayout(context);
            ((BaseFragment) this).fragmentView = frameLayout;
            FrameLayout frameLayout2 = frameLayout;
            ListView listView = new ListView(context);
            this.listView = listView;
            if (Theme.usePlusTheme) {
                listView.setBackgroundColor(Theme.prefBGColor);
            }
            this.listView.setDivider(null);
            this.listView.setDividerHeight(0);
            this.listView.setVerticalScrollBarEnabled(false);
            if (Theme.usePlusTheme) {
                AndroidUtilities.setListViewEdgeEffectColor(this.listView, Theme.prefActionbarColor);
            }
            frameLayout2.addView(this.listView);
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.listView.getLayoutParams();
            layoutParams.width = -1;
            layoutParams.height = -1;
            layoutParams.gravity = 48;
            this.listView.setLayoutParams(layoutParams);
            this.listView.setAdapter((android.widget.ListAdapter) this.listAdapter);
            int i2 = this.scrollToPosition;
            if (i2 > 0) {
                if (i2 == 1) {
                    i = this.generalSection2Row;
                } else {
                    i = this.dialogSection2Row;
                    i2 += 50;
                }
                int i3 = i + i2;
                this.listView.setSelection(i3);
                if (Theme.linkAndClick) {
                    clickItem(i3);
                }
            }
            this.listView.setOnItemClickListener(new AnonymousClass3());
            this.listView.setOnItemLongClickListener(new AnonymousClass4());
            frameLayout2.addView(((BaseFragment) this).actionBar);
        } else {
            ViewGroup viewGroup = (ViewGroup) view.getParent();
            if (viewGroup != null) {
                viewGroup.removeView(((BaseFragment) this).fragmentView);
            }
        }
        if (Theme.usePlusTheme) {
            updateTheme();
        }
        return ((BaseFragment) this).fragmentView;
    }

    public class AnonymousClass3 implements AdapterView.OnItemClickListener {
        public AnonymousClass3() {
        }

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0);
            int i2 = sharedPreferences.getInt("themeColor", -16738680);
            Theme.ThemeInfo themeInfo = null;
            if (i == ThemingActivity.this.themeColorRow) {
                if (ThemingActivity.this.getParentActivity() == null) {
                    return;
                }
                ((LayoutInflater) ThemingActivity.this.getParentActivity().getSystemService("layout_inflater")).inflate(R.layout.colordialog, (ViewGroup) null, false);
                new ColorSelectorDialog(ThemingActivity.this.getParentActivity(), new ColorSelectorDialog.OnColorChangedListener() {
                    public void colorChanged(int color) {
                        ThemingActivity.this.commitInt(color);
                        Theme.updateAllColors();
                        NotificationCenter.getInstance(ThemingActivity.this.currentAccount).postNotificationName(NotificationCenter.updateDialogsTheme, new Object[]{0});
                        if (((BaseFragment) ThemingActivity.this).parentLayout != null) {
                            ((BaseFragment) ThemingActivity.this).parentLayout.rebuildAllFragmentViews(false, false);
                        }
                    }
                }, i2, 0, 0, false).show();
                return;
            }
            if (i == ThemingActivity.this.dialogColorRow) {
                if (ThemingActivity.this.getParentActivity() == null) {
                    return;
                }
                ((LayoutInflater) ThemingActivity.this.getParentActivity().getSystemService("layout_inflater")).inflate(R.layout.colordialog, (ViewGroup) null, false);
                new ColorSelectorDialog(ThemingActivity.this.getParentActivity(), new ColorSelectorDialog.OnColorChangedListener() {
                    public void colorChanged(int color) {
                        Theme.dialogColor = color;
                        ThemingActivity.this.commitInt("dialogColor", color);
                        if (((BaseFragment) ThemingActivity.this).parentLayout != null) {
                            ((BaseFragment) ThemingActivity.this).parentLayout.rebuildAllFragmentViews(false, false);
                        }
                    }
                }, sharedPreferences.getInt("dialogColor", i2), 0, 0, false).show();
                return;
            }
            if (i == ThemingActivity.this.dialogTextColorRow) {
                if (ThemingActivity.this.getParentActivity() == null) {
                    return;
                }
                ((LayoutInflater) ThemingActivity.this.getParentActivity().getSystemService("layout_inflater")).inflate(R.layout.colordialog, (ViewGroup) null, false);
                new ColorSelectorDialog(ThemingActivity.this.getParentActivity(), new ColorSelectorDialog.OnColorChangedListener() {
                    public void colorChanged(int color) {
                        Theme.dialogTextColor = color;
                        ThemingActivity.this.commitInt("dialogTextColor", color);
                        if (((BaseFragment) ThemingActivity.this).parentLayout != null) {
                            ((BaseFragment) ThemingActivity.this).parentLayout.rebuildAllFragmentViews(false, false);
                        }
                    }
                }, sharedPreferences.getInt("dialogTextColor", -14540254), 0, 0, false).show();
                return;
            }
            if (i == ThemingActivity.this.dialogBGColorRow) {
                if (ThemingActivity.this.getParentActivity() == null) {
                    return;
                }
                ((LayoutInflater) ThemingActivity.this.getParentActivity().getSystemService("layout_inflater")).inflate(R.layout.colordialog, (ViewGroup) null, false);
                new ColorSelectorDialog(ThemingActivity.this.getParentActivity(), new ColorSelectorDialog.OnColorChangedListener() {
                    public void colorChanged(int color) {
                        Theme.dialogBGColor = color;
                        ThemingActivity.this.commitInt("dialogBGColor", color);
                        if (((BaseFragment) ThemingActivity.this).parentLayout != null) {
                            ((BaseFragment) ThemingActivity.this).parentLayout.rebuildAllFragmentViews(false, false);
                        }
                    }
                }, sharedPreferences.getInt("dialogBGColor", -1), 0, 0, false).show();
                return;
            }
            if (i == ThemingActivity.this.saveThemeRow) {
                File file = new File(Utilities.findPrefFolder(ThemingActivity.this.getParentActivity()), "theme.xml");
                if (!file.exists() || (file.exists() && file.length() < 100)) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(ThemingActivity.this.getParentActivity(), LocaleController.getString("SaveErrorMsg0", R.string.SaveErrorMsg0), 1).show();
                        }
                    });
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(ThemingActivity.this.getParentActivity());
                FrameLayout frameLayout = new FrameLayout(ThemingActivity.this.getParentActivity());
                final EditTextBoldCursor editTextBoldCursor = new EditTextBoldCursor(ThemingActivity.this.getParentActivity());
                frameLayout.addView((View) editTextBoldCursor, (ViewGroup.LayoutParams) LayoutHelper.createFrame(-1, -2.0f, 83, 20.0f, 10.0f, 20.0f, 10.0f));
                builder.setView(frameLayout);
                editTextBoldCursor.setHint(LocaleController.getString("EnterName", R.string.EnterName));
                editTextBoldCursor.setTextColor(Theme.usePlusTheme ? Theme.dialogTextColor : Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                AndroidUtilities.setCursorColor(editTextBoldCursor, Theme.usePlusTheme ? Theme.dialogTextColor : Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                editTextBoldCursor.setHintTextColor(Theme.usePlusTheme ? Theme.prefSummaryColor : Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                editTextBoldCursor.setBackgroundDrawable(Theme.createEditTextDrawable(ThemingActivity.this.getParentActivity(), false));
                if (Theme.usePlusTheme) {
                    editTextBoldCursor.getBackground().setColorFilter(Theme.dialogBGColor, PorterDuff.Mode.SRC_IN);
                }
                builder.setTitle(LocaleController.getString("SaveTheme", R.string.SaveTheme));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i3) {
                        if (ThemingActivity.this.saving) {
                            return;
                        }
                        final String obj = editTextBoldCursor.getText().toString();
                        if (obj.length() < 1) {
                            Toast.makeText(ThemingActivity.this.getParentActivity(), LocaleController.getString("NameTooShort", R.string.NameTooShort), 0).show();
                        } else {
                            ThemingActivity.this.saving = true;
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public void run() {
                                    ThemingActivity.this.saving = false;
                                    if (ThemingActivity.this.getParentActivity() != null) {
                                        AndroidUtilities.setStringPref(ThemingActivity.this.getParentActivity(), "themeName", obj);
                                        try {
                                            AndroidUtilities.setStringPref(ThemingActivity.this.getParentActivity(), "version", ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0).versionName);
                                        } catch (Exception e) {
                                            FileLog.e(e);
                                        }
                                        AndroidUtilities.setStringPref(ThemingActivity.this.getParentActivity(), "model", Build.MODEL + "/" + Build.VERSION.RELEASE);
                                        AndroidUtilities.setStringPref(ThemingActivity.this.getParentActivity(), "date", System.currentTimeMillis() + "");
                                        Utilities.savePreferencesToSD("/Themes", "theme.xml", obj + ".xml", true);
                                        Utilities.copyWallpaperToSD(ThemingActivity.this.getParentActivity(), obj, true);
                                    }
                                }
                            });
                        }
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                ThemingActivity.this.showDialog(builder.create());
                return;
            }
            if (i == ThemingActivity.this.applyThemeRow) {
                DocumentSelectActivity documentSelectActivity = new DocumentSelectActivity(false);
                documentSelectActivity.fileFilter = ".xml";
                documentSelectActivity.arrayFilter = new String[]{".xml"};
                documentSelectActivity.setDelegate(new AnonymousClass7());
                ThemingActivity.this.presentFragment(documentSelectActivity);
                return;
            }
            if (i == ThemingActivity.this.chatsRow) {
                ThemingActivity.this.presentFragment(new ThemingChatsActivity());
                return;
            }
            if (i == ThemingActivity.this.chatRow) {
                ThemingActivity.this.presentFragment(new ThemingChatActivity());
                return;
            }
            if (i == ThemingActivity.this.contactsRow) {
                ThemingActivity.this.presentFragment(new ThemingContactsActivity());
                return;
            }
            if (i == ThemingActivity.this.drawerRow) {
                ThemingActivity.this.presentFragment(new ThemingDrawerActivity());
                return;
            }
            if (i == ThemingActivity.this.profileRow) {
                ThemingActivity.this.presentFragment(new ThemingProfileActivity());
                return;
            }
            if (i == ThemingActivity.this.settingsRow) {
                ThemingActivity.this.presentFragment(new ThemingSettingsActivity());
                return;
            }
            if (i == ThemingActivity.this.resetThemeRow) {
                AlertDialog.Builder builder2 = new AlertDialog.Builder(ThemingActivity.this.getParentActivity());
                builder2.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
                builder2.setTitle(LocaleController.getString("ResetThemeSettings", R.string.ResetThemeSettings));
                builder2.setPositiveButton(LocaleController.getString("OK", R.string.OK), new AnonymousClass8());
                builder2.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (DialogInterface.OnClickListener) null);
                ThemingActivity.this.showDialog(builder2.create());
                return;
            }
            if (i == ThemingActivity.this.usePlusThemeRow) {
                boolean z = !Theme.usePlusTheme;
                Theme.usePlusTheme = z;
                Theme.setUsePlusThemeKey(z);
                if (view instanceof TextCheckCell) {
                    ((TextCheckCell) view).setChecked(Theme.usePlusTheme);
                }
                if (Theme.usePlusTheme) {
                    ThemingActivity.this.saveTGThemeAndApplyDefault();
                } else {
                    try {
                        SharedPreferences sharedPreferences2 = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0);
                        String string = sharedPreferences2.getString("prevTheme", sharedPreferences2.getString("theme", null));
                        if (string != null) {
                            themeInfo = Theme.getThemeList().get(string);
                        }
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    if (themeInfo == null) {
                        themeInfo = Theme.getDefaultTheme();
                    }
                    if (BuildVars.BETA) {
                        final String str = themeInfo.name;
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                if (ThemingActivity.this.getParentActivity() != null) {
                                    Toast.makeText(ThemingActivity.this.getParentActivity(), str, 0).show();
                                }
                            }
                        });
                    }
                    Theme.applyTheme(themeInfo);
                }
                Theme.applyPlusTheme(true);
                if (ThemingActivity.this.listView != null) {
                    ThemingActivity.this.listView.invalidateViews();
                }
                if (((BaseFragment) ThemingActivity.this).parentLayout != null) {
                    ((BaseFragment) ThemingActivity.this).parentLayout.rebuildAllFragmentViews(true, true);
                    return;
                }
                return;
            }
            if (i == ThemingActivity.this.convertThemesRow) {
                ThemingActivity.this.presentFragment(new ConvertThemesActivity());
            }
        }

        public class AnonymousClass7 implements DocumentSelectActivity.DocumentSelectActivityDelegate {
            @Override
            public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate) {
            }

            @Override
            public void startDocumentSelectActivity() {
            }

            @Override
            public void startMusicSelectActivity(BaseFragment baseFragment) {
                DocumentSelectActivity.DocumentSelectActivityDelegate.CC.$default$startMusicSelectActivity(this, baseFragment);
            }

            public AnonymousClass7() {
            }

            @Override
            public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files, String caption, boolean notify, int scheduleDate) {
                final String str = files.get(0);
                File file = new File(str);
                AlertDialog.Builder builder = new AlertDialog.Builder(ThemingActivity.this.getParentActivity());
                builder.setTitle(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile));
                builder.setMessage(file.getName());
                final String str2 = str.substring(0, str.lastIndexOf(".")) + "_wallpaper.jpg";
                final File file2 = new File(str2);
                if (file2.exists()) {
                    builder.setMessage(file.getName() + "\n" + file2.getName());
                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0);
                    if (sharedPreferences.getInt("selectedBackground", 1000001) == 1000001) {
                        SharedPreferences.Editor edit = sharedPreferences.edit();
                        edit.putInt("selectedBackground", 113);
                        edit.putInt("selectedColor", 0);
                        edit.commit();
                    }
                }
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                if (Utilities.loadPrefFromSD(ThemingActivity.this.getParentActivity(), str) == 4) {
                                    Utilities.applyWallpaper(str2);
                                    Theme.setPlusWallpaper(file2);
                                    Utilities.restartApp();
                                }
                            }
                        });
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (DialogInterface.OnClickListener) null);
                ThemingActivity.this.showDialog(builder.create());
            }
        }

        public class AnonymousClass8 implements DialogInterface.OnClickListener {
            public AnonymousClass8() {
            }

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (ThemingActivity.this.reseting) {
                    return;
                }
                Theme.setUsePlusThemeKey(true);
                ThemingActivity.this.saveTGThemeAndApplyDefault();
                ThemingActivity.this.reseting = true;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        ThemingActivity.this.reseting = false;
                        SharedPreferences.Editor edit = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0).edit();
                        edit.clear();
                        edit.apply();
                        SharedPreferences.Editor edit2 = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0).edit();
                        edit2.putInt("selectedBackground", 1000001);
                        edit2.putInt("selectedColor", 0);
                        edit2.apply();
                        File file = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
                        if (file.exists()) {
                            file.delete();
                        }
                        if (ThemingActivity.this.getParentActivity() != null) {
                            Toast.makeText(ThemingActivity.this.getParentActivity(), LocaleController.getString("ResetThemeToastText", R.string.ResetThemeToastText), 0).show();
                        }
                        Theme.updateAllColors();
                        if (ThemingActivity.this.listAdapter != null) {
                            ThemingActivity.this.listAdapter.notifyDataSetChanged();
                        }
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                if (((BaseFragment) ThemingActivity.this).parentLayout != null) {
                                    ((BaseFragment) ThemingActivity.this).parentLayout.rebuildAllFragmentViews(true, true);
                                }
                            }
                        }, 200L);
                        Toast.makeText(ThemingActivity.this.getParentActivity(), LocaleController.getString("AppWillRestart", R.string.AppWillRestart), 0).show();
                    }
                });
                AndroidUtilities.runOnUIThread(new Runnable(this) {
                    @Override
                    public void run() {
                        Utilities.restartApp();
                    }
                }, 1000L);
            }
        }
    }

    public class AnonymousClass4 implements AdapterView.OnItemLongClickListener {
        public AnonymousClass4() {
        }

        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (ThemingActivity.this.getParentActivity() == null) {
                return false;
            }
            final String obj = view.getTag() != null ? view.getTag().toString() : "";
            if (obj.contains("Color")) {
                AlertDialog.Builder builder = new AlertDialog.Builder(ThemingActivity.this.getParentActivity());
                ArrayList arrayList = new ArrayList();
                final ArrayList arrayList2 = new ArrayList();
                builder.setTitle(obj);
                arrayList.add(LocaleController.getString("CopyLink", R.string.CopyLink));
                arrayList2.add(0);
                arrayList.add(LocaleController.getString("ShareLink", R.string.ShareLink));
                arrayList2.add(2);
                arrayList.add(LocaleController.getString("Reset", R.string.Reset));
                arrayList2.add(1);
                final String prefix = ThemingActivity.this.getPrefix(i);
                builder.setItems((CharSequence[]) arrayList.toArray(new CharSequence[arrayList.size()]), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i2) {
                        int intValue = ((Integer) arrayList2.get(i2)).intValue();
                        final String format = String.format("https://t.me/thememods/%s", prefix);
                        if (intValue == 0) {
                            try {
                                ((ClipboardManager) ApplicationLoader.applicationContext.getSystemService("clipboard")).setPrimaryClip(ClipData.newPlainText("label", format));
                                AndroidUtilities.runOnUIThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (ThemingActivity.this.getParentActivity() != null) {
                                            Toast.makeText(ThemingActivity.this.getParentActivity(), format, 0).show();
                                        }
                                    }
                                });
                                return;
                            } catch (Exception e) {
                                FileLog.e(e);
                                return;
                            }
                        }
                        if (intValue == 1) {
                            ThemingActivity.this.resetPref(obj);
                            return;
                        }
                        if (intValue == 2) {
                            try {
                                Intent intent = new Intent("android.intent.action.SEND");
                                intent.setType("text/plain");
                                intent.putExtra("android.intent.extra.TEXT", format);
                                ThemingActivity.this.getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareLink", R.string.ShareLink)), 500);
                            } catch (Exception e2) {
                                FileLog.e(e2);
                            }
                        }
                    }
                });
                ThemingActivity.this.showDialog(builder.create());
            }
            return true;
        }
    }

    public final String getPrefix(int i) {
        if (i == this.themeColorRow) {
            return "0.1";
        }
        if (i == this.dialogColorRow) {
            return "0.2";
        }
        if (i == this.dialogBGColorRow) {
            return "0.3";
        }
        if (i != this.dialogTextColorRow) {
            return "0.";
        }
        return "0.4";
    }

    public final void saveTGThemeAndApplyDefault() {
        if (Theme.getCurrentTheme() != Theme.getDefaultTheme()) {
            SharedPreferences.Editor edit = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0).edit();
            edit.putString("prevTheme", Theme.getCurrentTheme().name);
            edit.apply();
            Theme.applyTheme(Theme.getDefaultTheme());
            Theme.setUsePlusThemeKey(true);
        }
    }

    public final void resetPref(String key) {
        SharedPreferences.Editor edit = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0).edit();
        edit.remove(key);
        edit.commit();
        Theme.updateMainColors();
        refreshTheme();
    }

    public final void commitInt(String key, int value) {
        SharedPreferences.Editor edit = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0).edit();
        edit.putInt(key, value);
        edit.commit();
        refreshTheme();
    }

    public final void commitInt(int i) {
        SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putInt("themeColor", i);
        AndroidUtilities.themeColor = i;
        edit.commit();
        Theme.updateAllColors();
        int darkColor = AndroidUtilities.setDarkColor(i, 21);
        edit.putInt("chatsHeaderColor", i);
        edit.putInt("chatsCountBGColor", i);
        edit.putInt("chatsChecksColor", i);
        edit.putInt("chatsMemberColor", darkColor);
        edit.putInt("chatsMediaColor", sharedPreferences.getInt("chatsMemberColor", darkColor));
        edit.putInt("chatsFloatingBGColor", i);
        edit.putInt("chatHeaderColor", i);
        edit.putInt("chatRBubbleColor", AndroidUtilities.getDefBubbleColor());
        edit.putInt("chatStatusColor", AndroidUtilities.setDarkColor(i, -64));
        edit.putInt("chatRTimeColor", darkColor);
        edit.putInt("chatEmojiViewTabColor", AndroidUtilities.setDarkColor(i, -21));
        edit.putInt("chatChecksColor", i);
        edit.putInt("chatSendIconColor", i);
        edit.putInt("chatMemberColor", darkColor);
        edit.putInt("chatForwardColor", darkColor);
        edit.putInt("contactsHeaderColor", i);
        edit.putInt("contactsOnlineColor", darkColor);
        edit.putInt("prefHeaderColor", i);
        edit.putInt("dialogColor", i);
        edit.commit();
        fixLayout();
        AndroidUtilities.themeColor = i;
        refreshTheme();
    }

    public final void refreshTheme() {
        if (!Theme.usePlusTheme) {
            Theme.usePlusTheme = true;
            SharedPreferences.Editor edit = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0).edit();
            edit.putBoolean("usePlusTheme", true);
            edit.commit();
        }
        Theme.applyPlusTheme();
        INavigationLayout iNavigationLayout = ((BaseFragment) this).parentLayout;
        if (iNavigationLayout != null) {
            iNavigationLayout.rebuildAllFragmentViews(false, false);
        }
        ListView listView = this.listView;
        if (listView != null) {
            listView.invalidateViews();
        }
    }

    public void onResume() {
        super.onResume();
        ListAdapter listAdapter = this.listAdapter;
        if (listAdapter != null) {
            listAdapter.notifyDataSetChanged();
        }
        fixLayout();
    }

    public final void updateTheme() {
        ((BaseFragment) this).actionBar.setTitleColor(Theme.prefActionbarTitleColor);
        ((BaseFragment) this).actionBar.setBackgroundColor(Theme.prefActionbarColor);
        Drawable drawable = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_back);
        drawable.setColorFilter(Theme.prefActionbarIconsColor, PorterDuff.Mode.MULTIPLY);
        ((BaseFragment) this).actionBar.setBackButtonDrawable(drawable);
        ((BaseFragment) this).actionBar.setItemsColor(Theme.prefActionbarIconsColor, false);
    }

    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        fixLayout();
    }

    public final void fixLayout() {
        View view = ((BaseFragment) this).fragmentView;
        if (view == null) {
            return;
        }
        view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                View view2 = ((BaseFragment) ThemingActivity.this).fragmentView;
                if (view2 == null) {
                    return false;
                }
                view2.getViewTreeObserver().removeOnPreDrawListener(this);
                return false;
            }
        });
        this.listView.setAdapter((android.widget.ListAdapter) this.listAdapter);
    }

    public class ListAdapter extends BaseAdapter {
        public Context mContext;

        @Override
        public boolean areAllItemsEnabled() {
            return false;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public int getViewTypeCount() {
            return 6;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }

        public ListAdapter(Context context) {
            this.mContext = context;
        }

        @Override
        public boolean isEnabled(int i) {
            return i == ThemingActivity.this.themeColorRow || i == ThemingActivity.this.dialogColorRow || i == ThemingActivity.this.chatsRow || i == ThemingActivity.this.chatRow || i == ThemingActivity.this.contactsRow || i == ThemingActivity.this.drawerRow || i == ThemingActivity.this.profileRow || i == ThemingActivity.this.settingsRow || i == ThemingActivity.this.resetThemeRow || i == ThemingActivity.this.saveThemeRow || i == ThemingActivity.this.applyThemeRow || i == ThemingActivity.this.usePlusThemeRow || i == ThemingActivity.this.convertThemesRow || i == ThemingActivity.this.dialogBGColorRow || i == ThemingActivity.this.dialogTextColorRow;
        }

        @Override
        public int getCount() {
            return ThemingActivity.this.rowCount;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            String str;
            int itemViewType = getItemViewType(i);
            if (ThemingActivity.this.showPrefix) {
                str = (i - ThemingActivity.this.screensSection2Row) + " ";
            } else {
                str = "";
            }
            if (itemViewType == 0) {
                if (view == null) {
                    view = new ShadowSectionCell(this.mContext);
                }
            } else if (itemViewType == 1) {
                if (view == null) {
                    view = new HeaderCell(this.mContext);
                }
                if (i == ThemingActivity.this.generalSection2Row) {
                    ((HeaderCell) view).setText(LocaleController.getString("General", R.string.General));
                } else if (i == ThemingActivity.this.screensSection2Row) {
                    ((HeaderCell) view).setText(LocaleController.getString("Screens", R.string.Screens));
                } else if (i == ThemingActivity.this.themesSection2Row) {
                    ((HeaderCell) view).setText(LocaleController.getString("Themes", R.string.Themes));
                } else if (i == ThemingActivity.this.dialogSection2Row) {
                    ((HeaderCell) view).setText(LocaleController.getString("Dialog", R.string.Dialog));
                }
            } else if (itemViewType == 2) {
                if (view == null) {
                    view = new TextSettingsCell(this.mContext);
                }
                TextSettingsCell textSettingsCell = (TextSettingsCell) view;
                if (i == ThemingActivity.this.chatsRow) {
                    textSettingsCell.setText(str + LocaleController.getString("MainScreen", R.string.MainScreen), true);
                } else if (i == ThemingActivity.this.chatRow) {
                    textSettingsCell.setText(str + LocaleController.getString("ChatScreen", R.string.ChatScreen), true);
                } else if (i == ThemingActivity.this.contactsRow) {
                    textSettingsCell.setText(str + LocaleController.getString("ContactsScreen", R.string.ContactsScreen), true);
                } else if (i == ThemingActivity.this.drawerRow) {
                    textSettingsCell.setText(str + LocaleController.getString("NavigationDrawer", R.string.NavigationDrawer), true);
                } else if (i == ThemingActivity.this.profileRow) {
                    textSettingsCell.setText(str + LocaleController.getString("ProfileScreen", R.string.ProfileScreen), true);
                } else if (i == ThemingActivity.this.settingsRow) {
                    textSettingsCell.setText(str + LocaleController.getString("SettingsScreen", R.string.SettingsScreen), false);
                }
            } else if (itemViewType == 3) {
                if (view == null) {
                    view = new TextDetailSettingsCell(this.mContext);
                }
                TextDetailSettingsCell textDetailSettingsCell = (TextDetailSettingsCell) view;
                if (i == ThemingActivity.this.saveThemeRow) {
                    textDetailSettingsCell.setMultilineDetail(true);
                    textDetailSettingsCell.setMultilineDetail(true);
                    String lowerCase = LocaleController.getString("SaveTheme", R.string.SaveTheme).toLowerCase();
                    if (lowerCase.length() > 0) {
                        lowerCase = String.valueOf(lowerCase.charAt(0)).toUpperCase() + ((Object) lowerCase.subSequence(1, lowerCase.length()));
                    }
                    textDetailSettingsCell.setTextAndValue(lowerCase, LocaleController.getString("SaveThemeSum", R.string.SaveThemeSum), true);
                } else if (i == ThemingActivity.this.applyThemeRow) {
                    textDetailSettingsCell.setMultilineDetail(true);
                    textDetailSettingsCell.setTextAndValue(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile), LocaleController.getString("ApplyThemeSum", R.string.ApplyThemeSum), true);
                } else if (i == ThemingActivity.this.resetThemeRow) {
                    textDetailSettingsCell.setMultilineDetail(true);
                    textDetailSettingsCell.setTextAndValue(LocaleController.getString("ResetThemeSettings", R.string.ResetThemeSettings), LocaleController.getString("ResetThemeSettingsSum", R.string.ResetThemeSettingsSum), false);
                } else if (i == ThemingActivity.this.convertThemesRow) {
                    textDetailSettingsCell.setMultilineDetail(true);
                    textDetailSettingsCell.setTextAndValue(LocaleController.getString("ConvertThemes", R.string.ConvertThemes), LocaleController.getString("ConvertThemesSum", R.string.ConvertThemesSum), false);
                }
            } else if (itemViewType == 4) {
                if (view == null) {
                    view = new TextColorCell(this.mContext);
                }
                TextColorCell textColorCell = (TextColorCell) view;
                SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0);
                int i2 = sharedPreferences.getInt("themeColor", -16738680);
                if (i == ThemingActivity.this.themeColorRow) {
                    textColorCell.setTag("themeColor");
                    textColorCell.setTextAndColor(LocaleController.getString("themeColor", R.string.themeColor), i2, false);
                } else if (i == ThemingActivity.this.dialogColorRow) {
                    textColorCell.setTag("dialogColor");
                    textColorCell.setTextAndColor(LocaleController.getString("DialogColor", R.string.DialogColor), sharedPreferences.getInt("dialogColor", i2), true);
                } else if (i == ThemingActivity.this.dialogTextColorRow) {
                    textColorCell.setTag("dialogTextColor");
                    textColorCell.setTextAndColor(LocaleController.getString("DialogTextColor", R.string.DialogTextColor), sharedPreferences.getInt("dialogTextColor", -14540254), false);
                } else if (i == ThemingActivity.this.dialogBGColorRow) {
                    textColorCell.setTag("dialogBGColor");
                    textColorCell.setTextAndColor(LocaleController.getString("DialogBGColor", R.string.DialogBGColor), sharedPreferences.getInt("dialogBGColor", -1), true);
                }
            } else if (itemViewType == 5) {
                if (view == null) {
                    view = new TextCheckCell(this.mContext);
                }
                TextCheckCell textCheckCell = (TextCheckCell) view;
                if (i == ThemingActivity.this.usePlusThemeRow) {
                    textCheckCell.setTag("usePlusTheme");
                    textCheckCell.setTextAndCheck(LocaleController.getString("UsePlusTheme", R.string.UsePlusTheme), Theme.usePlusTheme, false);
                }
            }
            if (view != null) {
                view.setBackgroundColor(Theme.usePlusTheme ? Theme.prefBGColor : Theme.getColor(Theme.key_windowBackgroundWhite));
            }
            return view;
        }

        @Override
        public int getItemViewType(int i) {
            if (i == ThemingActivity.this.screensSectionRow || i == ThemingActivity.this.themesSectionRow || i == ThemingActivity.this.dialogSectionRow) {
                return 0;
            }
            if (i == ThemingActivity.this.generalSection2Row || i == ThemingActivity.this.screensSection2Row || i == ThemingActivity.this.themesSection2Row || i == ThemingActivity.this.dialogSection2Row) {
                return 1;
            }
            if (i == ThemingActivity.this.chatsRow) {
                return 2;
            }
            if (i == ThemingActivity.this.resetThemeRow || i == ThemingActivity.this.saveThemeRow || i == ThemingActivity.this.applyThemeRow || i == ThemingActivity.this.convertThemesRow) {
                return 3;
            }
            if (i == ThemingActivity.this.themeColorRow || i == ThemingActivity.this.dialogColorRow || i == ThemingActivity.this.dialogTextColorRow || i == ThemingActivity.this.dialogBGColorRow) {
                return 4;
            }
            return i == ThemingActivity.this.usePlusThemeRow ? 5 : 2;
        }
    }
}