Kate Mobile v109.1版本的 MD5 值为:fcd76ded5f363ecbfac46035a4ed2a23

以下内容为反编译后的 PhotoViewerActrivity.java 源代码,内容仅作参考


package com.perm.kate;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.flurry.android.FlurryAgent;
import com.perm.kate.ContentLayout;
import com.perm.kate.PhotoViewerAdapter;
import com.perm.kate.api.Api;
import com.perm.kate.api.Photo;
import com.perm.kate.api.PhotoTag;
import com.perm.kate.api.User;
import com.perm.kate.db.DataHelper;
import com.perm.kate.imagezoom.ImageViewTouchBase;
import com.perm.kate.session.Callback;
import com.perm.kate.session.Session;
import com.perm.kate.theme.ColorTheme;
import com.perm.utils.SimpleListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class PhotoViewerActrivity extends BaseActivity implements ContentLayout.ViewChangeListener {
    private ImageButton btn_comments;
    private ImageButton btn_tags;
    private ContentLayout content_layout;
    private Photo currentPhoto;
    private FrameLayout fl_tags_placeholder;
    boolean high_quality;
    private int info_position_offset;
    private int info_total_count;
    boolean is_story;
    private ImageView iv_comments_marker;
    private ImageView iv_liked_marker;
    private ImageView iv_tags_marker;
    private LinearLayout ll_counters;
    private LinearLayout ll_placeholder_info;
    private LinearLayout ll_zoom_buttons;
    long owner_id;
    PhotoList photoList;
    private ArrayList photoTags;
    private PhotoViewerAdapter photo_viewer_adapter;
    private TextView tv_comments_count;
    private TextView tv_description;
    private TextView tv_likes_count;
    private TextView tv_tags_count;
    private final int REQUEST_PHOTO_EDIT = 12;
    private final int REQUEST_PHOTO_MOVE = 13;
    private ArrayList photos = new ArrayList();
    private boolean is_graffiti = false;
    private final View.OnClickListener zoom_leftListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PhotoViewerActrivity.this.setZoom(1);
        }
    };
    private final View.OnClickListener zoom_centerListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PhotoViewerActrivity.this.setZoom(0);
        }
    };
    private final View.OnClickListener zoom_rightListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PhotoViewerActrivity.this.setZoom(-1);
        }
    };
    private final PhotoViewerAdapter.OnPhotoZoomingListener zooming_listener = new PhotoViewerAdapter.OnPhotoZoomingListener() {
        @Override
        public void onPhotoZoomed(boolean z) {
            PhotoViewerActrivity.this.content_layout.is_zooming = z;
            PhotoViewerActrivity.this.hidePhotoTags();
            PhotoViewerActrivity.this.postRunShowPhotoTags();
        }

        @Override
        public void onSingleTap() {
            if (PhotoViewerActrivity.this.isPhotoClickEnabled()) {
                PhotoViewerActrivity.this.setShowHideInfoPanels();
            }
        }
    };
    private final Callback tag_callback = new Callback(this) {
        @Override
        public void error(Throwable th) {
            PhotoViewerActrivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(PhotoViewerActrivity.this, (int) R.string.toast_failed_to_get_phototag, 1).show();
                }
            });
        }

        @Override
        public void ready(Object obj) {
            if (obj != null) {
                ArrayList arrayList = (ArrayList) obj;
                if (arrayList.size() <= 0 || PhotoViewerActrivity.this.currentPhoto.pid != ((PhotoTag) arrayList.get(0)).pid) {
                    PhotoViewerActrivity.this.photoTags = null;
                } else {
                    PhotoViewerActrivity.this.photoTags = arrayList;
                }
            }
            PhotoViewerActrivity.this.showPhotoTagsUI();
        }
    };
    private int photoTagsState = 0;
    private final Handler handlerTimer = new Handler();
    private final Callback callback_like = new Callback(this) {
        @Override
        public void ready(Object obj) {
            KApplication.db.createOrUpdateWallLike(Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id), PhotoViewerActrivity.this.currentPhoto.pid, Long.parseLong(KApplication.session.getMid()), true, 1);
            if (PhotoViewerActrivity.this.currentPhoto.like_count != null) {
                KApplication.db.updatePhotoLikes(PhotoViewerActrivity.this.currentPhoto.pid, Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id), PhotoViewerActrivity.this.currentPhoto.like_count.intValue());
            }
        }
    };
    private final Callback callback_unlike = new Callback(this) {
        @Override
        public void ready(Object obj) {
            KApplication.db.createOrUpdateWallLike(Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id), PhotoViewerActrivity.this.currentPhoto.pid, Long.parseLong(KApplication.session.getMid()), false, 1);
            if (PhotoViewerActrivity.this.currentPhoto.like_count != null) {
                KApplication.db.updatePhotoLikes(PhotoViewerActrivity.this.currentPhoto.pid, Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id), PhotoViewerActrivity.this.currentPhoto.like_count.intValue());
            }
        }
    };
    private final View.OnClickListener likes_OnClickListerer = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (PhotoViewerActrivity.this.currentPhoto == null) {
                return;
            }
            if (PhotoViewerActrivity.this.currentPhoto.user_likes == null || !PhotoViewerActrivity.this.currentPhoto.user_likes.booleanValue()) {
                PhotoViewerActrivity.this.like();
            } else {
                PhotoViewerActrivity.this.unlike();
            }
            PhotoViewerActrivity.this.displayCounts();
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "like");
        }
    };
    private final View.OnLongClickListener likes_OnLongClickListerer = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "like_long");
            if (PhotoViewerActrivity.this.currentPhoto == null || PhotoViewerActrivity.this.currentPhoto.like_count == null || PhotoViewerActrivity.this.currentPhoto.like_count.intValue() <= 0) {
                return false;
            }
            PhotoViewerActrivity.this.wholikes();
            return true;
        }
    };
    private final View.OnClickListener details_OnClickListerer = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PhotoViewerActrivity.this.showPhotoDetailsActivity();
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "details");
        }
    };
    private final View.OnClickListener comments_OnClickListerer = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PhotoViewerActrivity.this.ShowCommentsActivity();
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "comments");
        }
    };
    private final View.OnLongClickListener comments_OnLongClickListerer = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "comments_long");
            if (PhotoViewerActrivity.this.currentPhoto == null || PhotoViewerActrivity.this.currentPhoto.can_comment == null || !PhotoViewerActrivity.this.currentPhoto.can_comment.booleanValue()) {
                return false;
            }
            PhotoViewerActrivity.this.ShowNewCommentActivity();
            return true;
        }
    };
    private final View.OnClickListener tags_OnClickListerer = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (PhotoViewerActrivity.this.currentPhoto != null && PhotoViewerActrivity.this.currentPhoto.tags_count != null && PhotoViewerActrivity.this.currentPhoto.tags_count.intValue() > 0) {
                PhotoViewerActrivity.this.OnPhotoTags();
            }
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "tags");
        }
    };
    private final View.OnClickListener share_OnClickListerer = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PhotoViewerActrivity.this.showShareDialog();
            Helper.reportItemClick(PhotoViewerActrivity.this.getClass().getSimpleName(), "share");
        }
    };
    private final Callback counters_callback = new Callback(this) {
        @Override
        public void error(Throwable th) {
            th.printStackTrace();
        }

        @Override
        public void ready(Object obj) {
            Iterator it = ((ArrayList) obj).iterator();
            while (it.hasNext()) {
                PhotoViewerActrivity.this.updatePhotoCounts((Photo) it.next());
            }
            PhotoViewerActrivity.this.displayCountsInUiThread(null);
        }
    };
    private final HashMap updated_counts = new HashMap();
    private final Callback photo_copy_callback = new Callback(this) {
        @Override
        public void ready(Object obj) {
            PhotoViewerActrivity.this.onSuccessPhotoCopy((Long) obj);
        }
    };
    private final Callback callback_delete = new Callback(this) {
        @Override
        public void ready(Object obj) {
            PhotoViewerActrivity.this.displayToast(R.string.toast_deleted_photo);
        }
    };

    public void OnPhotoTags() {
        int i = this.photoTagsState + 2;
        this.photoTagsState = i;
        if (i > 2) {
            this.photoTagsState = 0;
        }
        if (this.photoTagsState == 0) {
            hidePhotoTags();
        } else {
            showPhotoTags(true);
        }
    }

    private void SetAs() {
        try {
            File cacheFile = KApplication.getImageLoader().getCacheFile(this.currentPhoto.src_big);
            Uri.fromFile(cacheFile);
            File tempFile = getTempFile();
            copyFile(cacheFile, tempFile);
            Uri fromFile = Uri.fromFile(tempFile);
            if (Build.VERSION.SDK_INT >= 24) {
                fromFile = FileProvider.getUriForFile(this, "com.perm.kate.provider", tempFile);
            }
            Intent intent = new Intent("android.intent.action.ATTACH_DATA");
            intent.setDataAndType(fromFile, "image/jpg");
            intent.putExtra("mimeType", "image/jpg");
            startActivity(Intent.createChooser(intent, "Set As"));
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
        }
    }

    public void ShowCommentsActivity() {
        long j;
        Photo photo = this.currentPhoto;
        if (photo == null) {
            return;
        }
        String str = photo.owner_id;
        if (str != null) {
            j = Long.parseLong(str);
        } else {
            j = this.owner_id;
            if (j == 0) {
                j = 0;
            }
        }
        Helper.ShowComments(this.is_graffiti ? 1 : 0, Long.valueOf(this.currentPhoto.pid), j, this);
    }

    public void ShowNewCommentActivity() {
        Intent intent = new Intent();
        intent.setClass(this, NewCommentActivity.class);
        intent.putExtra("com.perm.kate.pid", String.valueOf(this.currentPhoto.pid));
        String str = this.currentPhoto.owner_id;
        if (str != null) {
            intent.putExtra("com.perm.kate.owner_id", str);
        }
        intent.putExtra("com.perm.kate.comment_type", this.is_graffiti ? 1 : 0);
        startActivity(intent);
    }

    public static boolean canDelete(Photo photo) {
        String str;
        String str2;
        try {
            long j = photo.pid;
            if (j == 0 || (str2 = photo.owner_id) == null || KApplication.db.fetchPhotoFull(j, Long.parseLong(str2)) == null) {
                return false;
            }
            long parseLong = Long.parseLong(photo.owner_id);
            if (parseLong < 0) {
                return true;
            }
            return parseLong == Long.parseLong(KApplication.session.getMid());
        } catch (Exception e) {
            if (photo != null) {
                str = "pid=" + photo.pid;
            } else {
                str = null;
            }
            Helper.reportError(e, str);
            return false;
        }
    }

    public static boolean canEdit(Photo photo) {
        String str;
        String str2;
        Photo fetchPhotoFull;
        try {
            long j = photo.pid;
            if (j == 0 || (str2 = photo.owner_id) == null || (fetchPhotoFull = KApplication.db.fetchPhotoFull(j, Long.parseLong(str2))) == null || fetchPhotoFull.aid == -6) {
                return false;
            }
            long parseLong = Long.parseLong(photo.owner_id);
            return parseLong < 0 || parseLong == Long.parseLong(KApplication.session.getMid());
        } catch (Exception e) {
            if (photo != null) {
                str = "pid=" + photo.pid;
            } else {
                str = null;
            }
            Helper.reportError(e, str);
            return false;
        }
    }

    private void changeInfoPanelsFlag() {
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        String str = defaultSharedPreferences.getString("key_info_panels", "1").equals("1") ? "0" : "1";
        SharedPreferences.Editor edit = defaultSharedPreferences.edit();
        edit.putString("key_info_panels", str);
        edit.apply();
    }

    private void checkPermissionAndSave() {
        if (PhotoSaver.isScopedStorage() || ContextCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
            savePhotoToSD();
        } else {
            ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 1);
        }
    }

    private void chooseSearchEngine() {
        final ArrayList arrayList = new ArrayList();
        arrayList.add(new MenuItemDetails("Yandex", 1));
        arrayList.add(new MenuItemDetails("Google", 0));
        arrayList.add(new MenuItemDetails("Bing", 2));
        AlertDialog create = new AlertDialog.Builder(this).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                int i2 = ((MenuItemDetails) arrayList.get(i)).code;
                if (i2 == 0) {
                    PhotoViewerActrivity.this.searchInGoogle();
                }
                if (i2 == 1) {
                    PhotoViewerActrivity.this.searchInYandex();
                }
                if (i2 == 2) {
                    PhotoViewerActrivity.this.searchInBing();
                }
            }
        }).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    private void clearPhotoTags() {
        this.fl_tags_placeholder.removeAllViews();
        ArrayList arrayList = this.photoTags;
        if (arrayList != null) {
            arrayList.clear();
        }
    }

    private void confirmDeletePhoto(final Photo photo) {
        AlertDialog create = new AlertDialog.Builder(this).setMessage(R.string.label_confirm_delete).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                PhotoViewerActrivity.this.deletePhoto(photo);
            }
        }).setNegativeButton(R.string.no, (DialogInterface.OnClickListener) null).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    public void copyDirectPhotoLink(int i) {
        String str;
        String str2;
        String str3;
        Helper.copyText((i != 1 || (str3 = this.currentPhoto.src_xbig) == null || str3.length() <= 0) ? (i != 2 || (str2 = this.currentPhoto.src_xxbig) == null || str2.length() <= 0) ? (i != 3 || (str = this.currentPhoto.src_xxxbig) == null || str.length() <= 0) ? this.currentPhoto.src_big : this.currentPhoto.src_xxxbig : this.currentPhoto.src_xxbig : this.currentPhoto.src_xbig, this);
    }

    public static void copyFile(File file, File file2) {
        FileInputStream fileInputStream = new FileInputStream(file);
        FileOutputStream fileOutputStream = new FileOutputStream(file2);
        Helper.CopyStream(fileInputStream, fileOutputStream);
        Helper.closeStream(fileInputStream);
        Helper.closeStream(fileOutputStream);
    }

    public void deletePhoto(final Photo photo) {
        final long parseLong = Long.parseLong(photo.owner_id);
        if (parseLong > 0) {
            KApplication.db.deletePhoto(parseLong, photo.pid);
        }
        new Thread() {
            @Override
            public void run() {
                KApplication.session.deletePhoto(Long.valueOf(parseLong), Long.valueOf(photo.pid), PhotoViewerActrivity.this.callback_delete, PhotoViewerActrivity.this);
            }
        }.start();
    }

    public void deletePhotoTag(final PhotoTag photoTag) {
        final Callback callback = new Callback(this) {
            @Override
            public void error(Throwable th) {
                super.error(th);
            }

            @Override
            public void ready(Object obj) {
                if (PhotoViewerActrivity.this.photoTags != null) {
                    PhotoViewerActrivity.this.photoTags.remove(photoTag);
                    PhotoViewerActrivity.this.currentPhoto.tags_count = Integer.valueOf(PhotoViewerActrivity.this.photoTags.size());
                }
                if (PhotoViewerActrivity.this.isFinishing()) {
                    return;
                }
                PhotoViewerActrivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (PhotoViewerActrivity.this.photoTagsState != 0) {
                            PhotoViewerActrivity.this.showPhotoTags(false);
                        }
                        PhotoViewerActrivity.this.displayCounts();
                    }
                });
            }
        };
        new Thread() {
            @Override
            public void run() {
                Session session = KApplication.session;
                PhotoTag photoTag2 = photoTag;
                session.removePhotoTag(photoTag2.owner_id, photoTag2.pid, photoTag2.tag_id, callback, PhotoViewerActrivity.this);
            }
        }.start();
    }

    public void describeForBlind() {
        Intent intent = new Intent(this, NewMessageActivity.class);
        intent.putExtra("com.perm.kate.user_id", String.valueOf(-185510846));
        String str = "photo" + this.currentPhoto.owner_id + "_" + this.currentPhoto.pid;
        if (!TextUtils.isEmpty(this.currentPhoto.access_key)) {
            str = str + "_" + this.currentPhoto.access_key;
        }
        intent.putExtra("com.perm.kate.photo_attachment", str);
        startActivity(intent);
        FlurryAgent.logEvent("DESCRIBE_PHOTO_HUMAN");
    }

    private void describeForBlindPrompt() {
        AlertDialog create = new AlertDialog.Builder(this).setTitle("Получить описание").setMessage("Возможность для людей с проблемами зрения получить описание фото. Работает благодаря боту Vision Bot https://vk.com/visiontest1").setPositiveButton("Отправить запрос боту", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                PhotoViewerActrivity.this.describeForBlind();
            }
        }).setNegativeButton(R.string.label_cancel, (DialogInterface.OnClickListener) null).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    public void displayCounts() {
        Photo photo = this.currentPhoto;
        if (photo == null || photo.pid == 0 || this.high_quality) {
            this.ll_counters.setVisibility(8);
            return;
        }
        Integer num = photo.like_count;
        if (num == null || num.intValue() <= 0) {
            this.tv_likes_count.setVisibility(8);
        } else {
            this.tv_likes_count.setText(String.valueOf(this.currentPhoto.like_count));
            this.tv_likes_count.setVisibility(0);
        }
        ImageView imageView = this.iv_liked_marker;
        Boolean bool = this.currentPhoto.user_likes;
        imageView.setColorFilter((bool == null || !bool.booleanValue()) ? -1 : ColorTheme.getColorTheme().getLikeColor());
        Integer num2 = this.currentPhoto.comments_count;
        if (num2 == null || num2.intValue() <= 0) {
            this.tv_comments_count.setVisibility(8);
            this.btn_comments.setEnabled(true);
            this.iv_comments_marker.setImageResource(R.drawable.footer_comments_icon);
        } else {
            this.tv_comments_count.setText(String.valueOf(this.currentPhoto.comments_count));
            this.tv_comments_count.setVisibility(0);
            this.btn_comments.setEnabled(true);
            this.iv_comments_marker.setImageResource(R.drawable.footer_comments_icon);
        }
        Integer num3 = this.currentPhoto.tags_count;
        if (num3 == null || num3.intValue() <= 0) {
            this.btn_tags.setEnabled(false);
            this.iv_tags_marker.setVisibility(8);
            this.tv_tags_count.setVisibility(8);
            return;
        }
        this.btn_tags.setEnabled(true);
        this.iv_tags_marker.setVisibility(0);
        this.tv_tags_count.setText(String.valueOf(this.currentPhoto.tags_count));
        this.tv_tags_count.setVisibility(0);
    }

    public void displayCountsInUiThread(Photo photo) {
        if (isFinishing()) {
            return;
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                PhotoViewerActrivity.this.displayCounts();
            }
        });
    }

    private void displayPhotoInfo() {
        String str;
        if (this.info_position_offset > 0 && this.info_total_count > 0) {
            str = (this.content_layout.getCurrentScreen() + this.info_position_offset + 1) + "/" + this.info_total_count;
        } else if (this.info_total_count > 0) {
            str = (this.content_layout.getCurrentScreen() + 1) + "/" + this.info_total_count;
        } else {
            str = (this.content_layout.getCurrentScreen() + 1) + "/" + this.content_layout.getScreenCount();
        }
        this.tv_description.setVisibility(0);
        if (this.content_layout.getScreenCount() == 1 && Helper.empty(this.currentPhoto.phototext)) {
            this.tv_description.setVisibility(8);
        } else if (this.content_layout.getScreenCount() == 1 && Helper.isNotEmpty(this.currentPhoto.phototext)) {
            this.tv_description.setText(this.currentPhoto.phototext);
        } else if (Helper.isNotEmpty(this.currentPhoto.phototext)) {
            this.tv_description.setText(str + " " + this.currentPhoto.phototext);
        } else {
            this.tv_description.setText(str);
        }
        findViewById(R.id.location).setVisibility(this.currentPhoto.lat == null ? 8 : 0);
        displayCounts();
        refreshCounts();
    }

    private boolean getInfoPanelsFlag() {
        return PreferenceManager.getDefaultSharedPreferences(this).getString("key_info_panels", "1").equals("1");
    }

    private void getPhotoTags() {
        new Thread() {
            @Override
            public void run() {
                KApplication.session.getPhotoTagsById(Long.valueOf(PhotoViewerActrivity.this.currentPhoto.pid), PhotoViewerActrivity.this.currentPhoto.owner_id != null ? Long.valueOf(Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id)) : null, PhotoViewerActrivity.this.tag_callback, PhotoViewerActrivity.this);
            }
        }.start();
    }

    private ArrayList getPhotosToRequest() {
        int indexOf = this.photos.indexOf(this.currentPhoto);
        ArrayList arrayList = new ArrayList(13);
        for (int i = indexOf - 4; i <= indexOf + 8; i++) {
            if (i >= 0 && i < this.photos.size()) {
                Photo photo = (Photo) this.photos.get(i);
                if (!this.updated_counts.containsKey(Long.valueOf(photo.pid))) {
                    arrayList.add(photo);
                }
            }
        }
        return arrayList;
    }

    public static File getTempFile() {
        return new File(KApplication.current.getExternalCacheDir(), "image.jpg");
    }

    public void hidePhotoTags() {
        if (this.fl_tags_placeholder.getChildCount() > 0) {
            this.fl_tags_placeholder.removeAllViews();
        }
    }

    public static boolean isBlind() {
        return ((AccessibilityManager) KApplication.current.getSystemService("accessibility")).isTouchExplorationEnabled();
    }

    public static boolean isGraffiti(String str) {
        if (str != null) {
            return str.startsWith("GRAF_") || str.startsWith("graffiti") || str.startsWith("stickers_") || str.startsWith("tg");
        }
        return false;
    }

    private boolean isMeOrFriend() {
        String str;
        String str2;
        Photo fetchPhotoFull;
        try {
            Photo photo = this.currentPhoto;
            long j = photo.pid;
            if (j == 0 || (str2 = photo.owner_id) == null || (fetchPhotoFull = KApplication.db.fetchPhotoFull(j, Long.parseLong(str2))) == null || fetchPhotoFull.aid < 0) {
                return false;
            }
            long parseLong = Long.parseLong(this.currentPhoto.owner_id);
            long parseLong2 = Long.parseLong(KApplication.session.getMid());
            if (parseLong != parseLong2) {
                if (!KApplication.db.isFriend(parseLong2, parseLong)) {
                    return false;
                }
            }
            return true;
        } catch (Exception e) {
            if (this.currentPhoto != null) {
                str = "pid=" + this.currentPhoto.pid;
            } else {
                str = null;
            }
            Helper.reportError(e, str);
            return false;
        }
    }

    public static boolean isMeizu() {
        try {
            String str = Build.MODEL;
            if (!str.equals("M040") && !str.equals("M353")) {
                if (!str.equals("M351")) {
                    return false;
                }
            }
            return true;
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }

    private boolean isMy(long j) {
        return Long.parseLong(KApplication.session.getMid()) == j;
    }

    public boolean isPhotoClickEnabled() {
        return PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key_photo_click", true);
    }

    public void lambda$onCreate$0(View view) {
        checkPermissionAndSave();
        Helper.reportItemClick(getClass().getSimpleName(), "save");
    }

    public void lambda$onCreate$1() {
        PhotoList photoList = this.photoList;
        if (photoList == null) {
            return;
        }
        this.photo_viewer_adapter.setPhotos(photoList.photos);
    }

    public void lambda$onCreate$2() {
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                PhotoViewerActrivity.this.lambda$onCreate$1();
            }
        });
    }

    public void like() {
        Photo photo = this.currentPhoto;
        if (photo.owner_id == null) {
            return;
        }
        photo.user_likes = Boolean.TRUE;
        Integer num = photo.like_count;
        if (num != null) {
            photo.like_count = Integer.valueOf(num.intValue() + 1);
        }
        new Thread() {
            @Override
            public void run() {
                KApplication.session.addLike(Long.valueOf(Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id)), Long.valueOf(PhotoViewerActrivity.this.currentPhoto.pid), "photo", PhotoViewerActrivity.this.currentPhoto.access_key, PhotoViewerActrivity.this.callback_like, PhotoViewerActrivity.this);
            }
        }.start();
    }

    private void makeMainProfilePhoto() {
        new Thread() {
            @Override
            public void run() {
                KApplication.session.makeMainProfilePhoto(Long.valueOf(PhotoViewerActrivity.this.currentPhoto.pid), new Callback(PhotoViewerActrivity.this) {
                    @Override
                    public void ready(Object obj) {
                        if (((Integer) obj).intValue() != 1) {
                            return;
                        }
                        PhotoViewerActrivity.this.displayToast(R.string.done);
                        User user = new User();
                        user.uid = Long.parseLong(KApplication.session.getMid());
                        user.photo_200 = PhotoViewerActrivity.this.currentPhoto.src_big;
                        KApplication.db.createOrUpdateUser(user, false);
                        ArrayList arrayList = new ArrayList();
                        arrayList.add(Long.valueOf(Long.parseLong(KApplication.session.getMid())));
                        Api.tag = "PVA";
                        KApplication.session.getProfiles(arrayList, null, "photo_200", null, new Callback(PhotoViewerActrivity.this) {
                            @Override
                            public void ready(Object obj2) {
                                KApplication.db.createOrUpdateUser((User) ((ArrayList) obj2).get(0), false);
                            }
                        }, PhotoViewerActrivity.this);
                    }
                }, PhotoViewerActrivity.this);
            }
        }.start();
    }

    private void moveToAlbum(final long j) {
        final Callback callback = new Callback(this) {
            @Override
            public void ready(Object obj) {
                Integer num = (Integer) obj;
                if (num == null || num.intValue() != 1) {
                    return;
                }
                DataHelper dataHelper = KApplication.db;
                long j2 = PhotoViewerActrivity.this.currentPhoto.aid;
                PhotoViewerActrivity photoViewerActrivity = PhotoViewerActrivity.this;
                dataHelper.deleteAlbumPhoto(j2, photoViewerActrivity.owner_id, photoViewerActrivity.currentPhoto.pid, Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id));
                PhotoViewerActrivity.this.currentPhoto.aid = j;
                KApplication.db.updatePhotoAlbumId(PhotoViewerActrivity.this.currentPhoto.pid, Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id), j);
                DataHelper dataHelper2 = KApplication.db;
                long j3 = PhotoViewerActrivity.this.currentPhoto.pid;
                long j4 = j;
                PhotoViewerActrivity photoViewerActrivity2 = PhotoViewerActrivity.this;
                dataHelper2.createAlbumPhoto(j3, j4, photoViewerActrivity2.owner_id, Long.parseLong(photoViewerActrivity2.currentPhoto.owner_id));
                PhotoViewerActrivity.this.displayToast(R.string.toast_success_photo_moved);
            }
        };
        new Thread() {
            @Override
            public void run() {
                KApplication.session.movePhoto(Long.valueOf(PhotoViewerActrivity.this.owner_id), j, PhotoViewerActrivity.this.currentPhoto.pid, callback, PhotoViewerActrivity.this);
            }
        }.start();
    }

    public void onClickByPhotoTag(PhotoTag photoTag) {
        long parseLong = Long.parseLong(KApplication.session.getMid());
        boolean z = true;
        if (photoTag.uid != parseLong && photoTag.placer_id != parseLong && photoTag.owner_id.longValue() != parseLong) {
            z = false;
        }
        if (z) {
            showPhotoTagDialog(photoTag);
        } else {
            openProfile(String.valueOf(photoTag.uid));
        }
    }

    public void onSuccessPhotoCopy(Long l) {
        if (l == null || isFinishing()) {
            return;
        }
        displayToast(R.string.toast_photo_saved_to_my_album);
    }

    private void openGroup(long j) {
        Intent intent = new Intent(this, GroupActivity.class);
        intent.putExtra("com.perm.kate.group_id", j * (-1));
        startActivity(intent);
    }

    private void openHighQuality() {
        Intent intent = new Intent();
        intent.setClass(this, PhotoViewerActrivity.class);
        ArrayList arrayList = new ArrayList();
        arrayList.add(this.currentPhoto);
        intent.putExtra("com.perm.kate.photos", arrayList);
        intent.putExtra("high_quality", true);
        startActivity(intent);
    }

    private void openPhotoOwner() {
        try {
            long parseLong = Helper.isNotEmpty(this.currentPhoto.user_id) ? Long.parseLong(this.currentPhoto.user_id) : 0L;
            if (parseLong == 100) {
                parseLong = 0;
            }
            if (parseLong == 0) {
                String str = this.currentPhoto.owner_id;
                parseLong = str != null ? Long.parseLong(str) : this.owner_id;
            }
            if (parseLong > 0) {
                openProfile(String.valueOf(parseLong));
            } else if (parseLong < 0) {
                openGroup(parseLong);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Helper.reportError(e);
        }
    }

    public void openProfile(String str) {
        if ("0".equals(str)) {
            return;
        }
        Intent intent = new Intent();
        intent.setClass(this, ProfileInfoActivity.class);
        intent.putExtra("com.perm.kate.user_id", str);
        startActivity(intent);
    }

    private void openSinglePhotoViewer() {
        Intent intent = new Intent();
        intent.setClass(this, SinglePhotoViewer.class);
        intent.putExtra("com.perm.kate.put_tag", true);
        intent.putExtra("com.perm.kate.photo", this.currentPhoto);
        startActivityForResult(intent, 1);
    }

    public void photoEdit() {
        Intent intent = new Intent();
        intent.setClass(this, PhotoEditActivity.class);
        intent.putExtra("com.perm.kate.pid", this.currentPhoto.pid);
        intent.putExtra("com.perm.kate.owner_id", this.currentPhoto.owner_id);
        startActivityForResult(intent, 12);
    }

    public String photosToParam(ArrayList arrayList) {
        Iterator it = arrayList.iterator();
        String str = "";
        while (it.hasNext()) {
            Photo photo = (Photo) it.next();
            if (!TextUtils.isEmpty(str)) {
                str = str + ",";
            }
            String str2 = str + photo.owner_id + "_" + photo.pid;
            if (TextUtils.isEmpty(photo.access_key)) {
                str = str2;
            } else {
                str = str2 + "_" + photo.access_key;
            }
        }
        return str;
    }

    public void postRunShowPhotoTags() {
        if (this.photoTagsState == 0) {
            return;
        }
        this.handlerTimer.postDelayed(new Runnable() {
            @Override
            public void run() {
                PhotoViewerActrivity.this.showPhotoTags(false);
            }
        }, 350L);
    }

    private void refreshCounts() {
        long j = this.currentPhoto.pid;
        if (j == 0 || this.is_story || this.updated_counts.containsKey(Long.valueOf(j))) {
            return;
        }
        final ArrayList photosToRequest = getPhotosToRequest();
        if (photosToRequest.size() == 0) {
            return;
        }
        new Thread() {
            @Override
            public void run() {
                String photosToParam = PhotoViewerActrivity.this.photosToParam(photosToRequest);
                if (KApplication.session == null) {
                    return;
                }
                long parseLong = Helper.isNotEmpty(PhotoViewerActrivity.this.currentPhoto.owner_id) ? Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id) : 0L;
                PhotoViewerActrivity photoViewerActrivity = PhotoViewerActrivity.this;
                KApplication.session.getPhotoCountsByIdWithExecute(photosToParam, photoViewerActrivity.owner_id < 0 || parseLong < 0, photoViewerActrivity.counters_callback, PhotoViewerActrivity.this);
            }
        }.start();
    }

    public void repostToGroup() {
        Intent intent = new Intent();
        intent.setClass(this, GroupsActivity2.class);
        intent.putExtra("com.perm.kate.select_group", true);
        startActivityForResult(intent, 11);
    }

    private void savePhotoToSD() {
        String str;
        int parseInt = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this).getString("key_size_saved_photo", "0"));
        if (parseInt != 4) {
            savePhotoToSD(parseInt);
            return;
        }
        String str2 = this.currentPhoto.src_xbig;
        if ((str2 == null || str2.equals("")) && ((str = this.currentPhoto.src_xxbig) == null || str.equals(""))) {
            savePhotoToSD(0);
        } else {
            selectPhotoSize(true);
        }
    }

    public void savePhotoToSD(int i) {
        PhotoSaver.savePhoto(getApplicationContext(), this.currentPhoto, i);
    }

    private void saveToMyAlbum() {
        new Thread() {
            @Override
            public void run() {
                KApplication.session.photoCopy(Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id), PhotoViewerActrivity.this.currentPhoto.pid, PhotoViewerActrivity.this.currentPhoto.access_key, PhotoViewerActrivity.this.photo_copy_callback, PhotoViewerActrivity.this);
            }
        }.start();
    }

    public void searchInBing() {
        try {
            String encode = URLEncoder.encode(this.currentPhoto.src_big, "utf-8");
            Helper.openUrlInBrowser("https://www.bing.com/images/search?view=detailv2&iss=sbi&q=imgurl:" + encode, this);
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
        }
    }

    public void searchInGoogle() {
        try {
            String encode = URLEncoder.encode(this.currentPhoto.src_big, "utf-8");
            Helper.openUrlInBrowser("http://www.google.com/searchbyimage?sbisrc=kate&image_url=" + encode, this);
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
        }
    }

    public void searchInYandex() {
        try {
            String encode = URLEncoder.encode(this.currentPhoto.src_big, "utf-8");
            Helper.openUrlInBrowser("https://yandex.ru/images/search?url=" + encode + "&rpt=imageview", this);
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
        }
    }

    public void selectPhotoSize(final boolean z) {
        int i;
        String str = this.currentPhoto.src_xxxbig;
        if (str == null || str.equals("")) {
            String str2 = this.currentPhoto.src_xxbig;
            i = (str2 == null || str2.equals("")) ? R.array.photo_size_values2 : R.array.photo_size_values1;
        } else {
            i = R.array.photo_size_values3;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.title_choose_photo_size);
        builder.setItems(i, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i2) {
                if (z) {
                    PhotoViewerActrivity.this.savePhotoToSD(i2);
                } else {
                    PhotoViewerActrivity.this.copyDirectPhotoLink(i2);
                }
            }
        });
        builder.create().show();
    }

    public void sendToFriend() {
        if (this.currentPhoto == null) {
            return;
        }
        KApplication.db.createOrUpdatePhoto(this.currentPhoto, Long.parseLong(KApplication.session.getMid()));
        String str = "photo" + this.currentPhoto.owner_id + "_" + this.currentPhoto.pid;
        if (!TextUtils.isEmpty(this.currentPhoto.access_key)) {
            str = str + "_" + this.currentPhoto.access_key;
        }
        Intent intent = new Intent();
        intent.setClass(this, MembersActivity.class);
        intent.putExtra("com.perm.kate.only_members", false);
        intent.putExtra("com.perm.kate.new_message", true);
        intent.putExtra("com.perm.kate.photo_attachment", str);
        startActivity(intent);
    }

    public void setShowHideInfoPanels() {
        changeInfoPanelsFlag();
        showHideInfoPanels();
    }

    public void setZoom(int i) {
        View findViewById = this.content_layout.getCurrentScreenView().findViewById(R.id.img_photo_view);
        if (findViewById instanceof ImageViewTouchBase) {
            ((ImageViewTouchBase) findViewById).setZoom(i);
        }
    }

    public void sharePhoto() {
        File cacheFile = KApplication.getImageLoader().getCacheFile(PhotoViewerAdapter.getPhotoUrl(this.currentPhoto, PhotoViewerAdapter.getQualityPreference()));
        Uri fromFile = Uri.fromFile(cacheFile);
        try {
            File tempFile = getTempFile();
            copyFile(cacheFile, tempFile);
            fromFile = Uri.fromFile(tempFile);
            cacheFile = tempFile;
        } catch (Throwable th) {
            Helper.reportError(th);
            th.printStackTrace();
        }
        if (Build.VERSION.SDK_INT >= 24) {
            fromFile = FileProvider.getUriForFile(this, "com.perm.kate.provider", cacheFile);
        }
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType("image/jpg");
        intent.putExtra("android.intent.extra.STREAM", fromFile);
        startActivity(Intent.createChooser(intent, null));
    }

    public void shareTo() {
        Photo photo = this.currentPhoto;
        if (photo == null) {
            return;
        }
        Helper.sharePhoto(photo.owner_id, String.valueOf(photo.pid), this);
    }

    public void showAlbums() {
        Intent intent = new Intent();
        intent.setClass(this, AlbumsActivity2.class);
        intent.putExtra("com.perm.kate.owner_id", this.owner_id);
        intent.putExtra("com.perm.kate.select_for_move", true);
        startActivityForResult(intent, 13);
    }

    private void showCopyPhotoLinkDialog() {
        final ArrayList arrayList = new ArrayList();
        arrayList.add(new MenuItemDetails((int) R.string.label_site_photo_link, 13));
        arrayList.add(new MenuItemDetails((int) R.string.label_direct_photo_link, 30));
        AlertDialog create = new AlertDialog.Builder(this).setTitle(R.string.label_copy_video_link).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    int i2 = ((MenuItemDetails) arrayList.get(i)).code;
                    if (i2 == 13) {
                        Helper.copyPhotoLink(PhotoViewerActrivity.this.currentPhoto, PhotoViewerActrivity.this, null);
                    } else if (i2 != 30) {
                    } else {
                        if ((PhotoViewerActrivity.this.currentPhoto.src_xbig != null && !PhotoViewerActrivity.this.currentPhoto.src_xbig.equals("")) || (PhotoViewerActrivity.this.currentPhoto.src_xxbig != null && !PhotoViewerActrivity.this.currentPhoto.src_xxbig.equals(""))) {
                            PhotoViewerActrivity.this.selectPhotoSize(false);
                            return;
                        }
                        PhotoViewerActrivity.this.copyDirectPhotoLink(0);
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                    Helper.reportError(th);
                }
            }
        }).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    private void showEditDialog() {
        long j = this.currentPhoto.aid;
        final boolean z = j == -15;
        boolean z2 = j == -7;
        CharSequence[] charSequenceArr = new CharSequence[(z || z2) ? 1 : 2];
        if (z) {
            charSequenceArr[0] = getText(R.string.label_move_to_album);
        } else {
            charSequenceArr[0] = getText(R.string.label_change_description);
            if (!z2) {
                charSequenceArr[1] = getText(R.string.label_move_to_album);
            }
        }
        AlertDialog create = new AlertDialog.Builder(this).setTitle(R.string.label_edit).setItems(charSequenceArr, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    if (i != 0) {
                        if (i != 1) {
                            return;
                        }
                        PhotoViewerActrivity.this.showAlbums();
                    } else if (z) {
                        PhotoViewerActrivity.this.showAlbums();
                    } else {
                        PhotoViewerActrivity.this.photoEdit();
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                    Helper.reportError(th);
                }
            }
        }).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    private void showHideInfoPanels() {
        boolean infoPanelsFlag = getInfoPanelsFlag();
        this.ll_counters.setVisibility((!infoPanelsFlag || this.is_story) ? 8 : 0);
        this.ll_placeholder_info.setVisibility(infoPanelsFlag ? 0 : 8);
    }

    public void showPhotoDetailsActivity() {
        Photo photo = this.currentPhoto;
        if (photo == null) {
            return;
        }
        if (photo.pid != 0) {
            KApplication.db.createOrUpdatePhoto(this.currentPhoto, Long.parseLong(KApplication.session.getMid()));
        }
        long parseLong = Helper.isNotEmpty(this.currentPhoto.user_id) ? Long.parseLong(this.currentPhoto.user_id) : 0L;
        if (parseLong == 100) {
            parseLong = 0;
        }
        if (parseLong == 0) {
            String str = this.currentPhoto.owner_id;
            parseLong = str != null ? Long.parseLong(str) : this.owner_id;
        }
        Intent intent = new Intent();
        intent.setClass(this, PhotoDetailsActivity.class);
        intent.putExtra("com.perm.kate.photo_owner_id", parseLong);
        intent.putExtra("com.perm.kate.photo_id", this.currentPhoto.pid);
        intent.putExtra("com.perm.kate.album_id", this.currentPhoto.aid);
        intent.putExtra("com.perm.kate.owner_id", this.currentPhoto.owner_id);
        startActivity(intent);
    }

    private void showPhotoTagDialog(final PhotoTag photoTag) {
        final ArrayList arrayList = new ArrayList();
        arrayList.add(new MenuItemDetails((int) R.string.label_open_profile, 0));
        arrayList.add(new MenuItemDetails((int) R.string.delete_tag, 1));
        AlertDialog create = new AlertDialog.Builder(this).setTitle(photoTag.tagged_name).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    int i2 = ((MenuItemDetails) arrayList.get(i)).code;
                    if (i2 == 0) {
                        PhotoViewerActrivity.this.openProfile(String.valueOf(photoTag.uid));
                    } else if (i2 == 1) {
                        PhotoViewerActrivity.this.deletePhotoTag(photoTag);
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                    Helper.reportError(th);
                }
            }
        }).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    public void showPhotoTags(boolean z) {
        ImageViewTouchBase imageViewTouchBase;
        PhotoViewerActrivity photoViewerActrivity = this;
        hidePhotoTags();
        if (photoViewerActrivity.photoTagsState == 0) {
            return;
        }
        ArrayList arrayList = photoViewerActrivity.photoTags;
        if (arrayList == null || arrayList.size() == 0 || photoViewerActrivity.currentPhoto.pid != ((PhotoTag) photoViewerActrivity.photoTags.get(0)).pid) {
            if (z) {
                getPhotoTags();
                return;
            }
            return;
        }
        ContentLayout contentLayout = photoViewerActrivity.content_layout;
        if (contentLayout == null || (imageViewTouchBase = (ImageViewTouchBase) contentLayout.getCurrentScreenView().findViewById(R.id.img_photo_view)) == null) {
            return;
        }
        imageViewTouchBase.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == 0) {
                    PhotoViewerActrivity.this.hidePhotoTags();
                    return false;
                } else if (motionEvent.getAction() == 1) {
                    PhotoViewerActrivity.this.postRunShowPhotoTags();
                    return false;
                } else {
                    return false;
                }
            }
        });
        Object[] values = imageViewTouchBase.getValues();
        double[] dArr = (double[]) values[0];
        if (dArr[0] == 0.0d || dArr[1] == 0.0d) {
            return;
        }
        double[] dArr2 = (double[]) values[1];
        float[] fArr = (float[]) values[2];
        double d = fArr[0];
        double d2 = dArr2[0];
        Double.isNaN(d);
        double d3 = (d * d2) / 100.0d;
        double d4 = fArr[4];
        double d5 = dArr2[1];
        Double.isNaN(d4);
        double d6 = (d4 * d5) / 100.0d;
        double d7 = fArr[2];
        double d8 = fArr[5];
        Iterator it = photoViewerActrivity.photoTags.iterator();
        while (it.hasNext()) {
            PhotoTag photoTag = (PhotoTag) it.next();
            double d9 = photoTag.x;
            Double.isNaN(d7);
            double d10 = d3;
            double d11 = d7 + (d9 * d3);
            double d12 = d7;
            double d13 = photoTag.y;
            Double.isNaN(d8);
            Iterator it2 = it;
            double d14 = d8 + (d13 * d6);
            double d15 = d8;
            int i = (int) ((photoTag.x2 - d9) * d10);
            int i2 = (int) ((photoTag.y2 - d13) * d6);
            if (d11 > dArr[0] || d11 < -50.0d || d14 > dArr[1] || d14 < -50.0d) {
                it = it2;
                d7 = d12;
                d3 = d10;
                d8 = d15;
                photoViewerActrivity = this;
            } else {
                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
                layoutParams.leftMargin = (int) d11;
                layoutParams.topMargin = (int) d14;
                View inflate = getLayoutInflater().inflate(R.layout.photo_tag_item, (ViewGroup) null);
                if (this.photoTagsState == 2) {
                    ((TextView) inflate.findViewById(R.id.tv_ph_tag_name)).setVisibility(0);
                    ((TextView) inflate.findViewById(R.id.tv_ph_tag_name)).setText(photoTag.tagged_name);
                    ((TextView) inflate.findViewById(R.id.tv_ph_tag_name)).setTag(photoTag);
                    ((TextView) inflate.findViewById(R.id.tv_ph_tag_name)).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            PhotoTag photoTag2 = (PhotoTag) view.getTag();
                            if (photoTag2 != null) {
                                PhotoViewerActrivity.this.onClickByPhotoTag(photoTag2);
                            }
                        }
                    });
                }
                ((ImageView) inflate.findViewById(R.id.iv_ph_tag_border)).setLayoutParams(new LinearLayout.LayoutParams(i, i2));
                this.fl_tags_placeholder.addView(inflate, layoutParams);
                photoViewerActrivity = this;
                it = it2;
                d7 = d12;
                d3 = d10;
                d8 = d15;
            }
        }
    }

    public void showPhotoTagsUI() {
        if (isFinishing()) {
            return;
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                PhotoViewerActrivity.this.showPhotoTags(false);
            }
        });
    }

    private void showPlaceholderInfo(int i) {
        this.ll_placeholder_info.setVisibility(i);
    }

    public void showShareDialog() {
        if (this.currentPhoto == null) {
            return;
        }
        final ArrayList arrayList = new ArrayList();
        arrayList.add(new MenuItemDetails((int) R.string.label_menu_send_to_friend, 10));
        if (this.currentPhoto.aid != -3) {
            arrayList.add(new MenuItemDetails((int) R.string.publish_desc, 25));
        }
        arrayList.add(new MenuItemDetails((int) R.string.publish_to_group, 37));
        arrayList.add(new MenuItemDetails((int) R.string.label_send_to, 22));
        arrayList.add(new MenuItemDetails((int) R.string.label_send_photo_to, 28));
        AlertDialog create = new AlertDialog.Builder(this).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    int i2 = ((MenuItemDetails) arrayList.get(i)).code;
                    if (i2 == 10) {
                        PhotoViewerActrivity.this.sendToFriend();
                    } else if (i2 == 22) {
                        PhotoViewerActrivity.this.shareTo();
                    } else if (i2 == 25) {
                        PhotoViewerActrivity.this.showWallPostForCurrentPhoto(0L);
                    } else if (i2 == 28) {
                        PhotoViewerActrivity.this.sharePhoto();
                    } else if (i2 == 37) {
                        PhotoViewerActrivity.this.repostToGroup();
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                    Helper.reportError(th);
                }
            }
        }).create();
        create.setCanceledOnTouchOutside(true);
        create.show();
    }

    public void showWallPostForCurrentPhoto(long j) {
        Intent intent = new Intent();
        intent.setClass(this, WallPostActivity.class);
        if (j != 0) {
            intent.putExtra("com.perm.kate.owner_id", j);
        }
        intent.putExtra("com.perm.kate.photo", this.currentPhoto);
        startActivity(intent);
    }

    private void showZoomButtons() {
        this.ll_zoom_buttons.setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key2_show_zoom_buttons", false) ? 0 : 8);
    }

    public void unlike() {
        Photo photo = this.currentPhoto;
        photo.user_likes = Boolean.FALSE;
        Integer num = photo.like_count;
        if (num != null) {
            photo.like_count = Integer.valueOf(num.intValue() - 1);
        }
        new Thread() {
            @Override
            public void run() {
                KApplication.session.deleteLike(Long.valueOf(Long.parseLong(PhotoViewerActrivity.this.currentPhoto.owner_id)), "photo", Long.valueOf(PhotoViewerActrivity.this.currentPhoto.pid), PhotoViewerActrivity.this.callback_unlike, PhotoViewerActrivity.this);
            }
        }.start();
    }

    public void updatePhotoCounts(Photo photo) {
        Iterator it = this.photos.iterator();
        while (it.hasNext()) {
            Photo photo2 = (Photo) it.next();
            long j = photo2.pid;
            long j2 = photo.pid;
            if (j == j2) {
                photo2.user_likes = photo.user_likes;
                photo2.like_count = photo.like_count;
                photo2.comments_count = photo.comments_count;
                photo2.can_comment = photo.can_comment;
                photo2.tags_count = photo.tags_count;
                photo2.user_id = photo.user_id;
                this.updated_counts.put(Long.valueOf(j2), Boolean.TRUE);
                return;
            }
        }
    }

    public void wholikes() {
        Intent intent = new Intent();
        intent.setClass(this, LikesActivity.class);
        intent.putExtra("com.perm.kate.item_id", this.currentPhoto.pid);
        intent.putExtra("com.perm.kate.owner_id", Long.parseLong(this.currentPhoto.owner_id));
        intent.putExtra("com.perm.kate.item_type", "photo");
        startActivity(intent);
    }

    @Override
    protected boolean fillMenuItems(Menu menu) {
        Photo photo = this.currentPhoto;
        if (photo == null) {
            return false;
        }
        if (photo.pid != 0) {
            menu.add(0, 8, 1001, R.string.who_likes);
        }
        menu.add(0, 3, 1009, R.string.label_save).setIcon(17301582);
        if (this.currentPhoto.pid != 0) {
            menu.add(0, 26, 1011, R.string.label_share).setIcon(17301584);
        }
        if (isMeOrFriend()) {
            menu.add(0, 11, 10015, R.string.label_menu_put_tag);
        }
        if (canEdit(this.currentPhoto)) {
            menu.add(0, 12, 10017, R.string.label_edit);
        }
        if (this.currentPhoto.pid != 0) {
            menu.add(0, 13, 10019, R.string.label_copy_video_link);
            menu.add(0, 14, 10021, R.string.label_photo_owner);
            menu.add(0, 27, 10022, R.string.title_photo_info);
        }
        String str = this.currentPhoto.owner_id;
        if (str != null && isMy(Long.parseLong(str)) && this.currentPhoto.aid == -6) {
            menu.add(0, 35, 10023, R.string.make_profile_photo);
        }
        menu.add(0, 4, 10024, R.string.set_as).setIcon(17301585);
        if (!isPhotoClickEnabled()) {
            if (getInfoPanelsFlag()) {
                menu.add(0, 15, 10025, R.string.label_hide_info);
            } else {
                menu.add(0, 15, 10025, R.string.label_show_info);
            }
        }
        String str2 = this.currentPhoto.owner_id;
        if (str2 != null && !isMy(Long.parseLong(str2))) {
            menu.add(0, 24, 1027, R.string.label_save_to_my_album).setIcon(17301582);
        }
        if (canDelete(this.currentPhoto)) {
            menu.add(0, 29, 1029, R.string.delete).setIcon(17301564);
        }
        String str3 = this.currentPhoto.owner_id;
        if (str3 != null && !isMy(Long.parseLong(str3))) {
            menu.add(0, 34, 10033, R.string.label_complain_report);
        }
        menu.add(0, 38, 10043, R.string.search_in_google);
        if (!this.high_quality && this.currentPhoto.pid != 0) {
            menu.add(0, 39, 10053, R.string.original);
        }
        if (isBlind()) {
            menu.add(0, 40, 10053, "Получить описание");
            return true;
        }
        return true;
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 1 && i2 == -1 && this.photoTagsState > 0) {
            ArrayList arrayList = this.photoTags;
            if (arrayList != null) {
                arrayList.clear();
            }
            showPhotoTags(true);
        }
        if (i == 12 && i2 == -1) {
            this.currentPhoto.phototext = intent.getStringExtra("com.perm.kate.photo_caption");
            displayPhotoInfo();
        }
        if (i == 13 && i2 == -1) {
            long longExtra = intent.getLongExtra("com.perm.kate.aid", 0L);
            if (longExtra > 0) {
                moveToAlbum(longExtra);
            }
        }
        if (i == 11 && i2 == -1) {
            showWallPostForCurrentPhoto(intent.getLongExtra("group_id", 0L) * (-1));
        }
    }

    @Override
    public void onCreate(Bundle bundle) {
        if (Build.VERSION.SDK_INT >= 31) {
            this.no_wallpaper = true;
        }
        super.onCreate(bundle);
        try {
            if (!isMeizu()) {
                getWindow().setFlags(1024, 1024);
            }
            this.no_translucent_status = true;
            setContentView(R.layout.photo_viewer);
            setTitle(R.string.label_photo);
            this.content_layout = (ContentLayout) findViewById(R.id.image_layout);
            TextView textView = (TextView) findViewById(R.id.tv_description);
            this.tv_description = textView;
            textView.setOnClickListener(this.details_OnClickListerer);
            this.ll_placeholder_info = (LinearLayout) findViewById(R.id.ll_placeholder_info);
            this.ll_zoom_buttons = (LinearLayout) findViewById(R.id.ll_zoom_buttons);
            this.fl_tags_placeholder = (FrameLayout) findViewById(R.id.fl_tags_placeholder);
            ((ImageView) findViewById(R.id.iv_zoom_left)).setOnClickListener(this.zoom_leftListener);
            ((ImageView) findViewById(R.id.iv_zoom_center)).setOnClickListener(this.zoom_centerListener);
            ((ImageView) findViewById(R.id.iv_zoom_right)).setOnClickListener(this.zoom_rightListener);
            ImageButton imageButton = (ImageButton) findViewById(R.id.btn_likes);
            this.btn_comments = (ImageButton) findViewById(R.id.btn_comments);
            this.btn_tags = (ImageButton) findViewById(R.id.btn_tags);
            imageButton.setOnClickListener(this.likes_OnClickListerer);
            imageButton.setOnLongClickListener(this.likes_OnLongClickListerer);
            this.btn_comments.setOnClickListener(this.comments_OnClickListerer);
            this.btn_comments.setOnLongClickListener(this.comments_OnLongClickListerer);
            this.btn_tags.setOnClickListener(this.tags_OnClickListerer);
            findViewById(R.id.btn_share).setOnClickListener(this.share_OnClickListerer);
            if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("photo_save_button", false)) {
                findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public final void onClick(View view) {
                        PhotoViewerActrivity.this.lambda$onCreate$0(view);
                    }
                });
            } else {
                ((View) findViewById(R.id.save).getParent()).setVisibility(8);
            }
            this.tv_likes_count = (TextView) findViewById(R.id.tv_likes_count);
            this.tv_comments_count = (TextView) findViewById(R.id.tv_comments_count);
            this.tv_tags_count = (TextView) findViewById(R.id.tv_tags_count);
            this.iv_liked_marker = (ImageView) findViewById(R.id.iv_liked_marker);
            this.iv_comments_marker = (ImageView) findViewById(R.id.iv_comments_marker);
            this.iv_tags_marker = (ImageView) findViewById(R.id.iv_tags_marker);
            this.ll_counters = (LinearLayout) findViewById(R.id.ll_counters);
            findViewById(R.id.location).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (PhotoViewerActrivity.this.currentPhoto == null) {
                        return;
                    }
                    Helper.openMap(PhotoViewerActrivity.this.currentPhoto.lat, PhotoViewerActrivity.this.currentPhoto.lon, PhotoViewerActrivity.this);
                }
            });
            int intExtra = getIntent().getIntExtra("com.perm.kate.position", 0);
            this.high_quality = getIntent().getBooleanExtra("high_quality", false);
            if (bundle != null) {
                intExtra = bundle.getInt("position");
                if (bundle.getBoolean("panels_visible")) {
                    showPlaceholderInfo(0);
                }
            }
            this.owner_id = getIntent().getLongExtra("com.perm.kate.owner_id", 0L);
            if (getIntent().hasExtra("com.perm.kate.photos")) {
                this.photos = (ArrayList) getIntent().getSerializableExtra("com.perm.kate.photos");
            } else {
                PhotoList photoList = new PhotoList(this.owner_id, getIntent().getLongExtra("album_id", 0L), new SimpleListener() {
                    @Override
                    public final void call() {
                        PhotoViewerActrivity.this.lambda$onCreate$2();
                    }
                });
                this.photoList = photoList;
                photoList.fetchPhotos();
                PhotoList photoList2 = this.photoList;
                this.photos = photoList2.photos;
                photoList2.state = 0;
            }
            this.info_position_offset = getIntent().getIntExtra("com.perm.kate.info_position_offset", 0);
            this.info_total_count = getIntent().getIntExtra("com.perm.kate.info_total_count", 0);
            this.is_graffiti = getIntent().getBooleanExtra("com.perm.kate.is_graffiti", false);
            if (this.photos == null) {
                return;
            }
            PhotoViewerAdapter photoViewerAdapter = new PhotoViewerAdapter(this.photos, this);
            this.photo_viewer_adapter = photoViewerAdapter;
            if (this.high_quality) {
                photoViewerAdapter.setHighQuality();
            }
            this.photo_viewer_adapter.setOnZoomingListener(this.zooming_listener);
            this.content_layout.setAdapter(this.photo_viewer_adapter);
            this.content_layout.setCurrentScreen(intExtra);
            Photo photo = (Photo) this.photos.get(intExtra);
            this.currentPhoto = photo;
            String str = photo.src;
            boolean z = str != null && str.contains("story");
            this.is_story = z;
            if (!z) {
                setupMenuButton();
            }
            this.content_layout.setViewChangeListener(this);
            showPlaceholderInfo(0);
            showZoomButtons();
            showHideInfoPanels();
            displayPhotoInfo();
            if (this.photos.size() <= 0 || !isGraffiti(((Photo) this.photos.get(0)).phototext)) {
                Helper.fixNavBarColor(this, false);
                return;
            }
            findViewById(R.id.root).setBackgroundColor(-1);
            Helper.fixNavBarColor(this, true);
        } catch (Throwable th) {
            Helper.reportError(th);
            th.printStackTrace();
            if (th instanceof OutOfMemoryError) {
                KApplication.getImageLoader().clearMemoryCache();
            }
        }
    }

    @Override
    public void onDestroy() {
        PhotoViewerAdapter photoViewerAdapter = this.photo_viewer_adapter;
        if (photoViewerAdapter != null) {
            photoViewerAdapter.Destroy();
            this.photo_viewer_adapter = null;
        }
        ContentLayout contentLayout = this.content_layout;
        if (contentLayout != null) {
            contentLayout.setAdapter(null);
            this.content_layout.setViewChangeListener(null);
            this.content_layout = null;
        }
        PhotoList photoList = this.photoList;
        if (photoList != null) {
            photoList.listener = null;
        }
        this.photoList = null;
        super.onDestroy();
    }

    @Override
    public void onFinishedScroll(View view) {
        View currentScreenView = this.content_layout.getCurrentScreenView();
        if (currentScreenView == null) {
            return;
        }
        this.currentPhoto = (Photo) currentScreenView.getTag();
        displayPhotoInfo();
        clearPhotoTags();
        this.photoTagsState = 0;
        if (this.photoList == null || this.content_layout.getCurrentScreen() < this.photo_viewer_adapter.getCount() - 2) {
            return;
        }
        PhotoList photoList = this.photoList;
        if (photoList.state == 0) {
            photoList.loadMore(this);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 1) {
            ShowCommentsActivity();
            return true;
        } else if (itemId == 2) {
            ShowNewCommentActivity();
            return true;
        } else if (itemId == 3) {
            checkPermissionAndSave();
            return true;
        } else if (itemId == 4) {
            SetAs();
            return true;
        } else if (itemId == 24) {
            saveToMyAlbum();
            return true;
        } else if (itemId == 29) {
            confirmDeletePhoto(this.currentPhoto);
            return true;
        } else if (itemId == 26) {
            showShareDialog();
            return true;
        } else if (itemId == 27) {
            showPhotoDetailsActivity();
            return true;
        } else if (itemId == 34) {
            ReportHelper reportHelper = new ReportHelper(this);
            Photo photo = this.currentPhoto;
            reportHelper.showReportPhotoDialog(photo.pid, Long.parseLong(photo.owner_id));
            return true;
        } else if (itemId == 35) {
            makeMainProfilePhoto();
            return true;
        } else {
            switch (itemId) {
                case 6:
                    like();
                    return true;
                case 7:
                    unlike();
                    return true;
                case 8:
                    wholikes();
                    return true;
                case 9:
                    OnPhotoTags();
                    return true;
                default:
                    switch (itemId) {
                        case 11:
                            openSinglePhotoViewer();
                            return true;
                        case 12:
                            showEditDialog();
                            return true;
                        case 13:
                            showCopyPhotoLinkDialog();
                            return true;
                        case 14:
                            openPhotoOwner();
                            return true;
                        case 15:
                            setShowHideInfoPanels();
                            return true;
                        default:
                            switch (itemId) {
                                case 38:
                                    chooseSearchEngine();
                                    return true;
                                case 39:
                                    openHighQuality();
                                    return true;
                                case 40:
                                    describeForBlindPrompt();
                                    break;
                            }
                            return super.onOptionsItemSelected(menuItem);
                    }
            }
        }
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.clear();
        if (this.currentPhoto == null) {
            return super.onPrepareOptionsMenu(menu);
        }
        fillMenuItems(menu);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i == 1 && iArr.length > 0 && iArr[0] == 0) {
            savePhotoToSD();
        }
    }

    @Override
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        ContentLayout contentLayout = this.content_layout;
        if (contentLayout == null) {
            return;
        }
        bundle.putInt("position", contentLayout.getCurrentScreen());
        bundle.putBoolean("panels_visible", this.ll_placeholder_info.getVisibility() == 0);
    }

    @Override
    public void onScroll() {
        hidePhotoTags();
    }

    @Override
    public void onVerticalSwipe() {
        if (isFinishing()) {
            return;
        }
        finish();
    }
}