addTrader
This commit is contained in:
parent
100cfe46aa
commit
329e763a26
|
|
@ -1,11 +1,17 @@
|
|||
package com.example.dcav2gui;
|
||||
|
||||
import static android.app.PendingIntent.getActivity;
|
||||
import static com.example.dcav2gui.MainActivity.globalSettings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.InputType;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -23,6 +29,7 @@ import okhttp3.Request;
|
|||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
||||
public class WorkerInterface {
|
||||
private static final String API_BASE_URL = globalSettings.apiUrl;
|
||||
private static final String API_KEY = globalSettings.apiKey;
|
||||
|
|
@ -760,7 +767,40 @@ public class WorkerInterface {
|
|||
}).start();
|
||||
}
|
||||
|
||||
public static void sendAddTraderCall(String exchange, Context context) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle("Enter pair to add to "+ exchange);
|
||||
|
||||
final EditText input = new EditText(context);
|
||||
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
input.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
builder.setView(input);
|
||||
|
||||
builder.setPositiveButton("Add", (dialog, which) -> {
|
||||
final String pair = input.getText().toString();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
JsonObject response = WorkerInterface.addTrader(exchange, pair, true);
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
showToggleDialog(response, context);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// Show an error dialog on the main thread
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
AlertDialog.Builder errorBuilder = new AlertDialog.Builder(context);
|
||||
errorBuilder.setTitle("Error");
|
||||
errorBuilder.setMessage("Failed to add trader: " + e.getMessage());
|
||||
errorBuilder.setPositiveButton("OK", null);
|
||||
errorBuilder.show();
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
|
||||
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
||||
public static void fetchWorkerStats(String exchange, String pair, Context context) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import kotlinx.coroutines.scheduling.CoroutineScheduler;
|
||||
|
||||
|
||||
public class BinanceFragment extends Fragment implements WorkerCardAdapter.OnCardLongClickListener {
|
||||
|
||||
|
|
@ -78,7 +76,7 @@ public class BinanceFragment extends Fragment implements WorkerCardAdapter.OnCar
|
|||
WorkerInterface.fetchWorkerStats("binance",pair, getContext());
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.addTrader) {
|
||||
System.err.println(pair + " Add trader option clicked");
|
||||
WorkerInterface.sendAddTraderCall("binance",getContext());
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.removeTrader) {
|
||||
System.err.println(pair + " Remove trader option clicked");
|
||||
|
|
|
|||
Loading…
Reference in New Issue