Skip to content
Permalink
Browse files

Improved error messages (#28)

  • Loading branch information
mathiascode authored and Cl1608Ho committed Nov 18, 2019
1 parent 9e51ddc commit c12a21547cba24e677249781be000c11fd6639dc
@@ -202,7 +202,7 @@ private String downloadFile(String stringUrl, String targetLocation) {
}
Log.d(Tags.INSTALL_SERVICE, "Finished downloading");
} catch (Exception e) {
result = e.toString();
result = e.getMessage();
Log.e(Tags.INSTALL_SERVICE, "An error occurred when downloading a zip", e);
} finally {
try {
@@ -270,7 +270,7 @@ private String unzip(File file, File targetLocation) {
zipInputStream.close();
} catch (IOException e) {
Log.e(Tags.INSTALL_SERVICE, "An error occurred while installing Cuberite", e);
result = getString(R.string.status_download_error);
result = getString(R.string.status_unzip_error);
}
Log.d(Tags.INSTALL_SERVICE, "Releasing wakeLock");
wakeLock.release();
@@ -54,8 +54,8 @@
// TODO: maybe improve landscape mode :P

// Helper functions
private boolean isServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
public static boolean isServiceRunning(Class<?> serviceClass, Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
@@ -74,7 +74,7 @@ private State getState() {
if (new File(preferences.getString("cuberiteLocation", "")).exists())
hasServer = true;

if(isServiceRunning(CuberiteService.class))
if(isServiceRunning(CuberiteService.class, context))
state = State.RUNNING;
else if (hasBinary && hasServer)
state = State.OK;
@@ -206,7 +206,6 @@ public void onClick(View view) {

protected void doKill() {
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("kill"));
checkState();
}

private void showLogLayout() {
@@ -270,7 +269,7 @@ public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
String error = intent.getStringExtra("error");
if(error != null) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + error, Snackbar.LENGTH_LONG).show();
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + " " + error, Snackbar.LENGTH_LONG).show();
}
checkState();
}
@@ -347,7 +346,7 @@ protected void onCreate(Bundle savedInstanceState) {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
String line = inputLine.getText().toString();
if (actionId == EditorInfo.IME_ACTION_DONE) {
if(!line.isEmpty() && isServiceRunning(CuberiteService.class)) {
if(!line.isEmpty() && isServiceRunning(CuberiteService.class, context)) {
sendExecuteLine(line);
inputLine.setText("");
}
@@ -363,7 +362,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
@Override
public void onClick(View v) {
String line = inputLine.getText().toString();
if(!line.isEmpty() && isServiceRunning(CuberiteService.class)) {
if(!line.isEmpty() && isServiceRunning(CuberiteService.class, context)) {
sendExecuteLine(line);
inputLine.setText("");
}
@@ -1,5 +1,6 @@
package org.cuberite.android;

import android.app.ActivityManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -94,6 +95,10 @@ protected void onCreate(Bundle savedInstanceState) {
installNoSha.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (MainActivity.isServiceRunning(CuberiteService.class, getBaseContext())) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_update_binary_error), Snackbar.LENGTH_LONG).show();
return;
}
Intent intent = new Intent(context, InstallService.class);
intent.setAction("installNoCheck");
intent.putExtra("downloadHost", preferences.getString("downloadHost", ""));
@@ -107,7 +112,7 @@ public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
String error = intent.getStringExtra("error");
if (error != null) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + error, Snackbar.LENGTH_LONG).show();
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + " " + error, Snackbar.LENGTH_LONG).show();
}
}
}, new IntentFilter("InstallService.callback"));
@@ -260,6 +265,11 @@ private void installSelectFileOnButtonClick(Button button, final int code) {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (code == PICK_FILE_BINARY &&
MainActivity.isServiceRunning(CuberiteService.class, getBaseContext())) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_update_binary_error), Snackbar.LENGTH_LONG).show();
return;
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
try {
@@ -275,6 +285,11 @@ private void updateOnButtonClick(final Context context, Button button, final Sta
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (state == State.NEED_DOWNLOAD_BINARY &&
MainActivity.isServiceRunning(CuberiteService.class, getBaseContext())) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_update_binary_error), Snackbar.LENGTH_LONG).show();
return;
}
Intent intent = new Intent(context, InstallService.class);
intent.setAction("install");
intent.putExtra("downloadHost", preferences.getString("downloadHost", ""));
@@ -289,7 +304,7 @@ public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
String error = intent.getStringExtra("error");
if(error != null) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + error, Snackbar.LENGTH_LONG).show();
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + " " + error, Snackbar.LENGTH_LONG).show();
}
}
}, new IntentFilter("InstallService.callback"));
@@ -335,7 +350,7 @@ public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
String error = intent.getStringExtra("error");
if(error != null) {
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + error, Snackbar.LENGTH_LONG).show();
Snackbar.make(findViewById(R.id.activity_main), getString(R.string.status_download_error) + " " + error, Snackbar.LENGTH_LONG).show();
}
}
}, new IntentFilter("InstallService.callback"));
@@ -12,7 +12,7 @@
<string name="do_open_settings">Einstellungen</string>

<string name="status_downloading_cuberite">Lade Cuberite herunter…</string>
<string name="status_download_error">Fehler beim Laden: </string>
<string name="status_download_error">Fehler beim Laden:</string>
<string name="status_delete_file_error">Fehler: konnte Datei nicht löschen</string>
<!-- yet unused --> <string name="status_program_exited">Info: Cuberite beendet, Code: </string>
<string name="status_permissions_needed">Berechtigung benötigt</string>
@@ -12,7 +12,7 @@
<string name="do_open_settings">Instellingen</string>

<string name="status_downloading_cuberite">Downloaden Cuberite…</string>
<string name="status_download_error">Download fout: </string>
<string name="status_download_error">Download fout:</string>
<string name="status_delete_file_error">Er ging iets fout: kon het bestand niet verwijderen</string>
<!-- yet unused --> <string name="status_program_exited">Info: Cuberite stopte met code: </string>
<string name="status_permissions_needed">Toestemming nodig</string>
@@ -12,7 +12,7 @@
<string name="do_open_settings">Configurações</string>

<string name="status_downloading_cuberite">Transferindo o Cuberite…</string>
<string name="status_download_error">Erro na transferência: </string>
<string name="status_download_error">Erro na transferência:</string>
<string name="status_delete_file_error">Algo deu errado: Não foi possível apagar o arquivo</string>
<!-- yet unused --> <string name="status_program_exited">Info: Encerrou com o código: </string>
<string name="status_permissions_needed">Permissões necessarias</string>
@@ -16,7 +16,9 @@
<string name="do_open_settings">Settings</string>

<string name="status_downloading_cuberite">Downloading Cuberite…</string>
<string name="status_download_error">Download error: </string>
<string name="status_download_error">Download error:</string>
<string name="status_unzip_error">Failed to unzip the server files</string>
<string name="status_update_binary_error">Please stop the server before updating the binary</string>
<string name="status_delete_file_error">Something went wrong: Couldn\'t delete file</string>
<string name="status_failed_start">Cuberite failed to start. Ensure that your binary has the following ABI:</string>
<!-- yet unused --> <string name="status_program_exited">Info: Cuberite exited with code: </string>

0 comments on commit c12a215

Please sign in to comment.
You can’t perform that action at this time.