Removed AndDown-Dependency and switched to Bypass library

This commit is contained in:
Stefan Niedermann 2015-10-21 17:47:07 +02:00
parent 41f9808f3f
commit f9a2efc692
18 changed files with 221 additions and 67 deletions

View file

@ -75,7 +75,7 @@
<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.commonsware.cwac/anddown/0.2.4/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" />
@ -96,7 +96,7 @@
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="gridlayout-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="anddown-0.2.4" level="project" />
<orderEntry type="library" exported="" name="bypasses-1.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
</component>

View file

@ -20,7 +20,7 @@ android {
}
dependencies {
compile 'com.commonsware.cwac:anddown:0.2.4'
compile 'com.commit451:bypasses:1.0.1'
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'

View file

@ -7,12 +7,6 @@ import junit.framework.TestCase;
* Created by stefan on 06.10.15.
*/
public class NoteUtilTest extends TestCase {
public void testParseMarkDown() {
assertTrue(NoteUtil.parseMarkDown("*cursive*").contains("<em>cursive</em>"));
assertTrue(NoteUtil.parseMarkDown("**bold**").contains("<strong>bold</strong>"));
assertTrue(NoteUtil.parseMarkDown("##header").contains("<h2>header</h2>"));
}
public void testRemoveMarkDown() {
assertTrue("Aufzählung".equals(NoteUtil.removeMarkDown("* Aufzählung")));
assertTrue("Header".equals(NoteUtil.removeMarkDown("# Header")));

View file

@ -60,7 +60,19 @@
android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity" >
</activity>
<!-- Widget -->
<!-- All Notes Widget -->
<receiver android:name="it.niedermann.owncloud.notes.android.widget.AllNotesWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/all_notes_widget_provider_info" />
</receiver>
<!-- Single Note Widget -->
<receiver android:name="it.niedermann.owncloud.notes.android.widget.SingleNoteWidget">
<intent-filter>

View file

@ -6,6 +6,7 @@ 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;

View file

@ -8,20 +8,20 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
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;
private Note note = null;
private int notePosition = 0;
private TextView noteContent = null;
private ActionBar actionBar = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -38,8 +38,8 @@ public class NoteActivity extends AppCompatActivity implements View.OnClickListe
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");
noteContent = (TextView) findViewById(R.id.singleNoteContent);
noteContent.setText(note.getSpannableContent());
}
@Override
@ -65,7 +65,7 @@ public class NoteActivity extends AppCompatActivity implements View.OnClickListe
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
NoteSQLiteOpenHelper db = null;
NoteSQLiteOpenHelper db;
switch (id) {
case R.id.menu_delete:
//setContentView(R.layout.activity_notes_list_view);
@ -106,7 +106,7 @@ public class NoteActivity extends AppCompatActivity implements View.OnClickListe
Note editedNote = (Note) data.getExtras().getSerializable(
EDIT_NOTE);
if (editedNote != null) {
noteContent.loadData(editedNote.getHtmlContent(), "text/html", "UTF-8");
noteContent.setText(editedNote.getSpannableContent());
actionBar.setTitle(editedNote.getTitle());
actionBar.setSubtitle(editedNote.getModified("dd.MM.yyyy HH:mm"));
}

View file

@ -31,6 +31,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
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";
public final static String CREDENTIALS_CHANGED = "it.niedermann.owncloud.notes.CREDENTIALS_CHANGED";
private final static int create_note_cmd = 0;
private final static int show_single_note_cmd = 1;
@ -211,7 +212,13 @@ public class NotesListViewActivity extends AppCompatActivity implements
adapter.remove(adapter.getItem(notePosition));
adapter.add(editedNote);
}
} else if (requestCode == SettingsActivity.CREDENTIALS_CHANGED) {
Log.v("Note", "Credentials Changed!!");
}
Log.v("Note", "New NoteSQLteOpenHelper instanciated");
//TODO Maybe only if previous activity == settings activity?
//db = new NoteSQLiteOpenHelper(this);
//db.synchronizeWithServer(); // Needed to instanciate new NotesClient with new URL
setListView(db.getNotes());
}
@ -293,6 +300,17 @@ public class NotesListViewActivity extends AppCompatActivity implements
}
}
/**
* Removes all selections.
*/
private void removeSelection() {
SparseBooleanArray checkedItemPositions = listView
.getCheckedItemPositions();
for (int i = 0; i < checkedItemPositions.size(); i++) {
listView.setItemChecked(i, false);
}
}
/**
* Handler for the MultiSelect Actions
*/
@ -345,15 +363,4 @@ public class NotesListViewActivity extends AppCompatActivity implements
adapter.notifyDataSetChanged();
}
}
/**
* Removes all selections.
*/
private void removeSelection() {
SparseBooleanArray checkedItemPositions = listView
.getCheckedItemPositions();
for (int i = 0; i < checkedItemPositions.size(); i++) {
listView.setItemChecked(i, false);
}
}
}

View file

@ -1,5 +1,6 @@
package it.niedermann.owncloud.notes.android.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
@ -27,6 +28,7 @@ public class SettingsActivity extends AppCompatActivity implements View.OnClickL
public static final String SETTINGS_USERNAME = "settingsUsername";
public static final String SETTINGS_PASSWORD = "settingsPassword";
public static final String DEFAULT_SETTINGS = "";
public static final int CREDENTIALS_CHANGED = 3;
private SharedPreferences preferences = null;
private EditText field_url = null;
@ -164,6 +166,10 @@ public class SettingsActivity extends AppCompatActivity implements View.OnClickL
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(getApplicationContext());
db.synchronizeWithServer();
final Intent data = new Intent();
//FIXME send correct note back to NotesListView
data.putExtra(NotesListViewActivity.CREDENTIALS_CHANGED, CREDENTIALS_CHANGED);
setResult(RESULT_OK, data);
finish();
} else {
Log.v("Note", "Invalid Credentials!");

View file

@ -1,8 +1,126 @@
package it.niedermann.owncloud.notes.android.widget;
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;
import android.widget.RemoteViewsService;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.model.Note;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
/**
* Widget to display a List of all notes
* Created by stefan on 08.10.15.
*/
public class AllNotesWidget {
public class AllNotesWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
Log.v("AllNotesWidget", "onUpdate appWidgetId: " + appWidgetId);
// Set up the intent that starts the StackViewService, which will
// provide the views for this collection.
Intent intent = new Intent(context, StackWidgetService.class);
// Add the app widget ID to the intent extras.
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
// Instantiate the RemoteViews object for the app widget layout.
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_all_notes);
rv.setRemoteAdapter(appWidgetIds[i], intent);
appWidgetManager.updateAppWidget(appWidgetId, rv);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.layout.widget_all_notes);
}
}
class StackWidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new StackRemoteViewsFactory(this.getApplicationContext(), intent);
}
}
class StackRemoteViewsFactory implements
RemoteViewsService.RemoteViewsFactory {
private static final int mCount = 10;
private List<Note> mWidgetItems = new ArrayList<Note>();
private Context mContext;
private int mAppWidgetId;
public StackRemoteViewsFactory(Context context, Intent intent) {
mContext = context;
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
Log.v("AllNotesWidget", "StackRemoteViewsFactory()");
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(mContext);
db.synchronizeWithServer();
mWidgetItems = db.getNotes();
mWidgetItems.add(new Note(0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung"));
}
public void onCreate() {
Log.v("AllNotesWidget", "StackRemoteViewsFactory.onCreate");
mWidgetItems.add(new Note(0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung"));
}
@Override
public void onDataSetChanged() {
}
@Override
public void onDestroy() {
}
@Override
public int getCount() {
return mWidgetItems.size();
}
@Override
public RemoteViews getViewAt(int position) {
Log.v("AllNotesWidget", "StackRemoteViewsFactory.getViewAt()");
// Construct a remote views item based on the app widget item XML file,
// and set the text based on the position.
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.fragment_notes_list_view);
rv.setTextViewText(R.id.list_view, mWidgetItems.get(position).getTitle());
// Return the remote views object.
return rv;
}
@Override
public RemoteViews getLoadingView() {
return null;
}
@Override
public int getViewTypeCount() {
return 0;
}
@Override
public long getItemId(int position) {
return mWidgetItems.get(position).getId();
}
@Override
public boolean hasStableIds() {
return false;
}
}
}

View file

@ -5,7 +5,6 @@ import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.widget.RemoteViews;
@ -22,7 +21,7 @@ public class SingleNoteWidget extends AppWidgetProvider {
public static void updateAppWidget(Note note, Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
if (note != null) {
updateViews.setTextViewText(R.id.singleNoteContent, Html.fromHtml(note.getHtmlContent()));
updateViews.setTextViewText(R.id.singleNoteContent, note.getSpannableContent());
}
appWidgetManager.updateAppWidget(appWidgetId, updateViews);

View file

@ -15,7 +15,7 @@ public class Note implements Serializable {
private Calendar modified = null;
private String content = "";
private String excerpt = "";
private String htmlContent = null;
private String spannableContent = null;
public Note(long id, Calendar modified, String title, String content) {
this.id = id;
@ -55,7 +55,7 @@ public class Note implements Serializable {
public void setContent(String content) {
setExcerpt(content);
this.content = content;
this.htmlContent = null;
this.spannableContent = null;
}
public String getExcerpt() {
@ -75,11 +75,11 @@ public class Note implements Serializable {
}
}
public String getHtmlContent() {
if(htmlContent == null && getContent() != null) {
htmlContent = NoteUtil.parseMarkDown(getContent());
public String getSpannableContent() {
if (spannableContent == null && getContent() != null) {
spannableContent = NoteUtil.parseMarkDown(getContent());
}
return htmlContent;
return spannableContent;
}
@Override

View file

@ -8,8 +8,8 @@ import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.util.Log;
import android.view.View;
import org.json.JSONException;
@ -34,14 +34,6 @@ public class NoteServerSyncHelper {
private NotesClient client = null;
private NoteSQLiteOpenHelper db = null;
private int operationsCount = 0;
private int operationsFinished = 0;
private Handler handler = null;
private List<ICallback> callbacks = new ArrayList<>();
private final View.OnClickListener goToSettingsListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -50,10 +42,10 @@ public class NoteServerSyncHelper {
parent.startActivity(intent);
}
};
public void addCallback(ICallback callback) {
callbacks.add(callback);
}
private int operationsCount = 0;
private int operationsFinished = 0;
private Handler handler = null;
private List<ICallback> callbacks = new ArrayList<>();
public NoteServerSyncHelper(NoteSQLiteOpenHelper db) {
this.db = db;
@ -76,6 +68,10 @@ public class NoteServerSyncHelper {
client = new NotesClient(url, username, password);
}
public void addCallback(ICallback callback) {
callbacks.add(callback);
}
public void synchronize() {
uploadEditedNotes();
uploadNewNotes();

View file

@ -1,25 +1,22 @@
package it.niedermann.owncloud.notes.util;
import android.text.Html;
import com.commonsware.cwac.anddown.AndDown;
import in.uncod.android.bypass.Bypass;
/**
* Provides basic functionality for Note operations.
* Created by stefan on 06.10.15.
*/
public class NoteUtil {
private static final Bypass bypass = new Bypass();
private static final AndDown and_down = new AndDown();
/**
* Parses a MarkDown-String and returns its HTML-Pendant
*
* @param s String MarkDown
* @return String HTML
* Parses a MarkDown-String and returns a Spannable
* @param s String - MarkDown
* @return Spannable
*/
public static String parseMarkDown(String s) {
return and_down.markdownToHtml(s);
return bypass.markdownToSpannable(s).toString();
}
/**
@ -29,7 +26,7 @@ public class NoteUtil {
* @return Plain Text-String
*/
public static String removeMarkDown(String s) {
return s == null ? "" : Html.fromHtml(and_down.markdownToHtml(s)).toString().trim();
return s == null ? "" : s.replaceAll("[#*-]", "").trim();
}
/**

View file

@ -5,13 +5,18 @@
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/singleNoteContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fg_default" />
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_edit"
style="@style/fab"

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>

View file

@ -11,6 +11,6 @@
android:background="@color/bg_transparent"
android:padding="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fg_default" />
android:textColor="@color/fg_contrast" />
</FrameLayout>

View file

@ -5,7 +5,7 @@
<color name="primary">#1d2d44</color>
<color name="primary_dark">#112233</color>
<color name="bg_transparent">#99f3f3f3</color>
<color name="bg_transparent">#aa081a2f</color>
<color name="bg_highlighted">#f3f3f3</color>
<color name="bg_normal">#ffffff</color>
<color name="fg_default">#000000</color>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_single_note"
android:minHeight="146dp"
android:minWidth="292dp"
android:resizeMode="vertical"
android:updatePeriodMillis="86400000"
android:widgetCategory="keyguard|home_screen" />