exchange section populated
This commit is contained in:
parent
3b289c0273
commit
85ca15269c
|
|
@ -644,6 +644,14 @@ public class InstanceInterface {
|
|||
workerDataList.add(workerData);
|
||||
}
|
||||
}
|
||||
// Sort the list by uptime
|
||||
workerDataList.sort(new Comparator<WorkerData>() {
|
||||
@Override
|
||||
public int compare(WorkerData w1, WorkerData w2) {
|
||||
return Double.compare(w1.getUptime(), w2.getUptime());
|
||||
}
|
||||
});
|
||||
|
||||
return workerDataList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,9 @@ import android.view.ViewGroup;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import com.example.dcav2gui.R;
|
||||
import com.example.dcav2gui.databinding.FragmentBinanceBinding;
|
||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||
import com.example.dcav2gui.ui.exchanges.WorkerData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class BinanceFragment extends Fragment {
|
||||
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@ import androidx.lifecycle.AndroidViewModel;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.example.dcav2gui.MainActivity;
|
||||
import com.example.dcav2gui.ui.settings.SettingsData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BinanceViewModel extends AndroidViewModel {
|
||||
|
||||
private MutableLiveData<List<WorkerData>> workerDataList;
|
||||
private final MutableLiveData<List<WorkerData>> workerDataList;
|
||||
SettingsData settingsData = MainActivity.getGlobalSettings();
|
||||
|
||||
public BinanceViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -30,21 +30,14 @@ public class BinanceViewModel extends AndroidViewModel {
|
|||
if (workerDataList.getValue() == null) {
|
||||
fetchWorkerData();
|
||||
}
|
||||
//System.err.println(workerDataList.getValue().get(0).toString());
|
||||
return workerDataList;
|
||||
}
|
||||
|
||||
private void fetchWorkerData() {
|
||||
// Simulate fetching data from a source
|
||||
//List<WorkerData> data = new ArrayList<>();
|
||||
// Add WorkerData objects to the list
|
||||
//workerDataList.setValue(data);
|
||||
|
||||
// Schedule a periodic update
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep((long) settingsData.timeBetweenQueries*1000);
|
||||
// Fetch and update the data
|
||||
List<WorkerData> newData = InstanceInterface.fetchWorkersDataForCards("binance");
|
||||
//System.err.println(newData.toString());
|
||||
|
|
|
|||
|
|
@ -4,34 +4,35 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.dcav2gui.databinding.FragmentGateioBinding;
|
||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||
|
||||
|
||||
public class GateioFragment extends Fragment {
|
||||
|
||||
private FragmentGateioBinding binding;
|
||||
private GateioViewModel GateioViewModel;
|
||||
private WorkerCardAdapter workerCardAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
GateioViewModel GateioViewModel =
|
||||
new ViewModelProvider(this).get(GateioViewModel.class);
|
||||
|
||||
binding = FragmentGateioBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textGateio;
|
||||
GateioViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
GateioViewModel = new ViewModelProvider(this).get(GateioViewModel.class);
|
||||
|
||||
workerCardAdapter = new WorkerCardAdapter(binding.gateioCardsContainer);
|
||||
|
||||
GateioViewModel.getWorkerData().observe(getViewLifecycleOwner(), workerDataList -> {
|
||||
if (workerDataList != null) {
|
||||
workerCardAdapter.updateData(workerDataList);
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,53 @@
|
|||
package com.example.dcav2gui.ui.exchanges;
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class GateioViewModel extends ViewModel {
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
import com.example.dcav2gui.MainActivity;
|
||||
import com.example.dcav2gui.ui.settings.SettingsData;
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public GateioViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is Gate.io fragment");
|
||||
public class GateioViewModel extends AndroidViewModel {
|
||||
|
||||
private final MutableLiveData<List<WorkerData>> workerDataList;
|
||||
SettingsData settingsData = MainActivity.getGlobalSettings();
|
||||
|
||||
public GateioViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
workerDataList = new MutableLiveData<>();
|
||||
fetchWorkerData(); // Initial data fetch
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
public LiveData<List<WorkerData>> getWorkerData() {
|
||||
//Iterate through workerDataList
|
||||
if (workerDataList.getValue() == null) {
|
||||
fetchWorkerData();
|
||||
}
|
||||
return workerDataList;
|
||||
}
|
||||
|
||||
private void fetchWorkerData() {
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep((long) settingsData.timeBetweenQueries*1000);
|
||||
// Fetch and update the data
|
||||
List<WorkerData> newData = InstanceInterface.fetchWorkersDataForCards("gateio");
|
||||
//System.err.println(newData.toString());
|
||||
workerDataList.postValue(newData);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,34 +4,35 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.dcav2gui.databinding.FragmentKucoinBinding;
|
||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||
|
||||
|
||||
public class KucoinFragment extends Fragment {
|
||||
|
||||
private FragmentKucoinBinding binding;
|
||||
private KucoinViewModel KucoinViewModel;
|
||||
private WorkerCardAdapter workerCardAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
KucoinViewModel KucoinViewModel =
|
||||
new ViewModelProvider(this).get(KucoinViewModel.class);
|
||||
|
||||
binding = FragmentKucoinBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textKucoin;
|
||||
KucoinViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
KucoinViewModel = new ViewModelProvider(this).get(KucoinViewModel.class);
|
||||
|
||||
workerCardAdapter = new WorkerCardAdapter(binding.kucoinCardsContainer);
|
||||
|
||||
KucoinViewModel.getWorkerData().observe(getViewLifecycleOwner(), workerDataList -> {
|
||||
if (workerDataList != null) {
|
||||
workerCardAdapter.updateData(workerDataList);
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,53 @@
|
|||
package com.example.dcav2gui.ui.exchanges;
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class KucoinViewModel extends ViewModel {
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
import com.example.dcav2gui.MainActivity;
|
||||
import com.example.dcav2gui.ui.settings.SettingsData;
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public KucoinViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is KuCoin fragment");
|
||||
public class KucoinViewModel extends AndroidViewModel {
|
||||
|
||||
private final MutableLiveData<List<WorkerData>> workerDataList;
|
||||
SettingsData settingsData = MainActivity.getGlobalSettings();
|
||||
|
||||
public KucoinViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
workerDataList = new MutableLiveData<>();
|
||||
fetchWorkerData(); // Initial data fetch
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
public LiveData<List<WorkerData>> getWorkerData() {
|
||||
//Iterate through workerDataList
|
||||
if (workerDataList.getValue() == null) {
|
||||
fetchWorkerData();
|
||||
}
|
||||
return workerDataList;
|
||||
}
|
||||
|
||||
private void fetchWorkerData() {
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep((long) settingsData.timeBetweenQueries*1000);
|
||||
// Fetch and update the data
|
||||
List<WorkerData> newData = InstanceInterface.fetchWorkersDataForCards("kucoin");
|
||||
//System.err.println(newData.toString());
|
||||
workerDataList.postValue(newData);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,34 +4,35 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.dcav2gui.databinding.FragmentOkxBinding;
|
||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||
|
||||
|
||||
public class OkxFragment extends Fragment {
|
||||
|
||||
private FragmentOkxBinding binding;
|
||||
private OkxViewModel OkxViewModel;
|
||||
private WorkerCardAdapter workerCardAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
OkxViewModel OkxViewModel =
|
||||
new ViewModelProvider(this).get(OkxViewModel.class);
|
||||
|
||||
binding = FragmentOkxBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textOkx;
|
||||
OkxViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
OkxViewModel = new ViewModelProvider(this).get(OkxViewModel.class);
|
||||
|
||||
workerCardAdapter = new WorkerCardAdapter(binding.okexCardsContainer);
|
||||
|
||||
OkxViewModel.getWorkerData().observe(getViewLifecycleOwner(), workerDataList -> {
|
||||
if (workerDataList != null) {
|
||||
workerCardAdapter.updateData(workerDataList);
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,53 @@
|
|||
package com.example.dcav2gui.ui.exchanges;
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class OkxViewModel extends ViewModel {
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
import com.example.dcav2gui.MainActivity;
|
||||
import com.example.dcav2gui.ui.settings.SettingsData;
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public OkxViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is OKX fragment");
|
||||
public class OkxViewModel extends AndroidViewModel {
|
||||
|
||||
private final MutableLiveData<List<WorkerData>> workerDataList;
|
||||
SettingsData settingsData = MainActivity.getGlobalSettings();
|
||||
|
||||
public OkxViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
workerDataList = new MutableLiveData<>();
|
||||
fetchWorkerData(); // Initial data fetch
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
public LiveData<List<WorkerData>> getWorkerData() {
|
||||
//Iterate through workerDataList
|
||||
if (workerDataList.getValue() == null) {
|
||||
fetchWorkerData();
|
||||
}
|
||||
return workerDataList;
|
||||
}
|
||||
|
||||
private void fetchWorkerData() {
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep((long) settingsData.timeBetweenQueries*1000);
|
||||
// Fetch and update the data
|
||||
List<WorkerData> newData = InstanceInterface.fetchWorkersDataForCards("okex");
|
||||
//System.err.println(newData.toString());
|
||||
workerDataList.postValue(newData);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/binance_cards_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible"
|
||||
android:scrollbars="vertical">
|
||||
android:visibility="visible">
|
||||
|
||||
<!-- Each card will be added dynamically here -->
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
@ -1,22 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.exchanges.GateioFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_gateio"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/gateio_cards_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<!-- Each card will be added dynamically here -->
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
@ -1,22 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.exchanges.KucoinFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_kucoin"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/kucoin_cards_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<!-- Each card will be added dynamically here -->
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
@ -1,22 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.exchanges.OkxFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_okx"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/okex_cards_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<!-- Each card will be added dynamically here -->
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
Loading…
Reference in New Issue