Commit b33bb731 authored by mahendri.md's avatar mahendri.md

remove some magic number

parent 5b8e2c40
...@@ -119,8 +119,8 @@ public class DataDownloadActivity extends AppCompatActivity ...@@ -119,8 +119,8 @@ public class DataDownloadActivity extends AppCompatActivity
public void onPostDownload(boolean successDownload, NotifData notifData) { public void onPostDownload(boolean successDownload, NotifData notifData) {
progressDialog.dismiss(); progressDialog.dismiss();
if (successDownload) if (successDownload)
Toast.makeText(this, "Gagal mengunduh", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "Isian sukses diunduh", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Isian sukses diunduh", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "Gagal mengunduh", Toast.LENGTH_SHORT).show();
} }
} }
...@@ -26,25 +26,34 @@ public class NotifDataDao { ...@@ -26,25 +26,34 @@ public class NotifDataDao {
String selectionArgs[] = {values.get(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID).toString(), String selectionArgs[] = {values.get(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID).toString(),
values.get(NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE).toString()}; values.get(NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE).toString()};
Cursor lebih = getNotifDataCursor(selection, selectionArgs); Cursor lebih = getNotifDataCursor(selection, selectionArgs);
/*
* untuk menghindari isian lama yang di download tampil pada list notifikasi, maka
* isian lama tersebut harus ditandai 0 (bukan terbaru)
*/
if(lebih.getCount()==0){ if(lebih.getCount()==0){
lebih.close(); lebih.close();
/*
* tandai isian yang tersimpan pada database menjadi bukan terbaru, jika data yang akan
* disimpan ternyata lebih baru
*/
String selection2 = NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID + " =? and " + String selection2 = NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID + " =? and " +
NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE + " < ? "; NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE + " < ? ";
String selectionArgs2[] = {values.get(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID).toString(), String selectionArgs2[] = {values.get(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID).toString(),
values.get(NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE).toString()}; values.get(NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE).toString()};
ContentValues valuesUpdate = new ContentValues(); ContentValues valuesUpdate = new ContentValues();
valuesUpdate.put(NotifDataProviderAPI.NotifDataColumns.LATEST,"0"); valuesUpdate.put(NotifDataProviderAPI.NotifDataColumns.LATEST,NotifDataColumns.DATA_NOT_LATEST);
Collect.getInstance().getContentResolver().update(NotifDataProviderAPI.NotifDataColumns.CONTENT_URI,valuesUpdate, selection2, selectionArgs2); Collect.getInstance().getContentResolver().update(NotifDataProviderAPI.NotifDataColumns.CONTENT_URI,valuesUpdate, selection2, selectionArgs2);
if(values.containsKey(NotifDataProviderAPI.NotifDataColumns.LATEST)){ if(values.containsKey(NotifDataProviderAPI.NotifDataColumns.LATEST)){
values.put(NotifDataProviderAPI.NotifDataColumns.LATEST,"1"); values.put(NotifDataProviderAPI.NotifDataColumns.LATEST, NotifDataColumns.DATA_LATEST);
} }
return Collect.getInstance().getContentResolver().insert(NotifDataProviderAPI.NotifDataColumns.CONTENT_URI, values); return Collect.getInstance().getContentResolver().insert(NotifDataColumns.CONTENT_URI, values);
}else{ }else{
lebih.close(); lebih.close();
if(values.containsKey(NotifDataProviderAPI.NotifDataColumns.LATEST)){ if(values.containsKey(NotifDataProviderAPI.NotifDataColumns.LATEST)){
values.put(NotifDataProviderAPI.NotifDataColumns.LATEST,"0"); values.put(NotifDataProviderAPI.NotifDataColumns.LATEST, NotifDataColumns.DATA_NOT_LATEST);
} }
return Collect.getInstance().getContentResolver().insert(NotifDataProviderAPI.NotifDataColumns.CONTENT_URI, values); return Collect.getInstance().getContentResolver().insert(NotifDataProviderAPI.NotifDataColumns.CONTENT_URI, values);
} }
...@@ -53,7 +62,7 @@ public class NotifDataDao { ...@@ -53,7 +62,7 @@ public class NotifDataDao {
//edit Mahendri //edit Mahendri
public Cursor getNotifDataCursor() { public Cursor getNotifDataCursor() {
String selection = NotifDataColumns.LATEST + " =? "; String selection = NotifDataColumns.LATEST + " =? ";
String[] selectionArgs = new String[]{String.valueOf(NotifDataColumns.IS_LATEST)}; String[] selectionArgs = new String[]{NotifDataColumns.DATA_LATEST};
return getNotifDataCursor(null, selection, selectionArgs, null); return getNotifDataCursor(null, selection, selectionArgs, null);
} }
......
...@@ -41,6 +41,7 @@ public final class NotifDataProviderAPI { ...@@ -41,6 +41,7 @@ public final class NotifDataProviderAPI {
public static final String LATEST = "mLatest"; public static final String LATEST = "mLatest";
//public static final String IS_DOWNLOADED = "mDownload"; //public static final String IS_DOWNLOADED = "mDownload";
public static final int IS_LATEST = 1; public static final String DATA_LATEST = "1";
public static final String DATA_NOT_LATEST = "0";
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment