...
This commit is contained in:
parent
5c2c8dbc68
commit
e9337c5bdf
|
|
@ -4,28 +4,37 @@ 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 androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.example.dcav2gui.databinding.FragmentBinanceBinding;
|
||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BinanceFragment extends Fragment {
|
||||
|
||||
private FragmentBinanceBinding binding;
|
||||
private WorkerCardAdapter adapter;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
BinanceViewModel BinanceViewModel =
|
||||
BinanceViewModel binanceViewModel =
|
||||
new ViewModelProvider(this).get(BinanceViewModel.class);
|
||||
|
||||
binding = FragmentBinanceBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textBinance;
|
||||
BinanceViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
RecyclerView recyclerView = binding.recyclerView;
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapter = new WorkerCardAdapter(new ArrayList<>());
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
binanceViewModel.getWorkerData().observe(getViewLifecycleOwner(), adapter::updateData);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,43 @@
|
|||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BinanceViewModel extends ViewModel {
|
||||
public class BinanceViewModel extends AndroidViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
private MutableLiveData<List<WorkerData>> workerDataList;
|
||||
|
||||
public BinanceViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is Binance fragment");
|
||||
public BinanceViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
workerDataList = new MutableLiveData<>();
|
||||
fetchWorkerData(); // Initial data fetch
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
public LiveData<List<WorkerData>> getWorkerData() {
|
||||
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);
|
||||
// Fetch and update the data
|
||||
fetchWorkerData();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
package com.example.dcav2gui.ui.exchanges.adapters;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.example.dcav2gui.R;
|
||||
import com.example.dcav2gui.ui.exchanges.WorkerData;
|
||||
import java.util.List;
|
||||
|
||||
public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.WorkerViewHolder> {
|
||||
|
||||
private List<WorkerData> workerDataList;
|
||||
|
||||
public WorkerCardAdapter(List<WorkerData> workerDataList) {
|
||||
this.workerDataList = workerDataList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public WorkerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.worker_card, parent, false);
|
||||
return new WorkerViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull WorkerViewHolder holder, int position) {
|
||||
WorkerData worker = workerDataList.get(position);
|
||||
|
||||
//Here goes all the logic to update the view
|
||||
|
||||
// holder.workerName.setText(worker.getName());
|
||||
// holder.workerStatus.setText(worker.getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return workerDataList.size();
|
||||
}
|
||||
|
||||
public void updateData(List<WorkerData> newData) {
|
||||
workerDataList = newData;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static class WorkerViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView pair;
|
||||
TextView safetyOrders;
|
||||
TextView uptime;
|
||||
TextView nextSoPrice;
|
||||
TextView price;
|
||||
TextView takeProfitPrice;
|
||||
TextView percentage;
|
||||
ProgressBar progressBar;
|
||||
TextView workerStatusString;
|
||||
ImageView workerCardIcon;
|
||||
|
||||
public WorkerViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
pair = itemView.findViewById(R.id.workerCardPair);
|
||||
safetyOrders = itemView.findViewById(R.id.workerCardSafetyOrders);
|
||||
uptime = itemView.findViewById(R.id.workerCardUptime);
|
||||
nextSoPrice = itemView.findViewById(R.id.workerCardNextSoPrice);
|
||||
price = itemView.findViewById(R.id.workerCardCurrentPrice);
|
||||
takeProfitPrice = itemView.findViewById(R.id.workerCardTakeProfitPrice);
|
||||
percentage = itemView.findViewById(R.id.workerCardPercentageToDeal);
|
||||
progressBar = itemView.findViewById(R.id.workerCardProgressBar);
|
||||
workerStatusString = itemView.findViewById(R.id.workerCardStatusString);
|
||||
workerCardIcon = itemView.findViewById(R.id.workerCardIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue