Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.csc.lesson6">
package="ru.csc.vikulov.todolist">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Expand All @@ -19,10 +19,11 @@
</activity>

<provider
android:name=".ReaderContentProvider"
android:authorities="com.csc.lesson6"
android:name=".ToDoListContentProvider"
android:authorities="ru.csc.vikulov.todolist.contentprovider"
android:enabled="true"
android:exported="true"></provider>
android:exported="true" />

</application>

</manifest>
</manifest>
11 changes: 0 additions & 11 deletions app/src/main/java/com/csc/lesson6/FeedsTable.java

This file was deleted.

58 changes: 0 additions & 58 deletions app/src/main/java/com/csc/lesson6/MainActivity.java

This file was deleted.

94 changes: 0 additions & 94 deletions app/src/main/java/com/csc/lesson6/ReaderContentProvider.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}

Expand All @@ -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);
}

}
13 changes: 13 additions & 0 deletions app/src/main/java/ru/csc/vikulov/todolist/FeedsTable.java
Original file line number Diff line number Diff line change
@@ -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";
}
83 changes: 83 additions & 0 deletions app/src/main/java/ru/csc/vikulov/todolist/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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<Cursor> {

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<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(this, ENTRIES_URI, null, null, null, SORT_ORDER);
}

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
cursorAdapterListView.swapCursor(data);
}


@Override
public void onLoaderReset(Loader loader) {
cursorAdapterListView.swapCursor(null);
}
}
Loading