package com.tejia.lijin.app.ui.recommend;
|
|
import android.content.DialogInterface;
|
import android.content.SharedPreferences;
|
import android.os.Build;
|
import android.os.Bundle;
|
import androidx.annotation.Nullable;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.EditText;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ui.BaseActivity;
|
import com.tejia.lijin.app.ui.dialog.EditTextPreviewDialog;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
/**
|
* 文字编辑模板
|
*/
|
public class ActivityContentCompile extends BaseActivity implements View.OnClickListener {
|
private TextView tv_top_bar_left;
|
private TextView tv_top_bar_middle;
|
|
private TextView content_compile_preview;//预览文字模板
|
private TextView content_compile_save;//保存文字模板
|
|
private TextView tv_special_hint;
|
|
private EditText et_content_compile;
|
private String content;
|
boolean hasCoupon = false;
|
String goodsId, tljId;
|
int goodsType;
|
|
@Override
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_content_compile);
|
init();
|
setListeners();
|
tv_top_bar_middle.setText("编辑文字模版");
|
|
goodsId = getIntent().getStringExtra("goodsId");
|
tljId = getIntent().getStringExtra("tljId");
|
goodsType = getIntent().getIntExtra("goodsType", 1);
|
hasCoupon = getIntent().getBooleanExtra("hasCoupon", false);
|
getShareTextTemplate();
|
getShareTextTemplateRules();
|
}
|
|
private void init() {
|
tv_top_bar_left = findViewById(R.id.tv_top_bar_left);
|
tv_top_bar_middle = findViewById(R.id.tv_top_bar_middle);
|
content_compile_preview = findViewById(R.id.content_compile_preview);
|
content_compile_save = findViewById(R.id.content_compile_save);
|
et_content_compile = findViewById(R.id.et_content_compile);
|
tv_special_hint = findViewById(R.id.tv_special_hint);
|
}
|
|
private void setListeners() {
|
//设置状态栏
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
Window window = getWindow();
|
//设置状态栏颜色为白色
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
window.setStatusBarColor(getResources().getColor(R.color.white));
|
}
|
//设置状态栏文字颜色及图标为深色
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
}
|
tv_top_bar_left.setOnClickListener(this);
|
content_compile_preview.setOnClickListener(this);
|
content_compile_save.setOnClickListener(this);
|
}
|
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
case R.id.content_compile_preview://预览模板
|
if (StringUtils.isEmpty(et_content_compile.getText().toString())) {
|
Toast.makeText(ActivityContentCompile.this, "内容不能为空",
|
Toast.LENGTH_LONG).show();
|
break;
|
}
|
content = et_content_compile.getText().toString();
|
viewShareTextTemplate();
|
break;
|
case R.id.content_compile_save://保存模板
|
saveShareTextTemplate();
|
break;
|
default:
|
|
break;
|
}
|
}
|
|
/*
|
* 获取规则
|
*/
|
private void getShareTextTemplateRules() {
|
ShoppingApi.getShareTextTemplateRules(ActivityContentCompile.this, tljId, goodsType,
|
new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
tv_special_hint.setText(jsonObject.optString("data"));
|
}
|
}
|
});
|
}
|
|
/*
|
* 获取模板
|
*/
|
private void getShareTextTemplate() {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
String uid = sp.getString("uid", "");
|
ShoppingApi.getShareTextTemplate(ActivityContentCompile.this, uid, hasCoupon + "", tljId, goodsType,
|
new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
content = jsonObject.optJSONObject("data").optString("template");
|
et_content_compile.setText(content);
|
if (!StringUtils.isEmpty(content))
|
et_content_compile.setSelection(content.length());
|
}
|
}
|
});
|
}
|
|
/*
|
* 预览模板
|
*/
|
private void viewShareTextTemplate() {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
String uid = sp.getString("uid", "");
|
ShoppingApi.viewShareTextTemplate(ActivityContentCompile.this, uid,
|
goodsId, hasCoupon + "", content, tljId, goodsType, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
String content = jsonObject.optJSONObject("data").optString("content");
|
EditTextPreviewDialog.Builder builder = new EditTextPreviewDialog.Builder(ActivityContentCompile.this);
|
builder.setMessage(content)
|
.setPositiveButton("继续编辑", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
}
|
}).create().show();
|
}
|
}
|
});
|
}
|
|
/*
|
* 保存模板
|
*/
|
private void saveShareTextTemplate() {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
String uid = sp.getString("uid", "");
|
ShoppingApi.saveShareTextTemplate(ActivityContentCompile.this, uid,
|
hasCoupon + "", et_content_compile.getText().toString(), tljId, goodsType, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
finish();
|
Toast.makeText(ActivityContentCompile.this, "文字模板保存成功", Toast.LENGTH_LONG).show();
|
} else {
|
Toast.makeText(ActivityContentCompile.this, jsonObject.optString("msg"), Toast.LENGTH_LONG).show();
|
}
|
}
|
});
|
}
|
}
|