Order by distance
This commit is contained in:
@ -606,16 +606,16 @@ public class LocustDelListActivity extends AppCompatActivity
|
||||
switch (spiList.getSelectedItemPosition())
|
||||
{
|
||||
case 0:
|
||||
cursor = rdb.rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and filled!=1 and device_id='" + android_id + "'", null); //Не отправленные
|
||||
cursor = rdb.rawQuery("select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and filled!=1 and device_id='" + android_id + "'", null); //Не отправленные
|
||||
break;
|
||||
case 1:
|
||||
cursor = rdb.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); //Не отправленные
|
||||
cursor = rdb.rawQuery("select uid, coalesce(area,'') || ' ' || 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 = rdb.rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and send=1 and device_id='"+android_id+"'", null); //Отправленные
|
||||
cursor = rdb.rawQuery("select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and send=1 and device_id='"+android_id+"'", null); //Отправленные
|
||||
break;
|
||||
default:
|
||||
cursor = rdb.rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and device_id='"+android_id+"'", null); //Все
|
||||
cursor = rdb.rawQuery("select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0 and device_id='"+android_id+"'", null); //Все
|
||||
//cursor = rdb.rawQuery("select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocustdel where del=0", null); //Все
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1,12 +1,20 @@
|
||||
package kz.istt.locust;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -26,6 +34,7 @@ import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
@ -35,8 +44,14 @@ import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class LocustHealthListActivity extends AppCompatActivity
|
||||
import dbfields.selectDB;
|
||||
import tools.LatLonListener;
|
||||
|
||||
public class LocustHealthListActivity extends AppCompatActivity implements LocationListener, LatLonListener
|
||||
{
|
||||
private LocationManager _lm;
|
||||
private double _lat = 0; // c GPS приёмника
|
||||
private double _lon = 0; // c GPS приёмника
|
||||
|
||||
public LinearLayout llList;
|
||||
public MyButton btn;
|
||||
@ -122,6 +137,13 @@ public class LocustHealthListActivity extends AppCompatActivity
|
||||
|
||||
//Чтоб список обновлялся раз в минуту в соответствии с текущем фильтром (для наглядности отправки данных)
|
||||
handler.post(runnable); // Начинаем выполнение задачи
|
||||
|
||||
// Чтоб слушать GPS (в конце метода чтобы успели присвоиться GUI компоненты локальным переменным)
|
||||
_lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
_lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -601,14 +623,28 @@ public class LocustHealthListActivity extends AppCompatActivity
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
_lat = location.getLatitude();
|
||||
_lon = location.getLongitude();
|
||||
|
||||
SELECT *,
|
||||
((latitude - ?) * (latitude - ?) + (longitude - ?) * (longitude - ?)) AS distance
|
||||
FROM locations
|
||||
ORDER BY distance ASC;
|
||||
*/
|
||||
|
||||
|
||||
switch (spiList.getSelectedItemPosition())
|
||||
{
|
||||
case 0:
|
||||
cursor = rdb.rawQuery("""
|
||||
select
|
||||
ld.seq,
|
||||
ld.uid as frmlocustdel_uid,
|
||||
lh.uid as frmlocusthealth_uid,
|
||||
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
coalesce(ld.area,'') || ' ' || coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
lh.date,
|
||||
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
|
||||
from
|
||||
@ -617,14 +653,16 @@ public class LocustHealthListActivity extends AppCompatActivity
|
||||
where
|
||||
lh.del=0
|
||||
and lh.filled!=1
|
||||
order by ld.seq desc
|
||||
""", null); //Не отправленные
|
||||
break;
|
||||
case 1:
|
||||
cursor = rdb.rawQuery("""
|
||||
select
|
||||
ld.seq,
|
||||
ld.uid as frmlocustdel_uid,
|
||||
lh.uid as frmlocusthealth_uid,
|
||||
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
coalesce(ld.area,'') || ' ' || coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
lh.date,
|
||||
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
|
||||
from
|
||||
@ -634,14 +672,16 @@ public class LocustHealthListActivity extends AppCompatActivity
|
||||
lh.del=0
|
||||
and lh.send=0
|
||||
and lh.filled=1
|
||||
order by ld.seq desc
|
||||
""", null); //Не отправленные
|
||||
break;
|
||||
case 2:
|
||||
cursor = rdb.rawQuery("""
|
||||
select
|
||||
ld.seq,
|
||||
ld.uid as frmlocustdel_uid,
|
||||
lh.uid as frmlocusthealth_uid,
|
||||
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
coalesce(ld.area,'') || ' ' || coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
lh.date,
|
||||
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
|
||||
from
|
||||
@ -650,21 +690,58 @@ public class LocustHealthListActivity extends AppCompatActivity
|
||||
where
|
||||
lh.del=0
|
||||
and lh.send=1
|
||||
order by ld.seq desc
|
||||
""", null); //Отправленные
|
||||
break;
|
||||
default:
|
||||
cursor = rdb.rawQuery("""
|
||||
select
|
||||
ld.uid as frmlocustdel_uid,
|
||||
lh.uid as frmlocusthealth_uid,
|
||||
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
coalesce(lh.date,ld.date) as date,
|
||||
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
|
||||
from
|
||||
frmlocustdel ld
|
||||
left join frmlocusthealth lh on lh.frmlocustdel_uid=ld.uid
|
||||
where ld.del=0 and ld.filled=1
|
||||
default: {
|
||||
|
||||
String prefName = "Distance";
|
||||
SharedPreferences prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
|
||||
String checked = prefs.getString(prefName, "");
|
||||
if(checked.isEmpty() || checked.equals("1")) {
|
||||
String[] selectionArgs = new String[]{
|
||||
String.valueOf(_lat),
|
||||
String.valueOf(_lat),
|
||||
String.valueOf(_lon),
|
||||
String.valueOf(_lon)
|
||||
};
|
||||
cursor = rdb.rawQuery("""
|
||||
|
||||
select
|
||||
ld.seq,
|
||||
ld.uid as frmlocustdel_uid,
|
||||
lh.uid as frmlocusthealth_uid,
|
||||
coalesce(ld.area,'') || ' ' || coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
coalesce(lh.date,ld.date) as date,
|
||||
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health,
|
||||
((ld.lat_center - ?) * (ld.lat_center - ?) + (ld.lon_center - ?) * (ld.lon_center - ?)) AS distance
|
||||
from
|
||||
frmlocustdel ld
|
||||
left join frmlocusthealth lh on lh.frmlocustdel_uid=ld.uid
|
||||
where
|
||||
ld.del=0
|
||||
and ld.filled=1
|
||||
order by distance, ld.seq desc
|
||||
""", selectionArgs); //Все
|
||||
}else{
|
||||
cursor = rdb.rawQuery("""
|
||||
select
|
||||
ld.seq,
|
||||
ld.uid as frmlocustdel_uid,
|
||||
lh.uid as frmlocusthealth_uid,
|
||||
coalesce(ld.area,'') || ' ' || coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
|
||||
coalesce(lh.date,ld.date) as date,
|
||||
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
|
||||
from
|
||||
frmlocustdel ld
|
||||
left join frmlocusthealth lh on lh.frmlocustdel_uid=ld.uid
|
||||
where
|
||||
ld.del=0
|
||||
and ld.filled=1
|
||||
order by ld.seq desc
|
||||
""", null); //Все
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -779,4 +856,21 @@ public class LocustHealthListActivity extends AppCompatActivity
|
||||
dboh.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location)
|
||||
{
|
||||
_lat = location.getLatitude(); // от устройства
|
||||
_lon = location.getLongitude(); // от устройства
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLat() {
|
||||
return this._lat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLon() {
|
||||
return this._lon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -583,19 +583,19 @@ public class LocustListActivity extends AppCompatActivity
|
||||
switch (spiList.getSelectedItemPosition())
|
||||
{
|
||||
case 0:
|
||||
sql = "select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0 and filled!=1";
|
||||
sql = "select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0 and filled!=1";
|
||||
cursor = rdb.rawQuery(sql, null); //Не заполненые
|
||||
break;
|
||||
case 1:
|
||||
sql = "select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0 and send=0 and filled=1";
|
||||
sql = "select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0 and send=0 and filled=1";
|
||||
cursor = rdb.rawQuery(sql, null); //Не отправленные
|
||||
break;
|
||||
case 2:
|
||||
sql = "select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0 and send=1";
|
||||
sql = "select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0 and send=1";
|
||||
cursor = rdb.rawQuery(sql, null); //Отправленные
|
||||
break;
|
||||
default:
|
||||
sql = "select uid, coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0";
|
||||
sql = "select uid, coalesce(area,'') || ' ' || coalesce(district,'') || ' ' || coalesce(terrain,'') terrain, date from frmlocust where del=0";
|
||||
cursor = rdb.rawQuery(sql, null); //Все
|
||||
break;
|
||||
}
|
||||
|
||||
@ -66,6 +66,8 @@ public class SetupActivity extends Activity {
|
||||
public EditText edtURL = null;
|
||||
public EditText edtSyncDays = null;
|
||||
public CheckBox cbIdentifyCountryRegion = null;
|
||||
public CheckBox cbOrderByDistance = null;
|
||||
|
||||
public CheckBox cbShowAdvancedSettings = null;
|
||||
|
||||
public final static int TASK1_CODE = 1;
|
||||
@ -292,11 +294,40 @@ public class SetupActivity extends Activity {
|
||||
editor.putString(prefName, "1"); //Default value
|
||||
else
|
||||
editor.putString(prefName, "0");
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
}
|
||||
};
|
||||
cbIdentifyCountryRegion.setOnClickListener(oclBtnId);
|
||||
|
||||
|
||||
|
||||
cbOrderByDistance = (CheckBox) findViewById(R.id.cbOrderByDistance);
|
||||
|
||||
prefName = "Distance";
|
||||
prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
|
||||
checked = prefs.getString(prefName, "");
|
||||
if(checked.equals("") || checked.equals("1"))
|
||||
cbOrderByDistance.setChecked(true);
|
||||
else
|
||||
cbOrderByDistance.setChecked(false);
|
||||
|
||||
oclBtnId = new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
String prefName = "Distance";
|
||||
SharedPreferences prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
if(cbOrderByDistance.isChecked())
|
||||
editor.putString(prefName, "1"); //Default value
|
||||
else
|
||||
editor.putString(prefName, "0");
|
||||
editor.apply();
|
||||
}
|
||||
};
|
||||
cbOrderByDistance.setOnClickListener(oclBtnId);
|
||||
|
||||
//Кнопка для сканирования QR кода
|
||||
btnQR = (Button) findViewById(R.id.btnQR);
|
||||
OnClickListener oclBtnQR = new OnClickListener()
|
||||
|
||||
Reference in New Issue
Block a user