Search in sources :

Example 6 with OrgDateTime

use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.

the class DatabaseMigration method addAndSetCreatedAt.

private static void addAndSetCreatedAt(SQLiteDatabase db, Context context) {
    db.execSQL("ALTER TABLE notes ADD COLUMN created_at INTEGER DEFAULT 0");
    if (!AppPreferences.createdAt(context)) {
        return;
    }
    String createdAtPropName = AppPreferences.createdAtProperty(context);
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables("note_properties" + " JOIN notes ON (notes._id = note_properties.note_id)" + " JOIN properties ON (properties._id = note_properties.property_id)" + " JOIN property_names ON (property_names._id = properties.name_id)" + " JOIN property_values ON (property_values._id = properties.value_id)");
    queryBuilder.setDistinct(true);
    try (Cursor cursor = queryBuilder.query(db, new String[] { "notes._id AS note_id", "property_values.value AS value" }, "note_id IS NOT NULL AND name IS NOT NULL AND value IS NOT NULL AND name = ?", new String[] { createdAtPropName }, null, null, null)) {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            long noteId = cursor.getLong(0);
            String propValue = cursor.getString(1);
            OrgDateTime dateTime = OrgDateTime.parseOrNull(propValue);
            if (dateTime != null) {
                long millis = dateTime.getCalendar().getTimeInMillis();
                ContentValues values = new ContentValues();
                values.put("created_at", millis);
                db.update("notes", values, "_id = " + noteId, null);
            }
        }
    }
}
Also used : ContentValues(android.content.ContentValues) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 7 with OrgDateTime

use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.

the class DatabaseMigration method migrateOrgTimestamps.

private static void migrateOrgTimestamps(SQLiteDatabase db) {
    db.execSQL("ALTER TABLE org_timestamps RENAME TO org_timestamps_prev");
    for (String sql : DbOrgTimestamp.CREATE_SQL) db.execSQL(sql);
    Cursor cursor = db.query("org_timestamps_prev", new String[] { "_id", "string" }, null, null, null, null, null);
    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            long id = cursor.getLong(0);
            String string = cursor.getString(1);
            OrgDateTime orgDateTime = OrgDateTime.parse(string);
            ContentValues values = new ContentValues();
            values.put("_id", id);
            DbOrgTimestamp.toContentValues(values, orgDateTime);
            db.insert("org_timestamps", null, values);
        }
    } finally {
        cursor.close();
    }
    db.execSQL("DROP TABLE org_timestamps_prev");
}
Also used : ContentValues(android.content.ContentValues) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) Cursor(android.database.Cursor)

Example 8 with OrgDateTime

use of com.orgzly.org.datetime.OrgDateTime 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 9 with OrgDateTime

use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.

the class TimestampDialogFragment method getCurrentOrgTime.

private OrgDateTime getCurrentOrgTime() {
    OrgDateTime.Builder builder = new OrgDateTime.Builder().setIsActive(true).setYear(mCurrentYear).setMonth(mCurrentMonth).setHasTime(mIsTimeUsed.isChecked()).setDay(mCurrentDay).setHour(mCurrentHour).setMinute(mCurrentMinute);
    if (mIsRepeaterUsed.isChecked()) {
        OrgRepeater repeater = OrgRepeater.parse(mRepeaterPicker.getText().toString());
        builder.setHasRepeater(true);
        builder.setRepeater(repeater);
    }
    return builder.build();
}
Also used : OrgDateTime(com.orgzly.org.datetime.OrgDateTime) OrgRepeater(com.orgzly.org.datetime.OrgRepeater)

Example 10 with OrgDateTime

use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.

the class TimestampDialogFragment method setViewsFromCurrentValues.

private void setViewsFromCurrentValues() {
    /*
         * Check if dialog has been created.
         * Toggle buttons get fired on initialization, calling this method.
         * Should not happen before with the current ordering of setup methods, but just in case.
         */
    if (mDialog != null) {
        OrgDateTime time = getCurrentOrgTime();
        mDatePicker.setText(mUserTimeFormatter.formatDate(time));
        mTimePicker.setText(mUserTimeFormatter.formatTime(time));
        if (time.hasRepeater()) {
            mRepeaterPicker.setText(mUserTimeFormatter.formatRepeater(time));
        }
        // mEndTimePicker.setText(mOrgTimeFormatter.formatEndTime(time));
        mDialog.setTitle(mUserTimeFormatter.formatAll(time));
    }
}
Also used : OrgDateTime(com.orgzly.org.datetime.OrgDateTime)

Aggregations

OrgDateTime (com.orgzly.org.datetime.OrgDateTime)16 ArrayList (java.util.ArrayList)4 Cursor (android.database.Cursor)3 Calendar (java.util.Calendar)3 DateTime (org.joda.time.DateTime)3 ContentValues (android.content.ContentValues)2 DbNote (com.orgzly.android.provider.models.DbNote)2 OrgRepeater (com.orgzly.org.datetime.OrgRepeater)2 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 ContentProviderOperation (android.content.ContentProviderOperation)1 Context (android.content.Context)1 OperationApplicationException (android.content.OperationApplicationException)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 Bundle (android.os.Bundle)1 RemoteException (android.os.RemoteException)1 DialogFragment (android.support.v4.app.DialogFragment)1