use of xyz.zedler.patrick.grocy.view.ActionButton in project grocy-android by patzly.
the class DateBottomSheet method onCreateView.
@SuppressLint("SimpleDateFormat")
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentBottomsheetDateBinding.inflate(inflater, container, false);
activity = (MainActivity) requireActivity();
args = requireArguments();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
;
keyboardInputEnabled = sharedPrefs.getBoolean(BEHAVIOR.DATE_KEYBOARD_INPUT, SETTINGS_DEFAULT.BEHAVIOR.DATE_KEYBOARD_INPUT);
boolean reverseDateFormat = sharedPrefs.getBoolean(BEHAVIOR.DATE_KEYBOARD_REVERSE, SETTINGS_DEFAULT.BEHAVIOR.DATE_KEYBOARD_REVERSE);
calendar = Calendar.getInstance();
dateUtil = new DateUtil(requireContext());
dateFormatGrocy = new SimpleDateFormat("yyyy-MM-dd");
if (reverseDateFormat) {
dateFormatKeyboardInput = new SimpleDateFormat("ddMMyy");
dateFormatKeyboardInputShort = new SimpleDateFormat("ddMM");
binding.textInputDate.setHint("DDMM | DDMMYY");
} else {
dateFormatKeyboardInput = new SimpleDateFormat("yyMMdd");
dateFormatKeyboardInputShort = new SimpleDateFormat("MMdd");
}
String selectedDate = args.getString(Constants.ARGUMENT.SELECTED_DATE);
defaultDueDays = args.getString(Constants.ARGUMENT.DEFAULT_DAYS_FROM_NOW);
binding.frameHelpButton.setOnClickListener(v -> {
if (keyboardInputEnabled) {
binding.helpKeyboard.setVisibility(View.VISIBLE);
} else {
binding.help.setVisibility(View.VISIBLE);
}
});
binding.help.setOnClickListener(v -> navigateToSettingsCatBehavior());
binding.helpKeyboard.setOnClickListener(v -> navigateToSettingsCatBehavior());
if (keyboardInputEnabled) {
binding.linearBodyPicker.setVisibility(View.GONE);
binding.linearBodyKeyboard.setVisibility(View.VISIBLE);
if (selectedDate == null || selectedDate.equals(DATE.NEVER_OVERDUE)) {
binding.editTextDate.setText("");
} else {
try {
Date date = dateFormatGrocy.parse(selectedDate);
if (date != null) {
calendar.setTime(date);
binding.editTextDate.setText(dateFormatKeyboardInput.format(calendar.getTime()));
} else {
binding.editTextDate.setText("");
}
} catch (ParseException e) {
binding.editTextDate.setText("");
}
}
if (savedInstanceState == null) {
new Handler().postDelayed(() -> activity.showKeyboard(binding.editTextDate), 50);
}
updateDateHint();
binding.editTextDate.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
updateDateHint();
}
});
binding.editTextDate.setOnEditorActionListener((TextView v, int actionId, KeyEvent event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE && getTextFieldDate() != null) {
dismiss();
return true;
}
return false;
});
ActionButton moreMonth = reverseDateFormat ? binding.moreMonthReverse : binding.moreMonth;
ActionButton lessMonth = reverseDateFormat ? binding.lessMonthReverse : binding.lessMonth;
binding.linearMonth.setVisibility(reverseDateFormat ? View.GONE : View.VISIBLE);
binding.linearMonthReverse.setVisibility(reverseDateFormat ? View.VISIBLE : View.GONE);
moreMonth.setOnClickListener(view -> {
Date date = getTextFieldDate();
if (date != null) {
String input = binding.editTextDate.getText() != null ? binding.editTextDate.getText().toString().trim() : "";
calendar.setTime(date);
calendar.add(Calendar.MONTH, 1);
if (input.length() == 6) {
binding.editTextDate.setText(dateFormatKeyboardInput.format(calendar.getTime()));
} else if (input.length() == 4) {
binding.editTextDate.setText(dateFormatKeyboardInputShort.format(calendar.getTime()));
}
}
});
binding.moreDay.setOnClickListener(view -> {
Date date = getTextFieldDate();
if (date != null) {
String input = binding.editTextDate.getText() != null ? binding.editTextDate.getText().toString().trim() : "";
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, 1);
if (input.length() == 6) {
binding.editTextDate.setText(dateFormatKeyboardInput.format(calendar.getTime()));
} else if (input.length() == 4) {
binding.editTextDate.setText(dateFormatKeyboardInputShort.format(calendar.getTime()));
}
}
});
lessMonth.setOnClickListener(view -> {
Date date = getTextFieldDate();
if (date != null) {
String input = binding.editTextDate.getText() != null ? binding.editTextDate.getText().toString().trim() : "";
calendar.setTime(date);
calendar.add(Calendar.MONTH, -1);
if (input.length() == 6) {
binding.editTextDate.setText(dateFormatKeyboardInput.format(calendar.getTime()));
} else if (input.length() == 4) {
binding.editTextDate.setText(dateFormatKeyboardInputShort.format(calendar.getTime()));
}
}
});
binding.lessDay.setOnClickListener(view -> {
Date date = getTextFieldDate();
if (date != null) {
String input = binding.editTextDate.getText() != null ? binding.editTextDate.getText().toString().trim() : "";
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, -1);
if (input.length() == 6) {
binding.editTextDate.setText(dateFormatKeyboardInput.format(calendar.getTime()));
} else if (input.length() == 4) {
binding.editTextDate.setText(dateFormatKeyboardInputShort.format(calendar.getTime()));
}
}
});
binding.clear.setOnClickListener(v -> {
binding.editTextDate.setText("");
activity.showKeyboard(binding.editTextDate);
});
} else {
initDatePickerLayout();
fillDatePickerForm(selectedDate);
}
setSkipCollapsedInPortrait();
return binding.getRoot();
}
use of xyz.zedler.patrick.grocy.view.ActionButton in project grocy-android by patzly.
the class ShoppingListsBottomSheet method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_bottomsheet_list_selection, container, false);
activity = (MainActivity) requireActivity();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
boolean multipleListsFeature = sharedPrefs.getBoolean(Constants.PREF.FEATURE_MULTIPLE_SHOPPING_LISTS, true);
MutableLiveData<Integer> selectedIdLive = activity.getCurrentFragment().getSelectedShoppingListIdLive();
if (selectedIdLive == null) {
dismiss();
return view;
}
ShoppingListRepository repository = new ShoppingListRepository(activity.getApplication());
TextView textViewTitle = view.findViewById(R.id.text_list_selection_title);
textViewTitle.setText(activity.getString(R.string.property_shopping_lists));
RecyclerView recyclerView = view.findViewById(R.id.recycler_list_selection);
recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(new ShoppingPlaceholderAdapter());
repository.getShoppingListsLive().observe(getViewLifecycleOwner(), shoppingLists -> {
if (shoppingLists == null) {
return;
}
if (recyclerView.getAdapter() == null || !(recyclerView.getAdapter() instanceof ShoppingListAdapter)) {
recyclerView.setAdapter(new ShoppingListAdapter(shoppingLists, selectedIdLive.getValue(), this, activity.getCurrentFragment() instanceof ShoppingListFragment && activity.isOnline()));
} else {
((ShoppingListAdapter) recyclerView.getAdapter()).updateData(shoppingLists, selectedIdLive.getValue());
}
});
selectedIdLive.observe(getViewLifecycleOwner(), selectedId -> {
if (recyclerView.getAdapter() == null || !(recyclerView.getAdapter() instanceof ShoppingListAdapter)) {
return;
}
((ShoppingListAdapter) recyclerView.getAdapter()).updateSelectedId(selectedIdLive.getValue());
});
ActionButton buttonNew = view.findViewById(R.id.button_list_selection_new);
if (activity.isOnline() && multipleListsFeature && activity.getCurrentFragment() instanceof ShoppingListFragment) {
buttonNew.setVisibility(View.VISIBLE);
buttonNew.setOnClickListener(v -> {
dismiss();
navigate(ShoppingListFragmentDirections.actionShoppingListFragmentToShoppingListEditFragment());
});
}
progressConfirm = view.findViewById(R.id.progress_confirmation);
return view;
}
Aggregations