public void removerImovel(ImovelMobile imovel) { open(); database.delete( SiDIMSQLiteHelper.TABLE_FAVORITOS, SiDIMSQLiteHelper.COLUMN_ID_MOVEL + " = " + imovel.getIdImovel(), null); close(); }
public int insertFavorito(ImovelMobile imovel, List<String> photos) throws SiDIMException { ContentValues values = new ContentValues(); values.put(SiDIMSQLiteHelper.COLUMN_ID_MOVEL, imovel.getIdImovel()); values.put(SiDIMSQLiteHelper.COLUMN_ESTADO, imovel.getEstado().getUf()); values.put(SiDIMSQLiteHelper.COLUMN_TIPO_IMOVEL, imovel.getTipoImovel().getDescricao()); values.put(SiDIMSQLiteHelper.COLUMN_CIDADE, imovel.getCidade().getNome()); values.put(SiDIMSQLiteHelper.COLUMN_BAIRRO, imovel.getBairro().getNome()); values.put(SiDIMSQLiteHelper.COLUMN_QTD_DORM, imovel.getDormitorios()); values.put(SiDIMSQLiteHelper.COLUMN_AREA_CONSTRUIDA, imovel.getAreaConstruida()); values.put(SiDIMSQLiteHelper.COLUMN_AREA_TOTAL, imovel.getAreaTotal()); values.put(SiDIMSQLiteHelper.COLUMN_QTD_GARAG, imovel.getGaragens()); values.put(SiDIMSQLiteHelper.COLUMN_QTD_SUITES, imovel.getSuites()); values.put(SiDIMSQLiteHelper.COLUMN_CEP, imovel.getCep()); values.put(SiDIMSQLiteHelper.COLUMN_RUA, imovel.getRua()); values.put(SiDIMSQLiteHelper.COLUMN_PRECO, imovel.getPreco().doubleValue()); values.put(SiDIMSQLiteHelper.COLUMN_DESCRICAO, imovel.getDescricao()); values.put(SiDIMSQLiteHelper.COLUMN_INTENCAO, imovel.getIntencao()); // SALVAR FOTOS NO SDCARD try { File root = new File(Environment.getExternalStorageDirectory(), "appsidim"); if (!root.exists()) { root.mkdirs(); } FileOutputStream os; String allPhotos = ""; ImageView image = new ImageView(context); Bitmap bitmap; int i = 0; for (String urlImage : photos) { if (SessionUserSidim.images.containsKey(urlImage)) { bitmap = SessionUserSidim.images.get(urlImage); } else { bitmap = drawManager.fetchDrawable(urlImage); } String nameFile = imovel.getIdImovel() + "00" + i + ".png"; File file = new File(root, nameFile); allPhotos += nameFile + ";"; os = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 100, os); os.flush(); os.close(); image.setImageResource(R.drawable.casabonita); i++; } removerImovel(imovel); values.put(SiDIMSQLiteHelper.COLUMN_FOTOS, allPhotos); } catch (NumberFormatException e2) { throw new NumberFormatException(); } catch (Exception e) { throw new SiDIMException("Seu SDCard não está disponível para salvar as fotos"); } open(); database.insert(SiDIMSQLiteHelper.TABLE_FAVORITOS, null, values); Cursor cursor = database.query( SiDIMSQLiteHelper.TABLE_FAVORITOS, null, SiDIMSQLiteHelper.COLUMN_ID_MOVEL + " = " + imovel.getIdImovel(), null, null, null, null); int id = 0; if (cursor.moveToFirst()) { id = cursor.getInt(SiDIMSQLiteHelper.COLUMN_ID_MOVEL_INDEX); } cursor.close(); close(); return id; }
public ImovelMobile getImovel(ImovelMobile imovelParam) { open(); ImovelMobile imovel = null; Cursor cursor = database.query( SiDIMSQLiteHelper.TABLE_FAVORITOS, null, SiDIMSQLiteHelper.COLUMN_ID_MOVEL + " = " + imovelParam.getIdImovel(), null, null, null, null); if (cursor.moveToNext()) { try { imovel = new ImovelMobile(); imovel.setIdImovel(cursor.getInt(SiDIMSQLiteHelper.COLUMN_ID_MOVEL_INDEX)); imovel.setEstado(new Estado(cursor.getString(SiDIMSQLiteHelper.COLUMN_ESTADO_INDEX), "")); imovel.setTipoImovel( new TipoImovel( (short) 0, cursor.getString(SiDIMSQLiteHelper.COLUMN_TIPO_IMOVEL_INDEX))); imovel.setCidade( new Cidade(0, null, cursor.getString(SiDIMSQLiteHelper.COLUMN_CIDADE_INDEX), "")); imovel.setBairro( new Bairro(0, null, cursor.getString(SiDIMSQLiteHelper.COLUMN_BAIRRO_INDEX), "")); imovel.setDormitorios((byte) cursor.getInt(SiDIMSQLiteHelper.COLUMN_QTD_DORM_INDEX)); imovel.setAreaConstruida(cursor.getDouble(SiDIMSQLiteHelper.COLUMN_AREA_CONSTRUIDA_INDEX)); imovel.setAreaTotal(cursor.getDouble(SiDIMSQLiteHelper.COLUMN_AREA_TOTAL_INDEX)); imovel.setSuites((byte) cursor.getInt(SiDIMSQLiteHelper.COLUMN_QTD_SUITES_INDEX)); imovel.setGaragens((byte) cursor.getInt(SiDIMSQLiteHelper.COLUMN_QTD_GARAG_INDEX)); imovel.setCep(cursor.getString(SiDIMSQLiteHelper.COLUMN_CEP_INDEX)); imovel.setRua(cursor.getString(SiDIMSQLiteHelper.COLUMN_RUA_INDEX)); imovel.setPreco(new BigDecimal(cursor.getDouble(SiDIMSQLiteHelper.COLUMN_PRECO_INDEX))); imovel.setDescricao(cursor.getString(SiDIMSQLiteHelper.COLUMN_DESCRICAO_INDEX)); imovel.setFotos( SessionUserSidim.getListPhotoUrl( cursor.getString(SiDIMSQLiteHelper.COLUMN_FOTOS_INDEX))); imovel.setIntencao(cursor.getString(SiDIMSQLiteHelper.COLUMN_INTENCAO_INDEX)); } catch (Exception e) { imovel = null; } finally { cursor.close(); close(); } } return imovel; }