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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ android {

dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'me.priyesh:chroma:1.0.2'
}
4 changes: 2 additions & 2 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="com.csc.tasklist">

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

Expand All @@ -20,7 +20,7 @@

<provider
android:name=".ReaderContentProvider"
android:authorities="com.csc.lesson6"
android:authorities="com.csc.tasklist"
android:enabled="true"
android:exported="true"></provider>
</application>
Expand Down
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.

14 changes: 14 additions & 0 deletions app/src/main/java/com/csc/tasklist/FeedsTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.csc.tasklist;

import android.provider.BaseColumns;

interface FeedsTable extends BaseColumns {
String TABLE_NAME = "TTASKLIST";

String COLUMN_HEADER = "CHEADER";
String COLUMN_BODY = "CBODY";
String COLUMN_DATE = "CDATE";
String COLUMN_DONE = "CDONE";
String COLUMN_STAR = "CSTAR";
String COLUMN_COLOR = "CCOLOR";
}
104 changes: 104 additions & 0 deletions app/src/main/java/com/csc/tasklist/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.csc.tasklist;

import android.app.ActionBar;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.Calendar;

import me.priyesh.chroma.ChromaDialog;
import me.priyesh.chroma.ColorMode;
import me.priyesh.chroma.ColorSelectListener;

public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private Button btnAddTask;
Cursor cursor;
TaskAdapter taskAdapter;
public static final Uri ENTRIES_URI = Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries");



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
btnAddTask = (Button) findViewById(R.id.add_task);
btnAddTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(getString(R.string.header_alert));
final LinearLayout ll = (LinearLayout) getLayoutInflater().inflate(R.layout.task_alert, null);
builder.setView(ll);


builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ContentValues values = new ContentValues();
String header = ((EditText) ll.findViewById(R.id.alert_header)).getText().toString();
String body = ((EditText) ll.findViewById(R.id.alert_body)).getText().toString();
values.put(FeedsTable.COLUMN_HEADER, header);
values.put(FeedsTable.COLUMN_BODY, body);
values.put(FeedsTable.COLUMN_COLOR, Color.WHITE);
getContentResolver().insert(ENTRIES_URI, values);
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();
}
});

ListView listTasks = (ListView) findViewById(R.id.list_tasks);
taskAdapter = new TaskAdapter(this, null, this);
listTasks.setAdapter(taskAdapter);
getSupportLoaderManager().initLoader(0, null, this);
}

@Override
protected void onDestroy() {
super.onDestroy();
}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(this, ENTRIES_URI, null, null, null, FeedsTable.COLUMN_DONE + ", " + FeedsTable.COLUMN_STAR + " DESC, " + FeedsTable.COLUMN_DATE + " DESC");
}

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

@Override
public void onLoaderReset(Loader<Cursor> loader) {
taskAdapter.swapCursor(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.csc.lesson6;
package com.csc.tasklist;

import android.content.ContentProvider;
import android.content.ContentUris;
Expand All @@ -11,7 +11,7 @@
import android.support.annotation.NonNull;

public class ReaderContentProvider extends ContentProvider {
public static final String AUTHORITY = "com.csc.lesson6";
public static final String AUTHORITY = "com.csc.tasklist";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);

public static final int ENTRIES = 1;
Expand All @@ -32,8 +32,18 @@ public ReaderContentProvider() {

@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");
int match = uriMatcher.match(uri);
String tableName;
switch (match) {
case ENTRIES:
tableName = FeedsTable.TABLE_NAME;
break;
default:
throw new UnsupportedOperationException("Not yet implemented");
}
int count = helper.getWritableDatabase().delete(tableName, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
return count;
}

@Override
Expand All @@ -51,7 +61,6 @@ public Uri insert(@NonNull Uri uri, ContentValues values) {
case ENTRIES:
tableName = FeedsTable.TABLE_NAME;
break;
case ENTRIES_ID:
default:
throw new UnsupportedOperationException("Not yet implemented");
}
Expand Down Expand Up @@ -88,7 +97,17 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection,
@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");
int match = uriMatcher.match(uri);
String tableName;
switch (match) {
case ENTRIES:
tableName = FeedsTable.TABLE_NAME;
break;
default:
throw new UnsupportedOperationException("Not yet implemented");
}
int count = helper.getWritableDatabase().update(tableName, values, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package com.csc.lesson6;
package com.csc.tasklist;

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 static final String DATABASE_NAME = "reader.db";
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "tasklist.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_HEADER + " TEXT, "
+ FeedsTable.COLUMN_BODY + " TEXT, "
+ FeedsTable.COLUMN_DATE + " DATETIME DEFAULT CURRENT_TIMESTAMP, "
+ FeedsTable.COLUMN_DONE + " INTEGER DEFAULT 0, " //BOOLEAN
+ FeedsTable.COLUMN_STAR + " INTEGER DEFAULT 0, " //BOOLEAN
+ FeedsTable.COLUMN_COLOR + " INTEGER " //COLOR
+ ")";

private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + FeedsTable.TABLE_NAME;

public ReaderOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
Expand All @@ -28,17 +29,6 @@ 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);
//skip now
}
}
Loading