diff --git a/app/build.gradle b/app/build.gradle index 5c04260..0fb124a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "23.0.2" defaultConfig { - applicationId "com.csc.lesson6" + applicationId "ru.csc.vikulov.todolist" minSdkVersion 15 targetSdkVersion 23 versionCode 1 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7ab0b4b..d1864fa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="ru.csc.vikulov.todolist"> @@ -19,10 +19,11 @@ + android:exported="true" /> + - \ No newline at end of file + diff --git a/app/src/main/java/com/csc/lesson6/FeedsTable.java b/app/src/main/java/com/csc/lesson6/FeedsTable.java deleted file mode 100644 index be48cec..0000000 --- a/app/src/main/java/com/csc/lesson6/FeedsTable.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.csc.lesson6; - -import android.provider.BaseColumns; - -interface FeedsTable extends BaseColumns { - String TABLE_NAME = "feeds"; - - String COLUMN_TITLE = "title"; - String COLUMN_DATE = "date"; - String COLUMN_CONTENT = "content"; -} diff --git a/app/src/main/java/com/csc/lesson6/MainActivity.java b/app/src/main/java/com/csc/lesson6/MainActivity.java deleted file mode 100644 index 14ccad0..0000000 --- a/app/src/main/java/com/csc/lesson6/MainActivity.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.csc.lesson6; - -import android.content.ContentValues; -import android.database.ContentObserver; -import android.database.Cursor; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; -import android.view.View; - -import static com.csc.lesson6.FeedsTable.COLUMN_CONTENT; -import static com.csc.lesson6.FeedsTable.COLUMN_TITLE; - -public class MainActivity extends AppCompatActivity { - public static final String TAG = "MainActivity"; - - public static final Uri ENTRIES_URI = Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries"); - - private final ContentObserver observer = new ContentObserver(new Handler()) { - @Override - public void onChange(boolean selfChange) { - super.onChange(selfChange); - Log.d(TAG, "ContentObserver: onChange"); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - Cursor cursor = managedQuery(ENTRIES_URI, - null, null, null, null); - - cursor.registerContentObserver(observer); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - getContentResolver().unregisterContentObserver(observer); - } - - public void addData(View view) { - ContentValues values = new ContentValues(); - values.put(COLUMN_TITLE, - "new title3"); - values.put(FeedsTable.COLUMN_CONTENT, - ""); - values.put(FeedsTable.COLUMN_DATE, - "Mon, 28 Mar 2016 19:04:05 +0300"); - getContentResolver().insert( - ENTRIES_URI, - values); - } -} diff --git a/app/src/main/java/com/csc/lesson6/ReaderContentProvider.java b/app/src/main/java/com/csc/lesson6/ReaderContentProvider.java deleted file mode 100644 index f8e6c21..0000000 --- a/app/src/main/java/com/csc/lesson6/ReaderContentProvider.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.csc.lesson6; - -import android.content.ContentProvider; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.UriMatcher; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteQueryBuilder; -import android.net.Uri; -import android.support.annotation.NonNull; - -public class ReaderContentProvider extends ContentProvider { - public static final String AUTHORITY = "com.csc.lesson6"; - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); - - public static final int ENTRIES = 1; - public static final int ENTRIES_ID = 2; - - private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); - - static { - uriMatcher.addURI(AUTHORITY, "/entries", ENTRIES); - uriMatcher.addURI(AUTHORITY, "/entries/#", ENTRIES_ID); - } - - private ReaderOpenHelper helper; - - public ReaderContentProvider() { - helper = new ReaderOpenHelper(getContext()); - } - - @Override - public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { - // Implement this to handle requests to delete one or more rows. - throw new UnsupportedOperationException("Not yet implemented"); - } - - @Override - public String getType(@NonNull Uri uri) { - // TODO: Implement this to handle requests for the MIME type of the data - // at the given URI. - throw new UnsupportedOperationException("Not yet implemented"); - } - - @Override - public Uri insert(@NonNull Uri uri, ContentValues values) { - int match = uriMatcher.match(uri); - String tableName; - switch (match) { - case ENTRIES: - tableName = FeedsTable.TABLE_NAME; - break; - case ENTRIES_ID: - default: - throw new UnsupportedOperationException("Not yet implemented"); - } - long rowId = helper.getWritableDatabase().insert(tableName, null, values); - Uri inserted = ContentUris.withAppendedId(uri, rowId); - getContext().getContentResolver().notifyChange(inserted, null); - return inserted; - } - - @Override - public boolean onCreate() { - helper = new ReaderOpenHelper(getContext()); - return true; - } - - @Override - public Cursor query(@NonNull Uri uri, String[] projection, String selection, - String[] selectionArgs, String sortOrder) { - int match = uriMatcher.match(uri); - SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); - switch (match) { - case ENTRIES: - builder.setTables(FeedsTable.TABLE_NAME); - break; - default: - throw new UnsupportedOperationException("Not yet implemented"); - } - SQLiteDatabase db = helper.getReadableDatabase(); - Cursor cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder); - cursor.setNotificationUri(getContext().getContentResolver(), uri); - return cursor; - } - - @Override - public int update(@NonNull Uri uri, ContentValues values, String selection, - String[] selectionArgs) { - // TODO: Implement this to handle requests to update one or more rows. - throw new UnsupportedOperationException("Not yet implemented"); - } -} diff --git a/app/src/main/java/com/csc/lesson6/ReaderOpenHelper.java b/app/src/main/java/ru/csc/vikulov/todolist/DatabaseHelper.java similarity index 63% rename from app/src/main/java/com/csc/lesson6/ReaderOpenHelper.java rename to app/src/main/java/ru/csc/vikulov/todolist/DatabaseHelper.java index 368bb0a..d769406 100644 --- a/app/src/main/java/com/csc/lesson6/ReaderOpenHelper.java +++ b/app/src/main/java/ru/csc/vikulov/todolist/DatabaseHelper.java @@ -1,25 +1,27 @@ -package com.csc.lesson6; +package ru.csc.vikulov.todolist; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -public class ReaderOpenHelper extends SQLiteOpenHelper { - public static final int DATABASE_VERSION = 2; +public class DatabaseHelper extends SQLiteOpenHelper { + + public static final int DATABASE_VERSION = 4; public static final String DATABASE_NAME = "reader.db"; private static final String SQL_CREATE_ENTRIES_TABLE = "CREATE TABLE " + FeedsTable.TABLE_NAME + "(" + FeedsTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " - + FeedsTable.COLUMN_TITLE + " TEXT, " + FeedsTable.COLUMN_CONTENT + " TEXT, " - + FeedsTable.COLUMN_DATE + " TEXT" + + FeedsTable.COLUMN_DATE + " DATETIME, " + + FeedsTable.COLUMN_DONE + " BOOLEAN, " + + FeedsTable.COLUMN_PRIOR + " BOOLEAN" + ")"; private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + FeedsTable.TABLE_NAME; - public ReaderOpenHelper(Context context) { + public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @@ -29,16 +31,7 @@ public void onCreate(SQLiteDatabase db) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(SQL_DELETE_ENTRIES); - switch (oldVersion) { - case 1: -// ... - break; - case 2: -// ... - break; - default: - throw new IllegalStateException(); - } onCreate(db); } + } diff --git a/app/src/main/java/ru/csc/vikulov/todolist/FeedsTable.java b/app/src/main/java/ru/csc/vikulov/todolist/FeedsTable.java new file mode 100644 index 0000000..1360d46 --- /dev/null +++ b/app/src/main/java/ru/csc/vikulov/todolist/FeedsTable.java @@ -0,0 +1,13 @@ +package ru.csc.vikulov.todolist; + +import android.provider.BaseColumns; + + +public interface FeedsTable extends BaseColumns { + String TABLE_NAME = "feeds"; + + String COLUMN_CONTENT = "content"; + String COLUMN_DATE = "date"; + String COLUMN_DONE = "done"; + String COLUMN_PRIOR = "prior"; +} diff --git a/app/src/main/java/ru/csc/vikulov/todolist/MainActivity.java b/app/src/main/java/ru/csc/vikulov/todolist/MainActivity.java new file mode 100644 index 0000000..4cbed6f --- /dev/null +++ b/app/src/main/java/ru/csc/vikulov/todolist/MainActivity.java @@ -0,0 +1,83 @@ +package ru.csc.vikulov.todolist; + +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.LoaderManager; +import android.support.v4.content.CursorLoader; +import android.support.v4.content.Loader; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ListView; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks { + + private static final String TAG = "MainActivity"; + + public static final Uri ENTRIES_URI = Uri.withAppendedPath(ToDoListContentProvider.CONTENT_URI, "entries"); + + private static final String SORT_ORDER = FeedsTable.COLUMN_DONE + " , " + + FeedsTable.COLUMN_DATE + " ASC , " + + FeedsTable.COLUMN_PRIOR + " DESC"; + + private static final String FALSE = "FALSE"; + + private Button addButton; + private EditText addEditText; + private ListView listViewTasks; + private TaskListAdapter cursorAdapterListView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + listViewTasks = (ListView) findViewById(R.id.lvTasks); + cursorAdapterListView = new TaskListAdapter(this, null, 0); + listViewTasks.setAdapter(cursorAdapterListView); + + addButton = (Button) findViewById(R.id.add_button); + addEditText = (EditText) findViewById(R.id.add_editText); + + addButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ContentValues values = new ContentValues(); + SimpleDateFormat format = new SimpleDateFormat(getString(R.string.date_format), Locale.getDefault()); + + values.put(FeedsTable.COLUMN_CONTENT, String.valueOf((addEditText.getText()))); + values.put(FeedsTable.COLUMN_DATE, format.format(new Date())); + values.put(FeedsTable.COLUMN_DONE, FALSE); + values.put(FeedsTable.COLUMN_PRIOR, FALSE); + getContentResolver().insert(ENTRIES_URI, values); + + addEditText.setText(""); + } + }); + + getSupportLoaderManager().initLoader(0, null, this); + } + + @Override + public Loader onCreateLoader(int id, Bundle args) { + return new CursorLoader(this, ENTRIES_URI, null, null, null, SORT_ORDER); + } + + @Override + public void onLoadFinished(Loader loader, Cursor data) { + cursorAdapterListView.swapCursor(data); + } + + + @Override + public void onLoaderReset(Loader loader) { + cursorAdapterListView.swapCursor(null); + } +} diff --git a/app/src/main/java/ru/csc/vikulov/todolist/TaskListAdapter.java b/app/src/main/java/ru/csc/vikulov/todolist/TaskListAdapter.java new file mode 100644 index 0000000..d6ca412 --- /dev/null +++ b/app/src/main/java/ru/csc/vikulov/todolist/TaskListAdapter.java @@ -0,0 +1,196 @@ +package ru.csc.vikulov.todolist; + +import android.app.AlertDialog; +import android.content.ContentValues; +import android.content.Context; +import android.content.DialogInterface; +import android.database.Cursor; +import android.graphics.Paint; +import android.net.Uri; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.CursorAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + + +public class TaskListAdapter extends CursorAdapter { + + private static final String TAG = "TaskListAdapter"; + + private static final String TRUE = "TRUE"; + + private static final String FALSE = "FALSE"; + + private final LayoutInflater layoutInflater; + + public TaskListAdapter(Context context, Cursor cursor, int flags) { + super(context, cursor, flags); + layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + public static class ViewHolder { + public CheckBox checkBox; + public TextView textView; + public TextView dateView; + public CheckBox checkBoxStar; + public LinearLayout textAll; + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + View view = layoutInflater.inflate(R.layout.task_item, parent, false); + + ViewHolder holder = new ViewHolder(); + + holder.checkBox = (CheckBox) view.findViewById(R.id.checkBox); + holder.textView = (TextView) view.findViewById(R.id.textView); + holder.dateView = (TextView) view.findViewById(R.id.textViewDate); + holder.checkBoxStar = (CheckBox) view.findViewById(R.id.checkBoxStar); + holder.textAll = (LinearLayout) view.findViewById(R.id.description); + + + view.setTag(holder); + + return view; + } + + @Override + public void bindView(View view, final Context context, Cursor cursor) { + + final String content = cursor.getString(cursor.getColumnIndex(FeedsTable.COLUMN_CONTENT)); + final String date = cursor.getString(cursor.getColumnIndex(FeedsTable.COLUMN_DATE)); + final String done = cursor.getString(cursor.getColumnIndex(FeedsTable.COLUMN_DONE)); + final String prior = cursor.getString(cursor.getColumnIndex(FeedsTable.COLUMN_PRIOR)); + final String _id = cursor.getString(cursor.getColumnIndex(FeedsTable._ID)); + + final ViewHolder holder = (ViewHolder) view.getTag(); + + if (holder != null) { + holder.textView.setText(content); + holder.dateView.setText(date); + + if (done.equals(TRUE)) { + holder.checkBox.setChecked(true); + holder.textView.setPaintFlags(holder.textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); + } else { + holder.checkBox.setChecked(false); + holder.textView.setPaintFlags(holder.textView.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); + } + + if (prior.equals(TRUE)) { + holder.checkBoxStar.setChecked(true); + } else { + holder.checkBoxStar.setChecked(false); + } + + holder.textAll.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + + if (holder.checkBox.isChecked()) { + + new AlertDialog.Builder(context) + .setTitle(R.string.delete) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + context.getContentResolver().delete( + Uri.withAppendedPath(MainActivity.ENTRIES_URI, _id), + null, + null); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }) + .setCancelable(false) + .show(); + + } else { + final EditText taskDescription = new EditText(context); + taskDescription.setText(content); + + new AlertDialog.Builder(context) + .setTitle(R.string.new_task) + .setView(taskDescription) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String newTask = taskDescription.getText().toString(); + ContentValues values = new ContentValues(); + values.put(FeedsTable.COLUMN_CONTENT, newTask); + values.put(FeedsTable.COLUMN_DATE, date); + values.put(FeedsTable.COLUMN_DONE, done); + values.put(FeedsTable.COLUMN_PRIOR, prior); + + context.getContentResolver().update( + Uri.withAppendedPath(MainActivity.ENTRIES_URI, _id), + values, + null, + null); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }) + .setCancelable(false) + .show(); + } + + return true; + } + }); + + + holder.checkBox.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ContentValues values = new ContentValues(); + values.put(FeedsTable.COLUMN_CONTENT, content); + values.put(FeedsTable.COLUMN_DATE, date); + values.put(FeedsTable.COLUMN_PRIOR, prior); + + if (holder.checkBox.isChecked()) { + values.put(FeedsTable.COLUMN_DONE, TRUE); + } else { + values.put(FeedsTable.COLUMN_DONE, FALSE); + } + + context.getContentResolver().update(Uri.withAppendedPath(MainActivity.ENTRIES_URI, _id), + values, null, null); + } + }); + + holder.checkBoxStar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ContentValues values = new ContentValues(); + values.put(FeedsTable.COLUMN_CONTENT, content); + values.put(FeedsTable.COLUMN_DATE, date); + values.put(FeedsTable.COLUMN_DONE, done); + + if (holder.checkBoxStar.isChecked()) { + values.put(FeedsTable.COLUMN_PRIOR, TRUE); + } else { + values.put(FeedsTable.COLUMN_PRIOR, FALSE); + } + + context.getContentResolver().update(Uri.withAppendedPath(MainActivity.ENTRIES_URI, _id), + values, null, null); + } + }); + } + + + } +} diff --git a/app/src/main/java/ru/csc/vikulov/todolist/ToDoListContentProvider.java b/app/src/main/java/ru/csc/vikulov/todolist/ToDoListContentProvider.java new file mode 100644 index 0000000..d745eed --- /dev/null +++ b/app/src/main/java/ru/csc/vikulov/todolist/ToDoListContentProvider.java @@ -0,0 +1,183 @@ +package ru.csc.vikulov.todolist; + +import android.content.ContentProvider; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteQueryBuilder; +import android.net.Uri; +import android.text.TextUtils; +import android.util.Log; + +public class ToDoListContentProvider extends ContentProvider { + + private final String LOG_TAG = "myLogs"; + + private static final String CONTENT_PATH = "entries"; + + public static final String AUTHORITY = "ru.csc.vikulov.todolist.contentprovider"; + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); + public static final Uri ENTRIES_URI = Uri.withAppendedPath(ToDoListContentProvider.CONTENT_URI, CONTENT_PATH); + + public static final int ENTRIES = 1; + public static final int ENTRIES_ID = 2; + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(AUTHORITY, CONTENT_PATH, ENTRIES); + uriMatcher.addURI(AUTHORITY, CONTENT_PATH + "/#", ENTRIES_ID); + } + + private DatabaseHelper databaseHelper; + + + public ToDoListContentProvider() { + databaseHelper = new DatabaseHelper(getContext()); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "delete, " + uri.toString()); + } + switch (uriMatcher.match(uri)) { + case ENTRIES: + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "URI_CONTACTS"); + } + break; + case ENTRIES_ID: + String id = uri.getLastPathSegment(); + + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "URI_CONTACTS_ID, " + id); + } + + if (TextUtils.isEmpty(selection)) { + selection = FeedsTable._ID + " = " + id; + } else { + selection = selection + " AND " + FeedsTable._ID + " = " + id; + } + break; + default: + throw new IllegalArgumentException("Wrong URI: " + uri); + } + + SQLiteDatabase db = databaseHelper.getWritableDatabase(); + int cnt = db.delete(FeedsTable.TABLE_NAME, selection, selectionArgs); + getContext().getContentResolver().notifyChange(uri, null); + + return cnt; + } + + @Override + public String getType(Uri uri) { + // TODO: Implement this to handle requests for the MIME type of the data + // at the given URI. + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "insert, " + uri.toString()); + } + + if (uriMatcher.match(uri) != ENTRIES) + throw new IllegalArgumentException("Wrong URI: " + uri); + + long rowID = databaseHelper.getWritableDatabase().insert(FeedsTable.TABLE_NAME, null, values); + Uri resultUri = ContentUris.withAppendedId(uri, rowID); + getContext().getContentResolver().notifyChange(resultUri, null); + + return resultUri; + } + + @Override + public boolean onCreate() { + databaseHelper = new DatabaseHelper(getContext()); + + return true; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "query, " + uri.toString()); + } + + SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); + + switch (uriMatcher.match(uri)) { + case ENTRIES: + + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "ENTRIES"); + } + + builder.setTables(FeedsTable.TABLE_NAME); + +// if (TextUtils.isEmpty(sortOrder)) { +// sortOrder = FeedsTable.COLUMN_DONE + " , " +// + FeedsTable.COLUMN_DATE + " ASC , " +// + FeedsTable.COLUMN_PRIOR + " DESC"; +// } + + break; + case ENTRIES_ID: + break; + default: + throw new IllegalArgumentException("Wrong URI: " + uri); + } + + SQLiteDatabase db = databaseHelper.getReadableDatabase(); + Cursor cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder); + cursor.setNotificationUri(getContext().getContentResolver(), uri); + + return cursor; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "update, " + uri.toString()); + } + + switch (uriMatcher.match(uri)) { + case ENTRIES: + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "URI_CONTACTS"); + } + break; + case ENTRIES_ID: + String id = uri.getLastPathSegment(); + + if (BuildConfig.DEBUG) { + Log.d(LOG_TAG, "URI_CONTACTS_ID, " + id); + } + + if (TextUtils.isEmpty(selection)) { + selection = FeedsTable._ID + " = " + id; + } else { + selection = selection + " AND " + FeedsTable._ID + " = " + id; + } + break; + default: + throw new IllegalArgumentException("Wrong URI: " + uri); + } + + SQLiteDatabase db = databaseHelper.getWritableDatabase(); + int cnt = db.update(FeedsTable.TABLE_NAME, values, selection, selectionArgs); + getContext().getContentResolver().notifyChange(uri, null); + + return cnt; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b49b9e4 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,35 @@ + + + + + + + +