Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 0caa9f7d authored by Niedermann IT-Dienstleistungen's avatar Niedermann IT-Dienstleistungen Committed by GitHub
Browse files

Merge branch 'master' into weblogin

parents b1260aca f95c18e4
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -390,13 +390,14 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
             */
            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.RIGHT) {
                switch(direction) {
                    case ItemTouchHelper.LEFT: {
                        final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
                        db.deleteNoteAndSync((dbNote).getId());
                        adapter.remove(dbNote);
                        refreshLists();
                        Log.v("Note", "Item deleted through swipe ----------------------------------------------");
                    Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, 7 * 1000)
                        Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG)
                                .setAction(R.string.action_undo, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
@@ -407,14 +408,22 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                                    }
                                })
                                .show();
                        break;
                    }
                    case ItemTouchHelper.RIGHT: {
                        final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
                        db.toggleFavorite(dbNote, null);
                        refreshLists();
                        break;
                    }
                }
            }

            @Override
            public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
                ItemAdapter.NoteViewHolder noteViewHolder = (ItemAdapter.NoteViewHolder) viewHolder;
                // show delete icon on the right side
                noteViewHolder.showSwipeDelete(dX > 0);
                // show swipe icon on the side
                noteViewHolder.showSwipe(dX>0);
                // move only swipeable part of item (not leave-behind)
                getDefaultUIUtil().onDraw(c, recyclerView, noteViewHolder.noteSwipeable, dX, dY, actionState, isCurrentlyActive);
            }
+2 −1
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class CloudNote implements Serializable {

    @Override
    public String toString() {
        return "R" + getRemoteId() + " " + (isFavorite() ? " (*) " : "     ") + getCategory() + " / " + getTitle() + " (" + getModified(NoteSQLiteOpenHelper.DATE_FORMAT) + " / " + getEtag() + ")";
        final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        return "R" + getRemoteId() + " " + (isFavorite() ? " (*) " : "     ") + getCategory() + " / " + getTitle() + " (" + getModified(DATE_FORMAT) + " / " + getEtag() + ")";
    }
}
 No newline at end of file
+18 −12
Original line number Diff line number Diff line
@@ -172,11 +172,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
        @BindView(R.id.noteSwipeable)
        public View noteSwipeable;
        @BindView(R.id.noteDeleteLeft)
        ImageView noteDeleteLeft;
        @BindView(R.id.noteDeleteRight)
        ImageView noteDeleteRight;
        @BindView(R.id.noteTitle)
        View noteSwipeFrame;
        ImageView noteFavoriteLeft, noteDeleteRight;
        TextView noteTitle;
        @BindView(R.id.noteCategory)
        TextView noteCategory;
@@ -187,11 +184,19 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        @BindView(R.id.noteFavorite)
        ImageView noteFavorite;

        private NoteViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            view.setOnClickListener(this);
            view.setOnLongClickListener(this);
        private NoteViewHolder(View v) {
            super(v);
            this.noteSwipeFrame = v.findViewById(R.id.noteSwipeFrame);
            this.noteSwipeable = v.findViewById(R.id.noteSwipeable);
            this.noteFavoriteLeft = v.findViewById(R.id.noteFavoriteLeft);
            this.noteDeleteRight = v.findViewById(R.id.noteDeleteRight);
            this.noteTitle = v.findViewById(R.id.noteTitle);
            this.noteCategory = v.findViewById(R.id.noteCategory);
            this.noteExcerpt = v.findViewById(R.id.noteExcerpt);
            this.noteStatus = v.findViewById(R.id.noteStatus);
            this.noteFavorite = v.findViewById(R.id.noteFavorite);
            v.setOnClickListener(this);
            v.setOnLongClickListener(this);
        }

        @Override
@@ -204,9 +209,10 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
            return noteClickListener.onNoteLongClick(getAdapterPosition(), v);
        }

        public void showSwipeDelete(boolean left) {
            noteDeleteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
        public void showSwipe(boolean left) {
            noteFavoriteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
            noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE);
            noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention);
        }
    }

+21 −19
Original line number Diff line number Diff line
@@ -12,13 +12,10 @@ import android.support.annotation.WorkerThread;
import android.text.TextUtils;
import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import it.niedermann.owncloud.notes.android.appwidget.NoteListWidget;
@@ -35,9 +32,7 @@ import it.niedermann.owncloud.notes.util.NoteUtil;
 */
public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {

    public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    private static final int database_version = 7;
    private static final int database_version = 8;
    private static final String database_name = "OWNCLOUD_NOTES";
    private static final String table_notes = "NOTES";
    private static final String key_id = "ID";
@@ -82,12 +77,16 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + table_notes + " ( " +
        createTable(db, table_notes);
    }

    private void createTable(SQLiteDatabase db, String tableName) {
        db.execSQL("CREATE TABLE " + tableName + " ( " +
                key_id + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                key_remote_id + " INTEGER, " +
                key_status + " VARCHAR(50), " +
                key_title + " TEXT, " +
                key_modified + " TEXT, " +
                key_modified + " INTEGER DEFAULT 0, " +
                key_content + " TEXT, " +
                key_favorite + " INTEGER DEFAULT 0, " +
                key_category + " TEXT NOT NULL DEFAULT '', " +
@@ -95,6 +94,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
        createIndexes(db);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion < 3) {
@@ -117,6 +117,14 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
            db.execSQL("ALTER TABLE " + table_notes + " ADD COLUMN " + key_etag + " TEXT");
            createIndexes(db);
        }
        if (oldVersion < 8) {
            final String table_temp = "NOTES_TEMP";
            createTable(db, table_temp);
            db.execSQL(String.format("INSERT INTO %s(%s,%s,%s,%s,%s,%s,%s,%s,%s) ", table_temp, key_id, key_remote_id, key_status, key_title, key_modified, key_content, key_favorite, key_category, key_etag)
                    + String.format("SELECT %s,%s,%s,%s,strftime('%%s',%s),%s,%s,%s,%s FROM %s", key_id, key_remote_id, key_status, key_title, key_modified, key_content, key_favorite, key_category, key_etag, table_notes));
            db.execSQL(String.format("DROP TABLE %s", table_notes));
            db.execSQL(String.format("ALTER TABLE %s RENAME TO %s", table_temp, table_notes));
        }
    }

    @Override
@@ -206,7 +214,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
            values.put(key_remote_id, note.getRemoteId());
        }
        values.put(key_title, note.getTitle());
        values.put(key_modified, note.getModified(NoteSQLiteOpenHelper.DATE_FORMAT));
        values.put(key_modified, note.getModified().getTimeInMillis() / 1000);
        values.put(key_content, note.getContent());
        values.put(key_favorite, note.isFavorite());
        values.put(key_category, note.getCategory());
@@ -258,13 +266,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
    @NonNull
    private DBNote getNoteFromCursor(@NonNull Cursor cursor) {
        Calendar modified = Calendar.getInstance();
        try {
            String modifiedStr = cursor.getString(4);
            if (modifiedStr != null)
                modified.setTime(new SimpleDateFormat(DATE_FORMAT, Locale.GERMANY).parse(modifiedStr));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        modified.setTimeInMillis(cursor.getLong(4) * 1000);
        return new DBNote(cursor.getLong(0), cursor.getLong(1), modified, cursor.getString(3), cursor.getString(5), cursor.getInt(6) > 0, cursor.getString(7), cursor.getString(8), DBStatus.parse(cursor.getString(2)));
    }

@@ -440,7 +442,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
        values.put(key_status, newNote.getStatus().getTitle());
        values.put(key_title, newNote.getTitle());
        values.put(key_category, newNote.getCategory());
        values.put(key_modified, newNote.getModified(DATE_FORMAT));
        values.put(key_modified, newNote.getModified().getTimeInMillis() / 1000);
        values.put(key_content, newNote.getContent());
        int rows = db.update(table_notes, values, key_id + " = ? AND (" + key_content + " != ? OR " + key_category + " != ?)", new String[]{String.valueOf(newNote.getId()), newNote.getContent(), newNote.getCategory()});
        // if data was changed, set new status and schedule sync (with callback); otherwise invoke callback directly.
@@ -482,7 +484,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
        values.clear();
        values.put(key_status, DBStatus.VOID.getTitle());
        values.put(key_title, remoteNote.getTitle());
        values.put(key_modified, remoteNote.getModified(DATE_FORMAT));
        values.put(key_modified, remoteNote.getModified().getTimeInMillis() / 1000);
        values.put(key_content, remoteNote.getContent());
        values.put(key_favorite, remoteNote.isFavorite());
        values.put(key_category, remoteNote.getCategory());
@@ -500,7 +502,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
            // used by: NoteServerSyncHelper.SyncTask.pullRemoteChanges()
            // update only, if not modified locally (i.e. STATUS="") and if modified remotely (i.e. any (!) column has changed)
            whereClause = key_id + " = ? AND " + key_status + " = ? AND (" + key_modified + "!=? OR " + key_title + "!=? OR " + key_favorite + "!=? OR " + key_category + "!=? OR " + (remoteNote.getEtag() != null ? key_etag + " IS NULL OR " : "") + key_etag + "!=? OR " + key_content + "!=?)";
            whereArgs = new String[]{String.valueOf(id), DBStatus.VOID.getTitle(), remoteNote.getModified(DATE_FORMAT), remoteNote.getTitle(), remoteNote.isFavorite() ? "1" : "0", remoteNote.getCategory(), remoteNote.getEtag(), remoteNote.getContent()};
            whereArgs = new String[]{String.valueOf(id), DBStatus.VOID.getTitle(), Long.toString(remoteNote.getModified().getTimeInMillis() / 1000), remoteNote.getTitle(), remoteNote.isFavorite() ? "1" : "0", remoteNote.getCategory(), remoteNote.getEtag(), remoteNote.getContent()};
        }
        int i = db.update(table_notes, values, whereClause, whereArgs);
        Log.d(getClass().getSimpleName(), "updateNote: " + remoteNote + " || forceUnchangedDBNoteState: " + forceUnchangedDBNoteState + "  => " + i + " rows updated");
+8 −7
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/noteSwipeFrame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/bg_attention">

    <ImageView
        android:id="@+id/noteDeleteLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/noteFavoriteLeft"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="@dimen/button_padding"
        android:layout_marginStart="@dimen/button_padding"
        android:contentDescription="@string/menu_delete"
        android:src="@drawable/ic_delete_white_32dp" />
        android:src="@drawable/ic_star_white_24dp" />

    <ImageView
        android:id="@+id/noteDeleteRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|center_vertical"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="right|end|center_vertical"
        android:layout_marginEnd="@dimen/button_padding"
        android:layout_marginRight="@dimen/button_padding"
        android:contentDescription="@string/menu_delete"
Loading