use of com.orgzly.android.util.UserTimeFormatter in project orgzly-android by orgzly.
the class TimestampDialogFragment method onCreateDialog.
/**
* Create a new instance of a dialog.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, savedInstanceState);
mUserTimeFormatter = new UserTimeFormatter(getActivity());
/* This makes sure that the fragment has implemented
* the callback interface. If not, it throws an exception
*/
if (!(getTargetFragment() instanceof OnDateTimeSetListener)) {
throw new IllegalStateException("Fragment " + getTargetFragment() + " must implement " + OnDateTimeSetListener.class);
}
mActivityListener = (OnDateTimeSetListener) getTargetFragment();
mContext = getActivity();
mId = getArguments().getInt(ARG_DIALOG_ID);
mNoteIds = new TreeSet<>();
for (long e : getArguments().getLongArray(ARG_NOTE_IDS)) {
mNoteIds.add(e);
}
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.dialog_timestamp, null, false);
mDatePicker = (Button) view.findViewById(R.id.dialog_timestamp_date_picker);
mTimePicker = (Button) view.findViewById(R.id.dialog_timestamp_time_picker);
mIsTimeUsed = (CompoundButton) view.findViewById(R.id.dialog_timestamp_time_check);
mRepeaterPicker = (Button) view.findViewById(R.id.dialog_timestamp_repeater_picker);
mIsRepeaterUsed = (CompoundButton) view.findViewById(R.id.dialog_timestamp_repeater_check);
/* Set before toggle buttons are setup, as they trigger dialog title update .*/
setValues(OrgDateTime.parseOrNull(getArguments().getString(ARG_TIME)));
mDialog = new AlertDialog.Builder(mContext).setTitle(getArguments().getInt(ARG_TITLE)).setView(view).setPositiveButton(R.string.set, (dialog, which) -> {
if (mActivityListener != null) {
OrgDateTime time = getCurrentOrgTime();
mActivityListener.onDateTimeSet(mId, mNoteIds, time);
}
}).setNeutralButton(R.string.clear, (dialog, which) -> {
if (mActivityListener != null) {
mActivityListener.onDateTimeCleared(mId, mNoteIds);
}
}).setNegativeButton(R.string.cancel, (dialog, which) -> {
if (mActivityListener != null) {
mActivityListener.onDateTimeAborted(mId, mNoteIds);
}
}).create();
mDatePicker.setOnClickListener(this);
mTimePicker.setOnClickListener(this);
mRepeaterPicker.setOnClickListener(this);
/*
* These callbacks are called not only on user press, but during initialization as well.
* It's important that they are *after* dialog has been created.
*/
mIsTimeUsed.setOnCheckedChangeListener(this);
mIsRepeaterUsed.setOnCheckedChangeListener(this);
view.findViewById(R.id.dialog_timestamp_today_shortcut).setOnClickListener(this);
view.findViewById(R.id.dialog_timestamp_tomorrow_shortcut).setOnClickListener(this);
view.findViewById(R.id.dialog_timestamp_next_week_shortcut).setOnClickListener(this);
view.findViewById(R.id.dialog_timestamp_time_icon).setOnClickListener(this);
view.findViewById(R.id.dialog_timestamp_repeater_icon).setOnClickListener(this);
restoreState(savedInstanceState);
setViewsFromCurrentValues();
return mDialog;
}
use of com.orgzly.android.util.UserTimeFormatter in project orgzly-android by orgzly.
the class NoteFragment method onAttach.
@Override
public void onAttach(Context context) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, getActivity());
super.onAttach(context);
/* This makes sure that the container activity has implemented
* the callback interface. If not, it throws an exception
*/
try {
mListener = (NoteFragmentListener) getActivity();
} catch (ClassCastException e) {
throw new ClassCastException(getActivity().toString() + " must implement " + NoteFragmentListener.class);
}
mShelf = new Shelf(getActivity().getApplicationContext());
parseArguments();
mUserTimeFormatter = new UserTimeFormatter(getActivity().getApplicationContext());
}
use of com.orgzly.android.util.UserTimeFormatter in project orgzly-android by orgzly.
the class OrgzlyTest method setUp.
@Before
public void setUp() throws Exception {
context = InstrumentationRegistry.getTargetContext();
shelf = new Shelf(context);
shelfTestUtils = new ShelfTestUtils(context, shelf);
userTimeFormatter = new UserTimeFormatter(context);
// new LocalFileStorage(context).cleanup();
/* Request content provider to close the current database
* and open a new one with a different name.
*/
DbClient.toTest(context);
/* Recreate all tables. */
DbClient.recreateTables(context);
setupPreferences();
}
Aggregations