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,
long id) {
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
openContextMenu(arg1);
}
@ -235,7 +238,8 @@ public class PcView extends Activity {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
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();
return;
}

View File

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

View File

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

View File

@ -50,6 +50,13 @@ public class PcGridAdapter extends GenericGridAdapter<PcView.ComputerObject> {
@Override
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;
}
}

View File

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