Skip to content

Commit

Permalink
Artemis Messenger 5.2.0: App cleanup on close, fixed mission counters,
Browse files Browse the repository at this point in the history
speed reconcile crash bug fixed, player ship destruction handling
  • Loading branch information
JordanLongstaff committed May 21, 2018
1 parent df70d69 commit 901e258
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 49 deletions.
6 changes: 3 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="artemis.messenger"
android:installLocation="preferExternal"
android:revisionCode="41"
android:versionCode="42"
android:versionName="5.1.1" >
android:revisionCode="42"
android:versionCode="43"
android:versionName="5.2.0" >

<uses-sdk
android:minSdkVersion="9"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Artemis Messenger 5.1.1
# Artemis Messenger 5.2.0

## What is Artemis Messenger?

Expand Down
6 changes: 3 additions & 3 deletions bin/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="artemis.messenger"
android:installLocation="preferExternal"
android:revisionCode="41"
android:versionCode="42"
android:versionName="5.1.1" >
android:revisionCode="42"
android:versionCode="43"
android:versionName="5.2.0" >

<uses-sdk
android:minSdkVersion="9"
Expand Down
Binary file modified bin/Artemis Messenger.apk
Binary file not shown.
Binary file modified bin/classes.dex
Binary file not shown.
1 change: 0 additions & 1 deletion bin/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/android/
/artemis/
/.gitignore
/com/
Binary file modified bin/dexedLibs/appcompat_v7-c958b99d5111e7b7a41e540bcdbc30da.jar
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<string name="basicsParagraph6">If you touch the Home button on your phone to return to your Home menu, Artemis Messenger will keep running in the background. It will continue to receive information about side missions, allies and stations via a Comms service. This information will be shown as notifications on your phone. If you click on one of those notifications, you will return to Artemis Messenger.</string>
<string name="basicsParagraph5">When you want to leave Artemis Messenger, just hit the Back button on your phone. If your phone doesn\'t have a Back button, you can also press the Close button in the top-right corner of the screen. If the app is connected to a server, a dialog will appear asking if you want to close the connection; otherwise, no dialog will appear.</string>
<string name="helpTitle">Help</string>
<string name="appVersionText">Artemis Messenger 5.1.1</string>
<string name="appVersionText">Artemis Messenger 5.2.0</string>
<string name="specialThanks">Special thanks to Robert J. Walker for writing the IAN (Interface for Artemis Networking) library, without which this app could not exist. IAN is available on GitHub.</string>
<string name="licenseText">\u00A9 Copyright 2017.</string>
<string name="writtenBy">Written by Jordan Longstaff</string>
Expand Down
164 changes: 127 additions & 37 deletions src/artemis/messenger/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class ListActivity extends Activity implements OnSharedPreferenceChangeLi
private int dockingStation;
private RoutingGraph graph;
private Version version;
private byte destroyedShips;

// Multithreading variables
private Thread packetThread;
Expand All @@ -120,6 +121,7 @@ public class ListActivity extends Activity implements OnSharedPreferenceChangeLi
private ConcurrentHashMap<String, ConcurrentHashMap<String, StationStatusRow>> bases;
private ConcurrentHashMap<String, ConcurrentHashMap<String, AllyStatusRow>> allies;
private ConcurrentHashMap<String, CopyOnWriteArrayList<String>> rogues;
private CopyOnWriteArrayList<String> baseKeys;
private LinkedList<CommsIncomingPacket> inPackets;
private LinkedList<CommsOutgoingPacket> outPackets;

Expand Down Expand Up @@ -246,6 +248,12 @@ public void run() {
final Runnable updateRoute = new Runnable() {
@Override
public void run() {
// If current ship does not exist, do nothing except empty table
if (playerDestroyed()) {
routeView.post(clearRoutingTable);
return;
}

// If we've destroyed our graph, Route table should be empty
if (graph == null) {
routeView.post(clearRoutingTable);
Expand Down Expand Up @@ -307,6 +315,7 @@ public void run() {

long flashTimer = new Date().getTime();
boolean flashOn = (flashTimer - startTime) % (flashTime << 1) < flashTime;
flashOn &= !playerDestroyed();

if (missionsView.getVisibility() == View.VISIBLE) missionViewButton.setBackgroundColor(clr_yellow);
else if (missionFlash && flashOn) missionViewButton.setBackgroundColor(clr_flash);
Expand Down Expand Up @@ -442,6 +451,7 @@ private void initDataTables() {
closed = new ConcurrentHashMap<String, CopyOnWriteArrayList<SideMissionRow>>();
allies = new ConcurrentHashMap<String, ConcurrentHashMap<String, AllyStatusRow>>();
bases = new ConcurrentHashMap<String, ConcurrentHashMap<String, StationStatusRow>>();
baseKeys = new CopyOnWriteArrayList<String>();
rogues = new ConcurrentHashMap<String, CopyOnWriteArrayList<String>>();
inPackets = new LinkedList<CommsIncomingPacket>();
outPackets = new LinkedList<CommsOutgoingPacket>();
Expand Down Expand Up @@ -624,8 +634,11 @@ public void onItemSelected(AdapterView<?> parent, View view,
}
}

// Update Missions table with missions exclusive to this ship
// Update table views
clearTableViews();
updateMissionsTable();
updateAlliesTable();
updateStationsTable();
}

@Override
Expand Down Expand Up @@ -714,6 +727,7 @@ private void removeAllNotifications() {

// Method to empty out all data in server data tables
private void clearDataTables() {
destroyedShips = 0;
missions.clear();
for (CopyOnWriteArrayList<SideMissionRow> list: closed.values()) list.clear();
for (ConcurrentHashMap<String, StationStatusRow> map: bases.values()) map.clear();
Expand All @@ -723,6 +737,13 @@ private void clearDataTables() {
bases.clear();
allies.clear();
rogues.clear();
baseKeys.clear();
}

// Returns whether or not the current player ship, if it exists, is destroyed
private boolean playerDestroyed() {
return manager != null && manager.getPlayerShip() != null &&
(destroyedShips & (1 << manager.getPlayerShip().getShipIndex())) != 0;
}

// Create a path resolver for vesselData.xml, location is according to preferences
Expand Down Expand Up @@ -1023,7 +1044,7 @@ public void onClick(View v) {

// Add table row to Stations view
final StationStatusRow row = bases.get(baseName).get(vesselName);
final int rowIndex = getStationSortIndex(row, baseName);
final int rowIndex = insertBaseKey(baseName);
stationsView.post(new Runnable() {
@Override
public void run() {
Expand All @@ -1034,15 +1055,13 @@ public void run() {
}

// Calculate index of where to insert a StationStatusRow using binary search
private int getStationSortIndex(StationStatusRow row, String name) {
int index = -1;
int minIndex = 0, maxIndex = stationsTable.getChildCount();
private int insertBaseKey(String name) {
int index = 0;
int minIndex = 0, maxIndex = baseKeys.size();
while (minIndex < maxIndex) {
index = (maxIndex + minIndex) / 2;
String rowName = name;
StationStatusRow otherRow = (StationStatusRow) stationsTable.getChildAt(index);
TextView statusText = (TextView) otherRow.getChildAt(0);
String otherName = statusText.getText().toString().split(" ")[0];
String otherName = baseKeys.get(index);

// If station names both start with DS, sort by number
if (otherName.startsWith("DS") && rowName.startsWith("DS")) {
Expand All @@ -1057,6 +1076,7 @@ private int getStationSortIndex(StationStatusRow row, String name) {
minIndex = ++index;
} else break;
}
baseKeys.add(index, name);
return index;
}

Expand Down Expand Up @@ -1267,6 +1287,7 @@ public void run() {
}
bases.get(baseName).clear();
bases.remove(baseName);
baseKeys.remove(baseName);
}
}

Expand Down Expand Up @@ -1315,6 +1336,47 @@ public void run() {
}
}

/**
* Called whenever a player ship is destroyed.
*/
private void onObjectDestroyed(ArtemisPlayer plr) {
// If the game's over, nothing to do
if (!gameRunning) return;

// Mark player ship destruction
destroyedShips |= 1 << plr.getShipIndex();

// If it was the player ship we were on, we'll get kicked out of the game
if (plr.getId() == manager.getPlayerShip().getId()) {
// Clear current data
dockingStation = -1;
clearTableViews();
}

if (version.ge(VERSION27)) {
// Cancel their exclusive side missions
String name = plr.getName().toString();
for (int i = 0; i < missions.size(); i++) {
final SideMissionRow row = missions.get(i);
if (row.getPlayerShip().equals(name)) {
missions.remove(i--);
if (!row.isCompleted()) {
ObjectStatusRow destRow = null;
String[] destParts = row.getDestination().split(" ", 2);
if (allies.containsKey(destParts[0]))
destRow = allies.get(destParts[0]).get(destParts[1]);
else if (bases.containsKey(destParts[0]))
destRow = bases.get(destParts[0]).get(destParts[1]);
if (destRow != null) {
destRow.removeMission(row);
postStatusUpdate(destRow);
}
}
}
}
}
}

/**
* Called when a destroyed object packet is received by the client.
* @param pkt the destroyed object packet
Expand All @@ -1333,6 +1395,9 @@ public void onPacket(DestroyObjectPacket pkt) {
case NPC_SHIP:
onObjectDestroyed((ArtemisNpc) object);
break;
case PLAYER_SHIP:
onObjectDestroyed((ArtemisPlayer) object);
break;
default:
// If neither a base nor an ally ship, exit
return;
Expand Down Expand Up @@ -1378,7 +1443,8 @@ public void onPacket(DestroyObjectPacket pkt) {
missionsView.post(new Runnable() {
@Override
public void run() {
missionsTable.removeView(row);
try { missionsTable.removeView(row); }
catch (IllegalStateException e) { }
}
});
} catch (Exception e) { }
Expand Down Expand Up @@ -2027,12 +2093,12 @@ public boolean parseToDestination(String sender, String message) {
}

// Update destination's record of the mission
ObjectStatusRow destRow = null;
if (allies.containsKey(destination))
destRow = allies.get(destination).get(row.getDestination().substring(destination.length() + 1));
else if (bases.containsKey(destination))
destRow = bases.get(destination).get(row.getDestination().substring(destination.length() + 1));
if (version.ge(VERSION27)) {
ObjectStatusRow destRow = null;
if (allies.containsKey(destination))
destRow = allies.get(destination).get(row.getDestination().substring(destination.length() + 1));
else if (bases.containsKey(destination))
destRow = bases.get(destination).get(row.getDestination().substring(destination.length() + 1));
if (destRow != null) {
destRow.removeMission(row);
}
Expand Down Expand Up @@ -2063,14 +2129,11 @@ else if (bases.containsKey(destination))
final String rewardStr = s;
for (int t = 0; t < quantity; t++) other.addReward(rewardStr);
}
missionsView.post(new Runnable() {
@Override
public void run() {
try { missionsTable.removeView(row); }
catch (IllegalStateException e) { }
}
});
missions.remove(row);
if (destRow != null) {
destRow.removeMission(row);
postStatusUpdate(destRow);
}
break;
}
updateMissionsTable();
Expand Down Expand Up @@ -2435,6 +2498,7 @@ public void clearTableViews() {

// Update Missions table
public void updateMissionsTable() {
if (playerDestroyed()) return;
missionsView.post(clearMissionsTable);
for (int i = 0; i < missions.size(); i++) {
final SideMissionRow row = missions.get(i);
Expand All @@ -2449,7 +2513,8 @@ public void run() {

// Update Stations table
public void updateStationsTable() {
for (final CharSequence n: bases.keySet()) {
if (playerDestroyed()) return;
for (final String n: baseKeys) {
for (final String s: bases.get(n).keySet()) {
stationsView.post(new Runnable() {
@Override
Expand All @@ -2466,7 +2531,13 @@ public void run() {
public void updateAlliesTable() {
// Start by emptying the table
alliesView.post(clearAlliesTable);

// If current player destroyed, do nothing else
if (playerDestroyed()) return;

int rowCount = 0;
for (CharSequence n: allies.keySet()) rowCount += allies.get(n).size();
final ArrayList<AllyStatusRow> rows = new ArrayList<AllyStatusRow>(rowCount);
boolean showDestroyed = preferences.getBoolean(getString(R.string.showDestroyedKey), true);

for (CharSequence n: allies.keySet()) {
Expand All @@ -2475,11 +2546,11 @@ public void updateAlliesTable() {
if (!showDestroyed && r.getStatus() == AllyStatus.DESTROYED) continue;

// Find index to insert row at using binary search
int index = -1;
int minIndex = 0, maxIndex = rowCount;
int index = 0;
int minIndex = 0, maxIndex = rows.size();
while (minIndex < maxIndex) {
index = (maxIndex + minIndex) / 2;
AllyStatusRow otherRow = (AllyStatusRow) alliesTable.getChildAt(index);
AllyStatusRow otherRow = rows.get(index);
if (otherRow == null) continue;
int compare = compare(r, otherRow);
if (compare < 0) {
Expand All @@ -2488,19 +2559,20 @@ public void updateAlliesTable() {
minIndex = ++index;
} else break;
}

// Add row to Allies table
final int rowIndex = index;
alliesView.post(new Runnable() {
@Override
public void run() {
try { alliesTable.addView(r, rowIndex); }
catch (IllegalStateException e) { }
}
});
rowCount++;
rows.add(index, r);
}
}

// Add all rows to Allies table
alliesView.post(new Runnable() {
@Override
public void run() {
for (AllyStatusRow r: rows) {
try { alliesTable.addView(r); }
catch (IllegalStateException e) { }
}
}
});
}

// Binary search comparison method for ally status rows
Expand All @@ -2509,7 +2581,6 @@ private int compare(AllyStatusRow row1, AllyStatusRow row2) {
if (row1.getStatus() == AllyStatus.DESTROYED || row2.getStatus() == AllyStatus.DESTROYED) {
if (row1.getStatus() != AllyStatus.DESTROYED) return -1;
if (row2.getStatus() != AllyStatus.DESTROYED) return 1;
return 0;
}

// Find variables including sort method
Expand Down Expand Up @@ -3079,6 +3150,25 @@ protected void onCreate(Bundle savedInstanceState) {
initNotifications();
}

@Override
public void onDestroy() {
// Shut down packet handler
inPackets.clear();
outPackets.clear();

// Shut down connection
if (serviceRunning) {
// Destroy all notifications
removeAllNotifications();
}

// Clear server data
endServer();
clearDataTables();

super.onDestroy();
}

@Override
public void onPause() {
super.onPause();
Expand Down
Loading

0 comments on commit 901e258

Please sign in to comment.