515 lines
21 KiB
Java
515 lines
21 KiB
Java
package com.ubt.jimu.widgets.choosePhotos;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.media.MediaMetadataRetriever;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.widget.CheckBox;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.liulishuo.filedownloader.model.FileDownloadModel;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.entities.Constant;
|
|
import com.ubt.jimu.utils.SPUtils;
|
|
import com.ubt.jimu.widgets.NavigationBarView;
|
|
import com.ubt.jimu.widgets.choosePhotos.media.HPImage;
|
|
import com.ubt.jimu.widgets.choosePhotos.media.HPMedia;
|
|
import com.ubt.jimu.widgets.choosePhotos.media.HPVideo;
|
|
import com.ubt.jimu.widgets.player.UbtPlayer;
|
|
import com.ubtech.permission.JimuPermissionRequest;
|
|
import com.ubtech.permission.PermissionRequestListener;
|
|
import com.ubtech.utils.BitmapFile;
|
|
import com.ubtech.view.widget.ToastView;
|
|
import java.io.File;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class AlbumActivity extends BaseActivity implements AlbumOnClickListener {
|
|
private static StaticHandler m;
|
|
private View a;
|
|
private RecyclerView c;
|
|
private AlbumRecyclerViewAdapter d;
|
|
private int k;
|
|
private NavigationBarView l;
|
|
private final String b = AlbumActivity.class.getSimpleName();
|
|
private ArrayList<HPMedia> e = new ArrayList<>();
|
|
private List<HPMedia> f = new ArrayList();
|
|
private List<HPMedia> g = new ArrayList();
|
|
private ArrayList<HPMedia> h = new ArrayList<>();
|
|
public String i = "MULTITERM_VIDEO_IMAGE";
|
|
private int j = 5;
|
|
|
|
private static class StaticHandler extends Handler {
|
|
private WeakReference<AlbumActivity> a;
|
|
|
|
public StaticHandler(AlbumActivity albumActivity) {
|
|
this.a = new WeakReference<>(albumActivity);
|
|
}
|
|
|
|
public WeakReference<AlbumActivity> a() {
|
|
return this.a;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void F0() {
|
|
this.e.add(D0());
|
|
this.e.addAll(this.g);
|
|
this.e.addAll(this.f);
|
|
Collections.sort(this.e, new HPMediaComparator());
|
|
this.d.a(this.i);
|
|
this.d.a(this.e);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void initData() {
|
|
this.c.setLayoutManager(new GridLayoutManager(this, 6));
|
|
this.d = new AlbumRecyclerViewAdapter(this);
|
|
this.d.a(this);
|
|
this.c.setAdapter(this.d);
|
|
Intent intent = getIntent();
|
|
ArrayList arrayList = (ArrayList) intent.getSerializableExtra("selected_items");
|
|
if (arrayList != null && arrayList.size() > 0) {
|
|
this.h.addAll(arrayList);
|
|
}
|
|
if (intent.getIntExtra("type", 0) == 1 && "UNITERMING_IMAGE".equals(intent.getStringExtra("FROM_PAGE_KEY"))) {
|
|
this.l.setTitle(R.string.my_albums);
|
|
this.i = "UNITERMING_IMAGE";
|
|
this.l.setMode(0);
|
|
}
|
|
if ("MULTITERM_VIDEO_IMAGE".equals(intent.getStringExtra("FROM_PAGE_KEY"))) {
|
|
this.l.setTitle(R.string.title_album);
|
|
this.l.setRightIcon(R.drawable.community_collection_icon);
|
|
this.l.setRightAlpha(0.3f);
|
|
this.l.setLeftIcon(R.drawable.community_cancel);
|
|
}
|
|
if ("MULTITERM_VIDEO".equals(intent.getStringExtra("FROM_PAGE_KEY"))) {
|
|
this.i = "MULTITERM_VIDEO";
|
|
this.l.setTitle(R.string.video);
|
|
this.l.setRightIcon(R.drawable.community_collection_icon);
|
|
}
|
|
if ("MULTITERM_IMAGE".equals(intent.getStringExtra("FROM_PAGE_KEY"))) {
|
|
this.i = "MULTITERM_IMAGE";
|
|
this.l.setTitle(R.string.title_photo);
|
|
this.l.setRightIcon(R.drawable.community_collection_icon);
|
|
}
|
|
if ("UNITERMING_VIDEO".equals(intent.getStringExtra("FROM_PAGE_KEY"))) {
|
|
this.i = "UNITERMING_VIDEO";
|
|
this.l.setTitle(R.string.video);
|
|
this.l.setRightIcon(R.drawable.community_collection_icon);
|
|
}
|
|
new Thread(new Runnable() { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.8
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (AlbumActivity.this.j == 1 || AlbumActivity.this.j == -1) {
|
|
AlbumActivity.this.f.addAll(HPImage.getImages(AlbumActivity.this));
|
|
} else if (AlbumActivity.this.j == 2) {
|
|
AlbumActivity.this.g.addAll(HPVideo.getVideos(AlbumActivity.this));
|
|
} else {
|
|
AlbumActivity.this.f.addAll(HPImage.getImages(AlbumActivity.this));
|
|
AlbumActivity.this.g.addAll(HPVideo.getVideos(AlbumActivity.this));
|
|
}
|
|
AlbumActivity.m.sendEmptyMessage(Constant.Publish.REQUEST_CODE_PICK_FILE);
|
|
ArrayList arrayList2 = new ArrayList();
|
|
Iterator it = AlbumActivity.this.h.iterator();
|
|
while (it.hasNext()) {
|
|
HPMedia hPMedia = (HPMedia) it.next();
|
|
for (HPMedia hPMedia2 : AlbumActivity.this.f) {
|
|
if (hPMedia.getId() == hPMedia2.getId() || hPMedia.getPath().equals(hPMedia2.getPath())) {
|
|
hPMedia2.setSelected(true);
|
|
arrayList2.add(hPMedia2);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
Iterator it2 = AlbumActivity.this.h.iterator();
|
|
while (it2.hasNext()) {
|
|
HPMedia hPMedia3 = (HPMedia) it2.next();
|
|
for (HPMedia hPMedia4 : AlbumActivity.this.g) {
|
|
if (hPMedia3.getId() == hPMedia4.getId() || hPMedia3.getPath().equals(hPMedia4.getPath())) {
|
|
hPMedia4.setSelected(true);
|
|
arrayList2.add(hPMedia4);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
AlbumActivity.this.h.clear();
|
|
AlbumActivity.this.h.addAll(arrayList2);
|
|
final ArrayList arrayList3 = new ArrayList();
|
|
ArrayList<HPMedia> arrayList4 = new ArrayList();
|
|
arrayList4.addAll(AlbumActivity.this.g);
|
|
for (HPMedia hPMedia5 : arrayList4) {
|
|
if (((HPVideo) hPMedia5).getDuration() < 500) {
|
|
arrayList3.add(hPMedia5);
|
|
} else {
|
|
HPVideo.getVideoThumnail(AlbumActivity.this, hPMedia5);
|
|
}
|
|
}
|
|
AlbumActivity.m.post(new Runnable() { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.8.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AlbumActivity.this.g.removeAll(arrayList3);
|
|
AlbumActivity.this.e.removeAll(arrayList3);
|
|
AlbumActivity.this.d.notifyDataSetChanged();
|
|
}
|
|
});
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
private void initView() {
|
|
this.l = (NavigationBarView) findViewById(R.id.nbv_bar);
|
|
this.l.setRightIcon(R.drawable.ic_nav_finish);
|
|
this.l.setRightAlpha(0.3f);
|
|
this.l.setRightEnabled(false);
|
|
this.l.setListener(new NavigationBarView.OnActionClickListener.Stub() { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.7
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener.Stub
|
|
public void onLeftClick(View view) {
|
|
AlbumActivity.this.e(false);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener.Stub
|
|
public void onRightClick(View view) {
|
|
AlbumActivity.this.e(true);
|
|
}
|
|
});
|
|
this.k = getIntent().getIntExtra(FileDownloadModel.TOTAL, 10);
|
|
this.j = getIntent().getIntExtra("type", 5);
|
|
this.c = (RecyclerView) findViewById(R.id.rv_album_list);
|
|
}
|
|
|
|
public HPMedia D0() {
|
|
HPMedia hPMedia = new HPMedia();
|
|
hPMedia.setId(Integer.MAX_VALUE);
|
|
hPMedia.setModifyDate("2147483647");
|
|
return hPMedia;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.choosePhotos.AlbumOnClickListener
|
|
public void n0() {
|
|
if (this.h.size() == this.k) {
|
|
ToastView.a(this, getString(R.string.choose_more_pictures), ToastView.Type.ERROR).a();
|
|
} else {
|
|
JimuPermissionRequest.a((Context) this, new PermissionRequestListener() { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.9
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onDenied() {
|
|
Log.i(AlbumActivity.this.b, "User denied CAMERA permission.");
|
|
}
|
|
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onGranted() {
|
|
AlbumActivity albumActivity = AlbumActivity.this;
|
|
int i = 5;
|
|
if (albumActivity.j != 5) {
|
|
i = AlbumActivity.this.j;
|
|
} else if (AlbumActivity.this.h.size() != 0) {
|
|
i = 1;
|
|
}
|
|
VideoCaptureActivity.a(albumActivity, 102, i);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
public void onActivityResult(int i, int i2, Intent intent) {
|
|
if (i == 101) {
|
|
a(i2, intent);
|
|
} else if (i == 102) {
|
|
b(i2, intent);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.choosePhotos.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity
|
|
protected void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
m = new StaticHandler(this, this) { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.5
|
|
@Override // android.os.Handler
|
|
public void handleMessage(Message message) {
|
|
if (a() == null || a().get() == null) {
|
|
return;
|
|
}
|
|
int i = message.what;
|
|
if (i == 201) {
|
|
a().get().a(message);
|
|
} else if (i == 202) {
|
|
a().get().F0();
|
|
}
|
|
}
|
|
};
|
|
this.a = View.inflate(this, R.layout.activity_album_select, null);
|
|
setContentView(this.a);
|
|
initView();
|
|
JimuPermissionRequest.c(this, new PermissionRequestListener() { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.6
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onDenied() {
|
|
Log.e(AlbumActivity.this.b, "Should not to here, should check storage permission before goto AlbumActivity!");
|
|
AlbumActivity.this.finish();
|
|
}
|
|
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onGranted() {
|
|
AlbumActivity.this.initData();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
public void onDestroy() {
|
|
m.removeCallbacksAndMessages(null);
|
|
this.f.clear();
|
|
this.g.clear();
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.KeyEvent.Callback
|
|
public boolean onKeyDown(int i, KeyEvent keyEvent) {
|
|
if (i != 4) {
|
|
return super.onKeyDown(i, keyEvent);
|
|
}
|
|
e(false);
|
|
return true;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onPause() {
|
|
super.onPause();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onResume() {
|
|
super.onResume();
|
|
}
|
|
|
|
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onStart() {
|
|
super.onStart();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onStop() {
|
|
super.onStop();
|
|
}
|
|
|
|
private void b(int i, Intent intent) {
|
|
if (i == 0) {
|
|
return;
|
|
}
|
|
String stringExtra = intent.getStringExtra("data");
|
|
if (!TextUtils.isEmpty(stringExtra) && new File(stringExtra).exists()) {
|
|
int intExtra = intent.getIntExtra("data_type", -1);
|
|
if (1 == intExtra) {
|
|
try {
|
|
HPVideo searchVideoByName = HPVideo.searchVideoByName(this, stringExtra);
|
|
if (searchVideoByName == null) {
|
|
searchVideoByName = new HPVideo();
|
|
searchVideoByName.setPath(stringExtra);
|
|
searchVideoByName.setMediaType(intExtra);
|
|
File file = new File(stringExtra);
|
|
if (!file.exists()) {
|
|
finish();
|
|
return;
|
|
} else {
|
|
searchVideoByName.setSize(file.length());
|
|
searchVideoByName.setDuration(HPVideo.getVideoDuration(stringExtra));
|
|
}
|
|
}
|
|
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
|
mediaMetadataRetriever.setDataSource(stringExtra);
|
|
String str = stringExtra.substring(0, stringExtra.lastIndexOf(".")) + ".jpg";
|
|
BitmapFile.a(mediaMetadataRetriever.getFrameAtTime(), str);
|
|
searchVideoByName.setPreview(str);
|
|
this.h.clear();
|
|
this.h.add(searchVideoByName);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
} else {
|
|
HPMedia searchImageByName = HPImage.searchImageByName(this, stringExtra);
|
|
if (searchImageByName == null) {
|
|
searchImageByName = new HPImage();
|
|
searchImageByName.setId(0);
|
|
searchImageByName.setPath(stringExtra);
|
|
searchImageByName.setPreview(stringExtra);
|
|
}
|
|
this.h.add(searchImageByName);
|
|
}
|
|
e(true);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void e(boolean z) {
|
|
if (this.h.size() == 0) {
|
|
finish();
|
|
return;
|
|
}
|
|
Intent intent = new Intent();
|
|
if (z) {
|
|
intent.putExtra("result_data", this.h);
|
|
setResult(-1, intent);
|
|
} else {
|
|
setResult(0, intent);
|
|
}
|
|
finish();
|
|
}
|
|
|
|
public static void a(final Activity activity, final int i, final int i2, final ArrayList<HPMedia> arrayList, final int i3, final String str) {
|
|
JimuPermissionRequest.c(activity, new PermissionRequestListener() { // from class: com.ubt.jimu.widgets.choosePhotos.AlbumActivity.2
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onDenied() {
|
|
}
|
|
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onGranted() {
|
|
Intent intent = new Intent(activity, (Class<?>) AlbumActivity.class);
|
|
intent.putExtra(FileDownloadModel.TOTAL, i2);
|
|
intent.putExtra("selected_items", arrayList);
|
|
intent.putExtra("type", i3);
|
|
intent.putExtra("FROM_PAGE_KEY", str);
|
|
activity.startActivityForResult(intent, i);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void a(int i, Intent intent) {
|
|
if (i == 0) {
|
|
return;
|
|
}
|
|
List list = (List) intent.getSerializableExtra("selected");
|
|
List list2 = (List) SPUtils.c("ResultDate");
|
|
int intExtra = intent.getIntExtra("current", 0);
|
|
intent.getIntExtra("type", -1);
|
|
intent.getBooleanExtra("done", false);
|
|
if (list == null) {
|
|
list = new ArrayList();
|
|
this.l.setRightEnabled(false);
|
|
} else if (list.size() > 0) {
|
|
this.l.setRightEnabled(true);
|
|
} else {
|
|
this.l.setRightEnabled(false);
|
|
}
|
|
this.h.clear();
|
|
this.h.addAll(list);
|
|
this.e.clear();
|
|
this.e.addAll(list2);
|
|
if (i == 105) {
|
|
e(true);
|
|
return;
|
|
}
|
|
ArrayList<HPMedia> arrayList = this.h;
|
|
if (arrayList != null && arrayList.size() > 0) {
|
|
this.l.setRightEnabled(true);
|
|
this.l.setRightAlpha(1.0f);
|
|
} else {
|
|
this.l.setRightEnabled(false);
|
|
this.l.setRightAlpha(0.3f);
|
|
}
|
|
Message message = new Message();
|
|
message.what = 201;
|
|
message.arg1 = intExtra;
|
|
m.sendMessage(message);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(Message message) {
|
|
if (this.h.size() == 0) {
|
|
this.l.setRightAlpha(0.4f);
|
|
} else {
|
|
this.l.setRightAlpha(1.0f);
|
|
}
|
|
this.d.notifyDataSetChanged();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.choosePhotos.AlbumOnClickListener
|
|
public void a(CheckBox checkBox, HPMedia hPMedia, int i) {
|
|
if (this.i.equals("UNITERMING_IMAGE")) {
|
|
checkBox.setVisibility(0);
|
|
checkBox.setChecked(true);
|
|
Intent intent = new Intent();
|
|
this.h.add(hPMedia);
|
|
intent.putExtra("result_data", this.h);
|
|
setResult(-1, intent);
|
|
finish();
|
|
return;
|
|
}
|
|
PreviewActivity.a(this, this.e, this.h, this.k, i);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.choosePhotos.AlbumOnClickListener
|
|
public void a(HPVideo hPVideo, int i) {
|
|
if (this.i.equals("UNITERMING_VIDEO")) {
|
|
UbtPlayer.a(this, null, hPVideo.getPath());
|
|
} else {
|
|
PreviewActivity.a(this, this.e, this.h, this.k, i);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.choosePhotos.AlbumOnClickListener
|
|
public void a(CheckBox checkBox, boolean z, HPMedia hPMedia) {
|
|
if (z) {
|
|
if ("MULTITERM_VIDEO".equals(this.i) && hPMedia.getMediaType() == 0) {
|
|
Iterator<HPMedia> it = this.h.iterator();
|
|
while (it.hasNext()) {
|
|
if (it.next().isVideo()) {
|
|
ToastView.a(this, getString(R.string.tips_type_limit), ToastView.Type.ERROR).a();
|
|
hPMedia.setSelected(false);
|
|
checkBox.setChecked(false);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if ("MULTITERM_VIDEO".equals(this.i) && hPMedia.getMediaType() == 1) {
|
|
Iterator<HPMedia> it2 = this.h.iterator();
|
|
while (it2.hasNext()) {
|
|
if (it2.next().getMediaType() == 0) {
|
|
ToastView.a(this, getString(R.string.tips_type_limit), ToastView.Type.ERROR).a();
|
|
hPMedia.setSelected(false);
|
|
checkBox.setChecked(false);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (this.h.size() >= this.k) {
|
|
checkBox.setSelected(false);
|
|
ToastView.a(this, getString(R.string.choose_more_pictures), ToastView.Type.ERROR).a();
|
|
} else {
|
|
hPMedia.setSelected(true);
|
|
this.h.add(hPMedia);
|
|
this.l.setRightEnabled(true);
|
|
}
|
|
} else {
|
|
hPMedia.setSelected(false);
|
|
Iterator<HPMedia> it3 = this.h.iterator();
|
|
while (true) {
|
|
if (!it3.hasNext()) {
|
|
break;
|
|
}
|
|
HPMedia next = it3.next();
|
|
if (next.getId() == hPMedia.getId()) {
|
|
this.h.remove(next);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (this.h.size() <= 0) {
|
|
this.l.setRightAlpha(0.3f);
|
|
this.l.setRightEnabled(false);
|
|
} else {
|
|
this.l.setRightAlpha(1.0f);
|
|
this.l.setRightEnabled(true);
|
|
}
|
|
}
|
|
}
|