Skip to content

Commit

Permalink
trying to address inconsistencies in search results - by creating new…
Browse files Browse the repository at this point in the history
… inconsistencies
  • Loading branch information
Andy Carra committed Nov 9, 2024
1 parent db149c3 commit bddcc2e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -131,7 +130,6 @@ public void onCreate(Bundle savedInstanceState) {
isDbResult = intent.getBooleanExtra(ListFragment.NETWORK_EXTRA_IS_DB_RESULT, false);
Logging.info( "bssid: " + bssid + " isDbResult: " + isDbResult);

final SimpleDateFormat format = NetworkListUtil.getConstructionTimeFormater(this);
if (null != MainActivity.getNetworkCache()) {
network = MainActivity.getNetworkCache().get(bssid);
}
Expand Down Expand Up @@ -181,7 +179,7 @@ public void onCreate(Bundle savedInstanceState) {
tv.setText( network.getType().name() );

tv = findViewById( R.id.na_firsttime );
tv.setText( NetworkListUtil.getTime(format, network ) );
tv.setText( NetworkListUtil.getTime(network, getApplicationContext()) );

tv = findViewById( R.id.na_chan );
Integer chan = network.getChannel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ private Network addOrUpdateBt(final String bssid, final String ssid,
if (network == null) {
//DEBUG: MainActivity.info("new BT net: "+bssid + "(new: "+newForRun+")");
//ALIBI: using frequency to hold deviceType
network = new Network(bssid, ssid, deviceType, capabilities, strength, type, uuid16Services, mfgrId);
network = new Network(bssid, ssid, deviceType, capabilities, strength, type, uuid16Services, mfgrId, null);
networkCache.put(bssid, network);
} else if (NetworkType.BLE.equals(type) && NetworkType.BT.equals(network.getType())) {
//ALIBI: detected via standard bluetooth, updated as LE (LE should win)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Network( final String bssid, final String ssid, final int frequency, fina
}

public Network( final String bssid, final String ssid, final int frequency, final String capabilities,
final int level, final NetworkType type, final List<String> bleServiceUuid16s, Integer bleMfgrId, final long lastTime) {
final int level, final NetworkType type, final List<String> bleServiceUuid16s, Integer bleMfgrId, final Long lastTime) {
this(bssid, ssid, frequency, capabilities, level, type, bleServiceUuid16s, bleMfgrId, null, lastTime);
}

Expand All @@ -147,7 +147,9 @@ private Network(final String bssid, final String ssid, final int frequency, fina
this.capabilities = ( capabilities == null ) ? "" : capabilities;
this.level = level;
this.type = type;
this.lastTime = lastTime;
if (null != lastTime && lastTime > 0L) {
this.lastTime = lastTime;
}
if (bleMfgrId != null) this.bleMfgrId = bleMfgrId;
if (NetworkType.WIFI.equals(this.type)) {
this.channel = channelForWiFiFrequencyMhz(frequency);
Expand Down Expand Up @@ -265,7 +267,7 @@ public String getRcoisOrBlank() {
return result == null ? "" : result;
}

public long getLastTime() {
public Long getLastTime() {
return lastTime;
}

Expand Down Expand Up @@ -331,7 +333,6 @@ public long getConstructionTime() {
return constructionTime;
}

public long getTime() { return null == lastTime?constructionTime:lastTime;}
/**
* try using a service UUID to lookup mfgr name
* @param fullUuid the raw esrvice UUID to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
*/
@Deprecated
public final class NetworkListAdapter extends AbstractListAdapter<Network> {

private final SimpleDateFormat format;

private final List<Network> unsafeNetworks = new ArrayList<>();
private final List<Network> networks = Collections.synchronizedList(unsafeNetworks);

Expand All @@ -45,7 +42,6 @@ public final class NetworkListAdapter extends AbstractListAdapter<Network> {

public NetworkListAdapter(final Context context, final int rowLayout) {
super(context, rowLayout);
format = NetworkListUtil.getConstructionTimeFormater(context);
if (ListFragment.lameStatic.oui == null) {
ListFragment.lameStatic.oui = new OUI(context.getAssets());
}
Expand Down Expand Up @@ -272,7 +268,7 @@ public View getView(final int position, final View convertView, final ViewGroup
tv.setText(ouiString + sep);

tv = row.findViewById(R.id.time);
tv.setText(NetworkListUtil.getTime(format, network));
tv.setText(NetworkListUtil.getTime(network, getContext()));

tv = row.findViewById(R.id.level_string);
final int level = network.getLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.text.format.DateFormat;

import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
Expand All @@ -33,6 +33,15 @@
* Common utility methods for the network list
*/
public class NetworkListUtil {
private static final Locale l = Locale.getDefault();
private static final String timePattern = DateFormat.getBestDateTimePattern(l, "h:mm:ss a");
private static final String timePattern24 = DateFormat.getBestDateTimePattern(l, "H:mm:ss");
private static final String dateTimePattern = DateFormat.getBestDateTimePattern(l, "yyyy-MM-dd h:mm:ss a");
private static final String dateTimePattern24 = DateFormat.getBestDateTimePattern(l, "yyyy-MM-dd H:mm:ss");
private static final SimpleDateFormat timeFormatter = new SimpleDateFormat(timePattern, l);
private static final SimpleDateFormat dateTimeFormatter = new SimpleDateFormat(dateTimePattern, l);
private static final SimpleDateFormat timeFormatter24 = new SimpleDateFormat(timePattern24, l);
private static final SimpleDateFormat dateTimeFormatter24 = new SimpleDateFormat(dateTimePattern24, l);

//color by signal strength
private static final int COLOR_1 = Color.rgb(0, 255, 0);
Expand All @@ -51,19 +60,22 @@ public class NetworkListUtil {
private static final int COLOR_6A = Color.argb(128, 255, 85, 0);
private static final int COLOR_7A = Color.argb(128, 255, 0, 0);

public static String getTime(final SimpleDateFormat format, final Network network) {
return format.format(new Date(network.getTime()));
}

public static SimpleDateFormat getConstructionTimeFormater(final Context context) {
final int value = Settings.System.getInt(context.getContentResolver(), Settings.System.TIME_12_24, -1);
SimpleDateFormat format;
if (value == 24) {
format = new SimpleDateFormat("H:mm:ss", Locale.getDefault());
public static String getTime(@NonNull final Network network, @NonNull final Context context) {
final Long last = network.getLastTime();
if (null == last) {
if (DateFormat.is24HourFormat(context)) {
return timeFormatter24.format(new Date(network.getConstructionTime()));
} else {
return timeFormatter.format(new Date(network.getConstructionTime()));
}
// SOMEDAY (SDK26+: return Instant.ofEpochSecond(network.getConstructionTime()).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(timePattern));
}
if (DateFormat.is24HourFormat(context)) {
return dateTimeFormatter24.format(new Date(network.getLastTime()));
} else {
format = new SimpleDateFormat("h:mm:ss a", Locale.getDefault());
return dateTimeFormatter.format(new Date(network.getLastTime()));
}
return format;
// SOMEDAY (SDK 26+): return Instant.ofEpochSecond(network.getConstructionTime()).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(timePattern));
}

public static int getSignalColor(final int level, final boolean alpha) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.widget.ImageViewCompat;

Expand All @@ -19,21 +20,18 @@
import net.wigle.wigleandroid.model.OUI;
import net.wigle.wigleandroid.util.Logging;

import java.text.SimpleDateFormat;
import java.util.Comparator;

/**
* the array adapter for a list of networks.
* note: separators aren't drawn if areAllItemsEnabled or isEnabled are false
*/
public final class SetNetworkListAdapter extends AbstractListAdapter<Network> {
private final SimpleDateFormat format;

private final SetBackedNetworkList networks = new SetBackedNetworkList();

public SetNetworkListAdapter(final Context context, final int rowLayout) {
super(context, rowLayout);
format = NetworkListUtil.getConstructionTimeFormater(context);
if (ListFragment.lameStatic.oui == null) {
ListFragment.lameStatic.oui = new OUI(context.getAssets());
}
Expand Down Expand Up @@ -167,10 +165,11 @@ public boolean hasStableIds() {
}

@Override
public void sort(Comparator comparator) {
public void sort(@NonNull Comparator comparator) {
networks.sort(comparator);
}

@NonNull
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
// long start = System.currentTimeMillis();
Expand Down Expand Up @@ -228,7 +227,7 @@ public View getView(final int position, final View convertView, final ViewGroup
}

tv = row.findViewById(R.id.time);
tv.setText(NetworkListUtil.getTime(format, network));
tv.setText(NetworkListUtil.getTime(network, getContext()));

tv = row.findViewById(R.id.level_string);
final int level = network.getLevel();
Expand Down

0 comments on commit bddcc2e

Please sign in to comment.