Linjiajia
2023-12-29 590c1cff46b105d774271f950caa9f65523f05c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.application.zhangshi_app_android.adapter;
 
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.util.TypedValue;
import android.view.View;
 
import com.android.app_base.base.adapter.BaseRVAdapter;
import com.application.zhangshi_app_android.R;
import com.application.zhangshi_app_android.databinding.ItemElectronicFileBinding;
import com.application.zhangshi_app_android.ui.ImagePreviewActivity;
import com.application.zhangshi_app_android.ui.VideoPlayActivity;
 
/**
 * @author Ljj
 * @date 2023.05.15. 21:46
 * @desc 卡片里的 电子文件 适配器
 */
public class ElectronicFileAdapter extends BaseRVAdapter<String,ItemElectronicFileBinding,BaseRVAdapter.BaseViewHolder<ItemElectronicFileBinding>> {
    public ElectronicFileAdapter(Context context) {
        super(context);
    }
 
    @Override
    protected int getLayoutId() {
        return R.layout.item_electronic_file;
    }
 
    @Override
    protected void onBind(BaseViewHolder<ItemElectronicFileBinding> holder, int position) {
        String item = mDataList.get(position);
        if (item != null) {
            int resid;
            if (item.endsWith(".pdf") || item.endsWith(".PDF")) {
                resid = R.attr.icPdf;
            } else if (item.endsWith(".zip") || item.endsWith(".ZIP") || item.endsWith(".aar") || item.endsWith(".AAR") || item.endsWith(".7z")) {
                resid = R.attr.icZip;
            } else if (item.endsWith(".doc") || item.endsWith(".docx") || item.endsWith(".DOC") || item.endsWith(".DOCX") || item.endsWith(".wps") || item.endsWith(".WPS")) {
                resid = R.attr.icWord;
            } else if (item.endsWith(".xls") || item.endsWith(".xlsx") || item.endsWith(".XLS") || item.endsWith(".XLSX")) {
                resid = R.attr.icExcel;
            } else if (item.endsWith(".ppt") || item.endsWith(".PPT") || item.endsWith(".pptx") || item.endsWith(".PPTX")) {
                resid = R.attr.icPpt;
            } else if (item.endsWith(".txt") || item.endsWith(".TXT")) {
                resid = R.attr.icTxt;
            } else if (item.endsWith(".jpg") || item.endsWith(".JPG") || item.endsWith(".jpeg") || item.endsWith(".JPEG") || item.endsWith(".png") || item.endsWith(".PNG") || item.endsWith(".gif") || item.endsWith(".GIF") || item.endsWith(".bmp") || item.endsWith(".BMP")) {
                resid = R.attr.icImage;
            } else if (item.endsWith(".mp4") || item.endsWith(".MP4") ) {
                resid = R.attr.icVideo;
            } else if (item.endsWith(".mp3") || item.endsWith(".m4a") || item.endsWith(".MP3") || item.endsWith(".M4A")) {
                resid = R.attr.icAudio;
            } else {
                resid = R.attr.icOther;
            }
            TypedValue typedValue = new TypedValue();
            mContext.getTheme().resolveAttribute(resid, typedValue, true);
            holder.getBinding().ivImage.setImageResource(typedValue.resourceId);
        }
    }
 
    @Override
    protected BaseViewHolder<ItemElectronicFileBinding> getViewHolder(ItemElectronicFileBinding itemBind, int viewType) {
        return new BaseViewHolder<>(itemBind);
    }
}