Search in sources :

Example 1 with UserTimeFormatter

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;
}
Also used : AlertDialog(android.app.AlertDialog) MiscUtils(com.orgzly.android.util.MiscUtils) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) Bundle(android.os.Bundle) OrgRepeater(com.orgzly.org.datetime.OrgRepeater) CompoundButton(android.widget.CompoundButton) LayoutInflater(android.view.LayoutInflater) Set(java.util.Set) Dialog(android.app.Dialog) DialogFragment(android.support.v4.app.DialogFragment) TreeSet(java.util.TreeSet) AlertDialog(android.app.AlertDialog) DateFormat(android.text.format.DateFormat) UserTimeFormatter(com.orgzly.android.util.UserTimeFormatter) SuppressLint(android.annotation.SuppressLint) Calendar(java.util.Calendar) DatePickerDialog(android.app.DatePickerDialog) R(com.orgzly.R) View(android.view.View) Button(android.widget.Button) BuildConfig(com.orgzly.BuildConfig) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) LogUtils(com.orgzly.android.util.LogUtils) UserTimeFormatter(com.orgzly.android.util.UserTimeFormatter) LayoutInflater(android.view.LayoutInflater) SuppressLint(android.annotation.SuppressLint) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) View(android.view.View)

Example 2 with UserTimeFormatter

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());
}
Also used : UserTimeFormatter(com.orgzly.android.util.UserTimeFormatter) Shelf(com.orgzly.android.Shelf)

Example 3 with UserTimeFormatter

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();
}
Also used : UserTimeFormatter(com.orgzly.android.util.UserTimeFormatter) Before(org.junit.Before)

Aggregations

UserTimeFormatter (com.orgzly.android.util.UserTimeFormatter)3 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 Dialog (android.app.Dialog)1 TimePickerDialog (android.app.TimePickerDialog)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 DialogFragment (android.support.v4.app.DialogFragment)1 DateFormat (android.text.format.DateFormat)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 BuildConfig (com.orgzly.BuildConfig)1 R (com.orgzly.R)1 Shelf (com.orgzly.android.Shelf)1 LogUtils (com.orgzly.android.util.LogUtils)1 MiscUtils (com.orgzly.android.util.MiscUtils)1 OrgDateTime (com.orgzly.org.datetime.OrgDateTime)1