Skip to content

Commit

Permalink
feat(servers): limit size name list server in dialog
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 9b462f9 commit 15a93c1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import org.flyve.inventory.agent.utils.FlyveLog;
import org.flyve.inventory.agent.utils.Helpers;
import org.flyve.inventory.agent.utils.HttpInventory;
import org.flyve.inventory.agent.utils.LocalPreferences;

import java.util.ArrayList;

public class TimeAlarm extends BroadcastReceiver {

Expand Down Expand Up @@ -68,24 +71,23 @@ public void onReceive(final Context context, Intent intent) {
@Override
public void onTaskSuccess(String data) {
HttpInventory httpInventory = new HttpInventory(context.getApplicationContext());
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));
Helpers.sendAnonymousData(context.getApplicationContext(), inventory);
}

@Override
public void onTaskError(String error) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_fail));
FlyveLog.e(error);
}
});
ArrayList<String> serverArray = new LocalPreferences(context).loadServerArray();
for (String serverName : serverArray) {
ServerModel model = httpInventory.setServerModel(serverName);
httpInventory.sendInventory(data, model, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_sent));
Helpers.sendAnonymousData(context.getApplicationContext(), inventory);
}

@Override
public void onTaskError(String error) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_fail));
FlyveLog.e(error);
}
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import org.flyve.inventory.agent.utils.FlyveLog;
import org.flyve.inventory.agent.utils.Helpers;
import org.flyve.inventory.agent.utils.HttpInventory;
import org.flyve.inventory.agent.utils.LocalPreferences;
import org.flyve.inventory.agent.utils.LocalStorage;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
Expand Down Expand Up @@ -181,24 +183,23 @@ private void sendInventory() {
@Override
public void onTaskSuccess(String data) {
HttpInventory httpInventory = new HttpInventory(context.getApplicationContext());
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));
Helpers.sendAnonymousData(context.getApplicationContext(), inventory);
}

@Override
public void onTaskError(String error) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_fail));
FlyveLog.e(error);
}
});
ArrayList<String> serverArray = new LocalPreferences(context).loadServerArray();
for (String serverName : serverArray) {
ServerModel model = httpInventory.setServerModel(serverName);
httpInventory.sendInventory(data, model, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_sent));
Helpers.sendAnonymousData(context.getApplicationContext(), inventory);
}

@Override
public void onTaskError(String error) {
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_fail));
FlyveLog.e(error);
}
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ public void showError(String message) {

@Override
public void showServer(ArrayList<String> model) {
RelativeLayout containerNoServer = findViewById(R.id.containerNoServer);
RecyclerView listServer = findViewById(R.id.recyclerListServer);
if (model.size() == 0) {
RelativeLayout containerNoServer = findViewById(R.id.containerNoServer);
containerNoServer.setVisibility(View.VISIBLE);
listServer.setVisibility(View.GONE);
} else {
RecyclerView listServer = findViewById(R.id.recyclerListServer);
listServer.setVisibility(View.VISIBLE);
containerNoServer.setVisibility(View.GONE);
ListServersAdapter adapter = new ListServersAdapter(model, this);
listServer.setLayoutManager(new LinearLayoutManager(this));
listServer.setAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public JSONObject loadJSONObject(String key) throws JSONException {
public ArrayList<String> loadServerArray() {
ArrayList<String> ids = new ArrayList<>();
SharedPreferences mSharedPreference1 = PreferenceManager.getDefaultSharedPreferences(mContext);
int size = Integer.parseInt(mSharedPreference1.getString("Status_size", ""));
int size = Integer.parseInt(mSharedPreference1.getString("Status_size", "0"));

for (int i = 0; i < size; i++) {
ids.add(mSharedPreference1.getString("Status_" + i, ""));
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/spinner_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:gravity="start"
android:maxLength="25"
android:padding="5dip"
android:textColor="@color/colorAccent"
android:textSize="20sp" />

0 comments on commit 15a93c1

Please sign in to comment.