Merge pull request #1 from stefan-niedermann/master

get up to date
This commit is contained in:
HeaDBanGer 2016-01-04 14:23:18 +01:00
commit bc30f1fecb
25 changed files with 362 additions and 300 deletions

View file

@ -1,13 +1,15 @@
# ownCloud Notes
An android client for OwnCloud Notes App.
An android client for [ownCloud Notes App](https://github.com/owncloud/notes/).
:construction: **Warning:** This app is beta. This means it is not tested well (only by some VMs and my personal device).
:arrow_forward: **Access:** Since this app is currently not available in any Appstore, i will provide some versions in [my ownCloud instance](http://owncloud.niedermann.it/index.php/s/BOM5V1VZwscFk1k). Feel free to download and distribute. But *be careful*: This kind of installation does not include any kind of automatic updates, so you will have to check manually for new security and feature updates.
## :rocket: Features
* List, Create, Edit, Share and Delete Notes
* Share Text and Links as new Note into the App
* Bulk Delete
* Render MarkDown (using [AndDown](https://github.com/commonsguy/cwac-anddown))
* Render MarkDown (using [Bypass](https://github.com/Uncodin/bypass))
* English, German and Serbian UI
## :checkered_flag: Planned Features
@ -30,8 +32,8 @@ An android client for OwnCloud Notes App.
* Send me a bottle of your favorite beer :beers: :wink:
## :link: Requirements
* [OwnCloud](https://github.com/owncloud/) instance running
* [OwnCloud Notes](https://github.com/owncloud/notes) app enabled
* [ownCloud](https://github.com/owncloud/) instance running
* [ownCloud Notes](https://github.com/owncloud/notes) app enabled
## :notebook: License
This Project is licensed under the [GNU GENERAL PUBLIC LICENSE](/LICENSE).

View file

@ -65,29 +65,23 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debugAndroidTest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/gridlayout-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.commit451/bypasses/1.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>

View file

@ -8,8 +8,8 @@ android {
applicationId "it.niedermann.owncloud.notes"
minSdkVersion 22
targetSdkVersion 23
versionCode 3
versionName "0.3.0"
versionCode 4
versionName "0.4.0"
}
buildTypes {
release {

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest
package="it.niedermann.owncloud.notes"
android:versionCode="3"
android:versionName="0.3.0">
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="4"
android:versionName="0.4.0">
<uses-sdk
android:minSdkVersion="11"

View file

@ -4,6 +4,7 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import it.niedermann.owncloud.notes.R;
public class AboutActivity extends AppCompatActivity {
@Override

View file

@ -8,7 +8,6 @@ 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 {
@ -49,10 +48,8 @@ public class CreateNoteActivity extends AppCompatActivity {
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));
data.putExtra(NotesListViewActivity.CREATED_NOTE, db.getNote(db.addNoteAndSync(content)));
setResult(RESULT_OK, data);
finish();
return true;

View file

@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.model.Note;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
import it.niedermann.owncloud.notes.util.ICallback;
public class EditNoteActivity extends AppCompatActivity {
private final long DELAY = 1000; // in ms
@ -82,15 +83,36 @@ public class EditNoteActivity extends AppCompatActivity {
}
note.setContent(((EditText) findViewById(R.id.editContent)).getText().toString());
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(this);
db.updateNoteAndSync(note);
if (ab != null) {
db.getNoteServerSyncHelper().addCallback(new ICallback() {
@Override
public void onFinish() {
runOnUiThread(new Runnable() {
@Override
public void run() {
getSupportActionBar().setSubtitle(getResources().getString(R.string.action_edit_saved));
}
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
getSupportActionBar().setSubtitle(null);
}
});
}
}, 1, TimeUnit.SECONDS);
}
});
/* TODO Notify widgets
int widgetIDs[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), SingleNoteWidget.class));
for (int id : widgetIDs) {
AppWidgetManager.getInstance(getApplication()).notifyAppWidgetViewDataChanged(id, R.layout.widget_single_note);
}*/
}
});
db.updateNoteAndSync(note);
}
}

View file

@ -69,6 +69,10 @@ public class NoteActivity extends AppCompatActivity implements View.OnClickListe
case R.id.menu_delete:
db = new NoteSQLiteOpenHelper(this);
db.deleteNoteAndSync(note.getId());
Intent data = new Intent();
data.putExtra(NotesListViewActivity.SELECTED_NOTE_POSITION,
notePosition);
setResult(RESULT_FIRST_USER, data);
finish();
return true;
case R.id.menu_share:
@ -102,11 +106,11 @@ public class NoteActivity extends AppCompatActivity implements View.OnClickListe
Note editedNote = (Note) data.getExtras().getSerializable(
EDIT_NOTE);
if (editedNote != null) {
noteContent.setText(editedNote.getSpannableContent());
actionBar.setTitle(editedNote.getTitle());
actionBar.setSubtitle(editedNote.getModified("dd.MM.yyyy HH:mm"));
note = editedNote;
noteContent.setText(note.getSpannableContent());
actionBar.setTitle(note.getTitle());
actionBar.setSubtitle(note.getModified("dd.MM.yyyy HH:mm"));
}
// TODO Fire changed note to noteslistviewactivity
data.putExtra(NotesListViewActivity.SELECTED_NOTE_POSITION,
notePosition);
setResult(RESULT_OK, data);

View file

@ -7,7 +7,6 @@ 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;
@ -71,8 +70,6 @@ public class NotesListViewActivity extends AppCompatActivity implements
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() {
@ -80,6 +77,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
setListView(db.getNotes());
}
});
db.synchronizeWithServer();
}
});
@ -196,7 +194,6 @@ public class NotesListViewActivity extends AppCompatActivity implements
Item item = adapter.getItem(position);
if (!item.isSection()) {
listView.setItemChecked(position, !listView.isItemChecked(position));
Log.v("Note", "getCheckedItemCount " + listView.getCheckedItemCount());
if (listView.getCheckedItemCount() < 1) {
removeSelection();
Intent intent = new Intent(getApplicationContext(),
@ -204,9 +201,6 @@ public class NotesListViewActivity extends AppCompatActivity implements
if (!item.isSection()) {
intent.putExtra(SELECTED_NOTE, (Note) item);
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
@ -267,24 +261,31 @@ public class NotesListViewActivity extends AppCompatActivity implements
if (resultCode == RESULT_OK) {
Note createdNote = (Note) data.getExtras().getSerializable(
CREATED_NOTE);
adapter.add(createdNote);
adapter.insert(createdNote, 0);
}
} else if (requestCode == NoteActivity.EDIT_NOTE_CMD) {
if (resultCode == RESULT_OK) {
Note editedNote = (Note) data.getExtras().getSerializable(
NoteActivity.EDIT_NOTE);
} else if (requestCode == show_single_note_cmd) {
if (resultCode == RESULT_OK || resultCode == RESULT_FIRST_USER) {
int notePosition = data.getExtras().getInt(
SELECTED_NOTE_POSITION);
adapter.remove(adapter.getItem(notePosition));
adapter.add(editedNote);
if (resultCode == RESULT_OK) {
Note editedNote = (Note) data.getExtras().getSerializable(
NoteActivity.EDIT_NOTE);
adapter.insert(editedNote, 0);
}
} else if (requestCode == SettingsActivity.CREDENTIALS_CHANGED) {
}
} else if (requestCode == server_settings) {
// Create new Instance with new URL and credentials
db = new NoteSQLiteOpenHelper(this);
db.synchronizeWithServer(); // Needed to instanciate new NotesClient with new URL
}
//TODO Maybe only if previous activity == settings activity?
db.getNoteServerSyncHelper().addCallback(new ICallback() {
@Override
public void onFinish() {
setListView(db.getNotes());
}
});
db.synchronizeWithServer();
}
}
/**
* Long click on one item in the list view. It starts the Action Mode and allows selecting more

View file

@ -11,9 +11,11 @@ import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
@ -91,20 +93,18 @@ public class SettingsActivity extends AppCompatActivity {
field_username.setText(preferences.getString(SETTINGS_USERNAME, DEFAULT_SETTINGS));
field_password.setText(preferences.getString(SETTINGS_PASSWORD, DEFAULT_SETTINGS));
field_password.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
login();
return true;
}
});
btn_submit.setOnClickListener(new View.OnClickListener() {
@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 += "/";
}
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
new LoginValidatorAsyncTask().execute(url, username, password);
login();
}
});
}
@ -119,6 +119,20 @@ public class SettingsActivity extends AppCompatActivity {
}
}
private void login() {
String url = field_url.getText().toString();
String username = field_username.getText().toString();
String password = field_password.getText().toString();
if (!url.endsWith("/")) {
url += "/";
}
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
new LoginValidatorAsyncTask().execute(url, username, password);
}
/************************************ Async Tasks ************************************/
/**

View file

@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;
@ -25,6 +26,11 @@ public class SingleNoteWidget extends AppWidgetProvider {
updateViews.setTextViewText(R.id.single_note_content, note.getSpannableContent());
Intent intent = new Intent(context, NoteActivity.class);
intent.putExtra(NotesListViewActivity.SELECTED_NOTE, note);
// http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget
Uri data = Uri.withAppendedPath(
Uri.parse("notes" + "://widget/id/")
, String.valueOf(appWidgetId));
intent.setData(data);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
updateViews.setOnClickPendingIntent(R.id.single_note, pendingIntent);
}

View file

@ -15,7 +15,6 @@ public class Note implements Item, Serializable {
private Calendar modified = null;
private String content = "";
private String excerpt = "";
private String spannableContent = null;
public Note(long id, Calendar modified, String title, String content) {
this.id = id;
@ -55,7 +54,6 @@ public class Note implements Item, Serializable {
public void setContent(String content) {
setExcerpt(content);
this.content = content;
this.spannableContent = null;
}
public String getExcerpt() {
@ -66,11 +64,9 @@ public class Note implements Item, Serializable {
excerpt = NoteUtil.generateNoteExcerpt(content);
}
public String getSpannableContent() {
if (spannableContent == null && getContent() != null) {
spannableContent = NoteUtil.parseMarkDown(getContent());
}
return spannableContent;
public CharSequence getSpannableContent() {
// TODO Cache the generated CharSequence not possible because CharSequence does not implement Serializable
return NoteUtil.parseMarkDown(getContent());
}
@Override

View file

@ -51,6 +51,7 @@ public class NoteServerSyncHelper {
for (ICallback callback : callbacks) {
callback.onFinish();
}
callbacks.clear();
}
};
SharedPreferences preferences = PreferenceManager
@ -64,10 +65,22 @@ public class NoteServerSyncHelper {
client = new NotesClient(url, username, password);
}
/**
* Adds a callback method to the NoteServerSyncHelper.
* All callbacks will be executed once all synchronize operations are done.
* After execution the callback will be deleted, so it has to be added again if it shall be
* executed the next time all synchronize operations are finished.
*
* @param callback Implementation of ICallback, contains one method that shall be executed.
*/
public void addCallback(ICallback callback) {
callbacks.add(callback);
}
/**
* Synchronizes Edited, New and Deleted Notes. After all changed content has been sent to the
* server, it downloads all changes that happened on the server.
*/
public void synchronize() {
uploadEditedNotes();
uploadNewNotes();
@ -75,12 +88,14 @@ public class NoteServerSyncHelper {
downloadNotes();
}
/**
* Helper method to check if all synchronize operations are done yet.
*/
private void asyncTaskFinished() {
operationsFinished++;
if (operationsFinished == operationsCount) {
handler.obtainMessage(1).sendToTarget();
}
}
public void uploadEditedNotes() {

View file

@ -12,11 +12,12 @@ public class NoteUtil {
/**
* Parses a MarkDown-String and returns a Spannable
*
* @param s String - MarkDown
* @return Spannable
*/
public static String parseMarkDown(String s) {
return bypass.markdownToSpannable(s).toString();
public static CharSequence parseMarkDown(String s) {
return bypass.markdownToSpannable(s);
}
/**

View file

@ -76,6 +76,7 @@ public class NotesClient {
/**
* Fetches a 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
@ -110,6 +111,7 @@ public class NotesClient {
/**
* 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

View file

@ -29,7 +29,6 @@ public class NotesClientUtil {
}
/**
*
* @param url String
* @param username String
* @param password String

View file

@ -1,22 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:id="@+id/editContentContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity"
android:id="@+id/editContentContainer" >
tools:context="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView2" >
android:layout_height="match_parent">
<EditText
android:id="@+id/editContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine" />
android:inputType="textMultiLine"
android:padding="16dp"/>
</ScrollView>
</LinearLayout>

View file

@ -41,7 +41,8 @@
android:id="@+id/settings_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_username" />
android:hint="@string/settings_username"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout

View file

@ -13,7 +13,7 @@
android:id="@+id/single_note_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:padding="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fg_default" />
</ScrollView>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
android:id="@+id/sectionItem"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="@color/bg_highlighted"
@ -17,6 +18,8 @@
android:layout_alignWithParentIfMissing="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textColor="@color/fg_default_selection"
android:textSize="12sp" />

View file

@ -32,7 +32,7 @@
<!-- About -->
<string name="about_version_title">Version</string>
<string name="about_version">Sie benutzen aktuell <strong>v0.3.0</strong></string>
<string name="about_version">Sie benutzen aktuell <strong>v0.4.0</strong></string>
<string name="about_author_title">Autor</string>
<string name="about_author">Diese Android-App wird entwickelt von <a href="http://www.niedermann.it/">Niedermann IT-Dienstleistungen</a></string>
<string name="about_app_icon_disclaimer_title">App-Icon</string>

View file

@ -21,7 +21,7 @@
<!-- About -->
<string name="about_version_title">Издање</string>
<string name="about_version">Текуће издање је <strong>0.3.0</strong></string>
<string name="about_version">Текуће издање је <strong>0.4.0</strong></string>
<string name="about_author_title">Аутор</string>
<string name="about_author">Ову апликацију за Андроид је направио и презентовао <a href="http://www.niedermann.it/">Niedermann IT-Dienstleistungen</a></string>
<string name="about_app_icon_disclaimer_title">Икона апликације</string>

View file

@ -32,7 +32,7 @@
<!-- About -->
<string name="about_version_title">Version</string>
<string name="about_version">You are currently using <strong>v0.3.0</strong></string>
<string name="about_version">You are currently using <strong>v0.4.0</strong></string>
<string name="about_author_title">Author</string>
<string name="about_author">This Android-Application is developed and presented by <a href="http://www.niedermann.it/">Niedermann IT-Dienstleistungen</a></string>
<string name="about_app_icon_disclaimer_title">App-Icon</string>

View file

@ -9,6 +9,7 @@
<!-- Snackbar Action Link -->
<item name="colorAccent">@color/primary</item>
<item name="android:buttonStyle">@style/ocbutton</item>
<item name="android:windowBackground">@color/bg_normal</item>
</style>
<style name="fab">
<item name="android:layout_margin">16dp</item>