Skip to content

Commit

Permalink
feat(servers): new dialog to list servers
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Del Pino <[email protected]>
  • Loading branch information
Ivan Del Pino authored and rafaelje committed Oct 16, 2018
1 parent d9a2ef4 commit 9b462f9
Show file tree
Hide file tree
Showing 24 changed files with 623 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.flyve.inventory.InventoryTask;
import org.flyve.inventory.agent.model.ServerModel;
import org.flyve.inventory.agent.utils.FlyveLog;
import org.flyve.inventory.agent.utils.HttpInventory;
import org.junit.Test;
Expand Down Expand Up @@ -79,7 +81,12 @@ public void sendInventoryTest() throws Exception {

// Send xml to default route
HttpInventory httpInventory = new HttpInventory(appContext);
httpInventory.sendInventory(data, new HttpInventory.OnTaskCompleted() {
ServerModel serverModel = new ServerModel();
serverModel.setAddress("https://demo-api.flyve.org/plugins/fusioninventory/");
serverModel.setTag("");
serverModel.setLogin("");
serverModel.setPass("");
httpInventory.sendInventory(data, serverModel, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
FlyveLog.d(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @author Ivan Del Pino
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-inventory-agent
Expand Down Expand Up @@ -52,7 +52,7 @@ public ListServersAdapter(ArrayList<String> data, Activity activity) {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
int resource = R.layout.list_item_inventory_child;
int resource = R.layout.list_item_servers;
View v = LayoutInflater.from(viewGroup.getContext()).inflate(resource, viewGroup, false);
return new DataViewHolder(v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.flyve.inventory.InventoryTask;
import org.flyve.inventory.agent.R;
import org.flyve.inventory.agent.model.ServerModel;
import org.flyve.inventory.agent.utils.FlyveLog;
import org.flyve.inventory.agent.utils.Helpers;
import org.flyve.inventory.agent.utils.HttpInventory;
Expand Down Expand Up @@ -67,7 +68,12 @@ public void onReceive(final Context context, Intent intent) {
@Override
public void onTaskSuccess(String data) {
HttpInventory httpInventory = new HttpInventory(context.getApplicationContext());
httpInventory.sendInventory(data, new HttpInventory.OnTaskCompleted() {
ServerModel serverModel = new ServerModel();
serverModel.setAddress("https://demo-api.flyve.org/plugins/fusioninventory/");
serverModel.setTag("");
serverModel.setLogin("");
serverModel.setPass("");
httpInventory.sendInventory(data, serverModel, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_sent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @author Ivan Del Pino
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-mdm-agent
Expand All @@ -23,29 +23,37 @@

package org.flyve.inventory.agent.core.detailserver;

import android.content.Context;

import org.flyve.inventory.agent.model.ServerModel;

import java.util.ArrayList;

public interface DetailServer {

interface View {
void showError(String message);
void successful(String message);
void modelServer(ServerModel model);
}

interface Presenter {
// Views
void showError(String message);
void successful(String message);
void modelServer(ServerModel model);

// Models
void saveServer(ArrayList<String> message);
void deleteServer(String serverName);
void updateServer(ArrayList<String> serverInfo, String serverName);
void saveServer(ArrayList<String> message, Context applicationContext);
void deleteServer(String serverName, Context applicationContext);
void updateServer(ArrayList<String> serverInfo, String serverName, Context applicationContext);
void loadServer(String serverName, Context applicationContext);
}

interface Model {
void saveServer(ArrayList<String> message);
void deleteServer(String serverName);
void updateServer(ArrayList<String> serverInfo, String serverName);
void saveServer(ArrayList<String> message, Context applicationContext);
void deleteServer(String serverName, Context applicationContext);
void updateServer(ArrayList<String> serverInfo, String serverName, Context applicationContext);
void loadServer(String serverName, Context applicationContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @author Ivan Del Pino
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-mdm-agent
Expand All @@ -23,6 +23,14 @@

package org.flyve.inventory.agent.core.detailserver;

import android.content.Context;

import org.flyve.inventory.agent.model.ServerModel;
import org.flyve.inventory.agent.utils.FlyveLog;
import org.flyve.inventory.agent.utils.LocalPreferences;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class DetailServerModel implements DetailServer.Model {
Expand All @@ -34,17 +42,94 @@ public class DetailServerModel implements DetailServer.Model {
}

@Override
public void saveServer(ArrayList<String> message) {
presenter.successful("Successful");
public void saveServer(ArrayList<String> modelServer, Context context) {
LocalPreferences preferences = new LocalPreferences(context);
if (modelServer.size() >= 4) {
if (!"".equals(modelServer.get(0))) {
JSONObject jo = new JSONObject();
try {
jo.put("address", modelServer.get(0));
jo.put("tag", modelServer.get(1));
jo.put("login", modelServer.get(2));
jo.put("pass", modelServer.get(3));
ArrayList<String> serverArray = preferences.loadServerArray();
serverArray.add(modelServer.get(0));
preferences.saveServerArray(serverArray);
} catch (JSONException e) {
FlyveLog.e(e.getMessage());
presenter.showError("Error");
}
preferences.saveJSONObject(modelServer.get(0), jo);
presenter.successful("Successful");
} else {
presenter.showError("Missing server");
}
} else {
presenter.showError("Error");
}
}

@Override
public void updateServer(ArrayList<String> modelServer, String serverName, Context context) {
LocalPreferences preferences = new LocalPreferences(context);
if (modelServer.size() >= 4) {
if (!"".equals(modelServer.get(0))) {
JSONObject jo = new JSONObject();
try {
jo.put("address", modelServer.get(0));
jo.put("tag", modelServer.get(1));
jo.put("login", modelServer.get(2));
jo.put("pass", modelServer.get(3));
ArrayList<String> serverArray = preferences.loadServerArray();
for (int i = 0; i < serverArray.size(); i++) {
if (serverArray.get(i).equals(serverName)) {
serverArray.set(i, modelServer.get(0));
preferences.saveServerArray(serverArray);
}
}
} catch (JSONException e) {
FlyveLog.e(e.getMessage());
presenter.showError("Error");
}
preferences.deletePreferences(serverName);
preferences.saveJSONObject(modelServer.get(0), jo);
presenter.successful("Successful");
} else {
presenter.showError("Missing Server");
}
} else {
presenter.showError("Error");
}
}

@Override
public void deleteServer(String serverName) {
presenter.successful("Successful");
public void loadServer(String serverName, Context context) {
LocalPreferences preferences = new LocalPreferences(context);
try {
JSONObject jo = preferences.loadJSONObject(serverName);
ServerModel serverModel = new ServerModel();
serverModel.setAddress(jo.getString("address"));
serverModel.setTag(jo.getString("tag"));
serverModel.setLogin(jo.getString("login"));
serverModel.setPass(jo.getString("pass"));
presenter.modelServer(serverModel);
} catch (JSONException e) {
FlyveLog.e(e.getMessage());
presenter.showError("Error");
}
}

@Override
public void updateServer(ArrayList<String> serverInfo, String serverName) {
presenter.successful("Successful");
public void deleteServer(String serverName, Context context) {
if (serverName != null && !"".equals(serverName)) {
LocalPreferences preferences = new LocalPreferences(context);
preferences.deletePreferences(serverName);
ArrayList<String> serverArray = preferences.loadServerArray();
serverArray.remove(serverName);
preferences.saveServerArray(serverArray);
presenter.successful("Successful Delete");
} else {
presenter.showError("Error");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @author Ivan Del Pino
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-mdm-agent
Expand All @@ -23,6 +23,10 @@

package org.flyve.inventory.agent.core.detailserver;

import android.content.Context;

import org.flyve.inventory.agent.model.ServerModel;

import java.util.ArrayList;

public class DetailServerPresenter implements DetailServer.Presenter {
Expand Down Expand Up @@ -50,18 +54,30 @@ public void successful(String message) {
}

@Override
public void saveServer(ArrayList<String> message) {
model.saveServer(message);
public void modelServer(ServerModel model) {
if (view != null) {
view.modelServer(model);
}
}

@Override
public void saveServer(ArrayList<String> message, Context applicationContext) {
model.saveServer(message, applicationContext);
}

@Override
public void deleteServer(String serverName, Context applicationContext) {
model.deleteServer(serverName, applicationContext);
}

@Override
public void deleteServer(String serverName) {
model.deleteServer(serverName);
public void updateServer(ArrayList<String> serverInfo, String serverName, Context applicationContext) {
model.updateServer(serverInfo, serverName, applicationContext);
}

@Override
public void updateServer(ArrayList<String> serverInfo, String serverName) {
model.updateServer(serverInfo, serverName);
public void loadServer(String serverName, Context applicationContext) {
model.loadServer(serverName, applicationContext);
}

}
Loading

0 comments on commit 9b462f9

Please sign in to comment.