From 976d277a787359fd0adab8cd50c84b9ea84b8d79 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 15 Jul 2024 07:29:23 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D1=81=D1=8F=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D1=89?= =?UTF-8?q?=D0=B8=D1=82=D0=BD=D0=BE=D0=B9=20=D0=BE=D0=B4=D0=B5=D0=B6=D0=B4?= =?UTF-8?q?=D0=B5=20(=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D0=B2=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=86=D1=8B=20=D1=8D=D1=82=D0=BE=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/dbfields/DateTimeTM.java | 31 +- .../main/java/kz/istt/locust/DBGUITable.java | 32 +- .../java/kz/istt/locust/DbOpenHelper.java | 29 +- .../java/kz/istt/locust/LocustActivity.java | 187 ----- .../kz/istt/locust/LocustDelActivity.java | 10 +- .../kz/istt/locust/LocustDelListActivity.java | 32 +- .../kz/istt/locust/LocustHealthActivity.java | 785 +++++++++++++++--- .../istt/locust/LocustHealthListActivity.java | 93 ++- .../main/java/kz/istt/locust/MyButton.java | 10 + .../kz/istt/locust/MySynchronizationOld.java | 7 +- .../drawable/{button.xml => button_blue.xml} | 6 +- ...on_focused.xml => button_blue_focused.xml} | 0 .../main/res/drawable/button_blue_normal.xml | 23 + ...ton_presed.xml => button_blue_pressed.xml} | 0 app/src/main/res/drawable/button_normal.xml | 49 -- app/src/main/res/drawable/button_pink.xml | 10 + .../main/res/drawable/button_pink_focused.xml | 27 + .../main/res/drawable/button_pink_normal.xml | 24 + .../main/res/drawable/button_pink_pressed.xml | 27 + .../res/layout/activity_locust_health.xml | 418 +++++----- .../layout/activity_locust_health_list.xml | 4 +- app/src/main/res/layout/activity_main.xml | 1 - app/src/main/res/menu/locust_del_list.xml | 4 +- app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/styles.xml | 10 +- 25 files changed, 1208 insertions(+), 613 deletions(-) rename app/src/main/res/drawable/{button.xml => button_blue.xml} (71%) rename app/src/main/res/drawable/{button_focused.xml => button_blue_focused.xml} (100%) create mode 100644 app/src/main/res/drawable/button_blue_normal.xml rename app/src/main/res/drawable/{button_presed.xml => button_blue_pressed.xml} (100%) delete mode 100644 app/src/main/res/drawable/button_normal.xml create mode 100644 app/src/main/res/drawable/button_pink.xml create mode 100644 app/src/main/res/drawable/button_pink_focused.xml create mode 100644 app/src/main/res/drawable/button_pink_normal.xml create mode 100644 app/src/main/res/drawable/button_pink_pressed.xml diff --git a/app/src/main/java/dbfields/DateTimeTM.java b/app/src/main/java/dbfields/DateTimeTM.java index 25268e8..5cc6c18 100644 --- a/app/src/main/java/dbfields/DateTimeTM.java +++ b/app/src/main/java/dbfields/DateTimeTM.java @@ -6,6 +6,10 @@ import android.os.Parcelable; import android.util.AttributeSet; import android.widget.EditText; +import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -32,13 +36,26 @@ public class DateTimeTM extends com.google.android.material.textfield.TextInputE m_Value = val; if(val!=null && !val.equals("")) { - Date date = new Date(Long.parseLong(m_Value)*1000); - - SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - //format.setTimeZone(TimeZone.getTimeZone("UTC")); - - String str = format.format(date); - setText(str); + Date date=null; + try { + date = new Date(Long.parseLong(m_Value)*1000); + } catch (NumberFormatException e) { + } + if(date==null){ + try { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + date = format.parse(m_Value); + } catch (ParseException e) { + } + } + if(date!=null) { + SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + //format.setTimeZone(TimeZone.getTimeZone("UTC")); + String str = format.format(date); + setText(str); + }else{ + setText(""); + } }else { setText(""); diff --git a/app/src/main/java/kz/istt/locust/DBGUITable.java b/app/src/main/java/kz/istt/locust/DBGUITable.java index 2e2da6c..31c230a 100644 --- a/app/src/main/java/kz/istt/locust/DBGUITable.java +++ b/app/src/main/java/kz/istt/locust/DBGUITable.java @@ -210,7 +210,9 @@ public class DBGUITable Object obj=findComponent(cursor.getColumnName(i)); if(obj!=null) { - Log.e("CCALM", "1 field " + cursor.getColumnName(i) + " = " + cursor.getString(i) + " type= " + cursor.getType(i)); + if(cursor.getColumnName(i).equals("date")) { + Log.e("CCALM", "1 field " + cursor.getColumnName(i) + " = " + cursor.getString(i) + " type= " + cursor.getType(i)); + } if(cursor.getType(i)==2){ //Because cutting double setValue(obj, ""+cursor.getDouble(i)); @@ -261,21 +263,21 @@ public class DBGUITable public void setValue(Object obj, String value) { if(obj==null) return; + String className = obj.getClass().toString(); + //Log.d("igor","getClass = "+className); - //Log.d("igor","getClass = "+obj.getClass().toString()); - - if(obj.getClass().toString().indexOf("android.widget.EditText")!=-1) ((EditText)obj).setText(value); - if(obj.getClass().toString().indexOf("android.material.textfield.TextInputEditText")!=-1) ((TextInputEditText)obj).setText(value); - if(obj.getClass().toString().indexOf("android.widget.Spinner")!=-1) Tools.selSpinnerIC(((Spinner)obj), value); - if(obj.getClass().toString().indexOf("android.widget.CheckBox")!=-1) ((CheckBox)obj).setChecked(value.equals("1") ? true : false); - //if(obj.getClass().toString().indexOf("java.lang.Integer")!=-1) ((Integer)obj)=Integer.parseInt(value); так не работает - //if(obj.getClass().toString().indexOf("java.lang.String")!=-1) ((String)obj)=value; так не работает - if(obj.getClass().toString().indexOf("dbfields.SpinnerDB")!=-1) ((SpinnerDB)obj).setValue(value); - if(obj.getClass().toString().indexOf("dbfields.AutoCompleteTextViewDB")!=-1) ((AutoCompleteTextViewDB)obj).setValue(value); - if(obj.getClass().toString().indexOf("dbfields.StringDB")!=-1) ((StringDB)obj).setValue(value); - if(obj.getClass().toString().indexOf("dbfields.DateTimeTM")!=-1) ((DateTimeTM)obj).setValue(value); - if(obj.getClass().toString().indexOf("dbfields.DateTimeText")!=-1) ((DateTimeText)obj).setValue(value); - if(obj.getClass().toString().indexOf("dbfields.DateInput")!=-1) + if(className.indexOf("android.widget.EditText")!=-1) ((EditText)obj).setText(value); + if(className.indexOf("android.material.textfield.TextInputEditText")!=-1) ((TextInputEditText)obj).setText(value); + if(className.indexOf("android.widget.Spinner")!=-1) Tools.selSpinnerIC(((Spinner)obj), value); + if(className.indexOf("android.widget.CheckBox")!=-1) ((CheckBox)obj).setChecked(value.equals("1") ? true : false); + //if(className.indexOf("java.lang.Integer")!=-1) ((Integer)obj)=Integer.parseInt(value); так не работает + //if(className.indexOf("java.lang.String")!=-1) ((String)obj)=value; так не работает + if(className.indexOf("dbfields.SpinnerDB")!=-1) ((SpinnerDB)obj).setValue(value); + if(className.indexOf("dbfields.AutoCompleteTextViewDB")!=-1) ((AutoCompleteTextViewDB)obj).setValue(value); + if(className.indexOf("dbfields.StringDB")!=-1) ((StringDB)obj).setValue(value); + if(className.indexOf("dbfields.DateTimeTM")!=-1) ((DateTimeTM)obj).setValue(value); + if(className.indexOf("dbfields.DateTimeText")!=-1) ((DateTimeText)obj).setValue(value); + if(className.indexOf("dbfields.DateInput")!=-1) { if(value==null) { ((DateInput)obj).setDate((Date)null); diff --git a/app/src/main/java/kz/istt/locust/DbOpenHelper.java b/app/src/main/java/kz/istt/locust/DbOpenHelper.java index c4a1feb..d9b6e72 100644 --- a/app/src/main/java/kz/istt/locust/DbOpenHelper.java +++ b/app/src/main/java/kz/istt/locust/DbOpenHelper.java @@ -22,7 +22,7 @@ import tctable.TCTable; public class DbOpenHelper extends SQLiteOpenHelper { - private static final int DB_VERSION = 152; //Версия ожидаемой базы + private static final int DB_VERSION = 153; //Версия ожидаемой базы private static final String DB_NAME = "Locust"; //Наименование базы //ArrayList lrFrmLocust = new ArrayList(); //Список обязательных полей для формы саранцчи @@ -478,7 +478,7 @@ public class DbOpenHelper extends SQLiteOpenHelper "terrain text, " + //Название местности либо урочища "observer text, " + //ФИО наблюдателя - "date integer, " + //Время создания секунд с 1970 года (long) (по гринвичу?) + "date text, " +//"date integer, " + //Время создания секунд с 1970 года (long) (по гринвичу?) "timezone text, " + //Временная зона "lat_center double, " + "lon_center double, " + @@ -582,7 +582,7 @@ public class DbOpenHelper extends SQLiteOpenHelper "terrain text, " + //Название местности либо урочища "observer text, " + //ФИО наблюдателя - "date integer," + //Время создания секунд с 1970 года (long), теоретически должна быть уникальной для пользователя (по гринвичу?) + "date text," + //"date integer," + //Время создания секунд с 1970 года (long), теоретически должна быть уникальной для пользователя (по гринвичу?) "timezone text, " + //Временная зона "lat_center double, " + "lon_center double, " + @@ -1350,6 +1350,29 @@ public class DbOpenHelper extends SQLiteOpenHelper oldVersion=152; } + if(oldVersion==152) { + //Теперь дата в виде текстового поля храниться так как при синхронизации с сервера она приходит в виде даты + db.execSQL("ALTER TABLE frmlocust ADD COLUMN date_temp TEXT;"); + db.execSQL("UPDATE frmlocust SET date_temp = date;"); + db.execSQL("ALTER TABLE frmlocust RENAME COLUMN date TO date_DEL;"); + db.execSQL("ALTER TABLE frmlocust RENAME COLUMN date_temp TO date;"); + + db.execSQL("ALTER TABLE frmlocustdel ADD COLUMN date_temp TEXT;"); + db.execSQL("UPDATE frmlocustdel SET date_temp = date;"); + db.execSQL("ALTER TABLE frmlocustdel RENAME COLUMN date TO date_DEL;"); + db.execSQL("ALTER TABLE frmlocustdel RENAME COLUMN date_temp TO date;"); + + db.execSQL("ALTER TABLE frmlocusthealth ADD COLUMN date_temp TEXT;"); + db.execSQL("UPDATE frmlocusthealth SET date_temp = date;"); + db.execSQL("ALTER TABLE frmlocusthealth RENAME COLUMN date TO date_DEL;"); + db.execSQL("ALTER TABLE frmlocusthealth RENAME COLUMN date_temp TO date;"); + + ++++++++ + sql = "ALTER TABLE frmlocusthealth ADD safety_clothing_clean boolean;"; + db.execSQL(sql); + + oldVersion=153; + } if(oldVersion < newVersion) //Это условие выполняется: если совсем старые версии и не знаю что поменялось... { diff --git a/app/src/main/java/kz/istt/locust/LocustActivity.java b/app/src/main/java/kz/istt/locust/LocustActivity.java index ad4ae83..541ba2c 100644 --- a/app/src/main/java/kz/istt/locust/LocustActivity.java +++ b/app/src/main/java/kz/istt/locust/LocustActivity.java @@ -835,194 +835,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener LocustActivity.this.edtLonCenter.setText(""); } }); -/* - btnGetGPS1 = (View) findViewById(R.id.btnGetGPS1); - OnClickListener oclBtnGetGPS = new OnClickListener() { - @Override - public void onClick(View v) { - DecimalFormatSymbols custom = new DecimalFormatSymbols(new Locale("en", "US")); - custom.setDecimalSeparator('.'); - DecimalFormat df = new DecimalFormat("0.0000000"); - df.setDecimalFormatSymbols(custom); - - if(LocustActivity.this._lat!=0 && LocustActivity.this._lon!=0) { - LocustActivity.this.edtLat1.setText(df.format(LocustActivity.this._lat)); - LocustActivity.this.edtLon1.setText(df.format(LocustActivity.this._lon)); - } - //TODO Если удалось получить координаты то добавляем ещё 1 поля для их ввода - - //Checking if the GPS is active and if it is inactive, I display a warning about it - LocationManager locationManager = (LocationManager) LocustActivity.this.getSystemService(Context.LOCATION_SERVICE);; - if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ - Toast.makeText(LocustActivity.this, LocustActivity.this.getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show(); - } - - } - }; - btnGetGPS1.setOnClickListener(oclBtnGetGPS); - - btnDelGPS1 = (View) findViewById(R.id.btnDelGPS1); - btnDelGPS1.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - LocustActivity.this.edtLat1.setText(""); - LocustActivity.this.edtLon1.setText(""); - } - }); - - btnGetGPS2 = (View) findViewById(R.id.btnGetGPS2); - OnClickListener oclGetGPS2 = new OnClickListener() { - @Override - public void onClick(View v) { - DecimalFormatSymbols custom = new DecimalFormatSymbols(new Locale("en", "US")); - custom.setDecimalSeparator('.'); - DecimalFormat df = new DecimalFormat("0.0000000"); - df.setDecimalFormatSymbols(custom); - if(LocustActivity.this._lat!=0 && LocustActivity.this._lon!=0) { - LocustActivity.this.edtLat2.setText(df.format(LocustActivity.this._lat)); - LocustActivity.this.edtLon2.setText(df.format(LocustActivity.this._lon)); - } - //Checking if the GPS is active and if it is inactive, I display a warning about it - LocationManager locationManager = (LocationManager) LocustActivity.this.getSystemService(Context.LOCATION_SERVICE);; - if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ - Toast.makeText(LocustActivity.this, LocustActivity.this.getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show(); - } - } - }; - btnGetGPS2.setOnClickListener(oclGetGPS2); - - btnDelGPS2 = (View) findViewById(R.id.btnDelGPS2); - btnDelGPS2.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - LocustActivity.this.edtLat2.setText(""); - LocustActivity.this.edtLon2.setText(""); - } - }); - - btnGetGPS3 = (View) findViewById(R.id.btnGetGPS3); - OnClickListener oclGetGPS3 = new OnClickListener() { - @Override - public void onClick(View v) { - DecimalFormatSymbols custom = new DecimalFormatSymbols(new Locale("en", "US")); - custom.setDecimalSeparator('.'); - DecimalFormat df = new DecimalFormat("0.0000000"); - df.setDecimalFormatSymbols(custom); - if(LocustActivity.this._lat!=0 && LocustActivity.this._lon!=0) { - LocustActivity.this.edtLat3.setText(df.format(LocustActivity.this._lat)); - LocustActivity.this.edtLon3.setText(df.format(LocustActivity.this._lon)); - } - //Checking if the GPS is active and if it is inactive, I display a warning about it - LocationManager locationManager = (LocationManager) LocustActivity.this.getSystemService(Context.LOCATION_SERVICE);; - if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ - Toast.makeText(LocustActivity.this, LocustActivity.this.getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show(); - } - } - }; - btnGetGPS3.setOnClickListener(oclGetGPS3); - - btnDelGPS3 = (View) findViewById(R.id.btnDelGPS3); - btnDelGPS3.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - LocustActivity.this.edtLat3.setText(""); - LocustActivity.this.edtLon3.setText(""); - } - }); - - - btnGetGPS4 = (View) findViewById(R.id.btnGetGPS4); - OnClickListener oclGetGPS4 = new OnClickListener() { - @Override - public void onClick(View v) { - DecimalFormatSymbols custom = new DecimalFormatSymbols(new Locale("en", "US")); - custom.setDecimalSeparator('.'); - DecimalFormat df = new DecimalFormat("0.0000000"); - df.setDecimalFormatSymbols(custom); - if(LocustActivity.this._lat!=0 && LocustActivity.this._lon!=0) { - LocustActivity.this.edtLat4.setText(df.format(LocustActivity.this._lat)); - LocustActivity.this.edtLon4.setText(df.format(LocustActivity.this._lon)); - } - //Checking if the GPS is active and if it is inactive, I display a warning about it - LocationManager locationManager = (LocationManager) LocustActivity.this.getSystemService(Context.LOCATION_SERVICE);; - if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ - Toast.makeText(LocustActivity.this, LocustActivity.this.getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show(); - } - } - }; - btnGetGPS4.setOnClickListener(oclGetGPS4); - - btnDelGPS4 = (View) findViewById(R.id.btnDelGPS4); - btnDelGPS4.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - LocustActivity.this.edtLat4.setText(""); - LocustActivity.this.edtLon4.setText(""); - } - }); - - - btnGetGPS5 = (View) findViewById(R.id.btnGetGPS5); - OnClickListener oclGetGPS5 = new OnClickListener() { - @Override - public void onClick(View v) { - DecimalFormatSymbols custom = new DecimalFormatSymbols(new Locale("en", "US")); - custom.setDecimalSeparator('.'); - DecimalFormat df = new DecimalFormat("0.0000000"); - df.setDecimalFormatSymbols(custom); - if(LocustActivity.this._lat!=0 && LocustActivity.this._lon!=0) { - LocustActivity.this.edtLat5.setText(df.format(LocustActivity.this._lat)); - LocustActivity.this.edtLon5.setText(df.format(LocustActivity.this._lon)); - } - //Checking if the GPS is active and if it is inactive, I display a warning about it - LocationManager locationManager = (LocationManager) LocustActivity.this.getSystemService(Context.LOCATION_SERVICE);; - if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ - Toast.makeText(LocustActivity.this, LocustActivity.this.getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show(); - } - } - }; - btnGetGPS5.setOnClickListener(oclGetGPS5); - - btnDelGPS5 = (View) findViewById(R.id.btnDelGPS5); - btnDelGPS5.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - LocustActivity.this.edtLat5.setText(""); - LocustActivity.this.edtLon5.setText(""); - } - }); - - btnGetGPS6 = (View) findViewById(R.id.btnGetGPS6); - OnClickListener oclGetGPS6 = new OnClickListener() { - @Override - public void onClick(View v) { - DecimalFormatSymbols custom = new DecimalFormatSymbols(new Locale("en", "US")); - custom.setDecimalSeparator('.'); - DecimalFormat df = new DecimalFormat("0.0000000"); - df.setDecimalFormatSymbols(custom); - if(LocustActivity.this._lat!=0 && LocustActivity.this._lon!=0) { - LocustActivity.this.edtLat6.setText(df.format(LocustActivity.this._lat)); - LocustActivity.this.edtLon6.setText(df.format(LocustActivity.this._lon)); - } - //Checking if the GPS is active and if it is inactive, I display a warning about it - LocationManager locationManager = (LocationManager) LocustActivity.this.getSystemService(Context.LOCATION_SERVICE);; - if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ - Toast.makeText(LocustActivity.this, LocustActivity.this.getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show(); - } - } - }; - btnGetGPS6.setOnClickListener(oclGetGPS6); - - btnDelGPS6 = (View) findViewById(R.id.btnDelGPS6); - btnDelGPS6.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - LocustActivity.this.edtLat6.setText(""); - LocustActivity.this.edtLon6.setText(""); - } - }); -*/ btnOnMap = (View) findViewById(R.id.btnOnMap); OnClickListener oclBtnOnMap = new OnClickListener() { @Override diff --git a/app/src/main/java/kz/istt/locust/LocustDelActivity.java b/app/src/main/java/kz/istt/locust/LocustDelActivity.java index 125e39f..70b79fb 100644 --- a/app/src/main/java/kz/istt/locust/LocustDelActivity.java +++ b/app/src/main/java/kz/istt/locust/LocustDelActivity.java @@ -151,13 +151,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe public View spiLocSpecies = null; // вид: CIT, DMA, LMI, др. public View spiLocHoppers = null; // Стадии личинок, возраста: Младшие Средние Старшие - - //public View spiImago = null; // Имаго (да, нет) - public EditText edtLocDensity = null; // плотность на м2 - //public View spiKuliguli = null; // Кулиги (да, нет) - //public View spiSwarm = null; // Стаи (да, нет) - //public View spiSparse = null; // Разреженные (да, нет) public View spiMainPurpose = null; // Основная цель при обработке (Имаго,Кулиги,Стаи,Разреженные) public View spiLocustPhaseId = null; // Фара саранчи @@ -464,9 +458,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe guiTable.add(edtLonCenter, "lon_center"); ArrayList latlon = new ArrayList(); - if(latlon.size()==0){ - latlon.add(new LatLon(0, 0)); - } + latlon.add(new LatLon(0, 0)); latlonList = findViewById(R.id.latlonList); LatLonAdapter adapter = new LatLonAdapter(this, R.layout.list_lat_lon, latlon, this, latlonList); latlonList.setAdapter(adapter); diff --git a/app/src/main/java/kz/istt/locust/LocustDelListActivity.java b/app/src/main/java/kz/istt/locust/LocustDelListActivity.java index f6b7332..cf461d1 100644 --- a/app/src/main/java/kz/istt/locust/LocustDelListActivity.java +++ b/app/src/main/java/kz/istt/locust/LocustDelListActivity.java @@ -29,6 +29,7 @@ import androidx.appcompat.app.AppCompatActivity; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.io.File; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -46,6 +47,8 @@ public class LocustDelListActivity extends AppCompatActivity private Timer timer = new Timer(); public File file = null; + public String android_id=""; + public void alert(String text) { AlertDialog.Builder adb = new AlertDialog.Builder(this,R.style.AlertDialogTheme); @@ -69,6 +72,7 @@ public class LocustDelListActivity extends AppCompatActivity //Загрузка сохранёного языка Tools.loadLocale(this); + android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); llList = (LinearLayout) findViewById(R.id.llList); @@ -600,17 +604,16 @@ public class LocustDelListActivity extends AppCompatActivity switch (spiList.getSelectedItemPosition()) { case 0: - cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and filled!=1", null); //Не отправленные + cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and filled!=1 and device_id='"+android_id+"'", null); //Не отправленные break; case 1: - cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and send=0 and filled=1", null); //Не отправленные + cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and send=0 and filled=1 and device_id='"+android_id+"'", null); //Не отправленные break; case 2: - cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and send=1", null); //Отправленные + cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and send=1 and device_id='"+android_id+"'", null); //Отправленные break; default: - //cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0", null); //Все - cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel", null); //Все + cursor = dboh.getReadableDatabase().rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and device_id='"+android_id+"'", null); //Все break; } @@ -639,9 +642,22 @@ public class LocustDelListActivity extends AppCompatActivity btn.uid = cursor.getString(cursor.getColumnIndex("uid")); // Преобразует с учётом временой зоны (пример long dv = 946684800L * 1000L; //2000 ный по гринвичу дало 6 утра) - long dv = cursor.getLong(cursor.getColumnIndex("date")) * (long) 1000;// its need to be in milisecond - Date df = new java.util.Date(dv); - String vv = new SimpleDateFormat("dd.MM.yyyy").format(df); + String vv = ""; + String val = cursor.getString(cursor.getColumnIndex("date")); + try { + long dv = Long.parseLong(val) * (long) 1000;// its need to be in milisecond + Date df = new java.util.Date(dv); + vv = new SimpleDateFormat("dd.MM.yyyy").format(df); + } catch (NumberFormatException e) { + } + if(vv.isEmpty()) { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date df = format.parse(val); + vv = new SimpleDateFormat("dd.MM.yyyy").format(df); + } catch (ParseException e) { + } + } btn.setText(cursor.getString(cursor.getColumnIndex("terrain")) + " (" + vv + ")"); diff --git a/app/src/main/java/kz/istt/locust/LocustHealthActivity.java b/app/src/main/java/kz/istt/locust/LocustHealthActivity.java index 03c3bb8..f4f4e01 100644 --- a/app/src/main/java/kz/istt/locust/LocustHealthActivity.java +++ b/app/src/main/java/kz/istt/locust/LocustHealthActivity.java @@ -122,10 +122,16 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi public EditText edtInsConcentration = null; // концентрация(г д.в./л или%) public View spiInsFormulation = null; // формуляция(УМО, КЭ, др.) public EditText edtInsDose = null; // норма расхода(л/га) + public View spiInsDiluted = null; // Коммерческий припарат разбавлен? + public EditText edtInsProportion = null; // пропорция разбавления рабочей жидкости public EditText edtInsRate = null; // расход рабочей жидкости(л/га) - public EditText edtInsUsedVolume = null; // Общий объем использованной рабочей жидкости (л) + public View spiEffectiveness = null; // Контроль эфективности + public View spiTypeImpact = null; // Тип оцениваемого биологического воздействия + + + //public EditText edtInsUsedVolume = null; // Общий объем использованной рабочей жидкости (л) // public DateInput edtInsExpiryDate = null; // окончание срока действия (дата) // public SpinnerDB spiInsMixed = null; // смешивается ли инсектицид с водой или растворителем? // public EditText edtInsMixedName = null; // Если да то с каким @@ -134,8 +140,8 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi public View spiWeaTimeEnd = null; // время окончания public EditText edtWeaTemperatureStart = null; // Температура нач.(°C) public EditText edtWeaTemperatureEnd = null; // Температура кон.(°C) - public EditText edtWeaWindSpeedStart = null; // скорость ветра нач. (м/с) - public EditText edtWeaWindSpeedEnd = null; // скорость ветра кон. (м/с) + //public EditText edtWeaWindSpeedStart = null; // скорость ветра нач. (м/с) + //public EditText edtWeaWindSpeedEnd = null; // скорость ветра кон. (м/с) public View spiWindDirectionStart = null; // направление ветра нач. public View spiWindDirectionEnd = null; // направление ветра кон. @@ -144,14 +150,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi public View spiLocSpecies = null; // вид: CIT, DMA, LMI, др. public View spiLocHoppers = null; // Стадии личинок, возраста: Младшие Средние Старшие - - //public View spiImago = null; // Имаго (да, нет) - public EditText edtLocDensity = null; // плотность на м2 - //public View spiKuliguli = null; // Кулиги (да, нет) - //public View spiSwarm = null; // Стаи (да, нет) - //public View spiSparse = null; // Разреженные (да, нет) public View spiMainPurpose = null; // Основная цель при обработке (Имаго,Кулиги,Стаи,Разреженные) + + public View spiLocustPhaseId = null; // Фара саранчи public View spiSprPlatform = null; // Вид опрыскивания @@ -165,6 +167,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi //public EditText edtSprModel = null; // Модель опрыскивателя // public DateInput edtDateCalibration = null; // Дата последней калибровки public EditText edtSprHeight = null; // Высота над поверхностью почвы (м) + // public EditText edtSprWidth = null; // Ширина захвата (м) // public EditText edtSprSpacing = null; // Расстояние между проходами опрыскивателя (м) (Надия Рашидовна сказала удалить) public View spiSprBarrier = null; // Барьеры (да, нет) @@ -179,6 +182,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi public EditText edtEffTime = null; // Прошло времени после обработки в часах public View spiEffMethod = null; // метод подсчета смертности + public CheckBox cbSafClothingGoggles = null; // Какой защитной одеждой пользовался оператор: Очки public CheckBox cbSafClothingMasks = null; // Какой защитной одеждой пользовался оператор: Маска public CheckBox cbSafClothingGloves = null; // Какой защитной одеждой пользовался оператор: Перчатки @@ -187,8 +191,12 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi public CheckBox cbSafClothingBoots = null; // Какой защитной одеждой пользовался оператор: Сапоги public CheckBox cbSafClothingAbsent = null; // Какой защитной одеждой пользовался оператор: Отсутствуют + public EditText edtClothing = null; // Сборная колонка + public View spiHlthProtectiveClothingClean = null; // Защитная одежда чистая и в хорошем состоянии + + public View spiProtectiveClothingClean = null; public View spiOperatorExposedInsecticide = null; public EditText edtDescription = null; @@ -273,9 +281,625 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi Intent intent = getIntent(); uid = intent.getStringExtra("uid"); // Параметр для Активити + guiTableDel = new DBGUITable(this, "frmlocustdel"); + guiTableDel.add(uid, "uid"); guiTableHealth = new DBGUITable(this, "frmlocusthealth"); guiTableHealth.add(uid, "uid"); + //Страна + spiCountry = findViewById(R.id.spiCountry); + guiTableDel.add(spiCountry, "country_id"); + ((selectDB)spiCountry).addField("", ""); + // Выбираем страны и заполняем поля + dboh = new DbOpenHelper(this); + cursor = dboh.getReadableDatabase().rawQuery("select id, uid, name from countries where del=0 order by name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiCountry).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // Чтоб при изменении страны обновлялся список регионов + ((selectDB)spiCountry).setOnChangeValueListener(new OnClickListener() + { + @Override + public void onClick(View v) + { + ((selectDB)spiRegion).clearFields(); + ((selectDB)spiRegion).addField("", ""); + + if(((selectDB)spiCountry).getValue() != null && ((selectDB)spiCountry).getValue() != "") + { + DbOpenHelper dboh = new DbOpenHelper(LocustHealthActivity.this); + Cursor cursor = dboh.getReadableDatabase().rawQuery( + "select id, name from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiRegion).addField(cursor.getString(cursor.getColumnIndex("name")), + cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + } + } + }); + //Область + spiRegion = findViewById(R.id.spiRegion); // Регион + guiTableDel.add(spiRegion, "region_id"); + //Район + edtArea = (EditText) findViewById(R.id.edtArea); // Район + guiTableDel.add(edtArea, "area"); + //Посёлок + edtVillage = (EditText) findViewById(R.id.edtVillage); // Название местности либо урочища + guiTableDel.add(edtVillage, "village"); + //Имя лидера команды по обработке + edtObserver = (EditText) findViewById(R.id.edtObserver); + guiTableDel.add(edtObserver, "observer"); + //Дата + edtDate = (EditText) findViewById(R.id.edtDate); // Должна быть уникальной + guiTableDel.add(edtDate, "date"); + //Событие для кнопки выбора даты тут не нужна поэтому её и нет + + edtLatCenter = (EditText) findViewById(R.id.edtLatCenter); // Широта + guiTableDel.add(edtLatCenter, "lat_center"); + edtLonCenter = (EditText) findViewById(R.id.edtLonCenter); // Долгота + guiTableDel.add(edtLonCenter, "lon_center"); + + ArrayList latlon = new ArrayList(); + latlon.add(new LatLon(0, 0)); + latlonList = findViewById(R.id.latlonList); + LatLonAdapter adapter = new LatLonAdapter(this, R.layout.list_lat_lon, latlon, this, latlonList); + latlonList.setAdapter(adapter); +// adapter.clc=new OnClickListener() { +// @Override +// public void onClick(View view) { +// Tools.setListViewHeightBasedOnItems(LocustHealthActivity.this.latlonList); +// } +// }; + + + + //Тип растительности + spiVegType = findViewById(R.id.spiVegType); // Тип(Дикая, Культурная) + guiTableDel.add(spiVegType, "vegetation_type_id"); + ((selectDB)spiVegType).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_vegetation d where d.del=0 order by d.sort, d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiVegType).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + //высота растительности + edtVegHeight = (EditText) findViewById(R.id.edtVegHeight); // Высота (м) + guiTableDel.add(edtVegHeight, "vegetation_height"); + + //Густота растительного покрова + spiVegCover = findViewById(R.id.spiVegCover); // Густота растительного покрова(%) + guiTableDel.add(spiVegCover, "vegetation_cover_id"); + ((selectDB)spiVegCover).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_cover d where d.del=0 order by d.sort, d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiVegCover).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + //Наименование сельхоз культуры + edtVegCrop = (EditText) findViewById(R.id.edtVegCrop); // Перечисление культур + guiTableDel.add(edtVegCrop, "vegetation_crop"); + + //Наименование инсектицида + edtInsName = (EditText) findViewById(R.id.edtInsName); // коммерческое название + guiTableDel.add(edtInsName, "insecticide_name"); + + // Наименование активного вещества отравы + edtInsActiveSubstance = (EditText) findViewById(R.id.edtInsActiveSubstance); + guiTableDel.add(edtInsActiveSubstance, "insecticide_active_substance"); + + // концентрация(г д.в./л или%) + edtInsConcentration = (EditText) findViewById(R.id.edtInsConcentration); + guiTableDel.add(edtInsConcentration, "insecticide_concentration"); + //edtInsConcentration.setFilters(new InputFilter[] { new InputFilterMinMax("0", "100") }); потому что текст + + // формуляция(УМО, КЭ, др.) + spiInsFormulation = findViewById(R.id.spiInsFormulation); + guiTableDel.add(spiInsFormulation, "insecticide_formulation_id"); + ((selectDB)spiInsFormulation).addField("", ""); + // Выбираем страны и заполняем поля + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_formulation d where d.del=0 order by d.sort, d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiInsFormulation).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // норма расхода(л/га) + edtInsDose = (EditText) findViewById(R.id.edtInsDose); + guiTableDel.add(edtInsDose, "insecticide_dose"); + + // Коммерческий припарат разбавлен? + spiInsDiluted = findViewById(R.id.spiInsDiluted); + guiTableDel.add(spiInsDiluted, "insecticide_diluted_id"); + ((selectDB)spiInsDiluted).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_diluted d where d.del=0 order by d.sort, d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiInsDiluted).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // расход рабочей жидкости(л/га) + edtInsProportion = (EditText) findViewById(R.id.edtInsProportion); + guiTableDel.add(edtInsProportion, "insecticide_proportion"); + + // расход рабочей жидкости(л/га) + edtInsRate = (EditText) findViewById(R.id.edtInsRate); + guiTableDel.add(edtInsRate, "insecticide_rate"); + + // время начала + spiWeaTimeStart = findViewById(R.id.spiWeaTimeStart); + guiTableDel.add(spiWeaTimeStart, "weather_time_start"); + ((selectDB)spiWeaTimeStart).addField("", ""); + for (int i = 0; i < 24; i++) { + ((selectDB) spiWeaTimeStart).addField(String.valueOf(i), String.valueOf(i)+".0"); + } + // время окончания + spiWeaTimeEnd = findViewById(R.id.spiWeaTimeEnd); + guiTableDel.add(spiWeaTimeEnd, "weather_time_end"); + ((selectDB)spiWeaTimeEnd).addField("", ""); + for (int i = 0; i < 24; i++) { + ((selectDB) spiWeaTimeEnd).addField(String.valueOf(i), String.valueOf(i)+".0"); + } + // Температура нач.(°C) + edtWeaTemperatureStart = (EditText) findViewById(R.id.edtWeaTemperatureStart); + guiTableDel.add(edtWeaTemperatureStart, "weather_temperature_start"); + // Температура кон.(°C) + edtWeaTemperatureEnd = (EditText) findViewById(R.id.edtWeaTemperatureEnd); + guiTableDel.add(edtWeaTemperatureEnd, "weather_temperature_end"); + + // направление ветра нач. + spiWindDirectionStart = findViewById(R.id.spiWindDirectionStart); + guiTableDel.add(spiWindDirectionStart, "weather_direction_start"); + ((selectDB)spiWindDirectionStart).addField("", ""); + dboh = new DbOpenHelper(this); + + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name, degree from list_directions d where d.del=0 order by d.degree", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiWindDirectionStart).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // направление ветра кон. + spiWindDirectionEnd = findViewById(R.id.spiWindDirectionEnd); + guiTableDel.add(spiWindDirectionEnd, "weather_direction_end"); + ((selectDB)spiWindDirectionEnd).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name, degree from list_directions d where d.del=0 order by d.degree", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiWindDirectionEnd).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // направление опрыскивания нач. + spiSprayDirectionStart = findViewById(R.id.spiSprayDirectionStart); + guiTableDel.add(spiSprayDirectionStart, "weather_spray_direction_start"); + ((selectDB)spiSprayDirectionStart).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name, d.degree from list_directions d where d.del=0 and d.degree>=0 order by d.degree", + null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprayDirectionStart).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // направление опрыскивания кон. + spiSprayDirectionEnd = findViewById(R.id.spiSprayDirectionEnd); + guiTableDel.add(spiSprayDirectionEnd, "weather_spray_direction_end"); + ((selectDB)spiSprayDirectionEnd).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name, degree from list_directions d where d.del=0 and d.degree>=0 order by d.degree", + null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprayDirectionEnd).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // Вид locuststypes + spiLocSpecies = findViewById(R.id.spiLocSpecies); + guiTableDel.add(spiLocSpecies, "locust_type_id"); + ((selectDB)spiLocSpecies).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select lt.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = lt.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),lt.name) name from LocustsTypes lt where lt.del=0 order by lt.sort,lt.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiLocSpecies).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + // Возраст личинок (Стадии личинок) + spiLocHoppers = findViewById(R.id.spiLocHoppers); + guiTableDel.add(spiLocHoppers, "locust_hoppers_id"); + ((selectDB)spiLocHoppers).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select lt.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = lt.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),lt.name) name from list_age lt where lt.del=0 order by lt.sort,lt.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiLocHoppers).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + // плотность на м2 + edtLocDensity = (EditText) findViewById(R.id.edtLocDensity); + guiTableDel.add(edtLocDensity, "locust_density"); + + //Основная цель при обработке + spiMainPurpose = findViewById(R.id.spiMainPurpose); + guiTableDel.add(spiMainPurpose, "locust_purpose_id"); + ((selectDB)spiMainPurpose).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select lt.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = lt.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),lt.name) name from list_purpose lt where lt.del=0 order by lt.sort,lt.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiMainPurpose).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + + // Вид опрыскивания + spiSprPlatform = findViewById(R.id.spiSprPlatform); + guiTableDel.add(spiSprPlatform, "spray_platform"); + ((selectDB)spiSprPlatform).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from sprayers_types d where d.del=0 order by d.sort,d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprPlatform).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // «Авиа» - выпадающий список:«Самолет», «Вертолет», «Дельтаплан». + spiSprPlatformA = findViewById(R.id.spiSprPlatformA); + guiTableDel.add(spiSprPlatformA, "spray_platform_a"); + ((selectDB)spiSprPlatformA).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from sprayers d where d.del=0 and d.sprayer_type_id=1 order by d.sort,d.name", + null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprPlatformA).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // «Наземное» - выпадающий список:«Трактор», «Машина», «Аэроз.генераторG». + spiSprPlatformG = findViewById(R.id.spiSprPlatformG); + guiTableDel.add(spiSprPlatformG, "spray_platform_g"); + ((selectDB)spiSprPlatformG).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from sprayers d where d.del=0 and d.sprayer_type_id=3 order by d.sort,d.name", + null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprPlatformG).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // «Ручное» - выпадающий список:«Ранцевый», «Моторный», «Батарейный». + spiSprPlatformH = findViewById(R.id.spiSprPlatformH); + guiTableDel.add(spiSprPlatformH, "spray_platform_h"); + ((selectDB)spiSprPlatformH).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from sprayers d where d.del=0 and d.sprayer_type_id=5 order by d.sort,d.name", + null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprPlatformH).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // Марка опрыскивателя + edtSprManufacturer = (EditText) findViewById(R.id.edtSprManufacturer); + guiTableDel.add(edtSprManufacturer, "spray_manufacturer_name"); + + // Высота над поверхностью почвы (м) + edtSprHeight = (EditText) findViewById(R.id.edtSprHeight); + guiTableDel.add(edtSprHeight, "spray_height"); + + + + + // Тип обработки + spiSprBarrier = findViewById(R.id.spiSprBarrier); + guiTableDel.add(spiSprBarrier, "spray_barrier"); + ((selectDB)spiSprBarrier).addField("", ""); + ((selectDB)spiSprBarrier).addField(getString(R.string.Barriers), "1"); + ((selectDB)spiSprBarrier).addField(getString(R.string.Continuous), "0"); + + // Интервал между проходами + edtSprBarrierSpace = (EditText) findViewById(R.id.edtSprBarrierSpace); + guiTableDel.add(edtSprBarrierSpace, "spray_barrier_space"); + + // Скорость движения (км/ч) + edtSprSpeed = (EditText) findViewById(R.id.edtSprSpeed); + guiTableDel.add(edtSprSpeed, "spray_speed"); + + // Наземная маркировка(Сиг-нальщики, GPS, Машина, Нет) + spiSprMarking = findViewById(R.id.spiSprMarking); + guiTableDel.add(spiSprMarking, "spray_marking_id"); + ((selectDB)spiSprMarking).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_markings d where d.del=0 order by d.sort,d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiSprMarking).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // обработанная площадь(га) + edtTreatedArea = (EditText) findViewById(R.id.edtTreatedArea); + guiTableDel.add(edtTreatedArea, "treated_area"); + + // Общий объем использованной рабочей жидкости (л) + edtInsUsedVolume = (EditText) findViewById(R.id.edtInsUsedVolume); + guiTableDel.add(edtInsUsedVolume, "insecticide_used_volume"); + + // Контроль эфективности + spiEffectiveness = findViewById(R.id.spiEffectiveness); + guiTableDel.add(spiEffectiveness, "efficiency"); + ((selectDB)spiEffectiveness).addField("", ""); + ((selectDB)spiEffectiveness).addField(getString(R.string.Yes), "1"); + ((selectDB)spiEffectiveness).addField(getString(R.string.No), "0"); + + //Тип оцениваемого биологического воздействия + spiTypeImpact = findViewById(R.id.spiTypeImpact); + guiTableDel.add(spiTypeImpact, "efficacy_impact_id"); + ((selectDB)spiTypeImpact).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_impact d where d.del=0 order by d.sort,d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiTypeImpact).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // Наблюдаемая эфективность обработок (%) + edtEffMortality = (EditText) findViewById(R.id.edtEffMortality); + guiTableDel.add(edtEffMortality, "efficacy_mortality"); + + // Прошло времени после обработки + edtEffTime = (EditText) findViewById(R.id.edtEffTime); + guiTableDel.add(edtEffTime, "efficacy_passed_time"); + + // Метод оценки эфективности обработок + spiEffMethod = findViewById(R.id.spiEffMethod); + guiTableDel.add(spiEffMethod, "efficacy_mortality_method"); + ((selectDB)spiEffMethod).addField("", ""); + dboh = new DbOpenHelper(this); + cursor = dboh + .getReadableDatabase() + .rawQuery( + "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + + Tools.getLang() + "' LIMIT 1),d.name) name from list_mortality d where d.del=0 order by d.sort,d.name", null); + if (cursor.moveToFirst()) + { + do + { + ((selectDB)spiEffMethod).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + + // Индивидуальные средства защиты + cbSafClothingGoggles = (CheckBox) findViewById(R.id.cbSafClothingGoggles); + //cbSafClothingGoggles.setOnCheckedChangeListener(cclsl); + cbSafClothingMasks = (CheckBox) findViewById(R.id.cbSafClothingMasks); + //cbSafClothingMasks.setOnCheckedChangeListener(cclsl); + cbSafClothingGloves = (CheckBox) findViewById(R.id.cbSafClothingGloves); + //cbSafClothingGloves.setOnCheckedChangeListener(cclsl); + cbSafClothingOveralls = (CheckBox) findViewById(R.id.cbSafClothingOveralls); + //cbSafClothingOveralls.setOnCheckedChangeListener(cclsl); + cbSafClothingCaps = (CheckBox) findViewById(R.id.cbSafClothingCaps); + //cbSafClothingCaps.setOnCheckedChangeListener(cclsl); + cbSafClothingBoots = (CheckBox) findViewById(R.id.cbSafClothingBoots); + //cbSafClothingBoots.setOnCheckedChangeListener(cclsl); + cbSafClothingAbsent = (CheckBox) findViewById(R.id.cbSafClothingAbsent); + //cbSafClothingAbsent.setOnCheckedChangeListener(cclsl); + + edtClothing = (EditText) findViewById(R.id.edtClothing); + guiTableDel.add(edtClothing, "safety_clothing"); + + edtClothing.addTextChangedListener(new TextWatcher() + { + public void afterTextChanged(Editable s) + { + } + + public void beforeTextChanged(CharSequence s, int start, int count, int after) + { + } + + public void onTextChanged(CharSequence s, int start, int before, int count) + { + String str = LocustHealthActivity.this.edtClothing.getText().toString(); + + if (str.indexOf("1") != -1) + LocustHealthActivity.this.cbSafClothingGoggles.setChecked(true); + if (str.indexOf("2") != -1) + LocustHealthActivity.this.cbSafClothingMasks.setChecked(true); + if (str.indexOf("3") != -1) + LocustHealthActivity.this.cbSafClothingGloves.setChecked(true); + if (str.indexOf("4") != -1) + LocustHealthActivity.this.cbSafClothingOveralls.setChecked(true); + if (str.indexOf("5") != -1) + LocustHealthActivity.this.cbSafClothingCaps.setChecked(true); + if (str.indexOf("6") != -1) + LocustHealthActivity.this.cbSafClothingBoots.setChecked(true); + if (str.indexOf("7") != -1) + LocustHealthActivity.this.cbSafClothingAbsent.setChecked(true); + + } + }); + + //Защитная одежда читая и в хорошем состоянии + spiHlthProtectiveClothingClean = findViewById(R.id.spiHlthProtectiveClothingClean); + guiTableHealth.add(spiEffectiveness, "safety_clothing_clean"); + ((selectDB)spiEffectiveness).addField("", ""); + ((selectDB)spiEffectiveness).addField(getString(R.string.Yes), "1"); + ((selectDB)spiEffectiveness).addField(getString(R.string.No), "0"); + + + + Integer user_id = null; /*DbOpenHelper dboh = new DbOpenHelper(this); SQLiteDatabase db = dboh.getReadableDatabase(); @@ -476,24 +1100,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi // edtTimeZone = (EditText) findViewById(R.id.edtTimeZone); // guiTable.add(edtTimeZone,"timezone"); // -// edtLatCenter = (EditText) findViewById(R.id.edtLatCenter); // Широта -// guiTable.add(edtLatCenter, "lat_center"); -// edtLonCenter = (EditText) findViewById(R.id.edtLonCenter); // Долгота -// guiTable.add(edtLonCenter, "lon_center"); -// -// ArrayList latlon = new ArrayList(); -// if(latlon.size()==0){ -// latlon.add(new LatLon(0, 0)); -// } -// latlonList = findViewById(R.id.latlonList); -// LatLonAdapter adapter = new LatLonAdapter(this, R.layout.list_lat_lon, latlon, this, latlonList); -// latlonList.setAdapter(adapter); -// adapter.clc=new OnClickListener() { -// @Override -// public void onClick(View view) { -// Tools.setListViewHeightBasedOnItems(LocustHealthActivity.this.latlonList); -// } -// }; + // edtInfestedArea = (EditText) findViewById(R.id.edtInfestedArea); // заселенная площадь(га) // guiTable.add(edtInfestedArea, "infested_area"); @@ -504,50 +1111,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi +// -// spiVegType = findViewById(R.id.spiVegType); // Тип(Дикая, Культурная) -// guiTable.add(spiVegType, "vegetation_type_id"); -// ((selectDB)spiVegType).addField("", ""); -// dboh = new DbOpenHelper(this); -// cursor = dboh -// .getReadableDatabase() -// .rawQuery( -// "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" -// + Tools.getLang() + "' LIMIT 1),d.name) name from list_vegetation d where d.del=0 order by d.sort, d.name", null); -// if (cursor.moveToFirst()) -// { -// do -// { -// ((selectDB)spiVegType).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); -// } while (cursor.moveToNext()); -// } -// cursor.close(); -// dboh.close(); // -// edtVegHeight = (EditText) findViewById(R.id.edtVegHeight); // Высота (м) -// guiTable.add(edtVegHeight, "vegetation_height"); -// -// spiVegCover = findViewById(R.id.spiVegCover); // Густота растительного покрова(%) -// guiTable.add(spiVegCover, "vegetation_cover_id"); -// ((selectDB)spiVegCover).addField("", ""); -// dboh = new DbOpenHelper(this); -// cursor = dboh -// .getReadableDatabase() -// .rawQuery( -// "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" -// + Tools.getLang() + "' LIMIT 1),d.name) name from list_cover d where d.del=0 order by d.sort, d.name", null); -// if (cursor.moveToFirst()) -// { -// do -// { -// ((selectDB)spiVegCover).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); -// } while (cursor.moveToNext()); -// } -// cursor.close(); -// dboh.close(); -// -// edtVegCrop = (EditText) findViewById(R.id.edtVegCrop); // Перечисление культур -// guiTable.add(edtVegCrop, "vegetation_crop"); + // // spiVegDamage = findViewById(R.id.spiVegDamage); // Повреждения растительного покрова(%) // guiTable.add(spiVegDamage, "vegetation_damage"); @@ -572,36 +1139,8 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi // edtVegDamageArea = (EditText) findViewById(R.id.edtVegDamageArea); // Площядь повреждения // guiTable.add(edtVegDamageArea, "vegetation_damage_area"); // -// edtInsName = (EditText) findViewById(R.id.edtInsName); // коммерческое название -// guiTable.add(edtInsName, "insecticide_name"); -// edtInsActiveSubstance = (EditText) findViewById(R.id.edtInsActiveSubstance); // Наименование активного вещества отравы -// guiTable.add(edtInsActiveSubstance, "insecticide_active_substance"); -// edtInsConcentration = (EditText) findViewById(R.id.edtInsConcentration); // концентрация(г д.в./л или%) -// guiTable.add(edtInsConcentration, "insecticide_concentration"); -// //edtInsConcentration.setFilters(new InputFilter[] { new InputFilterMinMax("0", "100") }); потому что текст -// -// spiInsFormulation = findViewById(R.id.spiInsFormulation); // формуляция(УМО, КЭ, др.) -// guiTable.add(spiInsFormulation, "insecticide_formulation_id"); -// ((selectDB)spiInsFormulation).addField("", ""); -// // Выбираем страны и заполняем поля -// dboh = new DbOpenHelper(this); -// cursor = dboh -// .getReadableDatabase() -// .rawQuery( -// "select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" -// + Tools.getLang() + "' LIMIT 1),d.name) name from list_formulation d where d.del=0 order by d.sort, d.name", null); -// if (cursor.moveToFirst()) -// { -// do -// { -// ((selectDB)spiInsFormulation).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); -// } while (cursor.moveToNext()); -// } -// cursor.close(); -// dboh.close(); -// -// edtInsDose = (EditText) findViewById(R.id.edtInsDose); // норма расхода(л/га) -// guiTable.add(edtInsDose, "insecticide_dose"); + + // edtInsRate = (EditText) findViewById(R.id.edtInsRate); // расход рабочей жидкости(л/га) // guiTable.add(edtInsRate, "insecticide_rate"); // edtInsUsedVolume = (EditText) findViewById(R.id.edtInsUsedVolume); // Общий объем использованной рабочей жидкости (л) @@ -1582,9 +2121,9 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi // // // // Взависимости от параметров создание или редактирование -// editData(uid); -// adapter.notifyDataSetChanged(); -// Tools.setListViewHeightBasedOnItems(latlonList); + editDataDel(uid); + adapter.notifyDataSetChanged(); + Tools.setListViewHeightBasedOnItems(latlonList); // // //updateAlpha(); movied to onResume // @@ -1889,33 +2428,33 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi /** * Редактирование данных по id если null то создание иначе редактирование */ - public void editData(String uid) + public void editDataDel(String uid) { // if (uid == null || uid == "") // { // ((fieldDB)edtDate).setValue(String.valueOf((new Date()).getTime()/1000)); // edtTimeZone.setText(Tools.getTimezone()); // } -// guiTable.read(uid); -// //Читаю список координат из базы данных -// if (uid != null) -// { -// LatLonAdapter adapter = (LatLonAdapter)latlonList.getAdapter(); -// ArrayList list = adapter.latlonList; -// list.clear(); -// DbOpenHelper dboh = new DbOpenHelper(this); -// Cursor cursor = dboh.getReadableDatabase().rawQuery("select lat,lon from frmlocustdel_locations where frmlocustdel_uid='" + uid + "' order by pos", null); -// if (cursor.moveToFirst()) -// { -// do -// { -// list.add(new LatLon(cursor.getDouble(0), cursor.getDouble(1))); -// } while (cursor.moveToNext()); -// } -// cursor.close(); -// dboh.close(); -// list.add(new LatLon(0, 0)); -// } + guiTableDel.read(uid); + //Читаю список координат из базы данных + if (uid != null) + { + LatLonAdapter adapter = (LatLonAdapter)latlonList.getAdapter(); + ArrayList list = adapter.latlonList; + list.clear(); + DbOpenHelper dboh = new DbOpenHelper(this); + Cursor cursor = dboh.getReadableDatabase().rawQuery("select lat,lon from frmlocustdel_locations where frmlocustdel_uid='" + uid + "' order by pos", null); + if (cursor.moveToFirst()) + { + do + { + list.add(new LatLon(cursor.getDouble(0), cursor.getDouble(1))); + } while (cursor.moveToNext()); + } + cursor.close(); + dboh.close(); + list.add(new LatLon(0, 0)); + } } /*** diff --git a/app/src/main/java/kz/istt/locust/LocustHealthListActivity.java b/app/src/main/java/kz/istt/locust/LocustHealthListActivity.java index dffa75e..9b6ce67 100644 --- a/app/src/main/java/kz/istt/locust/LocustHealthListActivity.java +++ b/app/src/main/java/kz/istt/locust/LocustHealthListActivity.java @@ -2,15 +2,18 @@ package kz.istt.locust; import android.annotation.SuppressLint; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.Settings; +import android.view.ContextThemeWrapper; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -28,6 +31,7 @@ import androidx.appcompat.app.AppCompatActivity; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.io.File; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -39,7 +43,7 @@ public class LocustHealthListActivity extends AppCompatActivity public LinearLayout llList; public MyButton btn; - public FloatingActionButton btnAdd = null; + //public FloatingActionButton btnAdd = null; public Spinner spiList = null; private Timer timer = new Timer(); @@ -102,13 +106,13 @@ public class LocustHealthListActivity extends AppCompatActivity } }); - btnAdd = (FloatingActionButton) findViewById(R.id.btnAdd); + /*btnAdd = (FloatingActionButton) findViewById(R.id.btnAdd); btnAdd.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(LocustHealthListActivity.this, LocustHealthActivity.class); startActivity(intent); } - }); + });*/ //Чтоб список обновлялся раз в минуту в соответствии с текущем фильтром (для наглядности отправки данных) timer.scheduleAtFixedRate(new TimerTask() @@ -599,16 +603,59 @@ public class LocustHealthListActivity extends AppCompatActivity switch (spiList.getSelectedItemPosition()) { case 0: - cursor = dboh.getReadableDatabase().rawQuery("select lh.uid, coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, lh.date from frmlocusthealth lh left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid where lh.del=0 and lh.filled!=1", null); //Не отправленные + cursor = dboh.getReadableDatabase().rawQuery(""" + select + ld.uid, + coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, + ld.date, + EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health + from + frmlocustdel ld + where + ld.del=0 + and ld.filled!=1 + """, null); //Не отправленные break; case 1: - cursor = dboh.getReadableDatabase().rawQuery("select lh.uid, coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, lh.date from frmlocusthealth lh left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid where lh.del=0 and lh.send=0 and lh.filled=1", null); //Не отправленные + cursor = dboh.getReadableDatabase().rawQuery(""" + select + ld.uid, + coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, + ld.date, + EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health + from + frmlocustdel ld + where + ld.del=0 + and ld.send=0 + and ld.filled=1 + """, null); //Не отправленные break; case 2: - cursor = dboh.getReadableDatabase().rawQuery("select lh.uid, coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, lh.date from frmlocusthealth lh left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid where lh.del=0 and lh.send=1", null); //Отправленные + cursor = dboh.getReadableDatabase().rawQuery(""" + select + ld.uid, + coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, + ld.date, + EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health + from + frmlocustdel ld + where + ld.del=0 + and ld.send=1 + """, null); //Отправленные break; default: - cursor = dboh.getReadableDatabase().rawQuery("select lh.uid, coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, lh.date from frmlocusthealth lh left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid where lh.del=0", null); //Все + cursor = dboh.getReadableDatabase().rawQuery(""" + select + ld.uid, + coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain, + ld.date, + EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health + from + frmlocustdel ld + where ld.del=0 + """, null); //Все break; } @@ -630,19 +677,43 @@ public class LocustHealthListActivity extends AppCompatActivity { do { - btn = new MyButton(this); + btn = null; + if(cursor.getInt(cursor.getColumnIndex("health"))==0){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //Задаю стиль для кнопки для которой нет анкеты здоровья + int buttonPinkStyle = R.style.ButtonPinkTheme; + ContextThemeWrapper newContext = new ContextThemeWrapper(this, R.style.ButtonPinkTheme); + btn = new MyButton(newContext, null, 0, buttonPinkStyle); + } + } + if(btn==null) { + btn = new MyButton(this); + } btn.setOnClickListener(oclBtn); btn.uid = cursor.getString(cursor.getColumnIndex("uid")); // Преобразует с учётом временой зоны (пример long dv = 946684800L * 1000L; //2000 ный по гринвичу дало 6 утра) - long dv = cursor.getLong(cursor.getColumnIndex("date")) * (long) 1000;// its need to be in milisecond - Date df = new Date(dv); - String vv = new SimpleDateFormat("dd.MM.yyyy").format(df); + String vv = ""; + String val = cursor.getString(cursor.getColumnIndex("date")); + try { + long dv = Long.parseLong(val) * (long) 1000;// its need to be in milisecond + Date df = new Date(dv); + vv = new SimpleDateFormat("dd.MM.yyyy").format(df); + } catch (NumberFormatException e) { + } + if(vv.isEmpty()) { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date df = format.parse(val); + vv = new SimpleDateFormat("dd.MM.yyyy").format(df); + } catch (ParseException e) { + } + } btn.setText(cursor.getString(cursor.getColumnIndex("terrain")) + " (" + vv + ")"); + LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = 2; diff --git a/app/src/main/java/kz/istt/locust/MyButton.java b/app/src/main/java/kz/istt/locust/MyButton.java index 6fe7905..48b30b0 100644 --- a/app/src/main/java/kz/istt/locust/MyButton.java +++ b/app/src/main/java/kz/istt/locust/MyButton.java @@ -1,8 +1,12 @@ package kz.istt.locust; import android.content.Context; +import android.os.Build; +import android.util.AttributeSet; import android.widget.Button; +import androidx.annotation.RequiresApi; + public class MyButton extends Button { public String uid; //Идентификатор записи может быть NULL если она создана на КПК @@ -11,4 +15,10 @@ public class MyButton extends Button { super(context); } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + MyButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) + { + super(context,attrs,defStyleAttr,defStyleRes); + } } diff --git a/app/src/main/java/kz/istt/locust/MySynchronizationOld.java b/app/src/main/java/kz/istt/locust/MySynchronizationOld.java index 4a755cc..c0e5f0c 100644 --- a/app/src/main/java/kz/istt/locust/MySynchronizationOld.java +++ b/app/src/main/java/kz/istt/locust/MySynchronizationOld.java @@ -77,6 +77,7 @@ public class MySynchronizationOld public static int SyncDays=30; private Context _context; //От какого контекста показывать алерты + private String android_id; //private boolean _showAlert; //Показывать ли окно подождите пожалуйста (его нельзя создавать если в сервисе) //public ProgressDialog dialog; @@ -317,7 +318,7 @@ public class MySynchronizationOld cursor.close(); dboh.close(); if(days!=null && !days.isEmpty() && country_id!=null && !country_id.isEmpty()){ - return myThread.addRequest(MySynchronizationOld.URL+"/get/?fn=1&r=0&n="+tableName+"&s=" + seq + "&l=1000&days="+days+"&country_id="+country_id,"", null); + return myThread.addRequest(MySynchronizationOld.URL+"/get/?fn=1&r=0&n="+tableName+"&s=" + seq + "&l=1000&days="+days+"&country_id="+country_id+"&android_id="+android_id,"", null); }else{ return myThread.addRequest(MySynchronizationOld.URL+"/get/?fn=1&r=0&n="+tableName+"&s=" + seq + "&l=1000","", null); } @@ -335,7 +336,7 @@ public class MySynchronizationOld String xml=""; - String android_id = Settings.Secure.getString(_context.getContentResolver(), Settings.Secure.ANDROID_ID); + android_id = Settings.Secure.getString(_context.getContentResolver(), Settings.Secure.ANDROID_ID); //Последовательно отправляю изменёные пользователям записи (send=0 и они заполнены) DbOpenHelper dboh = new DbOpenHelper(_context); @@ -402,7 +403,7 @@ public class MySynchronizationOld //Загружаю формы саранчовых обработок за последние X дней для страны Y dboh = new DbOpenHelper(_context); - cursor = dboh.getReadableDatabase().rawQuery("select t.country_id from terminals t where t.del=0 and t.serial='"+ Settings.Secure.getString(_context.getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null); + cursor = dboh.getReadableDatabase().rawQuery("select t.country_id from terminals t where t.del=0 and t.serial='"+ android_id +"';", null); if(cursor.moveToFirst()) { String country_id = cursor.getString(0); diff --git a/app/src/main/res/drawable/button.xml b/app/src/main/res/drawable/button_blue.xml similarity index 71% rename from app/src/main/res/drawable/button.xml rename to app/src/main/res/drawable/button_blue.xml index e097017..ead0f98 100644 --- a/app/src/main/res/drawable/button.xml +++ b/app/src/main/res/drawable/button_blue.xml @@ -4,7 +4,7 @@ - - - + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_focused.xml b/app/src/main/res/drawable/button_blue_focused.xml similarity index 100% rename from app/src/main/res/drawable/button_focused.xml rename to app/src/main/res/drawable/button_blue_focused.xml diff --git a/app/src/main/res/drawable/button_blue_normal.xml b/app/src/main/res/drawable/button_blue_normal.xml new file mode 100644 index 0000000..6ee2dcb --- /dev/null +++ b/app/src/main/res/drawable/button_blue_normal.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_presed.xml b/app/src/main/res/drawable/button_blue_pressed.xml similarity index 100% rename from app/src/main/res/drawable/button_presed.xml rename to app/src/main/res/drawable/button_blue_pressed.xml diff --git a/app/src/main/res/drawable/button_normal.xml b/app/src/main/res/drawable/button_normal.xml deleted file mode 100644 index ff177e6..0000000 --- a/app/src/main/res/drawable/button_normal.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/button_pink.xml b/app/src/main/res/drawable/button_pink.xml new file mode 100644 index 0000000..14f95ed --- /dev/null +++ b/app/src/main/res/drawable/button_pink.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_pink_focused.xml b/app/src/main/res/drawable/button_pink_focused.xml new file mode 100644 index 0000000..6bf1965 --- /dev/null +++ b/app/src/main/res/drawable/button_pink_focused.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_pink_normal.xml b/app/src/main/res/drawable/button_pink_normal.xml new file mode 100644 index 0000000..aaaa72b --- /dev/null +++ b/app/src/main/res/drawable/button_pink_normal.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_pink_pressed.xml b/app/src/main/res/drawable/button_pink_pressed.xml new file mode 100644 index 0000000..a65b465 --- /dev/null +++ b/app/src/main/res/drawable/button_pink_pressed.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_locust_health.xml b/app/src/main/res/layout/activity_locust_health.xml index ccbf38f..ec8007c 100644 --- a/app/src/main/res/layout/activity_locust_health.xml +++ b/app/src/main/res/layout/activity_locust_health.xml @@ -6,7 +6,6 @@ android:background="@drawable/gradient_example" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" - android:paddingRight="@dimen/activity_horizontal_margin" tools:context=".LocustHealthActivity"> + android:showDividers="middle" + android:paddingRight="@dimen/activity_vertical_margin"> + android:paddingLeft="@dimen/activity_horizontal_margin"> + android:layout_weight="1" + android:hint="@string/Country" + android:background="@color/disable"> + + android:paddingLeft="@dimen/activity_horizontal_margin"> + android:paddingLeft="@dimen/activity_horizontal_margin"> - - - + + android:columnCount="3" + android:rowCount="3" + android:background="@color/disable"> - + - + - + - + - + - + - - + + + + + + + android:layout_height="wrap_content"/> @@ -2773,6 +2803,7 @@ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="@color/disable" android:hint="@string/Operator_accidentally_exposed_to_insecticide_or_feeling_unwell"> - - - - + android:columnCount="2" + android:rowCount="3" + android:background="@color/disable" + android:paddingLeft="@dimen/activity_horizontal_margin"> - + - + - + - + - - + + + + + - - - + android:layout_height="wrap_content" + android:gravity="center" + android:paddingLeft="@dimen/activity_horizontal_margin"> + + - + /--> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bff897e..0847a09 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -106,7 +106,6 @@ android:text="@string/title_activity_locust_del"/>