android反馈简书,Android的5图选择举报反馈

1.反馈的页面

public class FeedBackActivity extends BaseBindBarActivity {

private List datas = new ArrayList<>();

private int target_id;

private int type=1;

@Override

protected int getLayoutId() {

return R.layout.activity_feedback;

}

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).statusBarDarkFont(true).init();

initView();

onEvent();

}

private void onEvent() {

db.tvSubmit.setOnClickListener(v -> submitLast());

}

private void initView() {

tvTitle.setText("举报");

target_id = getIntent().getIntExtra("id",0);

type = getIntent().getIntExtra("type",1);

FeedBackUtils.setImgs(this,"您可以上传截图,最多5张",db.recyclerView,datas);

}

/**

* 发起举报

* target_id 整型 必须 动态或订单ID 无

* type 整型 必须 类型 1动态(拌拌)2订单

* content 字符串 必须 举报内容 无

* images 字符串 可选 举报图片文件对象数组 无

*/

private void submitLast() {

if (EditTextUtils.isEmpty(db.etContent))return;

String content = db.etContent.getText().toString();

RequestBody idBody = RequestBody.create(MediaType.parse("text/plain"), target_id+"");

RequestBody typeBody = RequestBody.create(MediaType.parse("text/plain"), type+"");

RequestBody contentBody = RequestBody.create(MediaType.parse("text/plain"), content);

Map map = new HashMap<>();

for (int i = 0; i < datas.size(); i++) {

FeedBackPicBean feedBackPicBean = datas.get(i);

String path = feedBackPicBean.getPath();

if (!TextUtils.isEmpty(path)){

File file = new File(path);

RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);

map.put("images[]\"; filename=\"" + file.getName(), fileBody);

}

}

dataProvider.appUser.report(idBody,typeBody,contentBody,map)

.subscribe(new OnSuccessAndFailListener>(dialog) {

@Override

protected void onSuccess(BaseResponse baseResponse) {

BaseErrResponse data = baseResponse.getData();

String message = data.getMessage();

ToastUtil.showLong(message);

FeedBackActivity.this.finish();

}

});

}

}

2.布局activity_feedback

xmlns:app="http://schemas.android.com/apk/res-auto">

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/include1"

layout="@layout/action_common_bar_bill" />

android:id="@+id/et_content"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:background="@color/white"

android:gravity="top|left"

android:hint="请尽可能详细的输入举报内容"

android:lineSpacingExtra="5dp"

android:lines="6"

android:paddingLeft="16dp"

android:paddingTop="10dp"

android:paddingRight="16dp"

android:paddingBottom="10dp"

android:textColor="@color/tv_black"

android:textSize="16sp"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toBottomOf="@id/include1" />

android:overScrollMode="never"

android:background="@color/white"

android:id="@+id/recycler_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/et_content"

android:clipChildren="false"

/>

android:id="@+id/tv_submit"

android:layout_width="240dp"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_marginTop="100dp"

android:layout_marginBottom="60dp"

android:background="@drawable/round_brown_gradual_bg"

android:gravity="center"

android:paddingTop="12dp"

android:paddingBottom="12dp"

android:text="提交"

android:textColor="@color/white"

android:textSize="18sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent" />

3.工具类

public class FeedBackUtils {

/**

* 反馈的5图片操作

* @param context 页面

* @param desc 上传图片张数描述

* @param recyclerView 列表展示

* @param datas 要上传的图片集合

*/

public static void setImgs(Activity context,String desc, RecyclerView recyclerView, List datas){

int dp16 = DpPxUtils.dp2px(16);

TextView tvU = new TextView(context);

tvU.setText(desc);

tvU.setPadding(dp16,dp16,dp16,dp16);

tvU.setTextColor(ContextCompat.getColor(context, R.color.tv_gray));

tvU.setTextSize(14);

FeedBackPicAdapter mAdapter = new FeedBackPicAdapter();

mAdapter.openLoadAnimation();

mAdapter.addData(new FeedBackPicBean(""));

mAdapter.addFooterView(tvU);

recyclerView.setLayoutManager(new GridLayoutManager(context,5));

recyclerView.setAdapter(mAdapter);

//图片的删除和添加

mAdapter.setOnItemChildClickListener((adapter, view, position) -> {

FeedBackPicBean item = (FeedBackPicBean) adapter.getItem(position);

switch (view.getId()){

case R.id.iv_del:

mAdapter.remove(position);

List data = mAdapter.getData();

if (data.size()==0||!TextUtils.isEmpty(data.get(data.size()-1).getPath())){

FeedBackPicBean feedBackPicBean = new FeedBackPicBean("");

mAdapter.addData(feedBackPicBean);

}

break;

case R.id.iv_pic:

if (TextUtils.isEmpty(item.getPath()))

getPic(context,mAdapter,datas);

break;

}

});

getPermission(context);

}

private static void getPic(Activity activity, FeedBackPicAdapter mAdapter,List datas) {

int size = datas.size();

int maxSelectNum = size==0?5:(5-(size-1));

PictureParameterStyle pictureParameterStyle = new PictureParameterStyle();

pictureParameterStyle.pictureStatusBarColor = 0xFF393a3e;

pictureParameterStyle.pictureTitleBarBackgroundColor = 0xFF393a3e;

PictureSelector.create(activity)

.openGallery(PictureMimeType.ofImage())

.loadImageEngine(GlideEngine.createGlideEngine())

.isWeChatStyle(true)

.maxSelectNum(maxSelectNum)

.selectionMode(PictureConfig.MULTIPLE)

.isWithVideoImage(true)

.previewImage(true)

.isCamera(true)

.compress(true)

.compressSavePath(activity.getExternalCacheDir().getPath())

.setPictureStyle(pictureParameterStyle)

.forResult(result -> {

if (datas.size()>0){

String path = datas.get(datas.size() - 1).getPath();

if (TextUtils.isEmpty(path))datas.remove(datas.size()-1);

}

for (int i = 0; i < result.size(); i++) {

LocalMedia localMedia = result.get(i);

String androidQToPath = localMedia.getCompressPath();

datas.add(new FeedBackPicBean(androidQToPath));

}

if (datas.size()<5)datas.add(new FeedBackPicBean(""));

mAdapter.setNewData(datas);

});

}

private static void getPermission(Activity activity) {

AndPermission.with(activity)

.runtime()

.permission(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE)

.onGranted(permissions -> {

// ToastUtil.showShort("已经获取权限,可以提交反馈了。");

})

.onDenied(permissions -> {

ToastUtil.showShort("你拒绝了获取此权限!");

// 这些权限被用户总是拒绝。

if (AndPermission.hasAlwaysDeniedPermission(activity, permissions)) {

new AlertDialog.Builder(activity)

.setTitle("权限申请")

.setMessage("需要此权限才能使用此功能,去设置?")

.setPositiveButton("去设置", (dialog, which) -> AppUtils.goIntentSetting(activity))

.setNegativeButton("取消",null)

.show();

}

})

.start();

}

}

其中用到了图片选择器和权限申请

implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.4.6'

implementation 'com.yanzhenjie:permission:2.0.3'

3c19ea707fd8

image.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值