commit 820540ce48d756be16c51889ca8b00f77691369b Author: Stefan Niedermann Date: Thu Oct 1 17:54:20 2015 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ec870c9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..84405a01 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +OwnCloudNotes \ No newline at end of file diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 00000000..d8f708f1 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,229 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..96cc43ef --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..0833b17c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..1a3eaffb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..c884bee9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..6564d52d --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.navigation/app/raw/main.nvg.xml b/.navigation/app/raw/main.nvg.xml new file mode 100644 index 00000000..e69de29b diff --git a/OwnCloudNotes.iml b/OwnCloudNotes.iml new file mode 100644 index 00000000..dd9b22e6 --- /dev/null +++ b/OwnCloudNotes.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.classpath b/app/.classpath new file mode 100644 index 00000000..51769745 --- /dev/null +++ b/app/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..3543521e --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/.project b/app/.project new file mode 100644 index 00000000..b3936bdb --- /dev/null +++ b/app/.project @@ -0,0 +1,33 @@ + + + OwnCloudNotes + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 00000000..b52645ec --- /dev/null +++ b/app/app.iml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 00000000..05ec6f3e --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "it.niedermann.owncloud.notes" + minSdkVersion 22 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile 'com.commonsware.cwac:anddown:0.2.4' + compile 'com.android.support:support-v4:23.0.1' + compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:gridlayout-v7:23.0.1' + compile 'com.android.support:design:23.0.1' + compile fileTree(include: ['*.jar'], dir: 'libs') +} diff --git a/app/ic_launcher-web.png b/app/ic_launcher-web.png new file mode 100644 index 00000000..a18cbb48 Binary files /dev/null and b/app/ic_launcher-web.png differ diff --git a/app/proguard-project.txt b/app/proguard-project.txt new file mode 100644 index 00000000..f2fe1559 --- /dev/null +++ b/app/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..67f98d96 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\stnieder\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/project.properties b/app/project.properties new file mode 100644 index 00000000..4ab12569 --- /dev/null +++ b/app/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/app/src/androidTest/java/it/niedermann/owncloud/notes/ApplicationTest.java b/app/src/androidTest/java/it/niedermann/owncloud/notes/ApplicationTest.java new file mode 100644 index 00000000..f1ce72e4 --- /dev/null +++ b/app/src/androidTest/java/it/niedermann/owncloud/notes/ApplicationTest.java @@ -0,0 +1,13 @@ +package it.niedermann.owncloud.notes; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/it/niedermann/owncloud/notes/util/URLValidatorAsyncTaskTest.java b/app/src/androidTest/java/it/niedermann/owncloud/notes/util/URLValidatorAsyncTaskTest.java new file mode 100644 index 00000000..213bd1db --- /dev/null +++ b/app/src/androidTest/java/it/niedermann/owncloud/notes/util/URLValidatorAsyncTaskTest.java @@ -0,0 +1,14 @@ +package it.niedermann.owncloud.notes.util; + +import junit.framework.TestCase; + +/** + * Tests the URLValidatorAsyncTask + * Created by stefan on 24.09.15. + */ +public class URLValidatorAsyncTaskTest extends TestCase { + public void testIsHttp() { + assertTrue(URLValidatorAsyncTask.isHttp("http://www.example.com/")); + assertFalse(URLValidatorAsyncTask.isHttp("https://www.example.com/")); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..390d4aa0 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java new file mode 100644 index 00000000..d1f58cda --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java @@ -0,0 +1,14 @@ +package it.niedermann.owncloud.notes.android.activity; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import it.niedermann.owncloud.notes.R; +public class AboutActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_about); + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/CreateNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/CreateNoteActivity.java new file mode 100644 index 00000000..942905a4 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/CreateNoteActivity.java @@ -0,0 +1,66 @@ +package it.niedermann.owncloud.notes.android.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.EditText; + +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.Note; +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; + +public class CreateNoteActivity extends AppCompatActivity { + private EditText editTextField = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_create); + editTextField = (EditText) findViewById(R.id.createContent); + + // Get intent, action and MIME type + Intent intent = getIntent(); + String action = intent.getAction(); + String type = intent.getType(); + + if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type)) { + editTextField.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); + } + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_menu_create, menu); + return true; + } + + /** + * Main-Menu + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.action_create_save: + editTextField.setEnabled(false); + String content = editTextField.getText().toString(); + NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(this); + db.addNoteAndSync(content); + Intent data = new Intent(); + //FIXME send correct note back to NotesListView + data.putExtra(NotesListViewActivity.CREATED_NOTE, new Note(-1, null, "", content)); + setResult(RESULT_OK, data); + finish(); + return true; + case R.id.action_create_cancel: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java new file mode 100644 index 00000000..5dadd4b7 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java @@ -0,0 +1,64 @@ +package it.niedermann.owncloud.notes.android.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.EditText; +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.Note; +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; + +public class EditNoteActivity extends AppCompatActivity { + private EditText content = null; + private Note note = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit); + note = (Note) getIntent().getSerializableExtra( + NoteActivity.EDIT_NOTE); + content = (EditText) findViewById(R.id.editContent); + content.setEnabled(false); + content.setText(note.getContent()); + content.setSelection(note.getContent().length()); + content.setEnabled(true); + } + + /** + * Create Action Menu + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_menu_edit, menu); + return true; + } + + /** + * Handle Action Menu + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.action_edit_save: + content.setEnabled(false); + note.setContent(((EditText) findViewById(R.id.editContent)).getText().toString()); + NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(this); + db.updateNoteAndSync(note); + Intent data = new Intent(); + data.setAction(Intent.ACTION_VIEW); + data.putExtra(NoteActivity.EDIT_NOTE, note); + setResult(RESULT_OK, data); + finish(); + return true; + case R.id.action_edit_cancel: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NoteActivity.java new file mode 100644 index 00000000..1b637241 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NoteActivity.java @@ -0,0 +1,120 @@ +package it.niedermann.owncloud.notes.android.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.webkit.WebView; + +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.Note; +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; + +public class NoteActivity extends AppCompatActivity implements View.OnClickListener { + private Note note = null; + private int notePosition = 0; + private WebView noteContent = null; + private ActionBar actionBar = null; + // Intent backToListViewIntent = null; + public final static String EDIT_NOTE = "it.niedermann.owncloud.notes.edit_note_id"; + public final static int EDIT_NOTE_CMD = 1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // backToListViewIntent = new Intent(); + setContentView(R.layout.activity_single_note); + note = (Note) getIntent().getSerializableExtra( + NotesListViewActivity.SELECTED_NOTE); + notePosition = getIntent().getIntExtra( + NotesListViewActivity.SELECTED_NOTE_POSITION, 0); + findViewById(R.id.fab_edit).setOnClickListener(this); + actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(note.getTitle()); + actionBar.setSubtitle(note.getModified("dd.MM.yyyy HH:mm")); + } + noteContent = (WebView) findViewById(R.id.singleNoteContent); + noteContent.loadData(note.getHtmlContent(), "text/html", "UTF-8"); + } + + @Override + public void onClick(View v) { + Intent editIntent = new Intent(this, EditNoteActivity.class); + editIntent.putExtra(EDIT_NOTE, note); + startActivityForResult(editIntent, EDIT_NOTE_CMD); + } + + /** + * Main-Menu + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_note_list_view, menu); + return true; + } + + /** + * Main-Menu-Handler + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + NoteSQLiteOpenHelper db = null; + switch (id) { + case R.id.menu_delete: + //setContentView(R.layout.activity_notes_list_view); + db = new NoteSQLiteOpenHelper(this); + db.deleteNoteAndSync(note.getId()); + finish(); + return true; + case R.id.menu_share: + Log.v("Note", "Share Action pressed."); + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.setType("text/plain"); + shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, + note.getTitle()); + shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, + note.getContent()); + startActivity(shareIntent); + return true; + case R.id.menu_copy: + Log.v("Note", "Copy Action pressed."); + db = new NoteSQLiteOpenHelper(this); + Note newNote = db.getNote(db.addNoteAndSync(note.getContent())); + newNote.setTitle(note.getTitle() + " (" + getResources().getString(R.string.copy) + ")"); + db.updateNote(newNote); + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // Check which request we're responding to + if (requestCode == EDIT_NOTE_CMD) { + // Make sure the request was successful + if (resultCode == RESULT_OK) { + Note editedNote = (Note) data.getExtras().getSerializable( + EDIT_NOTE); + if (editedNote != null) { + noteContent.loadData(editedNote.getHtmlContent(), "text/html", "UTF-8"); + actionBar.setTitle(editedNote.getTitle()); + actionBar.setSubtitle(editedNote.getModified("dd.MM.yyyy HH:mm")); + } + // TODO Fire changed note to noteslistviewactivity + data.putExtra(NotesListViewActivity.SELECTED_NOTE_POSITION, + notePosition); + setResult(RESULT_OK, data); + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java new file mode 100644 index 00000000..49fbf6f9 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -0,0 +1,359 @@ +package it.niedermann.owncloud.notes.android.activity; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.view.ActionMode; +import android.util.Log; +import android.util.SparseBooleanArray; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemLongClickListener; +import android.widget.ListView; + +import java.util.List; + +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.Note; +import it.niedermann.owncloud.notes.model.NoteAdapter; +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; +import it.niedermann.owncloud.notes.util.ICallback; + +public class NotesListViewActivity extends AppCompatActivity implements + OnItemClickListener, View.OnClickListener { + + public final static String SELECTED_NOTE = "it.niedermann.owncloud.notes.clicked_note"; + public final static String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes"; + public final static String SELECTED_NOTE_POSITION = "it.niedermann.owncloud.notes.clicked_note_position"; + + private final static int create_note_cmd = 0; + private final static int show_single_note_cmd = 1; + private final static int server_settings = 2; + private final static int about = 3; + + private ListView listView = null; + private NoteAdapter adapter = null; + private ActionMode mActionMode; + private SwipeRefreshLayout swipeRefreshLayout = null; + private NoteSQLiteOpenHelper db = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // First Run Wizard + SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + Log.v("Note", "First Run: " + preferences.getBoolean(SettingsActivity.SETTINGS_FIRST_RUN, true)); + if(preferences.getBoolean(SettingsActivity.SETTINGS_FIRST_RUN, true)) { + Log.v("Note", "Seems to be the First Run..."); + Intent settingsIntent = new Intent(this, SettingsActivity.class); + startActivityForResult(settingsIntent, server_settings); + } + + setContentView(R.layout.activity_notes_list_view); + + // Display Data + db = new NoteSQLiteOpenHelper(this); + db.synchronizeWithServer(); + setListView(db.getNotes()); + + // Pull to Refresh + swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout); + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + Log.d("Swipe", "Refreshing Notes"); + db.synchronizeWithServer(); + db.getNoteServerSyncHelper().addCallback(new ICallback() { + @Override + public void onFinish() { + swipeRefreshLayout.setRefreshing(false); + setListView(db.getNotes()); + } + }); + } + }); + + // Floating Action Button + findViewById(R.id.fab_create).setOnClickListener(this); + } + + /** + * Click listener for Floating Action Button + *

+ * Creates a new Instance of CreateNoteActivity. + * + * @param v View + */ + @Override + public void onClick(View v) { + Intent createIntent = new Intent(this, CreateNoteActivity.class); + startActivityForResult(createIntent, create_note_cmd); + } + + /** + * Allows other classes to set a List of Notes. + * + * @param noteList List<Note> + */ + @SuppressWarnings("WeakerAccess") + public void setListView(List noteList) { + adapter = new NoteAdapter(getApplicationContext(), noteList); + listView = (ListView) findViewById(R.id.list_view); + listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + listView.setAdapter(adapter); + listView.setOnItemClickListener(this); + listView.setOnItemLongClickListener(new OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, + int position, long id) { + onListItemSelect(position); + return true; + } + }); + } + + /** + * A short click on one list item. Creates a new instance of NoteActivity. + */ + @Override + public void onItemClick(AdapterView parentView, View childView, + int position, long id) { + listView.setItemChecked(position, !listView.isItemChecked(position)); + Log.v("Note", "getCheckedItemCount " + listView.getCheckedItemCount()); + if (listView.getCheckedItemCount() < 1) { + removeSelection(); + Intent intent = new Intent(getApplicationContext(), + NoteActivity.class); + Note note = adapter.getItem(position); + intent.putExtra(SELECTED_NOTE, note); + intent.putExtra(SELECTED_NOTE_POSITION, position); + Log.v("Note", + "notePosition | NotesListViewActivity wurde abgesendet " + + position); + startActivityForResult(intent, show_single_note_cmd); + } else { // perform long click if already something is selected + onListItemSelect(position); + } + } + + /** + * Adds the Menu Items to the Action Bar. + * + * @param menu Menu + * @return boolean + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_list_view, menu); + return true; + } + + /** + * Handels click events on the Buttons in the Action Bar. + * + * @param item MenuItem - the clicked menu item + * @return boolean + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.action_settings: + Intent settingsIntent = new Intent(this, SettingsActivity.class); + startActivityForResult(settingsIntent, server_settings); + return true; + case R.id.action_about: + Intent aboutIntent = new Intent(this, AboutActivity.class); + startActivityForResult(aboutIntent, about); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + /** + * Handles the Results of started Sub Activities (Created Note, Edited Note) + * + * @param requestCode int to distinguish between the different Sub Activities + * @param resultCode int Return Code + * @param data Intent + */ + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // Check which request we're responding to + if (requestCode == create_note_cmd) { + // Make sure the request was successful + if (resultCode == RESULT_OK) { + Note createdNote = (Note) data.getExtras().getSerializable( + CREATED_NOTE); + adapter.add(createdNote); + } + } else if (requestCode == NoteActivity.EDIT_NOTE_CMD) { + if (resultCode == RESULT_OK) { + Log.v("Note", "Note was edited from single view"); + + Note editedNote = (Note) data.getExtras().getSerializable( + NoteActivity.EDIT_NOTE); + Log.v("Note", "Neuer Titel: " + editedNote); + + int notePosition = data.getExtras().getInt( + SELECTED_NOTE_POSITION); + Log.v("Note", "notePosition | NotesListViewActivity kam an " + + notePosition); + + adapter.remove(adapter.getItem(notePosition)); + adapter.add(editedNote); + } + } + setListView(db.getNotes()); + } + + // private class SingleSelectedActionModeCallback implements + // ActionMode.Callback { + // + // @Override + // public boolean onCreateActionMode(ActionMode mode, Menu menu) { + // // inflate contextual menu + // mode.getMenuInflater().inflate(R.menu.menu_list_context_single, + // menu); + // return true; + // } + // + // @Override + // public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + // return false; + // } + // + // @Override + // public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + // switch (item.getItemId()) { + // case R.id.menu_delete: + // SparseBooleanArray checkedItemPositions = listView + // .getCheckedItemPositions(); + // for (int i = (checkedItemPositions.size() - 1); i >= 0; i--) { + // if (checkedItemPositions.valueAt(i)) { + // + // Note checkedItem = adapter.getItem(checkedItemPositions + // .keyAt(i)); + // + // NoteDeleterAsyncTask deleter = new NoteDeleterAsyncTask(); + // deleter.execute(checkedItem); + // } + // } + // mode.finish(); // Action picked, so close the CAB + // return true; + // default: + // return false; + // } + // } + // + // @Override + // public void onDestroyActionMode(ActionMode mode) { + // removeSelection(); + // mActionMode = null; + // adapter.notifyDataSetChanged(); + // } + // } + + /** + * Long click on one item in the list view. It starts the Action Mode and allows selecting more + * items and execute bulk functions (e. g. delete) + * + * @param position int - position of the clicked item + */ + private void onListItemSelect(int position) { + listView.setItemChecked(position, !listView.isItemChecked(position)); + int checkedItemCount = listView.getCheckedItemCount(); + boolean hasCheckedItems = checkedItemCount > 0; + + if (hasCheckedItems && mActionMode == null) { + // TODO differ if one or more items are selected + // if (checkedItemCount == 1) { + // mActionMode = startActionMode(new + // SingleSelectedActionModeCallback()); + // } else { + // there are some selected items, start the actionMode + mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback()); + // } + } else if (!hasCheckedItems && mActionMode != null) { + // there no selected items, finish the actionMode + mActionMode.finish(); + } + + if (mActionMode != null) { + mActionMode.setTitle(String.valueOf(listView.getCheckedItemCount()) + + " " + getString(R.string.ab_selected)); + } + } + + /** + * Handler for the MultiSelect Actions + */ + private class MultiSelectedActionModeCallback implements + ActionMode.Callback { + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + // inflate contextual menu + mode.getMenuInflater().inflate(R.menu.menu_list_context_multiple, + menu); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + /** + * @param mode ActionMode - used to close the Action Bar after all work is done. + * @param item MenuItem - the item in the List that contains the Node + * @return boolean + */ + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_delete: + SparseBooleanArray checkedItemPositions = listView + .getCheckedItemPositions(); + for (int i = (checkedItemPositions.size() - 1); i >= 0; i--) { + if (checkedItemPositions.valueAt(i)) { + Note note = adapter.getItem(checkedItemPositions + .keyAt(i)); + db.deleteNoteAndSync(note.getId()); + adapter.remove(note); + } + } + mode.finish(); // Action picked, so close the CAB + return true; + default: + return false; + } + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + removeSelection(); + mActionMode = null; + adapter.notifyDataSetChanged(); + } + } + + /** + * Removes all selections. + */ + private void removeSelection() { + SparseBooleanArray checkedItemPositions = listView + .getCheckedItemPositions(); + for (int i = 0; i < checkedItemPositions.size(); i++) { + listView.setItemChecked(i, false); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java new file mode 100644 index 00000000..a9cd6006 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java @@ -0,0 +1,175 @@ +package it.niedermann.owncloud.notes.android.activity; + +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.AppCompatActivity; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; +import it.niedermann.owncloud.notes.util.NotesClientUtil; + +/** + * Allows to set Settings like URL, Username and Password for Server-Synchronization + * Created by stefan on 22.09.15. + */ +public class SettingsActivity extends AppCompatActivity implements View.OnClickListener { + + public static final String SETTINGS_FIRST_RUN = "firstRun"; + public static final String SETTINGS_URL = "settingsUrl"; + public static final String SETTINGS_USERNAME = "settingsUsername"; + public static final String SETTINGS_PASSWORD = "settingsPassword"; + public static final String DEFAULT_SETTINGS = ""; + + private SharedPreferences preferences = null; + private EditText field_url = null; + private EditText field_username = null; + private EditText field_password = null; + private Button btn_submit = null; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_settings); + + preferences = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + field_url = (EditText) findViewById(R.id.settings_url); + field_username = (EditText) findViewById(R.id.settings_username); + field_password = (EditText) findViewById(R.id.settings_password); + btn_submit = (Button) findViewById(R.id.settings_submit); + + field_url.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + String url = ((EditText) findViewById(R.id.settings_url)).getText().toString(); + new URLValidatorAsyncTask().execute(url); + + if (NotesClientUtil.isHttp(url)) { + findViewById(R.id.settings_url_warn_http).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.settings_url_warn_http).setVisibility(View.GONE); + } + } + + @Override + public void afterTextChanged(Editable s) {} + }); + + // Load current Preferences + field_url.setText(preferences.getString(SETTINGS_URL, DEFAULT_SETTINGS)); + field_username.setText(preferences.getString(SETTINGS_USERNAME, DEFAULT_SETTINGS)); + field_password.setText(preferences.getString(SETTINGS_PASSWORD, DEFAULT_SETTINGS)); + + btn_submit.setOnClickListener(this); + } + + /** + * Handle Submit Button Click + * Checks and Writes the new Preferences into the SharedPreferences Object. + * + * @param v View + */ + @Override + public void onClick(View v) { + String url = field_url.getText().toString(); + String username = field_username.getText().toString(); + String password = field_password.getText().toString(); + + if (!url.endsWith("/")) { + url += "/"; + } + + new LoginValidatorAsyncTask().execute(url, username, password); + } + + /************************************ Async Tasks ************************************/ + + /** + * Checks if the given URL returns a valid status code and sets the Check next to the URL-Input Field to visible. + * Created by stefan on 23.09.15. + */ + private class URLValidatorAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + findViewById(R.id.settings_url_check).setVisibility(View.INVISIBLE); + } + + @Override + protected Boolean doInBackground(String... params) { + return NotesClientUtil.isValidURL(params[0]); + } + + @Override + protected void onPostExecute(Boolean o) { + Log.v("Note", "Set Visible: " + o); + if (o) { + findViewById(R.id.settings_url_check).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.settings_url_check).setVisibility(View.INVISIBLE); + } + } + } + + /** + * If Log-In-Credentials are correct, save Credentials to Shared Preferences and finish First Run Wizard. + */ + private class LoginValidatorAsyncTask extends AsyncTask { + String url, username, password; + + @Override + protected void onPreExecute() { + btn_submit.setEnabled(false); + } + + /** + * @param params url, username and password + * @return isValidLogin + */ + @Override + protected Boolean doInBackground(String... params) { + url = params[0]; + username = params[1]; + password = params[2]; + return NotesClientUtil.isValidLogin(url, username, password); + } + + @Override + protected void onPostExecute(Boolean isValidLogin) { + if(isValidLogin) { + Log.v("Note", "Valid Credentials."); + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(SETTINGS_URL, url); + editor.putString(SETTINGS_USERNAME, username); + editor.putString(SETTINGS_PASSWORD, password); + + // Now it is no more First Run + Log.v("Note", "set First_Run to false."); + editor.putBoolean(SETTINGS_FIRST_RUN, false); + + editor.apply(); + + NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(getApplicationContext()); + db.synchronizeWithServer(); + + finish(); + } else { + Log.v("Note", "Invalid Credentials!"); + btn_submit.setEnabled(true); + //TODO Show Error Message + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java b/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java new file mode 100644 index 00000000..fc27f826 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java @@ -0,0 +1,20 @@ +package it.niedermann.owncloud.notes.model; + +/** + * Helps to distinguish between different local change types for Server Synchronization. + * Created by stefan on 19.09.15. + */ +public enum DBStatus { + + VOID(""), LOCAL_CREATED("LOCAL_CREATED"), LOCAL_EDITED("LOCAL_EDITED"), LOCAL_DELETED("LOCAL_DELETED"); + + private final String title; + + public String getTitle() { + return title; + } + + DBStatus(String title) { + this.title = title; + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/Note.java b/app/src/main/java/it/niedermann/owncloud/notes/model/Note.java new file mode 100644 index 00000000..3bf4af7f --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/Note.java @@ -0,0 +1,74 @@ +package it.niedermann.owncloud.notes.model; + +import android.text.Html; + +import com.commonsware.cwac.anddown.AndDown; + +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; + +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; + +@SuppressWarnings("serial") +public class Note implements Serializable { + + private static final AndDown and_down = new AndDown(); + private long id = 0; + private String title = ""; + private Calendar modified = null; + private String content = ""; + private String htmlContent = null; + + public Note(long id, Calendar modified, String title, String content) { + this.id = id; + if(title != null) + this.title = Html.fromHtml(and_down.markdownToHtml(title)).toString().trim(); + this.modified = modified; + this.content = content; + } + + public long getId() { + return id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @SuppressWarnings("WeakerAccess") + public Calendar getModified() { + return modified; + } + + public String getModified(String format) { + return new SimpleDateFormat(format, Locale.GERMANY) + .format(this.getModified().getTime()); + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + this.htmlContent = null; + } + + public String getHtmlContent() { + if(htmlContent == null && getContent() != null) { + htmlContent = and_down.markdownToHtml(getContent()); + } + return htmlContent; + } + + @Override + public String toString() { + return "#" + getId() + " " + getTitle() + " (" + getModified(NoteSQLiteOpenHelper.DATE_FORMAT) + ")"; + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/NoteAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/model/NoteAdapter.java new file mode 100644 index 00000000..a4b92915 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/NoteAdapter.java @@ -0,0 +1,70 @@ +package it.niedermann.owncloud.notes.model; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import java.util.List; + +import it.niedermann.owncloud.notes.R; + +public class NoteAdapter extends ArrayAdapter { + private List noteList = null; + + // private SparseBooleanArray mSelectedItemsIds; + + public NoteAdapter(Context context, + List noteList) { + super(context, android.R.layout.simple_list_item_1, noteList); + // mSelectedItemsIds = new SparseBooleanArray(); + this.noteList = noteList; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View v = convertView; + + // first check to see if the view is null. if so, we have to inflate it. + // to inflate it basically means to render, or show, the view. + if (v == null) { + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + v = inflater.inflate(R.layout.fragment_notes_list_view, null); + } + + /* + * Recall that the variable position is sent in as an argument to this + * method. The variable simply refers to the position of the current + * object in the list. (The ArrayAdapter iterates through the list we + * sent it) + * + * Therefore, i refers to the current Item object. + */ + Note note = noteList.get(position); + + if (note != null) { + + // This is how you obtain a reference to the TextViews. + // These TextViews are created in the XML files we defined. + + TextView noteTitle = (TextView) v.findViewById(R.id.noteTitle); + TextView noteModified = (TextView) v + .findViewById(R.id.noteModified); + + // check to see if each individual textview is null. + // if not, assign some text! + if (noteTitle != null) { + noteTitle.setText(note.getTitle()); + } + if (noteModified != null) { + noteModified.setText(note.getModified("dd.MM.yyyy HH:mm")); + } + } + + // the view must be returned to our activity + return v; + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java new file mode 100644 index 00000000..bc272a40 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java @@ -0,0 +1,305 @@ +package it.niedermann.owncloud.notes.persistence; + +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.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; + +import it.niedermann.owncloud.notes.model.DBStatus; +import it.niedermann.owncloud.notes.model.Note; + +/** + * Helps to add, get, update and delete Notes with the option to trigger a Resync with the Server. + *

+ * Created by stefan on 19.09.15. + */ +public class NoteSQLiteOpenHelper extends SQLiteOpenHelper { + public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + private static final int database_version = 4; + private static final String database_name = "OWNCLOUD_NOTES"; + private static final String table_notes = "NOTES"; + private static final String key_id = "ID"; + private static final String key_status = "STATUS"; + private static final String key_title = "TITLE"; + private static final String key_modified = "MODIFIED"; + private static final String key_content = "CONTENT"; + private static final String[] columns = {key_id, key_status, key_title, key_modified, key_content}; + + private NoteServerSyncHelper serverSyncHelper = null; + private Context context = null; + + public NoteSQLiteOpenHelper(Context context) { + super(context, database_name, null, database_version); + this.context = context; + serverSyncHelper = new NoteServerSyncHelper(this); + } + + public NoteServerSyncHelper getNoteServerSyncHelper() { + return serverSyncHelper; + } + + /** + * Creates initial the Database + * + * @param db Database + */ + @Override + public void onCreate(SQLiteDatabase db) { + Log.v("Note", "Creating Database"); + db.execSQL("CREATE TABLE '" + table_notes + "' ( '" + + key_id + "' INTEGER PRIMARY KEY AUTOINCREMENT, '" + + key_status + "' VARCHAR(50), '" + + key_title + "' TEXT, '" + + key_modified + "' TEXT, '" + + key_content + "' TEXT)"); + } + + /** + * Creates a new Note in the Database and adds a Synchronization Flag. + * + * @param content String + */ + @SuppressWarnings("UnusedReturnValue") + public long addNoteAndSync(String content) { + Log.v("Note", "addNoteAndSync"); + SQLiteDatabase db = this.getWritableDatabase(); + + ContentValues values = new ContentValues(); + values.put(key_status, DBStatus.LOCAL_CREATED.getTitle()); + values.put(key_content, content); + + long id = db.insert(table_notes, + null, + values); + db.close(); + serverSyncHelper.uploadNewNotes(); + return id; + } + + /** + * Inserts a note directly into the Database. + * No Synchronisation will be triggered! Use addNoteAndSync()! + * + * @param note Note to be added + */ + public void addNote(Note note) { + Log.v("Note", "addNote (" + note + ")"); + SQLiteDatabase db = this.getWritableDatabase(); + + ContentValues values = new ContentValues(); + values.put(NoteSQLiteOpenHelper.key_id, note.getId()); + values.put(NoteSQLiteOpenHelper.key_status, DBStatus.VOID.getTitle()); + values.put(NoteSQLiteOpenHelper.key_title, note.getTitle()); + values.put(NoteSQLiteOpenHelper.key_modified, note.getModified(NoteSQLiteOpenHelper.DATE_FORMAT)); + values.put(NoteSQLiteOpenHelper.key_content, note.getContent()); + + db.insert(NoteSQLiteOpenHelper.table_notes, + null, + values); + db.close(); + } + + /** + * Get a single Note by ID + * + * @param id int - ID of the requested Note + * @return requested Note + */ + @SuppressWarnings("unused") + public Note getNote(long id) { + Log.v("Note", "getNote(" + id + ")"); + SQLiteDatabase db = this.getReadableDatabase(); + Cursor cursor = + db.query(table_notes, + columns, + key_id + " = ? AND " + key_status + " != ?", + new String[]{String.valueOf(id), DBStatus.LOCAL_DELETED.getTitle()}, + null, + null, + null, + null); + if (cursor != null) { + cursor.moveToFirst(); + } + Calendar modified = Calendar.getInstance(); + try { + String modifiedStr = cursor != null ? cursor.getString(3) : null; + if (modifiedStr != null) + modified.setTime(new SimpleDateFormat(DATE_FORMAT, Locale.GERMANY).parse(modifiedStr)); + } catch (ParseException e) { + e.printStackTrace(); + } + Note note = new Note(Long.valueOf(cursor != null ? cursor.getString(0) : null), modified, cursor != null ? cursor.getString(2) : null, cursor.getString(4)); + cursor.close(); + return note; + } + + /** + * Returns a list of all Notes in the Database + * + * @return List<Note> + */ + public List getNotes() { + Log.v("Note", "getNotes"); + List notes = new ArrayList<>(); + SQLiteDatabase db = this.getWritableDatabase(); + Cursor cursor = db.rawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ?", new String[]{DBStatus.LOCAL_DELETED.getTitle()}); + if (cursor.moveToFirst()) { + do { + Calendar modified = Calendar.getInstance(); + try { + String modifiedStr = cursor.getString(3); + if (modifiedStr != null) + modified.setTime(new SimpleDateFormat(DATE_FORMAT, Locale.GERMANY).parse(modifiedStr)); + } catch (ParseException e) { + e.printStackTrace(); + } + notes.add(new Note(Long.valueOf(cursor.getString(0)), modified, cursor.getString(2), cursor.getString(4))); + } while (cursor.moveToNext()); + } + cursor.close(); + return notes; + } + + /** + * Returns a list of all Notes in the Database with a sepcial status, e.g. Edited, Deleted,... + * + * @return List<Note> + */ + public List getNotesByStatus(DBStatus status) { + Log.v("Note", "getNotesByStatus(" + status.getTitle() + ")"); + List notes = new ArrayList<>(); + SQLiteDatabase db = this.getWritableDatabase(); + Cursor cursor = db.rawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " = ?", new String[]{status.getTitle()}); + if (cursor.moveToFirst()) { + do { + Calendar modified = Calendar.getInstance(); + try { + String modifiedStr = cursor.getString(3); + if (modifiedStr != null) + modified.setTime(new SimpleDateFormat(DATE_FORMAT, Locale.GERMANY).parse(modifiedStr)); + } catch (ParseException e) { + e.printStackTrace(); + } + notes.add(new Note(Long.valueOf(cursor.getString(0)), modified, cursor.getString(2), cursor.getString(4))); + } while (cursor.moveToNext()); + } + cursor.close(); + return notes; + } + + /** + * Updates a single Note and sets a synchronization Flag. + * + * @param note Note - Note with the updated Information + * @return The number of the Rows affected. + */ + @SuppressWarnings("UnusedReturnValue") + public int updateNoteAndSync(Note note) { + Log.v("Note", "updateNoteAndSync(" + note + ")"); + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put(key_id, note.getId()); + values.put(key_status, DBStatus.LOCAL_EDITED.getTitle()); + values.put(key_title, note.getTitle()); + values.put(key_modified, note.getModified(DATE_FORMAT)); + values.put(key_content, note.getContent()); + int i = db.update(table_notes, + values, + key_id + " = ?", + new String[]{String.valueOf(note.getId())}); + db.close(); + serverSyncHelper.uploadEditedNotes(); + return i; + } + + /** + * Updates a single Note. No Synchronization will be triggered. Use updateNoteAndSync()! + * + * @param note Note - Note with the updated Information + * @return The number of the Rows affected. + */ + @SuppressWarnings("UnusedReturnValue") + public int updateNote(Note note) { + Log.v("Note", "updateNote(" + note + ")"); + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put(key_id, note.getId()); + values.put(key_status, DBStatus.VOID.getTitle()); + values.put(key_title, note.getTitle()); + values.put(key_modified, note.getModified(DATE_FORMAT)); + values.put(key_content, note.getContent()); + int i = db.update(table_notes, + values, + key_id + " = ?", + new String[]{String.valueOf(note.getId())}); + db.close(); + return i; + } + + /** + * Marks a Note in the Database as Deleted. In the next Synchronization it will be deleted + * from the Server. + * + * @param id long - ID of the Note that should be deleted + * @return Affected rows + */ + @SuppressWarnings("UnusedReturnValue") + public int deleteNoteAndSync(long id) { + Log.v("Note", "deleteNoteAndSync(" + id + ")"); + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put(key_status, DBStatus.LOCAL_DELETED.getTitle()); + int i = db.update(table_notes, + values, + key_id + " = ?", + new String[]{String.valueOf(id)}); + db.close(); + serverSyncHelper.uploadDeletedNotes(); + return i; + } + + /** + * Delete a single Note from the Database + * + * @param id long - ID of the Note that should be deleted. + */ + public void deleteNote(long id) { + Log.v("Note", "deleteNote(" + id + ")"); + SQLiteDatabase db = this.getWritableDatabase(); + db.delete(table_notes, + key_id + " = ?", + new String[]{String.valueOf(id)}); + db.close(); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.v("Note", "onUpgrade - DELETE *"); + clearDatabase(); + } + + public void clearDatabase() { + SQLiteDatabase db = this.getWritableDatabase(); + db.delete(table_notes, null, null); + db.close(); + } + + public Context getContext() { + return context; + } + + public void synchronizeWithServer() { + serverSyncHelper.synchronize(); + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java new file mode 100644 index 00000000..10722a67 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java @@ -0,0 +1,295 @@ +package it.niedermann.owncloud.notes.persistence; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.os.Handler; +import android.os.Message; +import android.preference.PreferenceManager; +import android.support.design.widget.Snackbar; +import android.util.Log; +import android.view.View; + +import org.json.JSONException; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.android.activity.SettingsActivity; +import it.niedermann.owncloud.notes.model.DBStatus; +import it.niedermann.owncloud.notes.model.Note; +import it.niedermann.owncloud.notes.util.ICallback; +import it.niedermann.owncloud.notes.util.NotesClient; + +/** + * Helps to synchronize the Database to the Server. + *

+ * Created by stefan on 20.09.15. + */ +public class NoteServerSyncHelper { + + private NotesClient client = null; + private NoteSQLiteOpenHelper db = null; + + private int operationsCount = 0; + private int operationsFinished = 0; + + private List callbacks = new ArrayList<>(); + + private final View.OnClickListener goToSettingsListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + Activity parent = (Activity) db.getContext(); + Intent intent = new Intent(parent, SettingsActivity.class); + parent.startActivity(intent); + } + }; + + public void addCallback(ICallback callback) { + callbacks.add(callback); + } + + public boolean isFinished() { + return operationsFinished == operationsCount; + } + + public NoteServerSyncHelper(NoteSQLiteOpenHelper db) { + this.db = db; + SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(db.getContext().getApplicationContext()); + String url = preferences.getString(SettingsActivity.SETTINGS_URL, + SettingsActivity.DEFAULT_SETTINGS); + String username = preferences.getString(SettingsActivity.SETTINGS_USERNAME, + SettingsActivity.DEFAULT_SETTINGS); + String password = preferences.getString(SettingsActivity.SETTINGS_PASSWORD, + SettingsActivity.DEFAULT_SETTINGS); + client = new NotesClient(url, username, password); + } + + public void synchronize() { + uploadEditedNotes(); + uploadNewNotes(); + uploadDeletedNotes(); + downloadNotes(); + final Handler handler = new Handler() { + @Override + public void handleMessage(Message msg) { + for (ICallback callback : callbacks) { + callback.onFinish(); + } + } + }; + Timer timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + Log.v("Note", "Sync operations: " + operationsFinished + "/" + operationsCount); + if (isFinished()) { + handler.obtainMessage(1).sendToTarget(); + cancel(); + } + } + }, 0, 200); + } + + public void uploadEditedNotes() { + List notes = db.getNotesByStatus(DBStatus.LOCAL_EDITED); + for (Note note : notes) { + UploadEditedNotesTask editedNotesTask = new UploadEditedNotesTask(); + editedNotesTask.execute(note); + } + } + + public void uploadNewNotes() { + List notes = db.getNotesByStatus(DBStatus.LOCAL_CREATED); + for (Note note : notes) { + UploadNewNoteTask newNotesTask = new UploadNewNoteTask(); + newNotesTask.execute(note); + } + } + + public void uploadDeletedNotes() { + List notes = db.getNotesByStatus(DBStatus.LOCAL_DELETED); + for (Note note : notes) { + UploadDeletedNoteTask deletedNotesTask = new UploadDeletedNoteTask(); + deletedNotesTask.execute(note); + } + } + + public void downloadNotes() { + DownloadNotesTask downloadNotesTask = new DownloadNotesTask(); + downloadNotesTask.execute(); + } + + private class UploadNewNoteTask extends AsyncTask { + @Override + protected Object[] doInBackground(Object... params) { + operationsCount++; + Note oldNote = (Note) params[0]; + try { + Note note = client.createNote(oldNote.getContent()); + return new Object[]{note, oldNote.getId()}; + } catch (MalformedURLException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_url_malformed, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, new View.OnClickListener() { + @Override + public void onClick(View v) { + Activity parent = (Activity) db.getContext(); + Intent intent = new Intent(parent, SettingsActivity.class); + parent.startActivity(intent); + } + }) + .show(); + e.printStackTrace(); + } catch (JSONException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_json, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, new View.OnClickListener() { + @Override + public void onClick(View v) { + Activity parent = (Activity) db.getContext(); + Intent intent = new Intent(parent, SettingsActivity.class); + parent.startActivity(intent); + } + }) + .show(); + e.printStackTrace(); + } catch (IOException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_io, Snackbar.LENGTH_LONG) + .show(); + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(Object[] params) { + if(params != null) { + Long id = (Long) params[1]; + if (id != null) { + db.deleteNote(((Long) params[1])); + } + db.addNote((Note) params[0]); + } + operationsFinished++; + } + } + + private class UploadEditedNotesTask extends AsyncTask { + @Override + protected Note doInBackground(Object... params) { + operationsCount++; + try { + Note oldNote = (Note) params[0]; + return client.editNote(oldNote.getId(), oldNote.getContent()); + } catch (MalformedURLException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_url_malformed, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, goToSettingsListener) + .show(); + e.printStackTrace(); + } catch (JSONException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_json, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, goToSettingsListener) + .show(); + e.printStackTrace(); + } catch (IOException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_io, Snackbar.LENGTH_LONG) + .show(); + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(Note note) { + db.updateNote(note); + operationsFinished++; + } + } + + private class UploadDeletedNoteTask extends AsyncTask { + Long id = null; + + @Override + protected Void doInBackground(Object... params) { + operationsCount++; + try { + id = ((Note) params[0]).getId(); + client.deleteNote(id); + } catch (MalformedURLException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_url_malformed, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, goToSettingsListener) + .show(); + e.printStackTrace(); + } catch (IOException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_io, Snackbar.LENGTH_LONG) + .show(); + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + db.deleteNote(id); + operationsFinished++; + } + } + + private class DownloadNotesTask extends AsyncTask> { + private boolean serverError = false; + + @Override + protected List doInBackground(Object... params) { + operationsCount++; + List notes = new ArrayList<>(); + try { + notes = client.getNotes(); + } catch (MalformedURLException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_url_malformed, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, goToSettingsListener) + .show(); + serverError = true; + e.printStackTrace(); + } catch (JSONException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_json, Snackbar.LENGTH_LONG) + .setAction(R.string.snackbar_settings, goToSettingsListener) + .show(); + serverError = true; + e.printStackTrace(); + } catch (IOException e) { + Snackbar + .make(((Activity) db.getContext()).getWindow().getDecorView(), R.string.error_io, Snackbar.LENGTH_LONG) + .show(); + serverError = true; + e.printStackTrace(); + } + return notes; + } + + @Override + protected void onPostExecute(List result) { + // Clear Database only if there is an Server + if(!serverError) { + db.clearDatabase(); + } + for (Note note : result) { + db.addNote(note); + } + operationsFinished++; + } + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/ICallback.java b/app/src/main/java/it/niedermann/owncloud/notes/util/ICallback.java new file mode 100644 index 00000000..7b0d8c88 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/util/ICallback.java @@ -0,0 +1,8 @@ +package it.niedermann.owncloud.notes.util; + +/** + * Created by stefan on 01.10.15. + */ +public interface ICallback { + public void onFinish(); +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/NotesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/util/NotesClient.java new file mode 100644 index 00000000..e8b6df6d --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/util/NotesClient.java @@ -0,0 +1,207 @@ +package it.niedermann.owncloud.notes.util; + +import android.util.Base64; +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.List; + +import it.niedermann.owncloud.notes.model.Note; + +public class NotesClient { + + private String url = ""; + private String username = ""; + private String password = ""; + + public NotesClient(String url, String username, String password) { + this.url = url; + this.username = username; + this.password = password; + } + + public List getNotes() throws JSONException, + IOException { + List notesList = new ArrayList<>(); + JSONArray notes = new JSONArray(requestServer("notes", "GET", null)); + long noteId = 0; + String noteTitle = ""; + String noteContent = ""; + Calendar noteModified = null; + JSONObject currentItem; + for (int i = 0; i < notes.length(); i++) { + currentItem = notes.getJSONObject(i); + + if (!currentItem.isNull("id")) { + noteId = currentItem.getLong("id"); + } + if (!currentItem.isNull("title")) { + noteTitle = currentItem.getString("title"); + } + if (!currentItem.isNull("content")) { + noteContent = currentItem.getString("content"); + } + if (!currentItem.isNull("modified")) { + noteModified = GregorianCalendar.getInstance(); + noteModified + .setTimeInMillis(currentItem.getLong("modified") * 1000); + } + notesList + .add(new Note(noteId, noteModified, noteTitle, noteContent)); + } + return notesList; + } + + /** + * Fetches on Note by ID from Server + * TODO Maybe fetch only id, title and modified from server until a note has been opened? + * @param id long - ID of the wanted note + * @return Requested Note + * @throws JSONException + * @throws IOException + */ + @SuppressWarnings("unused") + public Note getNoteById(long id) throws + JSONException, IOException { + long noteId = 0; + String noteTitle = ""; + String noteContent = ""; + Calendar noteModified = null; + JSONObject currentItem = new JSONObject( + requestServer("notes/" + id, "GET", null)); + + if (!currentItem.isNull("id")) { + noteId = currentItem.getLong("id"); + } + if (!currentItem.isNull("title")) { + noteTitle = currentItem.getString("title"); + } + if (!currentItem.isNull("content")) { + noteContent = currentItem.getString("content"); + } + if (!currentItem.isNull("modified")) { + noteModified = GregorianCalendar.getInstance(); + noteModified + .setTimeInMillis(currentItem.getLong("modified") * 1000); + } + return new Note(noteId, noteModified, noteTitle, noteContent); + } + + /** + * Creates a Note on the Server + * @param content String - Content of the new Note + * @return Created Note including generated Title, ID and lastModified-Date + * @throws JSONException + * @throws IOException + */ + public Note createNote(String content) throws + JSONException, IOException { + long noteId = 0; + String noteTitle = ""; + String noteContent = ""; + Calendar noteModified = null; + + JSONObject paramObject = new JSONObject(); + paramObject.accumulate("content", content); + JSONObject currentItem = new JSONObject(requestServer("notes", "POST", + paramObject)); + + if (!currentItem.isNull("id")) { + noteId = currentItem.getLong("id"); + } + if (!currentItem.isNull("title")) { + noteTitle = currentItem.getString("title"); + } + if (!currentItem.isNull("content")) { + noteContent = currentItem.getString("content"); + } + if (!currentItem.isNull("modified")) { + noteModified = GregorianCalendar.getInstance(); + noteModified + .setTimeInMillis(currentItem.getLong("modified") * 1000); + } + return new Note(noteId, noteModified, noteTitle, noteContent); + } + + public Note editNote(long noteId, String content) + throws JSONException, IOException { + String noteTitle = ""; + Calendar noteModified = null; + + JSONObject paramObject = new JSONObject(); + paramObject.accumulate("content", content); + JSONObject currentItem = new JSONObject(requestServer( + "notes/" + noteId, "PUT", paramObject)); + + if (!currentItem.isNull("title")) { + noteTitle = currentItem.getString("title"); + } + if (!currentItem.isNull("modified")) { + noteModified = GregorianCalendar.getInstance(); + noteModified + .setTimeInMillis(currentItem.getLong("modified") * 1000); + } + return new Note(noteId, noteModified, noteTitle, content); + } + + public void deleteNote(long noteId) throws + IOException { + this.requestServer("notes/" + noteId, "DELETE", null); + } + + /** + * Request-Method for POST, PUT with or without JSON-Object-Parameter + * + * @param target Filepath to the wanted function + * @param method GET, POST, DELETE or PUT + * @param params JSON Object which shall be transferred to the server. + * @return Body of answer + * @throws MalformedURLException + * @throws IOException + */ + private String requestServer(String target, String method, JSONObject params) + throws IOException { + String result = ""; + String targetURL = url + "index.php/apps/notes/api/v0.2/" + target; + Log.v("Note", targetURL); + HttpURLConnection con = (HttpURLConnection) new URL(targetURL) + .openConnection(); + con.setRequestMethod(method); + con.setRequestProperty( + "Authorization", + "Basic " + + new String(Base64.encode((username + ":" + + password).getBytes(), Base64.NO_WRAP))); + con.setConnectTimeout(10 * 1000); // 10 seconds + if (params != null) { + con.setFixedLengthStreamingMode(params.toString().getBytes().length); + con.setRequestProperty("Content-Type", "application/json"); + con.setDoOutput(true); + OutputStream os = con.getOutputStream(); + Log.v("Note", params.toString()); + os.write(params.toString().getBytes()); + os.flush(); + os.close(); + } + BufferedReader rd; + String line; + rd = new BufferedReader(new InputStreamReader(con.getInputStream())); + while ((line = rd.readLine()) != null) { + result += line; + } + return result; + } +} \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/NotesClientUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/NotesClientUtil.java new file mode 100644 index 00000000..cc02c0a8 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/util/NotesClientUtil.java @@ -0,0 +1,84 @@ +package it.niedermann.owncloud.notes.util; + +import android.util.Base64; +import android.util.Log; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +/** + * Utils for Validation etc + * Created by stefan on 25.09.15. + */ +public class NotesClientUtil { + + /** + * Checks if the given url String starts with http:// or https:// + * + * @param url String + * @return true, if the given String is only http + */ + public static boolean isHttp(String url) { + return url.length() > 4 && url.startsWith("http") && url.charAt(4) != 's'; + } + + /** + * Checks if the given URL returns a valid status code and sets the Check next to the URL-Input Field to visible. + * @param urlStr String URL + * @return URL is valid + */ + public static boolean isValidURL(String urlStr) { + try { + URL url = new URL(urlStr); + HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); + urlc.setRequestProperty("Connection", "close"); + urlc.setConnectTimeout(1000 * 10); // mTimeout is in seconds + urlc.connect(); + if (urlc.getResponseCode() == 200) { + Log.v("Note", "ResponseCode: " + urlc.getResponseCode()); + return true; + } else { + return false; + } + } catch (MalformedURLException e1) { + return false; + } catch (IOException e) { + return false; + } + } + + /** + * + * @param url String + * @param username String + * @param password String + * @return Username and Password are a valid Login-Combination for the given URL. + */ + public static boolean isValidLogin(String url, String username, String password) { + try { + String targetURL = url + "index.php/apps/notes/api/v0.2/notes"; + Log.v("Note", targetURL); + HttpURLConnection con = (HttpURLConnection) new URL(targetURL) + .openConnection(); + con.setRequestMethod("GET"); + con.setRequestProperty( + "Authorization", + "Basic " + + new String(Base64.encode((username + ":" + + password).getBytes(), Base64.NO_WRAP))); + con.setConnectTimeout(10 * 1000); // 10 seconds + con.connect(); + if (con.getResponseCode() == 200) { + return true; + } + } catch (MalformedURLException e1) { + return false; + } catch (IOException e) { + return false; + } + return false; + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/ic_action_cancel.png b/app/src/main/res/drawable-hdpi/ic_action_cancel.png new file mode 100644 index 00000000..71d5e118 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_cancel.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_copy.png b/app/src/main/res/drawable-hdpi/ic_action_copy.png new file mode 100644 index 00000000..c170a270 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_copy.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_delete.png b/app/src/main/res/drawable-hdpi/ic_action_delete.png new file mode 100644 index 00000000..21287cbd Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_delete.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_done.png b/app/src/main/res/drawable-hdpi/ic_action_done.png new file mode 100644 index 00000000..c6503fd0 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_done.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_done_dark.png b/app/src/main/res/drawable-hdpi/ic_action_done_dark.png new file mode 100644 index 00000000..392a259e Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_done_dark.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_edit.png b/app/src/main/res/drawable-hdpi/ic_action_edit.png new file mode 100644 index 00000000..02e19d04 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_edit.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_new.png b/app/src/main/res/drawable-hdpi/ic_action_new.png new file mode 100644 index 00000000..0fdced8f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_new.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_settings.png b/app/src/main/res/drawable-hdpi/ic_action_settings.png new file mode 100644 index 00000000..a1a19400 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_share.png b/app/src/main/res/drawable-hdpi/ic_action_share.png new file mode 100644 index 00000000..0c460c47 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_share.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 00000000..439747ce Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_cancel.png b/app/src/main/res/drawable-mdpi/ic_action_cancel.png new file mode 100644 index 00000000..46907806 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_cancel.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_copy.png b/app/src/main/res/drawable-mdpi/ic_action_copy.png new file mode 100644 index 00000000..afd28ddd Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_copy.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_delete.png b/app/src/main/res/drawable-mdpi/ic_action_delete.png new file mode 100644 index 00000000..9b0e2dbd Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_delete.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_done.png b/app/src/main/res/drawable-mdpi/ic_action_done.png new file mode 100644 index 00000000..4eb240b3 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_done.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_done_dark.png b/app/src/main/res/drawable-mdpi/ic_action_done_dark.png new file mode 100644 index 00000000..3f9b108f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_done_dark.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_edit.png b/app/src/main/res/drawable-mdpi/ic_action_edit.png new file mode 100644 index 00000000..5a06bff5 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_edit.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_new.png b/app/src/main/res/drawable-mdpi/ic_action_new.png new file mode 100644 index 00000000..67bb598e Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_new.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_settings.png b/app/src/main/res/drawable-mdpi/ic_action_settings.png new file mode 100644 index 00000000..8a2f886d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_share.png b/app/src/main/res/drawable-mdpi/ic_action_share.png new file mode 100644 index 00000000..1cafd213 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_share.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 00000000..de725181 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_cancel.png b/app/src/main/res/drawable-xhdpi/ic_action_cancel.png new file mode 100644 index 00000000..172acd0f Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_cancel.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_copy.png b/app/src/main/res/drawable-xhdpi/ic_action_copy.png new file mode 100644 index 00000000..c4d15780 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_copy.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_delete.png b/app/src/main/res/drawable-xhdpi/ic_action_delete.png new file mode 100644 index 00000000..beb1637e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_delete.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_done.png b/app/src/main/res/drawable-xhdpi/ic_action_done.png new file mode 100644 index 00000000..c297f32d Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_done.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_done_dark.png b/app/src/main/res/drawable-xhdpi/ic_action_done_dark.png new file mode 100644 index 00000000..3400099d Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_done_dark.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_edit.png b/app/src/main/res/drawable-xhdpi/ic_action_edit.png new file mode 100644 index 00000000..d6668a05 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_edit.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_new.png b/app/src/main/res/drawable-xhdpi/ic_action_new.png new file mode 100644 index 00000000..d64c22e9 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_new.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_settings.png b/app/src/main/res/drawable-xhdpi/ic_action_settings.png new file mode 100644 index 00000000..2fbddd2f Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_share.png b/app/src/main/res/drawable-xhdpi/ic_action_share.png new file mode 100644 index 00000000..e275d938 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_share.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 00000000..be0cc6a5 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_cancel.png b/app/src/main/res/drawable-xxhdpi/ic_action_cancel.png new file mode 100644 index 00000000..ef610fb4 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_cancel.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_copy.png b/app/src/main/res/drawable-xxhdpi/ic_action_copy.png new file mode 100644 index 00000000..eead97da Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_copy.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_delete.png b/app/src/main/res/drawable-xxhdpi/ic_action_delete.png new file mode 100644 index 00000000..026c3313 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_delete.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_done.png b/app/src/main/res/drawable-xxhdpi/ic_action_done.png new file mode 100644 index 00000000..e43c8985 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_done.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_done_dark.png b/app/src/main/res/drawable-xxhdpi/ic_action_done_dark.png new file mode 100644 index 00000000..7f67ee04 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_done_dark.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_edit.png b/app/src/main/res/drawable-xxhdpi/ic_action_edit.png new file mode 100644 index 00000000..377b2e8d Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_edit.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_new.png b/app/src/main/res/drawable-xxhdpi/ic_action_new.png new file mode 100644 index 00000000..7e699137 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_new.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_settings.png b/app/src/main/res/drawable-xxhdpi/ic_action_settings.png new file mode 100644 index 00000000..ccdaf494 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_share.png b/app/src/main/res/drawable-xxhdpi/ic_action_share.png new file mode 100644 index 00000000..19c907fd Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_share.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..4f2f0572 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_cancel.png b/app/src/main/res/drawable-xxxhdpi/ic_action_cancel.png new file mode 100644 index 00000000..ba88f122 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_cancel.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_copy.png b/app/src/main/res/drawable-xxxhdpi/ic_action_copy.png new file mode 100644 index 00000000..cf9da9d1 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_copy.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_delete.png b/app/src/main/res/drawable-xxxhdpi/ic_action_delete.png new file mode 100644 index 00000000..7cc287bd Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_delete.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_done.png b/app/src/main/res/drawable-xxxhdpi/ic_action_done.png new file mode 100644 index 00000000..7cec5ed4 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_done.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_done_dark.png b/app/src/main/res/drawable-xxxhdpi/ic_action_done_dark.png new file mode 100644 index 00000000..e63d05b4 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_done_dark.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_edit.png b/app/src/main/res/drawable-xxxhdpi/ic_action_edit.png new file mode 100644 index 00000000..bde8b21c Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_edit.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_new.png b/app/src/main/res/drawable-xxxhdpi/ic_action_new.png new file mode 100644 index 00000000..165c907d Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_new.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_settings.png b/app/src/main/res/drawable-xxxhdpi/ic_action_settings.png new file mode 100644 index 00000000..06bf6e3c Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_share.png b/app/src/main/res/drawable-xxxhdpi/ic_action_share.png new file mode 100644 index 00000000..04be4201 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_share.png differ diff --git a/app/src/main/res/drawable/list_item_background_selector.xml b/app/src/main/res/drawable/list_item_background_selector.xml new file mode 100644 index 00000000..bd502458 --- /dev/null +++ b/app/src/main/res/drawable/list_item_background_selector.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/list_item_color_selector.xml b/app/src/main/res/drawable/list_item_color_selector.xml new file mode 100644 index 00000000..14de8d58 --- /dev/null +++ b/app/src/main/res/drawable/list_item_color_selector.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/list_item_color_selector_low.xml b/app/src/main/res/drawable/list_item_color_selector_low.xml new file mode 100644 index 00000000..727f5c93 --- /dev/null +++ b/app/src/main/res/drawable/list_item_color_selector_low.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/settings.xml b/app/src/main/res/drawable/settings.xml new file mode 100644 index 00000000..3f626603 --- /dev/null +++ b/app/src/main/res/drawable/settings.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml new file mode 100644 index 00000000..31bfe772 --- /dev/null +++ b/app/src/main/res/layout/activity_about.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_create.xml b/app/src/main/res/layout/activity_create.xml new file mode 100644 index 00000000..03b6ba66 --- /dev/null +++ b/app/src/main/res/layout/activity_create.xml @@ -0,0 +1,24 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml new file mode 100644 index 00000000..a9134c2b --- /dev/null +++ b/app/src/main/res/layout/activity_edit.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_notes_list_view.xml b/app/src/main/res/layout/activity_notes_list_view.xml new file mode 100644 index 00000000..128eec61 --- /dev/null +++ b/app/src/main/res/layout/activity_notes_list_view.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 00000000..2a079658 --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + +