gestion des formats de tickets!
This commit is contained in:
@@ -20,8 +20,11 @@ import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.quiz.databinding.FragmentSoldBinding;
|
||||
import com.example.quiz.utils.LoaderDialog;
|
||||
import com.example.quiz.utils.MessageDialog;
|
||||
import com.example.quiz.utils.Result;
|
||||
import com.example.quiz.utils.SharedPrefsHelper;
|
||||
import com.example.quiz.viewModel.LogsViewModel;
|
||||
import com.example.quiz.viewModel.PariViewModel;
|
||||
import com.google.android.material.appbar.MaterialToolbar;
|
||||
|
||||
@@ -39,8 +42,11 @@ public class Sold extends Fragment {
|
||||
|
||||
FragmentSoldBinding binding;
|
||||
|
||||
LoaderDialog dialog;
|
||||
|
||||
PariViewModel pariViewModel;
|
||||
SharedPrefsHelper prefsHelper;
|
||||
LogsViewModel logsViewModel;
|
||||
|
||||
public Sold() {
|
||||
// Required empty public constructor
|
||||
@@ -73,6 +79,8 @@ public class Sold extends Fragment {
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentSoldBinding.inflate(inflater, container, false);
|
||||
dialog = new LoaderDialog(getContext());
|
||||
logsViewModel = new ViewModelProvider(this).get(LogsViewModel.class);
|
||||
return binding.getRoot();
|
||||
|
||||
}
|
||||
@@ -95,27 +103,36 @@ public class Sold extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
String _reformatDateForDate(int num){
|
||||
if(num<10){
|
||||
return "0"+num;
|
||||
}
|
||||
return String.valueOf(num);
|
||||
}
|
||||
void _showCalendar(){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
DatePickerDialog datePickerDialog = new DatePickerDialog(
|
||||
getContext(),
|
||||
(view, year, month, dayOfMonth) -> {
|
||||
String date = year + "-" + (month + 1) + "-" + dayOfMonth;
|
||||
pariViewModel.getSoldeByDay(prefsHelper.get("code"), date).observe(getViewLifecycleOwner(), new Observer<Result<Double>>() {
|
||||
String date = year + "-" + _reformatDateForDate(month + 1) + "-" + _reformatDateForDate(dayOfMonth);
|
||||
pariViewModel.getSoldeByDay(prefsHelper.get("id"), date).observe(getViewLifecycleOwner(), new Observer<Result<Double>>() {
|
||||
@Override
|
||||
public void onChanged(Result<Double> doubleResult) {
|
||||
switch (doubleResult.status){
|
||||
case LOADING:{
|
||||
Toast.makeText(getContext(), "En cours", Toast.LENGTH_SHORT).show();
|
||||
dialog.show("Solde du jour");
|
||||
break;
|
||||
}
|
||||
case ERROR:{
|
||||
Log.d("Response", doubleResult.message);
|
||||
dialog.dismiss();
|
||||
MessageDialog.showError(getContext(), doubleResult.message);
|
||||
break;
|
||||
}
|
||||
case SUCCESS:{
|
||||
dialog.dismiss();
|
||||
_showSold(doubleResult.data);
|
||||
logsViewModel.insertLog(prefsHelper.get("id"), "SOLDE JOUR", "Solde du "+date, System.currentTimeMillis());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user