Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TodoMan Activity 3 Final Version By Moez Jelassi #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
10 changes: 8 additions & 2 deletions todoman/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.uab.dedam.todoman">

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TaskActivity"></activity>
<receiver android:name=".NotificationPublisher" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.uab.dedam.todoman;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseOpenHelper extends SQLiteOpenHelper {


private static final String DATABASE_NAME = "todoman";
private static final int DATABASE_VERSION = 1;


static final String TASKS_TABLE_NAME = "tasks";
static final String _ID = "_id";
static final String TITLE = "Title";
static final String DESCRIPTION = "Description";
static final String COMPLETED = "Completed";
static final String ENDDATE = "EndDate";


static final String[] COLUMNS = {
_ID,
TITLE,
DESCRIPTION,
COMPLETED,
ENDDATE
};


private static final String CREATE_TASKS_TABLE =
"CREATE TABLE " + TASKS_TABLE_NAME + "( " +
_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
TITLE + " TEXT NOT NULL, " +
DESCRIPTION + " TEXT, " +
COMPLETED+ " TEXT, " +
ENDDATE + " TEXT)";


public DatabaseOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL(CREATE_TASKS_TABLE);
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {


}

}
42 changes: 42 additions & 0 deletions todoman/src/main/java/org/uab/dedam/todoman/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
package org.uab.dedam.todoman;

import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

public class HomeActivity extends AppCompatActivity {


private SQLiteDataRepository sqliteDatabase;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

sqliteDatabase = new SQLiteDataRepository(this);
sqliteDatabase.openDatabaseForReadOnly();
Cursor cursortoretrieve= sqliteDatabase.retrieveAllTasks();
ListView lvItems = (ListView) findViewById(R.id.ListVi);
TodoCursorAdapter todoAdapter = new TodoCursorAdapter(this, cursortoretrieve);
lvItems.setAdapter(todoAdapter);

Button newactivity = (Button) findViewById(R.id.NewTaskButton);
newactivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Intent intent = new Intent(HomeActivity.this, TaskActivity.class);
startActivity(intent);

}
}
);


}

@Override
protected void onResume() {
super.onResume();

sqliteDatabase = new SQLiteDataRepository(this);
sqliteDatabase.openDatabaseForReadOnly();
Cursor cursortoretrieve= sqliteDatabase.retrieveAllTasks();
ListView lvItems = (ListView) findViewById(R.id.ListVi);
TodoCursorAdapter todoAdapter = new TodoCursorAdapter(this, cursortoretrieve);
lvItems.setAdapter(todoAdapter);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.uab.dedam.todoman;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class NotificationPublisher extends BroadcastReceiver {



private static final int NOTIFICATIONID = 1;

public void onReceive(Context context, Intent intent) {

Intent intentnot = new Intent(context,HomeActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,1,intentnot,0);


NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentText("Task To Complete")
.setContentTitle("Urgent")
.setContentIntent(pendingIntent)
.setAutoCancel(true);

// Send the notification
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(
NOTIFICATIONID,
notificationBuilder.build()
);



}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.uab.dedam.todoman;

/**
* Created by kofax on 06/11/16.
*/


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class SQLiteDataRepository {


private DatabaseOpenHelper databaseOpenHelper;


private SQLiteDatabase sqliteDatabase;



public SQLiteDataRepository(Context context) {

this.databaseOpenHelper = new DatabaseOpenHelper(context);
}


public void openDatabaseForReadOnly() {

this.sqliteDatabase = this.databaseOpenHelper.getReadableDatabase();
}


public void openDatabaseForWrite() {

this.sqliteDatabase = this.databaseOpenHelper.getWritableDatabase();
}


public void saveTask(String title, String description,
String completed, String enddate) {

ContentValues values = new ContentValues();
values.put(DatabaseOpenHelper.TITLE, title);
values.put(DatabaseOpenHelper.DESCRIPTION, description);
values.put(DatabaseOpenHelper.COMPLETED, completed);
values.put(DatabaseOpenHelper.ENDDATE, enddate);

this.sqliteDatabase.insert(
DatabaseOpenHelper.TASKS_TABLE_NAME,
null,
values);
}



public Cursor retrieveAllTasks() {

Cursor result = this.sqliteDatabase.query(
DatabaseOpenHelper.TASKS_TABLE_NAME,
DatabaseOpenHelper.COLUMNS,
null,
null,
null,
null,
null);
return result;
}





public void release() {

if ( sqliteDatabase != null ) {
sqliteDatabase.close();
sqliteDatabase = null;
}
}
}
Loading