Skip to content

Commit

Permalink
Corrigindo Bug encontrado por Israel reportado nos comentários do blog
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson Glauber committed Jun 25, 2017
1 parent 6939932 commit 9708599
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.List;

public class HotelHttp {
public static final String SERVIDOR = "http://172.28.149.196/hotel_service";
public static final String SERVIDOR = "http://192.168.25.29/hotel_service";
private static final String WEBSERVICE_URL = SERVIDOR +"/webservice.php";
private Context mContext;
private HotelRepositorio mRepositorio;
Expand All @@ -29,11 +29,14 @@ public HotelHttp(Context ctx) {
public void sincronizar() throws Exception {
enviarDadosPendentes();
List<Hotel> hoteis = getHoteis();
List<Long> serverIds = new ArrayList<>();
ContentResolver cr = mContext.getContentResolver();
for (Hotel hotel : hoteis) {
serverIds.add(hotel.idServidor);
hotel.status = Hotel.Status.OK;
mRepositorio.inserirLocal(hotel, cr);
}
mRepositorio.excluirLocal(serverIds, cr);
}
private void enviarDadosPendentes() throws Exception{
Cursor cursor = mContext.getContentResolver().query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.CursorLoader;
import android.text.TextUtils;

import java.util.List;

public class HotelRepositorio {
private Context ctx;
public HotelRepositorio(Context ctx) {
Expand Down Expand Up @@ -107,5 +111,12 @@ public int excluirLocal(Hotel hotel, ContentResolver cr) {
int linhasAfetadas = cr.delete(uri, null, null);
return linhasAfetadas;
}

public int excluirLocal(List<Long> serverIds, ContentResolver cr) {
String ids = TextUtils.join(",", serverIds);
Uri uri = HotelProvider.CONTENT_URI;
int linhasAfetadas = cr.delete(uri, HotelSQLHelper.COLUNA_ID_SERVIDOR +" NOT IN (" + ids +")", null);
return linhasAfetadas;
}
}

0 comments on commit 9708599

Please sign in to comment.