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
8 changes: 4 additions & 4 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.malinovsky239">

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

Expand All @@ -10,7 +10,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="com.csc.malinovsky239.todoList.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -19,8 +19,8 @@
</activity>

<provider
android:name=".ReaderContentProvider"
android:authorities="com.csc.lesson6"
android:name="com.csc.malinovsky239.todoList.ReaderContentProvider"
android:authorities="com.csc.malinovsky239.todoList.ReaderContentProvider"
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.

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

This file was deleted.

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

import android.provider.BaseColumns;

interface FeedsTable extends BaseColumns {
String TABLE_NAME = "tasks";
String COLUMN_NAME = "name";
String COLUMN_IS_DONE = "is_done";
String COLUMN_DATETIME = "datetime";
String COLUMN_ID = "_id";
}
93 changes: 93 additions & 0 deletions app/src/main/java/com/csc/malinovsky239/todoList/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.csc.malinovsky239.todoList;

import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.csc.malinovsky239.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

final String order = FeedsTable.COLUMN_IS_DONE + ", " + FeedsTable.COLUMN_DATETIME;
TodoListCursorAdapter todoListAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Cursor cursor = getContentResolver().query(Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries"), new String[]{}, null, new String[]{}, order);
ListView taskList = (ListView) findViewById(R.id.taskList);
todoListAdapter = new TodoListCursorAdapter(this, cursor);
taskList.setAdapter(todoListAdapter);

taskList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView text = (TextView) view.findViewById(R.id.task);
showChangeTaskDialog(String.valueOf(text.getText()), (text.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) != 0,
(int) view.getTag());
}
});

Button add = (Button) findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ContentValues values = new ContentValues();
values.put(FeedsTable.COLUMN_NAME, String.valueOf(((EditText) findViewById(R.id.taskname)).getText()));
SimpleDateFormat format = new SimpleDateFormat(getString(R.string.datetimeFormat), Locale.getDefault());
values.put(FeedsTable.COLUMN_DATETIME, format.format(new Date()));
values.put(FeedsTable.COLUMN_IS_DONE, getString(R.string.FALSE));
getContentResolver().insert(Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries"), values);
Cursor cursor = getContentResolver().query(Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries"), new String[]{}, null, new String[]{}, order);
todoListAdapter.changeCursor(cursor);
}
});
}

public void showChangeTaskDialog(String taskname, boolean isDone, final int id) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.change_task_dialog, null);
dialogBuilder.setView(dialogView);
EditText edit_taskname = (EditText) dialogView.findViewById(R.id.edit_taskname);
edit_taskname.setText(taskname);
CheckBox is_done = (CheckBox) dialogView.findViewById(R.id.is_done);
is_done.setChecked(isDone);

dialogBuilder.setTitle(R.string.ChangeTaskButton);

dialogBuilder.setPositiveButton(R.string.DoneButton, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ContentValues values = new ContentValues();
int is_done = ((CheckBox) dialogView.findViewById(R.id.is_done)).isChecked() ? R.string.TRUE : R.string.FALSE;
values.put(FeedsTable.COLUMN_IS_DONE, getString(is_done));
String name = String.valueOf(((EditText) dialogView.findViewById(R.id.edit_taskname)).getText());
values.put(FeedsTable.COLUMN_NAME, name);
getContentResolver().update(Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries"), values, "_id = " + id, null);
Cursor cursor = getContentResolver().query(Uri.withAppendedPath(ReaderContentProvider.CONTENT_URI, "entries"), new String[]{}, null, new String[]{}, order);
todoListAdapter.changeCursor(cursor);
}
});
AlertDialog b = dialogBuilder.create();
b.show();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.csc.lesson6;
package com.csc.malinovsky239.todoList;

import android.content.ContentProvider;
import android.content.ContentValues;
Expand All @@ -9,7 +9,7 @@
import android.net.Uri;

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

public static final int ENTRIES = 1;
Expand Down Expand Up @@ -83,7 +83,15 @@ public Cursor query(Uri uri, String[] projection, String selection,
@Override
public int update(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");
}
return helper.getWritableDatabase().update(tableName, values, selection, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.csc.lesson6;
package com.csc.malinovsky239.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 = 1;
public static final String DATABASE_NAME = "reader.db";
public static final String DATABASE_NAME = "ToDoList";
static final String TASKS_TABLE_NAME = "tasks";

private static final String SQL_CREATE_ENTRIES_TABLE = "";
public static final String SQL_CREATE_ENTRIES_TABLE =
" CREATE TABLE " + TASKS_TABLE_NAME +
" (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" name TEXT NOT NULL, " +
" is_done BOOLEAN NOT NULL, " +
" datetime DATETIME NOT NULL);";

private static final String SQL_DELETE_ENTRIES = "";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.csc.malinovsky239.todoList;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.csc.malinovsky239.R;

public class TodoListCursorAdapter extends CursorAdapter {
public TodoListCursorAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.item_todo, parent, false);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tvTask = (TextView) view.findViewById(R.id.task);
TextView tvDatetime = (TextView) view.findViewById(R.id.datetime);
String task = cursor.getString(cursor.getColumnIndexOrThrow(FeedsTable.COLUMN_NAME));
String datetime = cursor.getString(cursor.getColumnIndexOrThrow(FeedsTable.COLUMN_DATETIME));
tvTask.setText(task);
tvDatetime.setText(datetime);
String isDone = cursor.getString(cursor.getColumnIndexOrThrow(FeedsTable.COLUMN_IS_DONE));
int id = cursor.getInt(cursor.getColumnIndexOrThrow(FeedsTable.COLUMN_ID));
view.setTag(id);
if (isDone.equals("TRUE")) {
tvTask.setPaintFlags(tvTask.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
tvDatetime.setPaintFlags(tvDatetime.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
tvTask.setPaintFlags(tvTask.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
tvDatetime.setPaintFlags(tvDatetime.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
}
}
18 changes: 18 additions & 0 deletions app/src/main/res/layout/change_task_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">

<EditText
android:id="@+id/edit_taskname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />

<CheckBox
android:id="@+id/is_done"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
20 changes: 20 additions & 0 deletions app/src/main/res/layout/item_todo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
android:id="@+id/task"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />

<TextView
android:id="@+id/datetime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />

</LinearLayout>
32 changes: 32 additions & 0 deletions app/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:id="@+id/taskname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textCapSentences|textAutoComplete" />

<Button
android:id="@+id/add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="@string/Add" />
</LinearLayout>

<ListView
android:id="@+id/taskList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Список задач</string>
<string name="ChangeTaskButton">Изменить задачу</string>
<string name="DoneButton">Готово</string>
<string name="Add">Добавить</string>
</resources>
8 changes: 7 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<resources>
<string name="app_name">lesson6</string>
<string name="app_name">ToDo List</string>
<string name="Add">Add</string>
<string name="datetimeFormat" translatable="false">yyyy-MM-dd HH:mm</string>
<string name="FALSE" translatable="false">FALSE</string>
<string name="TRUE" translatable="false">TRUE</string>
<string name="ChangeTaskButton">Change task</string>
<string name="DoneButton">Done</string>
</resources>