414 lines
16 KiB
Java
414 lines
16 KiB
Java
package com.bottle.hp.album.selector;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.text.TextUtils;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.widget.AdapterView;
|
|
import android.widget.Button;
|
|
import android.widget.CompoundButton;
|
|
import android.widget.GridView;
|
|
import android.widget.ImageView;
|
|
import android.widget.ListAdapter;
|
|
import androidx.core.content.ContextCompat;
|
|
import com.bottle.hp.album.BaseActivity;
|
|
import com.bottle.hp.album.R$id;
|
|
import com.bottle.hp.album.R$layout;
|
|
import com.bottle.hp.album.R$string;
|
|
import com.bottle.hp.album.capture.VideoCaptureActivity;
|
|
import com.bottle.hp.album.media.HPImage;
|
|
import com.bottle.hp.album.media.HPMedia;
|
|
import com.bottle.hp.album.media.HPVideo;
|
|
import com.bottle.hp.album.selector.AlbumAdapter;
|
|
import com.liulishuo.filedownloader.model.FileDownloadModel;
|
|
import com.ubt.jimu.base.entities.Constant;
|
|
import com.ubtech.permission.JimuPermissionRequest;
|
|
import com.ubtech.permission.PermissionRequestListener;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class AlbumActivity extends BaseActivity implements AdapterView.OnItemClickListener, View.OnClickListener {
|
|
public static List<HPMedia> m = new ArrayList();
|
|
public static List<HPMedia> n = new ArrayList();
|
|
private GridView c;
|
|
private AlbumAdapter d;
|
|
private List<HPMedia> e = new ArrayList();
|
|
private ArrayList<HPMedia> f = new ArrayList<>();
|
|
private int g = 5;
|
|
private int h;
|
|
private ImageView i;
|
|
private Button j;
|
|
private String k;
|
|
private Handler l;
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void F0() {
|
|
this.e.add(E0());
|
|
this.e.addAll(n);
|
|
this.e.addAll(m);
|
|
Collections.sort(this.e, new HPMediaComparator());
|
|
this.d = new AlbumAdapter(this, this.e, new AlbumAdapter.IAlbumAdapterUIListener() { // from class: com.bottle.hp.album.selector.AlbumActivity.5
|
|
@Override // com.bottle.hp.album.selector.AlbumAdapter.IAlbumAdapterUIListener
|
|
public void a(CompoundButton compoundButton, boolean z, HPMedia hPMedia) {
|
|
if (!z) {
|
|
hPMedia.setSelected(false);
|
|
Iterator it = AlbumActivity.this.f.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
break;
|
|
}
|
|
HPMedia hPMedia2 = (HPMedia) it.next();
|
|
if (hPMedia2.getId() == hPMedia.getId()) {
|
|
AlbumActivity.this.f.remove(hPMedia2);
|
|
break;
|
|
}
|
|
}
|
|
if (AlbumActivity.this.f.size() > 0) {
|
|
AlbumActivity.this.j.setText(AlbumActivity.this.k + "(" + AlbumActivity.this.f.size() + "/" + AlbumActivity.this.h + ")");
|
|
} else {
|
|
AlbumActivity.this.j.setText(AlbumActivity.this.k);
|
|
AlbumActivity.this.j.setEnabled(false);
|
|
}
|
|
} else if (AlbumActivity.this.f.size() >= AlbumActivity.this.h) {
|
|
AlbumActivity.this.a(AlbumActivity.this.getString(R$string.number_limit), 0);
|
|
compoundButton.setSelected(false);
|
|
} else {
|
|
hPMedia.setSelected(true);
|
|
AlbumActivity.this.f.add(hPMedia);
|
|
AlbumActivity.this.j.setText(AlbumActivity.this.k + "(" + AlbumActivity.this.f.size() + "/" + AlbumActivity.this.h + ")");
|
|
if (!AlbumActivity.this.j.isEnabled()) {
|
|
AlbumActivity.this.j.setEnabled(true);
|
|
}
|
|
}
|
|
AlbumActivity.this.d.notifyDataSetChanged();
|
|
}
|
|
});
|
|
this.c.setAdapter((ListAdapter) this.d);
|
|
ArrayList<HPMedia> arrayList = this.f;
|
|
if (arrayList == null || arrayList.size() <= 0) {
|
|
return;
|
|
}
|
|
this.j.setText(this.k + "(" + this.f.size() + "/" + this.h + ")");
|
|
this.j.setEnabled(true);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void initData() {
|
|
ArrayList arrayList = (ArrayList) getIntent().getSerializableExtra("input_selected");
|
|
if (arrayList != null && arrayList.size() > 0) {
|
|
this.f.addAll(arrayList);
|
|
}
|
|
new Thread(new Runnable() { // from class: com.bottle.hp.album.selector.AlbumActivity.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (AlbumActivity.this.g == 1) {
|
|
AlbumActivity.m.addAll(HPImage.getImages(AlbumActivity.this));
|
|
} else if (AlbumActivity.this.g == 2) {
|
|
AlbumActivity.n.addAll(HPVideo.getVideos(AlbumActivity.this));
|
|
} else {
|
|
AlbumActivity.m.addAll(HPImage.getImages(AlbumActivity.this));
|
|
AlbumActivity.n.addAll(HPVideo.getVideos(AlbumActivity.this));
|
|
}
|
|
AlbumActivity.this.l.sendEmptyMessage(Constant.Publish.REQUEST_CODE_PICK_FILE);
|
|
ArrayList arrayList2 = new ArrayList();
|
|
Iterator it = AlbumActivity.this.f.iterator();
|
|
while (it.hasNext()) {
|
|
HPMedia hPMedia = (HPMedia) it.next();
|
|
for (HPMedia hPMedia2 : AlbumActivity.m) {
|
|
if (hPMedia.getId() == hPMedia2.getId() || hPMedia.getPath().equals(hPMedia2.getPath())) {
|
|
hPMedia2.setSelected(true);
|
|
arrayList2.add(hPMedia2);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
AlbumActivity.this.f.clear();
|
|
AlbumActivity.this.f.addAll(arrayList2);
|
|
final ArrayList arrayList3 = new ArrayList();
|
|
for (HPMedia hPMedia3 : AlbumActivity.n) {
|
|
if (((HPVideo) hPMedia3).getDuration() < 500) {
|
|
arrayList3.add(hPMedia3);
|
|
} else {
|
|
HPVideo.getVideoThumnail(AlbumActivity.this, hPMedia3);
|
|
}
|
|
}
|
|
AlbumActivity.this.l.post(new Runnable() { // from class: com.bottle.hp.album.selector.AlbumActivity.3.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AlbumActivity.n.removeAll(arrayList3);
|
|
AlbumActivity.this.e.removeAll(arrayList3);
|
|
AlbumActivity.this.d.notifyDataSetChanged();
|
|
}
|
|
});
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
private void initView() {
|
|
this.k = getString(R$string.done);
|
|
this.i = (ImageView) findViewById(R$id.imgBack);
|
|
this.i.setOnClickListener(this);
|
|
this.j = (Button) findViewById(R$id.btnCompleted);
|
|
this.j.setOnClickListener(this);
|
|
this.c = (GridView) findViewById(R$id.gridView);
|
|
this.c.setOnItemClickListener(this);
|
|
this.h = getIntent().getIntExtra(FileDownloadModel.TOTAL, 5);
|
|
this.g = getIntent().getIntExtra("type", 5);
|
|
}
|
|
|
|
public HPMedia E0() {
|
|
HPMedia hPMedia = new HPMedia();
|
|
hPMedia.setId(Integer.MAX_VALUE);
|
|
hPMedia.setModifyDate("2147483647");
|
|
return hPMedia;
|
|
}
|
|
|
|
@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 // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R$id.imgBack) {
|
|
e(false);
|
|
} else if (id == R$id.btnCompleted) {
|
|
e(true);
|
|
}
|
|
}
|
|
|
|
@Override // com.bottle.hp.album.BaseActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity
|
|
protected void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
this.l = new Handler() { // from class: com.bottle.hp.album.selector.AlbumActivity.1
|
|
@Override // android.os.Handler
|
|
public void handleMessage(Message message) {
|
|
int i = message.what;
|
|
if (i == 201) {
|
|
AlbumActivity.this.a(message);
|
|
} else if (i == 202) {
|
|
AlbumActivity.this.F0();
|
|
}
|
|
}
|
|
};
|
|
setContentView(R$layout.activity_album);
|
|
initView();
|
|
if (Build.VERSION.SDK_INT < 23 || ContextCompat.a(this, "android.permission.READ_EXTERNAL_STORAGE") == 0) {
|
|
initData();
|
|
} else {
|
|
JimuPermissionRequest.c(this, new PermissionRequestListener() { // from class: com.bottle.hp.album.selector.AlbumActivity.2
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onDenied() {
|
|
AlbumActivity.this.finish();
|
|
}
|
|
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onGranted() {
|
|
AlbumActivity.this.initData();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
public void onDestroy() {
|
|
this.l.removeCallbacksAndMessages(null);
|
|
this.l = null;
|
|
m.clear();
|
|
n.clear();
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override // android.widget.AdapterView.OnItemClickListener
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
|
|
if (i != 0) {
|
|
HPMedia hPMedia = this.e.get(i);
|
|
if (hPMedia.getMediaType() == 0) {
|
|
AlbumActivity2.a(this, 101, this.h, a(hPMedia, m), 0, this.f);
|
|
return;
|
|
} else if (this.f.size() > 0) {
|
|
b(R$string.tips_type_limit, 0);
|
|
return;
|
|
} else {
|
|
if (((HPVideo) hPMedia).getDuration() > 20500) {
|
|
return;
|
|
}
|
|
AlbumActivity2.a(this, 101, this.h, a(hPMedia, n), 1, this.f);
|
|
return;
|
|
}
|
|
}
|
|
if (this.f.size() == this.h) {
|
|
a(getString(R$string.number_limit), 0);
|
|
return;
|
|
}
|
|
if (Build.VERSION.SDK_INT < 23) {
|
|
int i2 = this.g;
|
|
if (i2 == 5) {
|
|
i2 = this.f.size() == 0 ? 5 : 1;
|
|
}
|
|
VideoCaptureActivity.a(this, 102, i2);
|
|
return;
|
|
}
|
|
if (ContextCompat.a(this, "android.permission.CAMERA") != 0) {
|
|
JimuPermissionRequest.a((Context) this, new PermissionRequestListener() { // from class: com.bottle.hp.album.selector.AlbumActivity.4
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onDenied() {
|
|
}
|
|
|
|
@Override // com.ubtech.permission.PermissionRequestListener
|
|
public void onGranted() {
|
|
AlbumActivity albumActivity = AlbumActivity.this;
|
|
int i3 = 5;
|
|
if (albumActivity.g != 5) {
|
|
i3 = AlbumActivity.this.g;
|
|
} else if (AlbumActivity.this.f.size() != 0) {
|
|
i3 = 1;
|
|
}
|
|
VideoCaptureActivity.a(albumActivity, 102, i3);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
int i3 = this.g;
|
|
if (i3 == 5) {
|
|
i3 = this.f.size() == 0 ? 5 : 1;
|
|
}
|
|
VideoCaptureActivity.a(this, 102, i3);
|
|
}
|
|
|
|
@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;
|
|
}
|
|
|
|
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) {
|
|
HPVideo searchVideoByName = HPVideo.searchVideoByName(this, stringExtra);
|
|
if (searchVideoByName == null) {
|
|
searchVideoByName = new HPVideo();
|
|
searchVideoByName.setPath(stringExtra);
|
|
searchVideoByName.setMediaType(intExtra);
|
|
searchVideoByName.setSize(new File(stringExtra).length());
|
|
searchVideoByName.setDuration(HPVideo.getVideoDuration(stringExtra));
|
|
}
|
|
HPVideo.getVideoThumnail(this, searchVideoByName);
|
|
this.f.clear();
|
|
this.f.add(searchVideoByName);
|
|
} else {
|
|
HPMedia searchImageByName = HPImage.searchImageByName(this, stringExtra);
|
|
if (searchImageByName == null) {
|
|
searchImageByName = new HPImage();
|
|
searchImageByName.setId(0);
|
|
searchImageByName.setPath(stringExtra);
|
|
searchImageByName.setPreview(stringExtra);
|
|
}
|
|
this.f.add(searchImageByName);
|
|
}
|
|
e(true);
|
|
}
|
|
}
|
|
|
|
private void e(boolean z) {
|
|
Intent intent = new Intent();
|
|
if (z) {
|
|
intent.putExtra("result_data", this.f);
|
|
setResult(-1, intent);
|
|
} else {
|
|
setResult(0, intent);
|
|
}
|
|
finish();
|
|
}
|
|
|
|
public static void a(Activity activity, int i, int i2, ArrayList<HPMedia> arrayList, int i3) {
|
|
Intent intent = new Intent(activity, (Class<?>) AlbumActivity.class);
|
|
intent.putExtra(FileDownloadModel.TOTAL, i2);
|
|
intent.putExtra("input_selected", arrayList);
|
|
intent.putExtra("type", i3);
|
|
activity.startActivityForResult(intent, i);
|
|
}
|
|
|
|
private void a(int i, Intent intent) {
|
|
int indexOf;
|
|
if (i == 0) {
|
|
return;
|
|
}
|
|
List list = (List) intent.getSerializableExtra("selected");
|
|
int intExtra = intent.getIntExtra("current", 0);
|
|
int intExtra2 = intent.getIntExtra("type", -1);
|
|
boolean booleanExtra = intent.getBooleanExtra("done", false);
|
|
if (list == null) {
|
|
list = new ArrayList();
|
|
this.j.setEnabled(false);
|
|
} else if (list.size() > 0) {
|
|
this.j.setEnabled(true);
|
|
} else {
|
|
this.j.setEnabled(false);
|
|
}
|
|
this.f.clear();
|
|
this.f.addAll(list);
|
|
if (intExtra2 == 1) {
|
|
if (list.size() > 0) {
|
|
e(true);
|
|
return;
|
|
} else {
|
|
indexOf = this.e.indexOf(n.get(intExtra));
|
|
}
|
|
} else {
|
|
indexOf = this.e.indexOf(m.get(intExtra));
|
|
}
|
|
if (booleanExtra) {
|
|
e(true);
|
|
return;
|
|
}
|
|
Message message = new Message();
|
|
message.what = 201;
|
|
message.arg1 = indexOf;
|
|
this.l.sendMessage(message);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(Message message) {
|
|
this.d.notifyDataSetChanged();
|
|
this.c.smoothScrollToPosition(message.arg1);
|
|
if (this.f.size() > 0) {
|
|
this.j.setText(this.k + "(" + this.f.size() + "/" + this.h + ")");
|
|
return;
|
|
}
|
|
this.j.setText(this.k);
|
|
}
|
|
|
|
private int a(HPMedia hPMedia, List<HPMedia> list) {
|
|
for (int i = 0; i < list.size(); i++) {
|
|
if (hPMedia.getId() == list.get(i).getId()) {
|
|
return i;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|