Browse Source

增加本地图片库22

tags/old_version_1
fyf 1 year ago
parent
commit
c86402dd75
2 changed files with 121 additions and 7 deletions
  1. +53
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/systeminternetfragment.java
  2. +68
    -7
      app/src/main/res/layout/fragment_system_internet.xml

+ 53
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/systeminternetfragment.java View File

@@ -11,6 +11,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
@@ -24,19 +25,23 @@ import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET;
import com.bonait.bnframework.common.filepicker.PickerManager;
import com.bonait.bnframework.common.filepicker.adapter.FilePickerShowAdapter;
import com.bonait.bnframework.common.filepicker.adapter.OnDeleteListener;
import com.bonait.bnframework.common.filepicker.adapter.OnFileItemClickListener;
import com.bonait.bnframework.common.filepicker.model.FileEntity;
import com.bonait.bnframework.common.filepicker.model.FileType;
import com.bonait.bnframework.common.filepicker.util.OpenFile;
import com.bonait.bnframework.common.image.utils.LocalCacheUtils;
import com.bonait.bnframework.common.image.utils.MD5Encoder;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.common.view.MyLayoutManager;
import com.bonait.bnframework.modules.home.fragment.from.FileActivity;
import com.bonait.bnframework.modules.home.fragment.mode.image_sp;
import com.orhanobut.logger.Logger;
import com.qmuiteam.qmui.arch.QMUIFragment;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
@@ -50,6 +55,8 @@ import pub.devrel.easypermissions.EasyPermissions;
public class systeminternetfragment extends BaseFragment{
@BindView(R.id.rl_file)
RecyclerView mRecyclerView;
@BindView(R.id.rl_yx_file)
RecyclerView rl_yx_file;
@BindView(R.id.baocunbendi)
Button baocunbendi;
private Context context;
@@ -65,6 +72,7 @@ public class systeminternetfragment extends BaseFragment{
super.onViewCreated(view, savedInstanceState);
Logger.d("我的fragment创建");
context = getContext();
FlushedImage();
}

@OnClick({R.id.xuanzhewenjian,R.id.baocunbendi})
@@ -90,6 +98,51 @@ public class systeminternetfragment extends BaseFragment{
break;
}
}
ArrayList<FileEntity> yx_files=new ArrayList<>();
private static final String CACHE_PATH= Environment.getExternalStorageDirectory().getAbsolutePath()+"/hblxiaochaodb/WebImage";
public void FlushedImage()
{
File path = new File(CACHE_PATH);// 获得路径
File[] files = path.listFiles();// 读取文件
yx_files.clear();
for (File f : files) {
String absolutePath = f.getAbsolutePath();
FileEntity e;
if (checkExits(absolutePath)) {
e = new FileEntity(absolutePath, f, true);
} else {
e = new FileEntity(absolutePath, f, false);
}
if(f.isFile())
{
String[] imgs = {"png","jpg","jpeg","gif"};
e.setFileType(new FileType("IMG",imgs,0));
yx_files.add(e);
}
}
rl_yx_file.setLayoutManager(new LinearLayoutManager(context));
FilePickerShowAdapter adapter = new FilePickerShowAdapter(context,yx_files);
rl_yx_file.setAdapter(adapter);
adapter.setOnDeleteListener(new OnDeleteListener() {
@Override
public void delete(int position) {
File file= yx_files.get(position).getFile();
if (file.exists() && file.isFile())
{
file.delete();
}
}
});
}

private static boolean checkExits(String path) {
for (FileEntity entity : PickerManager.getInstance().files) {
if (entity.getPath().equals(path)) {
return true;
}
}
return false;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {


+ 68
- 7
app/src/main/res/layout/fragment_system_internet.xml View File

@@ -11,16 +11,77 @@
android:orientation="vertical"
android:background="@color/main_background">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rl_file"
<!-- 本地已存在资源 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/dp_10"
android:paddingTop="@dimen/dp_10"
android:paddingRight="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_10">
<RelativeLayout
android:background="@color/qmui_config_color_white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="已有图片列表"/>
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="@dimen/dp_10"

android:background="@color/main_background">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rl_yx_file"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
/>
</RelativeLayout>
</LinearLayout>

<!-- 选择资源 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:scrollbars="none"
/>
android:orientation="vertical"
android:paddingLeft="@dimen/dp_10"
android:paddingRight="@dimen/dp_10">
<RelativeLayout
android:background="@color/qmui_config_color_white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择图片列表"/>
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="@dimen/dp_10"
android:background="@color/main_background">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rl_file"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
/>
</RelativeLayout>
</LinearLayout>

<LinearLayout
android:layout_margin="@dimen/dp_10"
android:layout_width="match_parent"


Loading…
Cancel
Save