From 7a49e97b79621a8c641e8fe9b7b0fb1c2146eb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Fri, 20 Dec 2019 22:32:14 +0100 Subject: [PATCH 01/25] added database implementation for tasks --- .../Database/DatabaseHandler.java | 120 ++++++++++++++++++ .../rcloneexplorer/Database/DatabaseInfo.java | 14 ++ .../ca/pkay/rcloneexplorer/Database/Task.java | 84 ++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseHandler.java create mode 100644 app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseInfo.java create mode 100644 app/src/main/java/ca/pkay/rcloneexplorer/Database/Task.java diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseHandler.java b/app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseHandler.java new file mode 100644 index 00000000..e9560a64 --- /dev/null +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseHandler.java @@ -0,0 +1,120 @@ +package ca.pkay.rcloneexplorer.Database; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +public class DatabaseHandler extends SQLiteOpenHelper { + + + // If you change the database schema, you must increment the database version. + public static final int DATABASE_VERSION = 1; + public static final String DATABASE_NAME = "rcloneExplorer.db"; + + public DatabaseHandler(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + @Override + public void onCreate(SQLiteDatabase sqLiteDatabase) { + sqLiteDatabase.execSQL(DatabaseInfo.SQL_CREATE_TABLES); + } + + @Override + public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) { + + } + + public List getAllTasks(){ + SQLiteDatabase db = getReadableDatabase(); + + String[] projection = { + Task.COLUMN_NAME_ID, + Task.COLUMN_NAME_TITLE, + Task.COLUMN_NAME_REMOTE_ID, + Task.COLUMN_NAME_REMOTE_TYPE, + Task.COLUMN_NAME_REMOTE_PATH, + Task.COLUMN_NAME_LOCAL_PATH, + Task.COLUMN_NAME_SYNC_DIRECTION + }; + + String selection = ""; + String[] selectionArgs = {}; + + String sortOrder = Task.COLUMN_NAME_ID + " ASC"; + + Cursor cursor = db.query( + Task.TABLE_NAME, // The table to query + projection, // The array of columns to return (pass null to get all) + selection, // The columns for the WHERE clause + selectionArgs, // The values for the WHERE clause + null, // don't group the rows + null, // don't filter by row groups + sortOrder // The sort order + ); + List results = new ArrayList<>(); + while(cursor.moveToNext()) { + + Task task = new Task(cursor.getLong(0)); + task.setTitle(cursor.getString(1)); + task.setRemote_id(cursor.getString(2)); + task.setRemote_type(cursor.getInt(3)); + task.setRemote_path(cursor.getString(4)); + task.setLocal_path(cursor.getString(5)); + task.setDirection(cursor.getInt(6)); + + results.add(task); + Log.e("app!", "List: "+task.toString()); + } + cursor.close(); + + return results; + + } + + public Task createEntry(Task taskToStore){ + SQLiteDatabase db = getWritableDatabase(); + + // Create a new map of values, where column names are the keys + ContentValues values = new ContentValues(); + values.put(Task.COLUMN_NAME_TITLE, taskToStore.getTitle()); + values.put(Task.COLUMN_NAME_LOCAL_PATH, taskToStore.getLocal_path()); + values.put(Task.COLUMN_NAME_REMOTE_ID, taskToStore.getRemote_id()); + values.put(Task.COLUMN_NAME_REMOTE_PATH, taskToStore.getRemote_path()); + values.put(Task.COLUMN_NAME_REMOTE_TYPE, taskToStore.getRemote_type()); + values.put(Task.COLUMN_NAME_SYNC_DIRECTION, taskToStore.getDirection()); + + + Log.e("app!", "Pre Store: "+taskToStore.toString()); + + // Insert the new row, returning the primary key value of the new row + long newRowId = db.insert(Task.TABLE_NAME, null, values); + + Task newObject = new Task(newRowId); + newObject.setTitle(taskToStore.getTitle()); + newObject.setLocal_path(taskToStore.getLocal_path()); + newObject.setRemote_id(taskToStore.getRemote_id()); + newObject.setRemote_path(taskToStore.getRemote_path()); + newObject.setRemote_type(taskToStore.getRemote_type()); + newObject.setDirection(taskToStore.getDirection()); + + Log.e("app!", "Post Store: "+newObject.toString()); + + return newObject; + + } + + public int deleteEntry(long id){ + SQLiteDatabase db = getWritableDatabase(); + String selection = Task.COLUMN_NAME_ID + " LIKE ?"; + String[] selectionArgs = {String.valueOf(id)}; + return db.delete(Task.TABLE_NAME, selection, selectionArgs); + + } + +} diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseInfo.java b/app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseInfo.java new file mode 100644 index 00000000..e6154de5 --- /dev/null +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Database/DatabaseInfo.java @@ -0,0 +1,14 @@ +package ca.pkay.rcloneexplorer.Database; + +class DatabaseInfo { + + + public static final String SQL_CREATE_TABLES = "CREATE TABLE " + Task.TABLE_NAME + " (" + + Task.COLUMN_NAME_ID + " INTEGER PRIMARY KEY," + + Task.COLUMN_NAME_TITLE + " TEXT," + + Task.COLUMN_NAME_REMOTE_ID + " TEXT," + + Task.COLUMN_NAME_REMOTE_TYPE + " INTEGER," + + Task.COLUMN_NAME_REMOTE_PATH+ " TEXT," + + Task.COLUMN_NAME_LOCAL_PATH + " TEXT," + + Task.COLUMN_NAME_SYNC_DIRECTION + " INTEGER)"; +} diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Database/Task.java b/app/src/main/java/ca/pkay/rcloneexplorer/Database/Task.java new file mode 100644 index 00000000..bfd6ffb8 --- /dev/null +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Database/Task.java @@ -0,0 +1,84 @@ +package ca.pkay.rcloneexplorer.Database; + +public class Task { + + public static String TABLE_NAME = "task_table"; + + public static String COLUMN_NAME_ID= "task_id"; + public static String COLUMN_NAME_TITLE = "task_title"; + public static String COLUMN_NAME_REMOTE_ID = "task_remote_id"; + public static String COLUMN_NAME_REMOTE_TYPE = "task_remote_type"; + public static String COLUMN_NAME_REMOTE_PATH = "task_remote_path"; + public static String COLUMN_NAME_LOCAL_PATH = "task_local_path"; + public static String COLUMN_NAME_SYNC_DIRECTION = "task_direction"; + + private Long id; + + private String title=""; + private String remote_id=""; + private int remote_type=0; + private String remote_path=""; + private String local_path = ""; + private int direction=0; + + + public Task(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getRemote_id() { + return remote_id; + } + + public void setRemote_id(String remote_id) { + this.remote_id = remote_id; + } + + public int getRemote_type() { + return remote_type; + } + + public void setRemote_type(int remote_type) { + this.remote_type = remote_type; + } + + public String getRemote_path() { + return remote_path; + } + + public void setRemote_path(String remote_path) { + this.remote_path = remote_path; + } + + public String getLocal_path() { + return local_path; + } + + public void setLocal_path(String local_path) { + this.local_path = local_path; + } + + public int getDirection() { + return direction; + } + + public void setDirection(int direction) { + this.direction = direction; + } + + public String toString(){ + return title + ": " + remote_id + ": " + remote_type + ": " + remote_path + ": " + local_path + ": " + direction; + } +} From b7d1edb53aaf7d4c072ef2aa3eae167bb5118377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Fri, 20 Dec 2019 22:34:40 +0100 Subject: [PATCH 02/25] added taskdialog --- .../rcloneexplorer/Dialogs/TaskDialog.java | 194 ++++++++++++++++++ app/src/main/res/layout/task_dialog.xml | 140 +++++++++++++ app/src/main/res/values/strings.xml | 7 + 3 files changed, 341 insertions(+) create mode 100644 app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/TaskDialog.java create mode 100644 app/src/main/res/layout/task_dialog.xml diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/TaskDialog.java b/app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/TaskDialog.java new file mode 100644 index 00000000..71d6801c --- /dev/null +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/TaskDialog.java @@ -0,0 +1,194 @@ +package ca.pkay.rcloneexplorer.Dialogs; + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.util.Log; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; + +import ca.pkay.rcloneexplorer.Database.DatabaseHandler; +import ca.pkay.rcloneexplorer.Database.Task; +import ca.pkay.rcloneexplorer.Items.RemoteItem; +import ca.pkay.rcloneexplorer.R; +import ca.pkay.rcloneexplorer.Rclone; +import ca.pkay.rcloneexplorer.RecyclerViewAdapters.TasksRecyclerViewAdapter; + +public class TaskDialog extends Dialog { + + private Button task_back; + private Button task_next; + private Button task_save; + private Button task_cancel; + private TasksRecyclerViewAdapter recyclerViewAdapter; + private Rclone r = new Rclone(getContext()); + + private int state = 0; + + public TaskDialog(@NonNull Context context, TasksRecyclerViewAdapter recyclerViewAdapter) { + super(context); + this.recyclerViewAdapter=recyclerViewAdapter; + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.task_dialog); + + + getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); + setCanceledOnTouchOutside(true); + + task_back = findViewById(R.id.task_back); + task_next = findViewById(R.id.task_next); + task_save = findViewById(R.id.task_save); + task_cancel = findViewById(R.id.task_cancel); + + task_back.setVisibility(View.INVISIBLE); + + + + Spinner remoteDropdown = findViewById(R.id.task_remote_spinner); + + String[] items = new String[r.getRemotes().size()]; + + for (int i = 0; i< r.getRemotes().size();i++) { + items[i]=r.getRemotes().get(i).getName(); + } + + ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_dropdown_item, items); + remoteDropdown.setAdapter(adapter); + + + Spinner directionDropdown = findViewById(R.id.task_direction_spinner); + String[] options = new String[] {getContext().getResources().getString(R.string.sync_direction_local_remote),getContext().getString(R.string.sync_direction_remote_local)}; + ArrayAdapter directionAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_dropdown_item, options); + directionDropdown.setAdapter(directionAdapter); + + hideAll(); + decideState(); + + + task_next.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Log.e("APP!", "TaskDialog: next!"); + hideAll(); + state++; + decideState(); + } + }); + task_back.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Log.e("APP!", "TaskDialog: back!"); + hideAll(); + state--; + decideState(); + } + }); + task_cancel.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Log.e("APP!", "TaskDialog: cancel!"); + cancel(); + } + }); + task_save.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Log.e("APP!", "TaskDialog: Save!"); + save(); + } + }); + } + + private void save(){ + + DatabaseHandler dbHandler = new DatabaseHandler(getContext()); + Task t = new Task(0L); + + t.setTitle(((EditText)findViewById(R.id.task_title_textfield)).getText().toString()); + + String remotename=((Spinner)findViewById(R.id.task_remote_spinner)).getSelectedItem().toString(); + t.setRemote_id(remotename); + + int direction = ((Spinner)findViewById(R.id.task_direction_spinner)).getSelectedItemPosition()+1; + + + + for (RemoteItem ri: r.getRemotes()) { + if(ri.getName().equals(t.getRemote_id())){ + t.setRemote_type(ri.getType()); + } + } + + t.setRemote_path(((EditText)findViewById(R.id.task_remote_path_textfield)).getText().toString()); + t.setLocal_path(((EditText)findViewById(R.id.task_local_path_textfield)).getText().toString()); + t.setDirection(direction); + + Task newTask = dbHandler.createEntry(t); + recyclerViewAdapter.addTask(newTask); + + Log.e("app!", "Task Dialog: "+newTask.toString()); + + cancel(); + } + + + private void hideAll(){ + + findViewById(R.id.task_name_layout).setVisibility(View.GONE); + findViewById(R.id.task_remote_layout).setVisibility(View.GONE); + findViewById(R.id.task_remote_path_layout).setVisibility(View.GONE); + findViewById(R.id.task_local_path_layout).setVisibility(View.GONE); + findViewById(R.id.task_direction_layout).setVisibility(View.GONE); + + } + + private void decideState(){ + + if(state==0){ + task_back.setVisibility(View.INVISIBLE); + task_save.setVisibility(View.GONE); + task_next.setVisibility(View.VISIBLE); + }else if (state == 4){ + task_save.setVisibility(View.VISIBLE); + task_back.setVisibility(View.VISIBLE); + task_next.setVisibility(View.GONE); + }else { + task_back.setVisibility(View.VISIBLE); + task_next.setVisibility(View.VISIBLE); + task_save.setVisibility(View.GONE); + } + + switch(state) { + case 0: + ((TextView)findViewById(R.id.task_dialog_title)).setText("Name"); + findViewById(R.id.task_name_layout).setVisibility(View.VISIBLE); + break; + case 1: + ((TextView)findViewById(R.id.task_dialog_title)).setText("remote"); + findViewById(R.id.task_remote_layout).setVisibility(View.VISIBLE); + break; + case 2: + ((TextView)findViewById(R.id.task_dialog_title)).setText("remote path"); + findViewById(R.id.task_remote_path_layout).setVisibility(View.VISIBLE); + break; + case 3: + ((TextView)findViewById(R.id.task_dialog_title)).setText("local path"); + findViewById(R.id.task_local_path_layout).setVisibility(View.VISIBLE); + break; + case 4: + ((TextView)findViewById(R.id.task_dialog_title)).setText("direction"); + findViewById(R.id.task_direction_layout).setVisibility(View.VISIBLE); + break; + } + } + +} diff --git a/app/src/main/res/layout/task_dialog.xml b/app/src/main/res/layout/task_dialog.xml new file mode 100644 index 00000000..eec84981 --- /dev/null +++ b/app/src/main/res/layout/task_dialog.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +