正在查看: 微商客 v2.1.2 应用的 PickerAlbumPreviewActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 微商客 v2.1.2 应用的 PickerAlbumPreviewActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.qiyukf.uikit.common.media.picker.activity;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.luck.picture.lib.config.FileSizeUnit;
import com.qiyukf.module.zip4j.util.InternalZipConstants;
import com.qiyukf.uikit.common.activity.BlackFragmentActivity;
import com.qiyukf.uikit.common.media.picker.a.b;
import com.qiyukf.uikit.common.media.picker.adapter.PickerPreviewPagerAdapter;
import com.qiyukf.uikit.common.media.picker.model.PhotoInfo;
import com.qiyukf.uikit.common.ui.imageview.BaseZoomableImageView;
import com.qiyukf.unicorn.R;
import com.qiyukf.unicorn.n.n;
import com.qiyukf.unicorn.n.r;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class PickerAlbumPreviewActivity extends BlackFragmentActivity implements View.OnClickListener, ViewPager.OnPageChangeListener {
public static final int RESULT_FROM_USER = 2;
private ViewPager imageViewPager;
private PickerPreviewPagerAdapter imageViewPagerAdapter;
private boolean isSendOriginalImage;
private boolean isSupportOriginal;
private int multiSelectLimitSize;
private TextView originalImageSizeTip;
private CheckboxImageView previewSelectBtn;
private TextView previewSendBtn;
private int totalSize;
private List<PhotoInfo> selectPhotoList = new ArrayList();
private List<PhotoInfo> photoLists = new ArrayList();
private int firstDisplayImageIndex = 0;
private int currentPosition = -1;
public void onPageScrollStateChanged(int i) {
}
public void onPageScrolled(int i, float f, int i2) {
}
public static void start(Activity activity, List<PhotoInfo> list, int i, boolean z, boolean z2, List<PhotoInfo> list2, int i2) {
b.a(activity, new ArrayList(list));
Intent intent = new Intent();
intent.setClass(activity, PickerAlbumPreviewActivity.class);
intent.putExtra("selected_photo_list", new ArrayList(list2));
intent.putExtra("current_pos", i);
intent.putExtra("support_original", z);
intent.putExtra("is_original", z2);
intent.putExtra("multi_select_size_limit", i2);
activity.startActivityForResult(intent, 5);
}
public static void start(Fragment fragment, List<PhotoInfo> list, int i, boolean z, boolean z2, List<PhotoInfo> list2, int i2) {
b.a(fragment.getContext(), new ArrayList(list));
Intent intent = new Intent();
intent.setClass(fragment.getActivity(), PickerAlbumPreviewActivity.class);
intent.putExtra("selected_photo_list", new ArrayList(list2));
intent.putExtra("current_pos", i);
intent.putExtra("support_original", z);
intent.putExtra("is_original", z2);
intent.putExtra("multi_select_size_limit", i2);
fragment.startActivityForResult(intent, 5);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.ysf_picker_image_preview_activity);
proceedExtras();
initTitleBar();
initUI();
}
private void proceedExtras() {
Intent intent = getIntent();
this.isSupportOriginal = intent.getBooleanExtra("support_original", false);
this.isSendOriginalImage = intent.getBooleanExtra("is_original", false);
this.firstDisplayImageIndex = intent.getIntExtra("current_pos", 0);
this.multiSelectLimitSize = intent.getIntExtra("multi_select_size_limit", 9);
this.photoLists.addAll(b.a(this));
this.totalSize = this.photoLists.size();
this.selectPhotoList.clear();
List<PhotoInfo> b = com.qiyukf.uikit.common.media.picker.model.b.b(intent);
if (b != null) {
this.selectPhotoList.addAll(b);
}
}
private void initTitleBar() {
CheckboxImageView checkboxImageView = (CheckboxImageView) addViewMenu(R.layout.ysf_action_bar_right_picker_preview).findViewById(R.id.picker_image_preview_photos_select);
this.previewSelectBtn = checkboxImageView;
checkboxImageView.setOnClickListener(this);
}
private void initUI() {
ImageButton imageButton = (ImageButton) findViewById(R.id.picker_image_preview_orignal_image);
imageButton.setOnClickListener(this);
this.originalImageSizeTip = (TextView) findViewById(R.id.picker_image_preview_orignal_image_tip);
if (!this.isSupportOriginal) {
imageButton.setVisibility(4);
this.originalImageSizeTip.setVisibility(4);
}
TextView textView = (TextView) findViewById(R.id.picker_image_preview_send);
this.previewSendBtn = textView;
textView.setOnClickListener(this);
updateSelectBtnStatus();
updateOriImageSizeTip(this.isSendOriginalImage);
ViewPager findViewById = findViewById(R.id.picker_image_preview_viewpager);
this.imageViewPager = findViewById;
findViewById.addOnPageChangeListener(this);
this.imageViewPager.setOffscreenPageLimit(2);
PickerPreviewPagerAdapter pickerPreviewPagerAdapter = new PickerPreviewPagerAdapter(this.firstDisplayImageIndex, this.photoLists, getLayoutInflater());
this.imageViewPagerAdapter = pickerPreviewPagerAdapter;
this.imageViewPager.setAdapter(pickerPreviewPagerAdapter);
setTitleIndex(this.firstDisplayImageIndex);
updateTitleSelect(this.firstDisplayImageIndex);
updateCurrentItem(this.firstDisplayImageIndex);
this.imageViewPager.setCurrentItem(this.firstDisplayImageIndex);
}
private void updateTitleSelect(int i) {
List<PhotoInfo> list = this.photoLists;
if (list == null || i >= list.size()) {
return;
}
this.previewSelectBtn.setChecked(this.photoLists.get(i).isChoose());
}
private void setTitleIndex(int i) {
if (this.totalSize <= 0) {
setTitle("");
} else {
setTitle((i + 1) + InternalZipConstants.ZIP_FILE_SEPARATOR + this.totalSize);
}
}
private void updateSelectBtnStatus() {
int size = this.selectPhotoList.size();
if (size > 0) {
this.previewSendBtn.setEnabled(true);
this.previewSendBtn.setText(String.format(getResources().getString(R.string.ysf_picker_image_send_select), Integer.valueOf(size)));
} else {
this.previewSendBtn.setEnabled(true);
this.previewSendBtn.setText(R.string.ysf_send);
}
}
private void updateOriImageSizeTip(boolean z) {
String str;
if (this.selectPhotoList == null) {
return;
}
if (z) {
long j = 0;
for (int i = 0; i < this.selectPhotoList.size(); i++) {
j += this.selectPhotoList.get(i).getSize();
}
TextView textView = this.originalImageSizeTip;
String string = getResources().getString(R.string.ysf_picker_image_preview_original_select);
if (j <= 0) {
str = "0B";
} else if (j < FileSizeUnit.KB) {
str = j + "B";
} else if (j >= FileSizeUnit.KB && j < FileSizeUnit.MB) {
str = ((int) new BigDecimal(j / 1024.0d).setScale(0, 4).doubleValue()) + "K";
} else if (j >= FileSizeUnit.MB && j < FileSizeUnit.GB) {
str = new BigDecimal(j / 1048576.0d).setScale(1, 4).doubleValue() + "M";
} else {
str = new BigDecimal(j / 1.073741824E9d).setScale(2, 4).doubleValue() + "GB";
}
textView.setText(String.format(string, str));
return;
}
this.originalImageSizeTip.setText(R.string.ysf_picker_image_preview_original);
}
private boolean checkSelectPhoto(PhotoInfo photoInfo) {
for (int i = 0; i < this.selectPhotoList.size(); i++) {
if (this.selectPhotoList.get(i).getImageId() == photoInfo.getImageId()) {
return true;
}
}
return false;
}
private void removeSelectPhoto(PhotoInfo photoInfo) {
Iterator<PhotoInfo> it = this.selectPhotoList.iterator();
while (it.hasNext()) {
if (it.next().getImageId() == photoInfo.getImageId()) {
it.remove();
}
}
}
@Override
public void onClick(View view) {
List<PhotoInfo> list;
int i;
if (view.getId() == R.id.picker_image_preview_photos_select) {
List<PhotoInfo> list2 = this.photoLists;
if (list2 == null || this.currentPosition >= list2.size() || (i = this.currentPosition) < 0) {
return;
}
PhotoInfo photoInfo = this.photoLists.get(i);
boolean isChoose = photoInfo.isChoose();
List<PhotoInfo> list3 = this.selectPhotoList;
if (list3 != null && list3.size() >= this.multiSelectLimitSize && !isChoose) {
r.b(String.format(getResources().getString(R.string.ysf_picker_image_exceed_max_image_select), Integer.valueOf(this.multiSelectLimitSize)));
return;
}
photoInfo.setChoose(!isChoose);
this.previewSelectBtn.setChecked(!isChoose);
if (!isChoose) {
if (!checkSelectPhoto(photoInfo)) {
this.selectPhotoList.add(photoInfo);
}
} else {
removeSelectPhoto(photoInfo);
}
updateSelectBtnStatus();
if (this.selectPhotoList.size() == 0 && this.isSendOriginalImage) {
this.isSendOriginalImage = false;
}
updateOriImageSizeTip(this.isSendOriginalImage);
return;
}
if (view.getId() == R.id.picker_image_preview_send) {
List<PhotoInfo> list4 = this.selectPhotoList;
if (list4 != null && list4.size() == 0 && this.currentPosition >= 0 && (list = this.photoLists) != null) {
int size = list.size();
int i2 = this.currentPosition;
if (size > i2) {
PhotoInfo photoInfo2 = this.photoLists.get(i2);
photoInfo2.setChoose(true);
this.selectPhotoList.add(photoInfo2);
}
}
setResult(-1, com.qiyukf.uikit.common.media.picker.model.b.a(this.selectPhotoList, this.isSendOriginalImage));
finish();
return;
}
if (view.getId() == R.id.picker_image_preview_orignal_image) {
if (!this.isSendOriginalImage) {
this.isSendOriginalImage = true;
List<PhotoInfo> list5 = this.selectPhotoList;
if ((list5 != null ? list5.size() : 0) < this.multiSelectLimitSize) {
PhotoInfo photoInfo3 = this.photoLists.get(this.currentPosition);
if (!photoInfo3.isChoose()) {
photoInfo3.setChoose(true);
this.selectPhotoList.add(photoInfo3);
updateSelectBtnStatus();
this.previewSelectBtn.setChecked(true);
}
}
} else {
this.isSendOriginalImage = false;
}
updateOriImageSizeTip(this.isSendOriginalImage);
}
}
@Override
protected void onDestroy() {
this.imageViewPager.setAdapter((PagerAdapter) null);
super.onDestroy();
}
@Override
public void onBackPressed() {
Intent intent = new Intent();
intent.putExtra("selected_photo_list", new ArrayList(this.selectPhotoList));
intent.putExtra("is_original", this.isSendOriginalImage);
setResult(2, intent);
finish();
}
public void onPageSelected(int i) {
setTitleIndex(i);
updateTitleSelect(i);
updateCurrentItem(i);
}
public void updateCurrentItem(final int i) {
List<PhotoInfo> list = this.photoLists;
if (list != null) {
if (i <= 0 || i < list.size()) {
int i2 = this.currentPosition;
if (i2 != i || i2 == 0) {
this.currentPosition = i;
LinearLayout linearLayout = (LinearLayout) this.imageViewPager.findViewWithTag(Integer.valueOf(i));
if (linearLayout == null) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
PickerAlbumPreviewActivity.this.updateCurrentItem(i);
}
}, 300L);
} else {
((BaseZoomableImageView) linearLayout.findViewById(R.id.imageView)).setViewPager(this.imageViewPager);
}
}
}
}
}
@Override
public void onConfigurationChanged(Configuration configuration) {
super.onConfigurationChanged(configuration);
ViewGroup.LayoutParams layoutParams = this.imageViewPager.getLayoutParams();
layoutParams.height = (n.b() - getTitleBarHeight()) - n.a(50.0f);
layoutParams.width = n.a();
this.firstDisplayImageIndex = this.imageViewPager.getCurrentItem();
this.imageViewPager.setLayoutParams(layoutParams);
PickerPreviewPagerAdapter pickerPreviewPagerAdapter = new PickerPreviewPagerAdapter(this.firstDisplayImageIndex, this.photoLists, getLayoutInflater());
this.imageViewPagerAdapter = pickerPreviewPagerAdapter;
this.imageViewPager.setAdapter(pickerPreviewPagerAdapter);
this.imageViewPager.setCurrentItem(this.firstDisplayImageIndex);
}
}