d
This commit is contained in:
@@ -8,6 +8,7 @@ import android.support.multidex.MultiDex;
|
||||
import android.util.Log;
|
||||
|
||||
import com.lzy.ninegrid.NineGridView;
|
||||
import com.sl.house_property.db.dao.DataBaseHelper;
|
||||
import com.tencent.bugly.Bugly;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@@ -74,7 +75,7 @@ public class MyApplication extends Application{
|
||||
StrictMode.setVmPolicy(builder.build());
|
||||
NineGridView.setImageLoader(new NineImageLoader());
|
||||
|
||||
|
||||
DataBaseHelper.initOrmLite(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sl.house_property.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@DatabaseTable(tableName = "tab_comment")
|
||||
public class CommentBeanData extends DbBean implements Serializable {
|
||||
@DatabaseField(id = true,columnName = "Id")
|
||||
private String id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@DatabaseField(columnName = "comment")
|
||||
private String comment;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@DatabaseField(columnName = "type")
|
||||
private String type;//1.评论话术 2.私信话术 3.直播话术 4.回访话术 5.首关话术
|
||||
}
|
||||
4
app/src/main/java/com/sl/house_property/db/DbBean.java
Normal file
4
app/src/main/java/com/sl/house_property/db/DbBean.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.sl.house_property.db;
|
||||
|
||||
public class DbBean {
|
||||
}
|
||||
120
app/src/main/java/com/sl/house_property/db/dao/CommentDao.java
Normal file
120
app/src/main/java/com/sl/house_property/db/dao/CommentDao.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package com.sl.house_property.db.dao;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.SQLException;
|
||||
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.sl.house_property.db.CommentBeanData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentDao {
|
||||
private static Dao<CommentBeanData, Integer> userAccountDao;
|
||||
|
||||
public CommentDao(Context mContext) {
|
||||
DataBaseHelper dataBaseHelper = DataBaseHelper.getInstance(mContext);
|
||||
try {
|
||||
try {
|
||||
userAccountDao = dataBaseHelper.getDao(CommentBeanData.class);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public long addInsert(CommentBeanData userData) {
|
||||
int id = 0;
|
||||
try {
|
||||
try {
|
||||
id = userAccountDao.create(userData);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public List<CommentBeanData> queryByCustom(String columnName, String columnValue) {
|
||||
List<CommentBeanData> ormTables = new ArrayList<>();
|
||||
try {
|
||||
ormTables = userAccountDao.queryBuilder().where().eq(columnName, columnValue).query();
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ormTables;
|
||||
}
|
||||
|
||||
public List<CommentBeanData> queryByCustomtwo(String columnName, String columnValue) {
|
||||
List<CommentBeanData> ormTables = new ArrayList<>();
|
||||
try {
|
||||
// ormTables = userAccountDao.queryBuilder().where().eq(columnName, columnValue).query();
|
||||
ormTables= userAccountDao.queryBuilder().where().like("phone", "%"+columnValue+"%").or().like("name","%"+columnValue+"%").query();
|
||||
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ormTables;
|
||||
}
|
||||
|
||||
public boolean updateData(CommentBeanData userData) {
|
||||
|
||||
try {
|
||||
int result = userAccountDao.update(userData);
|
||||
if (result != -1) {
|
||||
return true;
|
||||
|
||||
}
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<CommentBeanData> queryInByCustom(String columnName, String columnValues){
|
||||
List<CommentBeanData> ormTables = new ArrayList<>();
|
||||
try {
|
||||
List<String> strings = Arrays.asList(columnValues.split(","));
|
||||
|
||||
ormTables = userAccountDao.queryBuilder().where().in(columnName,strings ).query();
|
||||
}catch (java.sql.SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ormTables;
|
||||
}
|
||||
|
||||
public ArrayList<CommentBeanData> queryAll() {
|
||||
ArrayList<CommentBeanData> userAccountList = new ArrayList<>();
|
||||
try {
|
||||
userAccountList = (ArrayList<CommentBeanData>) userAccountDao.queryForAll();
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userAccountList;
|
||||
}
|
||||
|
||||
public long delete(List<CommentBeanData> DATA){
|
||||
int id = 0;
|
||||
try {
|
||||
try {
|
||||
id = userAccountDao.delete(DATA);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.sl.house_property.db.dao;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import com.sl.house_property.db.CommentBeanData;
|
||||
|
||||
public class DataBaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private static final String TABLE_NAME = "sqlite-test.db";
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private static final int DBVERSION = 1;
|
||||
|
||||
private static Context mContext;
|
||||
/**
|
||||
* 单例
|
||||
*/
|
||||
private static DataBaseHelper mInstance;
|
||||
private static DataBaseHelper dataBaseHelper;
|
||||
|
||||
|
||||
private DataBaseHelper(Context context) {
|
||||
super(context, TABLE_NAME, null, DBVERSION);
|
||||
}
|
||||
|
||||
public synchronized static DataBaseHelper getInstance(Context mContext) {
|
||||
if (dataBaseHelper == null) {
|
||||
dataBaseHelper = new DataBaseHelper(mContext);
|
||||
}
|
||||
return dataBaseHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static void initOrmLite(Context context) {
|
||||
mContext = context;
|
||||
getIntence();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据库表
|
||||
*
|
||||
* @param database
|
||||
* @param connectionSource
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database,
|
||||
ConnectionSource connectionSource) {
|
||||
try {
|
||||
|
||||
TableUtils.createTable(connectionSource, CommentBeanData.class);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级数据库
|
||||
*
|
||||
* @param database
|
||||
* @param connectionSource
|
||||
* @param oldVersion
|
||||
* @param newVersion
|
||||
*/
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database,
|
||||
ConnectionSource connectionSource, int oldVersion, int newVersion) {
|
||||
try {
|
||||
|
||||
|
||||
onCreate(database, connectionSource);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单例获取该Helper
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static synchronized DataBaseHelper getIntence() {
|
||||
|
||||
if (null == mInstance) {
|
||||
synchronized (DataBaseHelper.class) {
|
||||
if (null == mInstance) {
|
||||
mInstance = new DataBaseHelper(mContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据对象
|
||||
*
|
||||
* @param classz 对应的表实体的字节码对象
|
||||
* @return Dao<T, ID> :T:表实体对象类型.ID:对应的表实体中被指定为id字段的属性类型
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Override
|
||||
public Dao getDao(Class classz) throws SQLException, java.sql.SQLException {
|
||||
return super.getDao(classz);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import com.lxj.xpopup.XPopup;
|
||||
import com.selectpicker.OptionsPopupWindow;
|
||||
import com.sl.house_property.BaseActivity;
|
||||
import com.sl.house_property.R;
|
||||
import com.sl.house_property.db.CommentBeanData;
|
||||
import com.sl.house_property.db.dao.CommentDao;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -32,18 +34,22 @@ import my_loader.Resultcode;
|
||||
import rx.Subscription;
|
||||
import rx.functions.Action1;
|
||||
import tools.Config;
|
||||
import utils.DateUtils;
|
||||
import utils.DateUtilss;
|
||||
import utils.Md5;
|
||||
|
||||
public class ShareCodeActivity extends BaseActivity<com.sl.house_property.databinding.ActivityEntranceguardControl2Binding> {
|
||||
|
||||
private String user_home_id;
|
||||
private String fangchan,time;
|
||||
private CommentDao commentDao;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_entranceguard_control2;
|
||||
}
|
||||
|
||||
private int timeday = 7;
|
||||
private int timeday = 1;
|
||||
private OptionsPopupWindow alarmOptionPop;
|
||||
|
||||
@Override
|
||||
@@ -55,18 +61,19 @@ public class ShareCodeActivity extends BaseActivity<com.sl.house_property.databi
|
||||
finish();
|
||||
}
|
||||
}, 0, null, 0, null, 0, null, "");
|
||||
// Map<String, String> map = new HashMap<>();
|
||||
// RegisterUser registerUser = Config.getInstance(ShareCodeActivity.this).getUser();
|
||||
// if (registerUser != null) {
|
||||
// map.put("userid", registerUser.getUserid());
|
||||
// } else {
|
||||
// map.put("userid", 0 + "");
|
||||
// }
|
||||
//
|
||||
// map.put("sign", Md5.md5("Cas" + "GetMyAddress" + Md5.secret));
|
||||
// map.put("app", "Cas");
|
||||
// map.put("class", "GetMyAddress");
|
||||
// getGankList(ApiConfig.BASE_URL, map, "", 0);
|
||||
commentDao = new CommentDao(ShareCodeActivity.this);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
RegisterUser registerUser = Config.getInstance(ShareCodeActivity.this).getUser();
|
||||
if (registerUser != null) {
|
||||
map.put("userid", registerUser.getUserid());
|
||||
} else {
|
||||
map.put("userid", 0 + "");
|
||||
}
|
||||
|
||||
map.put("sign", Md5.md5("Cas" + "GetMyAddress" + Md5.secret));
|
||||
map.put("app", "Cas");
|
||||
map.put("class", "GetMyAddress");
|
||||
getGankList(ApiConfig.BASE_URL, map, "", 0);
|
||||
user_home_id= getIntent().getStringExtra("id");
|
||||
// String address = getIntent().getStringExtra("address");
|
||||
|
||||
@@ -74,6 +81,9 @@ public class ShareCodeActivity extends BaseActivity<com.sl.house_property.databi
|
||||
mDataBinding.myradio2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup radioGroup, int i) {
|
||||
if (i == R.id.myradio20) {
|
||||
timeday = 1;
|
||||
}
|
||||
if (i == R.id.myradio21) {
|
||||
timeday = 7;
|
||||
}
|
||||
@@ -190,6 +200,7 @@ public class ShareCodeActivity extends BaseActivity<com.sl.house_property.databi
|
||||
list = new Gson().fromJson(jsonArray.toString(), type);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
mDataBinding.tvAddress.setText(list.get(0).getAddress());
|
||||
fangchan=list.get(0).getAddress();
|
||||
user_home_id = list.get(0).getUser_home_id();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
@@ -280,6 +291,7 @@ public class ShareCodeActivity extends BaseActivity<com.sl.house_property.databi
|
||||
map.put("app", "Door");
|
||||
map.put("class", "SendCustomerCode");
|
||||
map.put("type", "password");
|
||||
map.put("validity_time", timeday + "");
|
||||
// map.put("phone", mDataBinding.telephone.getText().toString().trim());
|
||||
// map.put("validity_time", mDataBinding.daytiems.getText().toString().trim());
|
||||
map.put("user_home_id", user_home_id);
|
||||
@@ -299,9 +311,30 @@ public class ShareCodeActivity extends BaseActivity<com.sl.house_property.databi
|
||||
JSONObject jsonArray = new JSONObject(s);
|
||||
String pwd = jsonArray.optString("code", "");
|
||||
|
||||
// time= DateUtilss.getDate();
|
||||
time= DateUtilss.getDateTime();
|
||||
ArrayList<CommentBeanData> commentBeanData1 = commentDao.queryAll();
|
||||
if(commentBeanData1.size()>5){
|
||||
setToast("最多只能申请5条秘钥");
|
||||
return;
|
||||
}else {
|
||||
CommentBeanData commentBeanData = new CommentBeanData();
|
||||
commentBeanData.setId("1");
|
||||
commentBeanData.setComment(fangchan);
|
||||
commentBeanData.setType(time);
|
||||
if (null != commentDao.queryByCustom("Id", commentBeanData.getId()) && commentDao.queryByCustom("Id", commentBeanData.getId()).size() > 0) {
|
||||
commentDao.updateData(commentBeanData);
|
||||
} else {
|
||||
commentDao.addInsert(commentBeanData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ShareCodeDialog shareCodeDialog = new ShareCodeDialog(ShareCodeActivity.this);
|
||||
shareCodeDialog.setCode(code);
|
||||
shareCodeDialog.setPwd(pwd);
|
||||
shareCodeDialog.setPwd(pwd,time,fangchan);
|
||||
new XPopup.Builder(ShareCodeActivity.this).asCustom(shareCodeDialog).show();
|
||||
|
||||
} catch (JSONException e) {
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.sl.house_property.discovery;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.lxj.xpopup.core.CenterPopupView;
|
||||
@@ -15,15 +17,18 @@ import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import utils.QRCodeUtil;
|
||||
|
||||
public class ShareCodeDialog extends CenterPopupView {
|
||||
private String pwd;
|
||||
private String pwd,time,fangchan;
|
||||
private String code;
|
||||
private TextView tvPwd;
|
||||
private TextView tvPwd,title3,title5;
|
||||
private ImageView ivCode;
|
||||
private TextView tvShare;
|
||||
private TextView tvCancel;
|
||||
private LinearLayout ly_all;
|
||||
// APP_ID 替换为你的应用从官方网站申请到的合法appID
|
||||
private static final String APP_ID = "wx7e09fff168f6e58d";
|
||||
// IWXAPI 是第三方app和微信通信的openApi接口
|
||||
@@ -61,9 +66,12 @@ public class ShareCodeDialog extends CenterPopupView {
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
tvPwd = findViewById(R.id.title2);
|
||||
title3 = findViewById(R.id.title3);
|
||||
title5 = findViewById(R.id.title5);
|
||||
ivCode = findViewById(R.id.myImage);
|
||||
tvShare = findViewById(R.id.tv_share);
|
||||
tvCancel = findViewById(R.id.tv_cancel);
|
||||
ly_all = findViewById(R.id.ly_all);
|
||||
tvCancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -78,15 +86,37 @@ public class ShareCodeDialog extends CenterPopupView {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
tvPwd.setText("密码:" + pwd);
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
for (int i = 0; i < pwd.length(); i++) {
|
||||
char item = pwd.charAt(i);
|
||||
strings.add(String.valueOf(item));
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append(strings.get(0));
|
||||
sb.append(" ");//空格
|
||||
sb.append(strings.get(1));
|
||||
sb.append(" ");//空格
|
||||
sb.append(strings.get(2));
|
||||
sb.append(" ");//空格
|
||||
sb.append(strings.get(3));
|
||||
String pwdd = sb.toString();
|
||||
tvPwd.setText("" + pwdd);
|
||||
// title3.setText("注:分享临时门禁给访客,扫描二维码或输入密码开门" +"(有效期至"+ time+"时)");
|
||||
title3.setText(Html.fromHtml("注:分享临时门禁给访客,扫描二维码或输入密码开门" +"(有效期至"+"<font color='#ff0000'>"+ time +"</font>"+"分)"));
|
||||
|
||||
title5.setText("" + fangchan);
|
||||
final Bitmap qrCodeBitmap = QRCodeUtil.createQRCodeBitmap(code, QRCodeUtil.dip2px(getContext(), 220), QRCodeUtil.dip2px(getContext(), 220));
|
||||
ivCode.setImageBitmap(qrCodeBitmap);
|
||||
findViewById(R.id.tv_share).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bitmap bitmap_view = takeScreenShotOfView(ly_all);
|
||||
|
||||
|
||||
//初始化 WXImageObject 和 WXMediaMessage 对象
|
||||
WXImageObject imgObj = new WXImageObject(qrCodeBitmap);
|
||||
// WXImageObject imgObj = new WXImageObject(qrCodeBitmap);
|
||||
WXImageObject imgObj = new WXImageObject(bitmap_view);
|
||||
WXMediaMessage msg = new WXMediaMessage();
|
||||
msg.mediaObject = imgObj;
|
||||
msg.title = "临时门禁";
|
||||
@@ -103,9 +133,19 @@ public class ShareCodeDialog extends CenterPopupView {
|
||||
});
|
||||
}
|
||||
|
||||
public Bitmap takeScreenShotOfView(View v) {
|
||||
v.setDrawingCacheEnabled(true);
|
||||
v.buildDrawingCache(true);
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
|
||||
v.setDrawingCacheEnabled(false); // clear drawing cache
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd,String time,String fangchan) {
|
||||
this.pwd = pwd;
|
||||
this.time = time;
|
||||
this.fangchan = fangchan;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user