Display machines as they are being refreshed

This commit is contained in:
Cameron Gutman 2014-11-08 13:14:35 -08:00
parent 2df2f850d5
commit 21e46a5c3b
5 changed files with 27 additions and 7 deletions

View File

@ -110,7 +110,10 @@ public class PcView extends Activity {
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long id) { long id) {
ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(pos); ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(pos);
if (computer.details.reachability == ComputerDetails.Reachability.OFFLINE) { if (computer.details.reachability == ComputerDetails.Reachability.UNKNOWN) {
// Do nothing
}
else if (computer.details.reachability == ComputerDetails.Reachability.OFFLINE) {
// Open the context menu if a PC is offline // Open the context menu if a PC is offline
openContextMenu(arg1); openContextMenu(arg1);
} }
@ -235,7 +238,8 @@ public class PcView extends Activity {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(info.position); ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(info.position);
if (computer == null || computer.details == null) { if (computer == null || computer.details == null ||
computer.details.reachability == ComputerDetails.Reachability.UNKNOWN) {
startComputerUpdates(); startComputerUpdates();
return; return;
} }

View File

@ -99,15 +99,17 @@ public class ComputerDatabaseManager {
details.macAddress = c.getString(4); details.macAddress = c.getString(4);
// This signifies we don't have dynamic state (like pair state) // This signifies we don't have dynamic state (like pair state)
details.state = ComputerDetails.State.UNKNOWN; details.state = ComputerDetails.State.UNKNOWN;
details.reachability = ComputerDetails.Reachability.UNKNOWN;
// If a field is corrupt or missing, skip the database entry // If a field is corrupt or missing, skip the database entry
if (details.uuid == null || details.localIp == null || details.remoteIp == null || if (details.uuid == null || details.localIp == null || details.remoteIp == null ||
details.macAddress == null) { details.macAddress == null) {
continue; continue;
} }
computerList.add(details);
computerList.add(details);
} }
c.close(); c.close();
@ -151,6 +153,9 @@ public class ComputerDatabaseManager {
details.macAddress = c.getString(4); details.macAddress = c.getString(4);
c.close(); c.close();
details.state = ComputerDetails.State.UNKNOWN;
details.reachability = ComputerDetails.Reachability.UNKNOWN;
// If a field is corrupt or missing, delete the database entry // If a field is corrupt or missing, delete the database entry
if (details.uuid == null || details.localIp == null || details.remoteIp == null || if (details.uuid == null || details.localIp == null || details.remoteIp == null ||

View File

@ -151,6 +151,9 @@ public class ComputerManagerService extends Service {
for (ComputerDetails computer : computerList) { for (ComputerDetails computer : computerList) {
// This polling thread might already be there // This polling thread might already be there
if (!pollingThreads.containsKey(computer)) { if (!pollingThreads.containsKey(computer)) {
// Report this computer initially
listener.notifyComputerUpdated(computer);
Thread t = createPollingThread(computer); Thread t = createPollingThread(computer);
pollingThreads.put(computer, t); pollingThreads.put(computer, t);
t.start(); t.start();

View File

@ -50,6 +50,13 @@ public class PcGridAdapter extends GenericGridAdapter<PcView.ComputerObject> {
@Override @Override
public boolean populateOverlayView(ImageView overlayView, PcView.ComputerObject obj) { public boolean populateOverlayView(ImageView overlayView, PcView.ComputerObject obj) {
if (obj.details.reachability == ComputerDetails.Reachability.UNKNOWN) {
// Still refreshing this PC so display the overlay
overlayView.setImageResource(R.drawable.image_loading);
return true;
}
// No overlay
return false; return false;
} }
} }

View File

@ -15,8 +15,9 @@
</ImageView> </ImageView>
<ImageView <ImageView
android:id="@+id/grid_overlay" android:id="@+id/grid_overlay"
android:layout_centerHorizontal="true" android:layout_marginTop="15dp"
android:layout_centerVertical="true" android:layout_marginLeft="65dp"
android:layout_marginRight="20dp"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp"> android:layout_height="50dp">
</ImageView> </ImageView>