-
-
Save Ulop/8d389019ef4fa8ddcac0d147e2a20ba5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OnlineAdapter extends RecyclerView.Adapter<OnlineAdapter.RowsViewHolder> { | |
private List<List<PriceOffer>> currentList = new ArrayList<>(); | |
Context context; | |
String data; | |
int count = 0; | |
public static class RowsViewHolder extends RecyclerView.ViewHolder{ | |
LinearLayout linearLayout; | |
HorizontalBarChart barChart; | |
public RowsViewHolder(View itemView) { | |
super(itemView); | |
linearLayout = (LinearLayout) itemView.findViewById(R.id.onlineauctionadapter_layout); | |
barChart = (HorizontalBarChart) itemView.findViewById(R.id.chart); | |
} | |
} | |
public OnlineAdapter( Context context) { | |
this.context = context; | |
} | |
public void setData(List<PriceOffer> data) { | |
currentList.add(data); | |
Log.d("SET DATA ", String.valueOf(currentList.size())); | |
notifyDataSetChanged(); | |
} | |
@Override | |
public OnlineAdapter.RowsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.onlineauction_adapter, parent, false); | |
return new RowsViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(RowsViewHolder holder, int position) { | |
List<BarEntry> entries = new ArrayList<>(); | |
public static ArrayList<String> list = new ArrayList<>(); | |
for (int i = 0; i < entries.size(); i++) { | |
BarEntry barEntry = new BarEntry(currentList.get(position).getLotPriceOffer(), i); | |
entries.add(barEntry); | |
list.add(currentList.get(i).getFirmName()); | |
} | |
BarDataSet dataSet = new BarDataSet(entries, data); | |
BarData barData = new BarData(list, dataSet); | |
dataSet.setColors(new int[]{Color.argb(42, 92, 92, 98)}); | |
barData.setValueTextSize(10f); | |
holder.barChart.setData(barData); | |
holder.barChart.animateY(5000); | |
holder.barChart.setDrawBarShadow(false); | |
holder.barChart.setDrawValueAboveBar(false); | |
holder.barChart.setDrawGridBackground(false); | |
holder.barChart.setDescription(""); | |
holder.barChart.setNoDataText(""); | |
holder.barChart.setNoDataTextDescription(""); | |
holder.barChart.getAxisLeft().setDrawLabels(false); | |
// barChart.getLegend().setEnabled(false); | |
holder.barChart.getAxisRight().setDrawLabels(false); | |
holder.barChart.setDescriptionTextSize(12); | |
} | |
@Override | |
public int getItemCount() { | |
return currentList.size(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OnlineFragment extends Fragment { | |
RecyclerView recyclerView; | |
HorizontalBarChart barChart; | |
OnlineAdapter onlineAdapter; | |
Spinner spinner; | |
ProgressBar progressBar; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.online_auction2, container, false); | |
} | |
@Override | |
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_onlineauction2); | |
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); | |
barChart = (HorizontalBarChart) view.findViewById(R.id.chart); | |
barChart.setDrawBarShadow(false); | |
barChart.setDrawValueAboveBar(false); | |
barChart.setDrawGridBackground(false); | |
barChart.setDescription(""); | |
barChart.setNoDataText(""); | |
barChart.setNoDataTextDescription(""); | |
barChart.getAxisLeft().setDrawLabels(false); | |
// barChart.getLegend().setEnabled(false); | |
barChart.getAxisRight().setDrawLabels(false); | |
barChart.setDescriptionTextSize(12); | |
recyclerView.removeView(view); | |
((MainActivity) getActivity()).setTitle("Альта и К"); | |
spinner = (Spinner) getActivity().findViewById(R.id.spinner); | |
spinner.setVisibility(View.GONE); | |
progressBar = (ProgressBar) getActivity().findViewById(R.id.mainprogressBar); | |
progressBar.setVisibility(View.INVISIBLE); | |
Bundle mBundle = this.getArguments(); | |
ArrayList<String> data = new ArrayList<>(); | |
if (mBundle != null) { | |
data = mBundle.getStringArrayList("data"); | |
} | |
for (int i = 0; i < data.size(); i++) { | |
String message = data.get(0); | |
requestToServer(message); | |
} | |
onlineAdapter = new OnlineAdapter(getContext()); | |
recyclerView.setAdapter(onlineAdapter); | |
} | |
private void requestToServer(final String data) { | |
TestInterface testInterface = ApiClientTest.getClient().create(TestInterface.class); | |
Call<MessageOfArrayOfPriceOffermW4_P7aJm> call = testInterface.getMessage(data); | |
call.enqueue(new Callback<MessageOfArrayOfPriceOffermW4_P7aJm>() { | |
@Override | |
public void onResponse(Call<MessageOfArrayOfPriceOffermW4_P7aJm> call, Response<MessageOfArrayOfPriceOffermW4_P7aJm> response) { | |
List<PriceOffer> arrayList = response.body().dataTest.getPriceOfferList(); | |
onlineAdapter.setData(arrayList); | |
} | |
@Override | |
public void onFailure(Call<MessageOfArrayOfPriceOffermW4_P7aJm> call, Throwable t) { | |
Log.d("TAG", "FAIL: "); | |
t.printStackTrace(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment