Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Fixes example
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Frank committed Dec 17, 2015
1 parent 46b977e commit edb4a57
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 32 deletions.
8 changes: 4 additions & 4 deletions examples/Notes/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

apt {
arguments {
manifest variant.outputs[0].processResources.manifestFile
}
apt {
arguments {
manifest notesManifest
}
}

Expand Down
12 changes: 12 additions & 0 deletions examples/Notes/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest
package="com.arconsis.notes"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:droitateddb="http://droitateddb.org"
android:versionCode="1"
android:versionName="1.0">

Expand All @@ -24,6 +25,17 @@
</activity>
<activity android:name=".ui.NotesActivity"/>
<activity android:name=".ui.EditNoteActivity"/>

<provider
android:name="com.arconsis.notes.generated.NoteContentProvider"
android:authorities="org.droitateddb.provider.notes"
android:exported="false"
droitateddb:generated="true"/>
<provider
android:name="com.arconsis.notes.generated.UserContentProvider"
android:authorities="com.arconsis.notes.generated.provider.user"
android:exported="false"
droitateddb:generated="true"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.arconsis.notes.generated.DB;

import org.droitateddb.config.Persistence;
import org.droitateddb.hooks.Create;
import org.droitateddb.hooks.DbCreate;
Expand All @@ -16,13 +18,12 @@ public class UpdateHook implements DbUpdate, DbCreate {

@Override
public void onUpdate(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
// db.execSQL("DROP TABLE IF EXISTS " + DB.NoteTable.TABLE_NAME);
// db.execSQL("DROP TABLE IF EXISTS " + DB.UserTable.TABLE_NAME);
// db.execSQL("DROP TABLE IF EXISTS " + DB.UserNoteAssociation.TABLE_NAME);
// db.execSQL(DB.NoteTable.SQL_CREATION);
// db.execSQL(DB.UserTable.SQL_CREATION);
// db.execSQL(DB.UserNoteAssociation.SQL_CREATION);
db.execSQL("asd");
db.execSQL("DROP TABLE IF EXISTS " + DB.NoteTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + DB.UserTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + DB.UserNoteAssociation.TABLE_NAME);
db.execSQL(DB.NoteTable.SQL_CREATION);
db.execSQL(DB.UserTable.SQL_CREATION);
db.execSQL(DB.UserNoteAssociation.SQL_CREATION);

db.execSQL("CREATE INDEX simple_idx on Simple (_id)");
db.execSQL("CREATE INDEX note_idx on Note (_id, fk_user)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -11,6 +12,8 @@
import com.arconsis.notes.NotesApplication;
import com.arconsis.notes.R;
import com.arconsis.notes.db.Note;
import com.arconsis.notes.generated.DB;
import com.arconsis.notes.generated.NoteContentProvider;

import org.droitateddb.EntityService;

Expand Down Expand Up @@ -57,9 +60,9 @@ public boolean onOptionsItemSelected(final MenuItem item) {
Note newNote = new Note(title.getText().toString(), content.getText().toString(), new Date());
NotesApplication.get().getUser().addNote(newNote);
newNote.setUser(NotesApplication.get().getUser());
// Uri saved = NoteContentProvider.uriForItem(DB.NoteTable.TABLE_NAME, noteService.save(newNote));
Uri saved = NoteContentProvider.uriForItem(DB.NoteTable.TABLE_NAME, noteService.save(newNote));
Intent result = new Intent();
// result.setData(saved);
result.setData(saved);
setResult(CODE_CREATED, result);
finish();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.arconsis.notes.NotesApplication;
import com.arconsis.notes.R;
import com.arconsis.notes.db.User;
import com.arconsis.notes.generated.DB;
import com.arconsis.notes.preferences.LoginPreferences;

import org.droitateddb.EntityService;
Expand Down Expand Up @@ -86,8 +87,7 @@ protected void onDestroy() {
}

private List<User> findUserByName() {
// return userService.find(DB.UserTable.NAME.columnName() + "=?", new String[]{user.getText().toString()}, null);
return null;
return userService.find(DB.UserTable.NAME.columnName() + "=?", new String[]{user.getText().toString()}, null);
}

private boolean checkLoginData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.TextView;

import com.arconsis.notes.R;
import com.arconsis.notes.generated.DB;

public class NoteCursorAdapter extends CursorAdapter {

Expand All @@ -35,7 +36,7 @@ private void setDataToView(final View view, final Cursor cursor) {
icon.setImageResource(R.drawable.note);

TextView text = (TextView) view.findViewById(R.id.text);
// text.setText(cursor.getString(DB.NoteTable.TITLE.columnIndex()));
text.setText(cursor.getString(DB.NoteTable.TITLE.columnIndex()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.CursorAdapter;

import com.arconsis.notes.NotesApplication;
import com.arconsis.notes.db.User;
import com.arconsis.notes.generated.DB;

import org.droitateddb.BaseContentProvider;

public class NoteLoaderCallback implements LoaderCallbacks<Cursor> {

Expand All @@ -27,12 +31,12 @@ public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
if (loaderId == id) {
User user = NotesApplication.get().getUser();

// return new CursorLoader(context,
// BaseContentProvider.uri(DB.NoteTable.TABLE_NAME),
// DB.NoteTable.PROJECTION,
// DB.NoteTable.FK_USER.columnName() + "=?",
// new String[]{Integer.toString(user.getId())},
// null);
return new CursorLoader(context,
BaseContentProvider.uri(DB.NoteTable.TABLE_NAME),
DB.NoteTable.PROJECTION,
DB.NoteTable.FK_USER.columnName() + "=?",
new String[]{Integer.toString(user.getId())},
null);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.arconsis.notes.NotesApplication;
import com.arconsis.notes.R;
import com.arconsis.notes.db.Note;
import com.arconsis.notes.generated.DB;
import com.arconsis.notes.preferences.LoginPreferences;
import com.arconsis.notes.ui.NoteDialog.NoteDialogAction;

import org.droitateddb.BaseContentProvider;
import org.droitateddb.DbConsumer;
import org.droitateddb.DbCreator;
import org.droitateddb.EntityService;
import org.droitateddb.FlatEntityParcelable;
Expand Down Expand Up @@ -50,13 +53,13 @@ protected void onCreate(final Bundle savedInstanceState) {
@Override
public boolean onItemLongClick(final AdapterView<?> adapterView, final View view, final int postition, final long id) {
Cursor cursor = (Cursor) noteCursorAdapter.getItem(postition);
// int noteId = cursor.getInt(DB.NoteTable._ID.columnIndex());
// if (noteService.delete(noteId)) {
// getLoaderManager().getLoader(NOTE_LOADER_ID).forceLoad();
// Toast.makeText(NotesActivity.this, R.string.delete_success, Toast.LENGTH_LONG).show();
// } else {
// Toast.makeText(NotesActivity.this, R.string.delete_fail, Toast.LENGTH_LONG).show();
// }
int noteId = cursor.getInt(DB.NoteTable._ID.columnIndex());
if (noteService.delete(noteId)) {
getLoaderManager().getLoader(NOTE_LOADER_ID).forceLoad();
Toast.makeText(NotesActivity.this, R.string.delete_success, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(NotesActivity.this, R.string.delete_fail, Toast.LENGTH_LONG).show();
}
return true;
}
});
Expand Down Expand Up @@ -88,9 +91,12 @@ public boolean onOptionsItemSelected(final MenuItem item) {
return true;
} else if (R.id.delete_all == item.getItemId()) {
getContentResolver().delete(BaseContentProvider.uri(Note.class.getSimpleName()), null, null);
SQLiteDatabase db = DbCreator.getInstance(this).getWritableDatabase();
// db.delete(DB.UserNoteAssociation.TABLE_NAME, null, null);
db.close();
DbCreator.getInstance(this).consumeDatabase(new DbConsumer() {
@Override
public void consume(SQLiteDatabase db) {
db.delete(DB.UserNoteAssociation.TABLE_NAME, null, null);
}
});
NotesApplication.get().getUser().getNotes().clear();
getLoaderManager().getLoader(NOTE_LOADER_ID).forceLoad();
} else if (R.id.logout == item.getItemId()) {
Expand Down

0 comments on commit edb4a57

Please sign in to comment.