This commit is contained in:
m_broelemann 2021-01-07 21:05:26 +01:00
commit 4fabe8e024
4 changed files with 57 additions and 12 deletions

View File

@ -1,5 +1,6 @@
{ {
"address": "192.168.2.203", "address": "192.168.1.100",
"port" : 8080, "port" : 8080,
"currentView" : "",
"favorites" : [ ] "favorites" : [ ]
} }

View File

@ -298,8 +298,8 @@ public class MainActivity extends AppCompatActivity {
} }
/** /**
* paul * Method to set the config.xml to a default.
* @param xmlFile * @param xmlFile the config.xml file
*/ */
private void setDefaultXML(final File xmlFile) { private void setDefaultXML(final File xmlFile) {
try { try {
@ -312,23 +312,23 @@ public class MainActivity extends AppCompatActivity {
fileOutputStream.write(buffer); fileOutputStream.write(buffer);
fileOutputStream.close(); fileOutputStream.close();
} catch (Exception e) { } catch (Exception e) {
Log.e("MainActivity", "error while transferring the " Log.e("MainActivity", "error while transferring"
+ "default.xml into the config.xml: " + e.getMessage()); + "a default config: " + e.getMessage());
} }
} }
/** /**
* paul * Method to set the config.json to a default.
* @param xmlFile * @param jsonFile the config.json file
*/ */
private void setDefaultConfig(final File xmlFile) { private void setDefaultConfig(final File jsonFile) {
try { try {
InputStream inputStream = getAssets().open( InputStream inputStream = getAssets().open(
"defaultConfig.json"); "defaultConfig.json");
byte[] buffer = new byte[inputStream.available()]; byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer); inputStream.read(buffer);
inputStream.close(); inputStream.close();
FileOutputStream fileOutputStream = new FileOutputStream(xmlFile); FileOutputStream fileOutputStream = new FileOutputStream(jsonFile);
fileOutputStream.write(buffer); fileOutputStream.write(buffer);
fileOutputStream.close(); fileOutputStream.close();
} catch (Exception e) { } catch (Exception e) {

View File

@ -163,9 +163,9 @@ public class Communicator {
} }
/** /**
* paul * Method for handling various {@link VolleyError}.
* @param error * @param error the {@link VolleyError}
* @param method * @param method the name of the method where the error occurred
*/ */
private void handleError(final VolleyError error, final String method) { private void handleError(final VolleyError error, final String method) {
if (error instanceof ServerError) { if (error instanceof ServerError) {
@ -181,6 +181,10 @@ public class Communicator {
} }
} }
/**
* Method for making a custom toast message for serious {@link VolleyError}.
* @param message the message to be displayed in the toast
*/
private void makeToast(final String message) { private void makeToast(final String message) {
Toast toast = new Toast(mainActivity); Toast toast = new Toast(mainActivity);
View toastView = mainActivity.getLayoutInflater().inflate(R.layout. View toastView = mainActivity.getLayoutInflater().inflate(R.layout.

View File

@ -117,6 +117,25 @@ public class ConfigurationHandler implements IFAVORITES {
return deviceName; return deviceName;
} }
/**
* Method to get the name of the current view.
* @return the name of the current view
*/
public String getCurrentView() {
return configurations.getCurrentView();
}
/**
* Method to set the name of the current view.
* @param viewName the name to be set
* @return the name that has been set
*/
public String setCurrentView(final String viewName) {
configurations.setCurrentView(viewName);
writeJsonFile();
return getCurrentView();
}
//endregion //endregion
//region private methods //region private methods
@ -136,6 +155,7 @@ public class ConfigurationHandler implements IFAVORITES {
JSONObject jsonObject = new JSONObject(jsonData); JSONObject jsonObject = new JSONObject(jsonData);
configurations.setAddress(jsonObject.getString("address")); configurations.setAddress(jsonObject.getString("address"));
configurations.setPort(jsonObject.getInt("port")); configurations.setPort(jsonObject.getInt("port"));
configurations.setCurrentView(jsonObject.getString("currentView"));
List<String> favoriteNames = new ArrayList<>(); List<String> favoriteNames = new ArrayList<>();
JSONArray favorites = jsonObject.getJSONArray("favorites"); JSONArray favorites = jsonObject.getJSONArray("favorites");
for (int i = 0; i < favorites.length(); i++) { for (int i = 0; i < favorites.length(); i++) {
@ -192,6 +212,25 @@ public class ConfigurationHandler implements IFAVORITES {
/** The names of the favorite devices. **/ /** The names of the favorite devices. **/
private List<String> favoriteNames = new ArrayList<>(); private List<String> favoriteNames = new ArrayList<>();
/**
* Getter for currentView.
* @return the name of the current view
*/
public String getCurrentView() {
return currentView;
}
/**
* Setter for currentView.
* @param pCurrentView the name of the current view
*/
public void setCurrentView(final String pCurrentView) {
this.currentView = pCurrentView;
}
/** The name of the current view. **/
private String currentView = "";
/** /**
* Getter for the address variable. * Getter for the address variable.
* @return the address of the raspberry * @return the address of the raspberry
@ -254,6 +293,7 @@ public class ConfigurationHandler implements IFAVORITES {
return "{\n" return "{\n"
+ "\t\"address\":\"" + address + "\",\n" + "\t\"address\":\"" + address + "\",\n"
+ "\t\"port\":\"" + port + "\",\n" + "\t\"port\":\"" + port + "\",\n"
+ "\t\"currentView\":\"" + currentView + "\",\n"
+ "\t\"favorites\":" + favoriteNamesString.toString() + "\n" + "\t\"favorites\":" + favoriteNamesString.toString() + "\n"
+ "}"; + "}";
} }