diff --git a/.gitignore b/.gitignore index 7307e71..dbba6d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,229 +1,10 @@ -################# -## Android -################# - -gen/ -out/ - -################# -## Android Studio/Intellij -################# - -.idea -*.iml - -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -############# -## Windows detritus -############# - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap +.gradle +/local.properties +/.idea/workspace.xml .DS_Store +/build.gradle +/project.properties +/gradlew +/gradlew.bat - -############# -## Python -############# - -*.py[co] - -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -#Translations -*.mo - -#Mr Developer -.mr.developer.cfg +.idea diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..01b420f --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +ClassNote \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..26aaedc --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b153e48 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..948386a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c80f219 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/AndroidManifest.xml b/AndroidManifest.xml deleted file mode 100644 index 437d64b..0000000 --- a/AndroidManifest.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ClassNote.iml b/ClassNote.iml new file mode 100644 index 0000000..d9c631d --- /dev/null +++ b/ClassNote.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..80eec1a --- /dev/null +++ b/build.gradle @@ -0,0 +1,16 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:0.9.+' + } +} + +allprojects { + repositories { + mavenCentral() + } +} diff --git a/classnote/.gitignore b/classnote/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/classnote/.gitignore @@ -0,0 +1 @@ +/build diff --git a/classnote/build.gradle b/classnote/build.gradle new file mode 100644 index 0000000..e343e94 --- /dev/null +++ b/classnote/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'android' + +android { + compileSdkVersion 19 + buildToolsVersion "19.0.1" + + defaultConfig { + minSdkVersion 8 + targetSdkVersion 19 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + runProguard false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} + +dependencies { + compile 'com.android.support:support-v4:19.0.1' + compile 'com.android.support:appcompat-v7:19.0.1' + compile fileTree(dir: 'libs', include: ['*.jar']) + compile files('libs/android-async-http-1.4.4.jar') +} diff --git a/classnote/classnote.iml b/classnote/classnote.iml new file mode 100644 index 0000000..8b13d6e --- /dev/null +++ b/classnote/classnote.iml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/classnote/libs/android-async-http-1.4.4.jar b/classnote/libs/android-async-http-1.4.4.jar new file mode 100644 index 0000000..75af701 Binary files /dev/null and b/classnote/libs/android-async-http-1.4.4.jar differ diff --git a/classnote/proguard-rules.txt b/classnote/proguard-rules.txt new file mode 100644 index 0000000..b7ef581 --- /dev/null +++ b/classnote/proguard-rules.txt @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:/Program Files (x86)/Android/android-studio1/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} \ No newline at end of file diff --git a/classnote/src/main/AndroidManifest.xml b/classnote/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7d793d7 --- /dev/null +++ b/classnote/src/main/AndroidManifest.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/auth/AuthenticationService.java b/classnote/src/main/java/com/hellabreakfast/classnote/auth/AuthenticationService.java new file mode 100644 index 0000000..311fc42 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/auth/AuthenticationService.java @@ -0,0 +1,17 @@ +package com.hellabreakfast.classnote.auth; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +/** + * This class is necessary for the AccountManager integration + */ +public class AuthenticationService extends Service { + + @Override + public IBinder onBind(Intent intent) { + return new GatechAccountAuthenticator(this).getIBinder(); + } + +} \ No newline at end of file diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/auth/GatechAccountAuthenticator.java b/classnote/src/main/java/com/hellabreakfast/classnote/auth/GatechAccountAuthenticator.java new file mode 100644 index 0000000..ee091ef --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/auth/GatechAccountAuthenticator.java @@ -0,0 +1,73 @@ +package com.hellabreakfast.classnote.auth; + +import android.accounts.AbstractAccountAuthenticator; +import android.accounts.Account; +import android.accounts.AccountAuthenticatorResponse; +import android.accounts.AccountManager; +import android.accounts.NetworkErrorException; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +import com.hellabreakfast.classnote.ui.UpdatePasswordActivity; + +/** + * This class is necessary for the AccountManager integration + */ +public class GatechAccountAuthenticator extends AbstractAccountAuthenticator { + + public static String ACCOUNT_TYPE = "edu.gatech.classnote"; + Context mContext; + + public GatechAccountAuthenticator(Context context) { + super(context); + this.mContext = context; + } + + @Override + public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { + return null; + } + + @Override + public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) + throws NetworkErrorException { + + final Bundle result; + final Intent intent; + + intent = new Intent(this.mContext, UpdatePasswordActivity.class); + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); + + result = new Bundle(); + result.putParcelable(AccountManager.KEY_INTENT, intent); + + return result; + } + + @Override + public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException { + return null; + } + + @Override + public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { + return null; + } + + @Override + public String getAuthTokenLabel(String authTokenType) { + return null; + } + + @Override + public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { + return null; + } + + @Override + public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { + return null; + } + +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/model/Announcement.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/Announcement.java new file mode 100644 index 0000000..3b953ab --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/Announcement.java @@ -0,0 +1,103 @@ +package com.hellabreakfast.classnote.model; + +import java.io.Serializable; +import java.util.Date; + +/** + * An Announcement is one of the T-Square, from-teacher notifications that are not actually assignments + * but should be visible within the list function, thus it implements DataItem so we know we can + * show it in our upcoming list + */ +public class Announcement implements Comparable, Serializable { + + public String name; + public String author; + public String description; + public Boolean isRead; + public Date dueDate; + public Course course; + public String id; + + public Announcement(String id, String name, String author, String description, Boolean isRead, Date dueDate) { + this.id = id; + this.name = name; + this.author = author; + this.description = description; + this.isRead = isRead; + this.dueDate = dueDate; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + + public Boolean getIsRead() { + return isRead; + } + + + public Date getDueDate() { + return dueDate; + } + + + public Course getCourse() { + return course; + } + + + public void setName(String name) { + this.name = name; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public void setIsRead(Boolean isRead) { + this.isRead = isRead; + } + + + public void setDueDate(Date dueDate) { + this.dueDate = dueDate; + } + + + public void setCourse(Course course) { + this.course = course; + } + + @Override + public int compareTo(Announcement announcement) { + return dueDate.compareTo(announcement.dueDate); + } + + @Override + public boolean equals(Object object) { + return object instanceof Announcement && ((Announcement)object).getId().equals(this.getId()); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/model/Assignment.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/Assignment.java new file mode 100644 index 0000000..7f9b31a --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/Assignment.java @@ -0,0 +1,27 @@ +package com.hellabreakfast.classnote.model; + +import java.io.Serializable; +import java.util.Date; + +/** + * An assignment is a normal, t-square assignment that will be shown in the assignments list + * and be able to be added to the final grade of the course + */ +public class Assignment extends GradedWork implements Comparable, Serializable { + private String id; + + public Assignment(String id, String name, String description, Boolean isRead, Date dueDate) { + super(name, description, isRead, dueDate, 0,0,0,0); + this.id = id; + } + + public String getId() { + return id; + } + + @Override + public int compareTo(Assignment assignment) { + return dueDate.compareTo(assignment.dueDate); + } + +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/model/AsyncResultHandler.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/AsyncResultHandler.java new file mode 100644 index 0000000..25b6781 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/AsyncResultHandler.java @@ -0,0 +1,8 @@ +package com.hellabreakfast.classnote.model; + +public interface AsyncResultHandler { + + public void onSuccess(); + public void onFailure(); + +} diff --git a/src/com/rumbleworks/classnote/Course.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/Course.java similarity index 51% rename from src/com/rumbleworks/classnote/Course.java rename to classnote/src/main/java/com/hellabreakfast/classnote/model/Course.java index 461b7f2..d8f306e 100644 --- a/src/com/rumbleworks/classnote/Course.java +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/Course.java @@ -1,5 +1,6 @@ -package com.rumbleworks.classnote; +package com.hellabreakfast.classnote.model; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -9,38 +10,35 @@ * one for objects that inherit from GradedWork (tests and assignments) * and the other for Announcements from the professor */ +public class Course implements Serializable { + + private String title, siteId; -public class Course { - private String courseName; - private String courseSchool; - private int courseNumber; - private ArrayList assignmentList; private ArrayList announcementList; - public Course(String courseName, String courseSchool, int courseNumber) { - this.courseName = courseName; - this.courseSchool = courseSchool; - this.courseNumber = courseNumber; - + public Course(String title, String siteId) { + this.title = title; + this.siteId = siteId; + this.assignmentList = new ArrayList(); this.announcementList = new ArrayList(); } - public String getCourseId() { - return courseSchool+" "+courseNumber; + public String getTitle() { + return title; } - public String getCourseName() { - return courseName; + public void setTitle(String title) { + this.title = title; } - public String getCourseSchool() { - return courseSchool; + public String getSiteId() { + return siteId; } - public int getCourseNumber() { - return courseNumber; + public void setSiteId(String siteId) { + this.siteId = siteId; } public List getAssignmentList() { @@ -52,12 +50,24 @@ public List getAnnouncementList() { } public void addAssignment(Assignment assignment) { + if (assignment.getId() != null) { + for (Assignment a : assignmentList) { + if (a.getId().equals(assignment.getId())) return; + } + } + assignment.setCourse(this); assignmentList.add(assignment); } public void addAnnouncement(Announcement announcement) { + announcement.setCourse(this); announcementList.add(announcement); } - + public boolean hasAnnouncement(Announcement announcement) { + if (announcementList.contains(announcement)) + return true; + else + return false; + } } diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/model/Datamart.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/Datamart.java new file mode 100644 index 0000000..dbdbca2 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/Datamart.java @@ -0,0 +1,263 @@ +package com.hellabreakfast.classnote.model; + +import android.app.Activity; + +import com.hellabreakfast.classnote.ui.ClassNoteApp; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.Observable; + +/** + * The datamart is a singleton object that contains all data in our application. It is serializable + * so it can be saved to disk. + */ +public class Datamart extends Observable implements Serializable { + + static String SAVE_FILE_NAME = "datamart-classnote"; + + static Datamart instance; + + private ArrayList courseList; + + private Date lastRefreshed; + + private String username; + + private boolean offline; + + private boolean[] visited = { false, false, false, false, false, true, true }; + private int currentScreen = 0; + + public Datamart() { + courseList = new ArrayList(); + } + + /** + * @return whether a user is logged in + */ + public static boolean isLoggedIn() { + return getInstance().getUsername() != null; + } + + /** + * @return the singleton instance of the Datamart + */ + public static Datamart getInstance() { + if (instance == null) { + instance = load(); + if (instance == null || !(instance instanceof Datamart)) { + instance = new Datamart(); + } + } + return instance; + } + + /** + * deletes the instance from the disk. (used for logout) + */ + public static void clearInstance() { + ClassNoteApp.getApplication().deleteFile(SAVE_FILE_NAME); + instance = null; + } + + /** + * saves the instance to disk. + */ + public void save() { + this.setChanged(); + this.notifyObservers(); + ObjectOutputStream objectOut = null; + try { + + FileOutputStream fileOut = ClassNoteApp.getApplication().getApplicationContext().openFileOutput(SAVE_FILE_NAME, Activity.MODE_PRIVATE); + + objectOut = new ObjectOutputStream(fileOut); + objectOut.writeObject(this); + fileOut.getFD().sync(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (objectOut != null) { + try { + objectOut.close(); + } catch (IOException e) { + } + } + } + } + + /** + * @return loads the model from disk and returns it + */ + public static Datamart load() { + ObjectInputStream objectIn = null; + Object object = null; + try { + ClassNoteApp application = ClassNoteApp.getApplication(); + FileInputStream fileIn = application.getApplicationContext().openFileInput(SAVE_FILE_NAME); + objectIn = new ObjectInputStream(fileIn); + object = objectIn.readObject(); + + } catch (FileNotFoundException e) { + // Do nothing + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } finally { + if (objectIn != null) { + try { + objectIn.close(); + } catch (IOException e) { + // do nowt + } + } + } + return (Datamart)object; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + /** + * @return the titles for the courses + */ + public List getCourseTitles() { + ArrayList courseTitles = new ArrayList(); + for (Course c : courseList) { + courseTitles.add(c.getTitle()); + } + return courseTitles; + } + + /** + * @param title + * @return the course object with the specified title + */ + public Course getCourseByTitle(String title) { + for (Course c : courseList) { + if (c.getTitle().equals(title)) return c; + } + return null; + } + + /** + * Getter for the announcements through the course + * @return + */ + public List getAllAnnouncements() { + List list = new LinkedList(); + for (Course c : getCourseList()) { + list.addAll(c.getAnnouncementList()); + } + return list; + } + + /** + * Getter for the assignments through the course + * @return + */ + public List getAllAssignments() { + List list = new LinkedList(); + for (Course c : getCourseList()) { + list.addAll(c.getAssignmentList()); + } + return list; + } + + /** + * Getter for upcoming assignments through the course + * @return + */ + public List getUpcomingAssignments() { + List list = new LinkedList(); + for (Course c : getCourseList()) { + for (Assignment a : c.getAssignmentList()) { + if (a != null && a.getDueDate().after(new Date())) { + list.add(a); + } + } + } + return list; + } + + /** + * Getter for past assignments through the course + * @return + */ + public List getPastAssignments() { + List list = new LinkedList(); + for (Course c : getCourseList()) { + for (Assignment a : c.getAssignmentList()) { + if (a != null && a.getDueDate().before(new Date())) { + list.add(a); + } + } + } + return list; + } + + + public List getCourseList() { + return courseList; + } + + /** + * adds the course to the datamart + * @param c The course to add + */ + public void addCourse(Course c) { + for (Course course : courseList) { + if (course.getSiteId().equals(c.getSiteId())) return; + } + courseList.add(c); + } + + public boolean[] getVisited() { + return visited; + } + public void setVisited( int index, boolean value ) { + visited[ index ] = value; + save(); + } + + + public int getCurrentScreen() { + return currentScreen; + } + public void setCurrentScreen( int currentScreen ) { + + this.currentScreen = currentScreen; + } + + public boolean isOffline() { + return offline; + } + + public void setOffline(boolean offline) { + this.offline = offline; + } + + public Date getLastRefreshed() { + return lastRefreshed; + } + + public void setLastRefreshed(Date lastRefreshed) { + this.lastRefreshed = lastRefreshed; + } +} diff --git a/src/com/rumbleworks/classnote/GradedWork.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/GradedWork.java similarity index 72% rename from src/com/rumbleworks/classnote/GradedWork.java rename to classnote/src/main/java/com/hellabreakfast/classnote/model/GradedWork.java index 7653dba..aa73559 100644 --- a/src/com/rumbleworks/classnote/GradedWork.java +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/GradedWork.java @@ -1,26 +1,26 @@ -package com.rumbleworks.classnote; +package com.hellabreakfast.classnote.model; +import java.io.Serializable; import java.util.Date; -public class GradedWork { +public class GradedWork implements Serializable { public String name; public String description; public Boolean isRead; public Date dueDate; - public String courseId; + public Course course; public double pointsEarned; public double pointsPossible; public double overallScore; public double percentageOfFinal; - public GradedWork(String name, String description, Boolean isRead, Date dueDate, String courseId, double pointsEarned, double pointsPossible, double overallScore, double percentageOfFinal) { + public GradedWork(String name, String description, Boolean isRead, Date dueDate, double pointsEarned, double pointsPossible, double overallScore, double percentageOfFinal) { this.name = name; this.description = description; this.isRead = isRead; this.dueDate = dueDate; - this.courseId = courseId; this.pointsEarned = pointsEarned; this.pointsPossible = pointsPossible; this.overallScore = overallScore; @@ -29,31 +29,27 @@ public GradedWork(String name, String description, Boolean isRead, Date dueDate, public String getName() { - // TODO Auto-generated method stub return name; } public String getDescription() { - // TODO Auto-generated method stub return description; } public Boolean getIsRead() { - // TODO Auto-generated method stub return isRead; } public Date getDueDate() { - // TODO Auto-generated method stub return dueDate; } - public String getCourseId() { - return courseId; + public Course getCourse() { + return course; } @@ -77,28 +73,24 @@ public void setDueDate(Date dueDate) { } - public void setCourseId(String courseId) { - this.courseId = courseId; + public void setCourse(Course course) { + this.course = course; } public double getPointsEarned() { - // TODO Auto-generated method stub return pointsEarned; } public double getPointsPossible() { - // TODO Auto-generated method stub return pointsPossible; } public double getOverallScore() { - // TODO Auto-generated method stub return overallScore; } public double getPercentageOfFinal() { - // TODO Auto-generated method stub return percentageOfFinal; } diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/model/TSquareAPI.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/TSquareAPI.java new file mode 100644 index 0000000..52019d7 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/TSquareAPI.java @@ -0,0 +1,232 @@ +package com.hellabreakfast.classnote.model; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.content.Intent; +import android.text.Html; +import android.util.Log; + +import com.loopj.android.http.AsyncHttpClient; +import com.loopj.android.http.AsyncHttpResponseHandler; +import com.loopj.android.http.RequestParams; +import com.hellabreakfast.classnote.ui.ClassNoteApp; +import com.hellabreakfast.classnote.auth.GatechAccountAuthenticator; +import com.hellabreakfast.classnote.ui.UpdatePasswordActivity; + +import org.apache.http.impl.client.BasicCookieStore; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Date; + +/** + * This class handles all of our interaction with the T-Square API thorugh static methods that login and refresh data. + */ +public class TSquareAPI { + // This cookie store holds the cookie that we get back when we login. + public static BasicCookieStore cookieStore = new BasicCookieStore(); + public static final String BASE_URL = "https://t-square.gatech.edu/direct"; + + /** + * Send a POST request to /direct/session with the specified credentials. Call the appropriate method of the handler on completion. + * + * @param username + * @param password + * @param handler The handler to be called with a success or failure message + */ + public static void login(final String username, final String password, final AsyncResultHandler handler) { + // Create a new HttpClient and Post Header + AsyncHttpClient client = new AsyncHttpClient(); + client.setCookieStore(TSquareAPI.cookieStore); + client.post(TSquareAPI.BASE_URL+"/session", new RequestParams("_username", username, "_password", password), new AsyncHttpResponseHandler() { + public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) { + if (statusCode == 201) { + if (handler != null) handler.onSuccess(); + Datamart.getInstance().setUsername(username); + Datamart.getInstance().setOffline(false); + } else { + if (handler != null) handler.onFailure(); + } + } + }); + } + + /** + * Loops through the courses and refreshes the list of announcements for each course and inserts the new data into the Datamart + */ + public static void refreshAnnouncements() { + for (Course c : Datamart.getInstance().getCourseList()) { + AsyncHttpClient client = new AsyncHttpClient(); + client.setCookieStore(TSquareAPI.cookieStore); + + //Execute get request using asynchttpclient for announcements 50 days old and 20 in number + final Course course = c; + client.get(TSquareAPI.BASE_URL + "/announcement/site/"+c.getSiteId()+".json", new AsyncHttpResponseHandler() { + + @Override + public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) { + try { + JSONObject res = new JSONObject(new String(responseBody)); + JSONArray ann = res.getJSONArray("announcement_collection"); + int len = ann.length(); + + //Need to trim the message to remove tags + for (int i = 0; i < len; i++) { + Announcement announcement = new Announcement( + ann.getJSONObject(i).getString("id"), + ann.getJSONObject(i).getString("title"), + ann.getJSONObject(i).getString("createdByDisplayName"), + (stripHtml(ann.getJSONObject(i).getString("body"))), + false, + new Date(ann.getJSONObject(i).getLong("createdOn"))); + if (!course.hasAnnouncement(announcement)) { + course.addAnnouncement(announcement); + } + } + Datamart.getInstance().save(); + } catch (JSONException e) { + + } + } + + }); + } + } + + /** + * Loops through the courses and refreshes the list of assignments for each course and inserts the new data into the Datamart + */ + public static void refreshAssignments() { + for (Course c : Datamart.getInstance().getCourseList()) { + AsyncHttpClient client = new AsyncHttpClient(); + client.setCookieStore(TSquareAPI.cookieStore); + + //Execute get request using asynchttpclient for announcements 50 days old and 20 in number + final Course course = c; + client.get(TSquareAPI.BASE_URL + "/assignment/site/"+c.getSiteId()+".json", new AsyncHttpResponseHandler() { + @Override + public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) { + try { + if (statusCode != 200) return; + JSONObject res = new JSONObject(new String(responseBody)); + JSONArray assArray = res.getJSONArray("assignment_collection"); + for (int i = 0; i < assArray.length(); i++) { + JSONObject assObject = assArray.optJSONObject(i); + JSONObject dueDateObject = assObject.optJSONObject("dueTime"); + Date dueDate = null; + if (dueDateObject != null) { + long dueDateInt = dueDateObject.optLong("time"); + dueDate = dueDateInt > 0 ? new Date(dueDateInt) : null; + } + JSONObject content = assObject.optJSONObject("content"); + //Log.d("Content: ", content.toString()); + + Assignment assignment = new Assignment(assObject.optString("id"),assObject.optString("title"),stripHtml(content.optString("instructions")),false, dueDate); + + course.addAssignment(assignment); + } + Datamart.getInstance().save(); + } catch (JSONException e) {} + } + }); + } + } + + + /** + * First refresh the list of courses from T-Square (making sure to only get courses for this semester), and then refresh the assignments and announcements. + */ + public static void refreshAll() { + AsyncHttpClient client = new AsyncHttpClient(); + client.setCookieStore(TSquareAPI.cookieStore); + + //Execute get request using asynchttpclient for announcements 50 days old and 20 in number + client.get(TSquareAPI.BASE_URL + "/site.json", new AsyncHttpResponseHandler() { + + @Override + public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) { + try { + JSONObject siteObject = new JSONObject(new String(responseBody)); + JSONArray siteArray = siteObject.getJSONArray("site_collection"); + + if (siteArray.length() == 0) { + tryReauth(); + return; + } + + //Need to trim the message to remove tags + for (int i = 0; i < siteArray.length(); i++) { + JSONObject site = siteArray.optJSONObject(i); + JSONObject props = site.optJSONObject("props"); + if (props == null) { + System.out.println("no props"); + continue; + } + String term = props.optString("term"); + if (term == null || !term.equals("SPRING 2014")) { + System.out.println("wrong term"); + continue; + } + + Course c = new Course(site.optString("title"), site.optString("entityId")); + Datamart.getInstance().addCourse(c); + } + Datamart.getInstance().setLastRefreshed(new Date()); + Datamart.getInstance().save(); + + TSquareAPI.refreshAnnouncements(); + TSquareAPI.refreshAssignments(); + } + catch (JSONException e) { + + } + } + + }); + } + + /** + * This method is called if our cookie expires. It retrieves the password from the AccountManager + * and logs in again to get a new cookie. Once it gets the cookie, it refreshes. + */ + public static void tryReauth() { + try { + AccountManager accountManager = AccountManager.get(ClassNoteApp.getApplication().getApplicationContext()); + Account account = new Account(Datamart.getInstance().getUsername(), GatechAccountAuthenticator.ACCOUNT_TYPE); + String password = accountManager.getPassword(account); + login(Datamart.getInstance().getUsername(), password, new AsyncResultHandler() { + @Override + public void onSuccess() { + refreshAll(); + } + + @Override + public void onFailure() { + requirePasswordUpdateToRefresh(); + } + }); + } catch (Exception e) { + requirePasswordUpdateToRefresh(); + } + } + + /** + * Start the password update activity (because the user has changed their T-Square password) + */ + public static void requirePasswordUpdateToRefresh() { + Intent intent = new Intent(ClassNoteApp.getApplication().getApplicationContext(), UpdatePasswordActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + ClassNoteApp.getApplication().startActivity(intent); + } + + /** + * Stripping html tags from the message + * @param html + * @return + */ + public static String stripHtml(String html) { + return Html.fromHtml(html).toString(); + } + +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/model/Test.java b/classnote/src/main/java/com/hellabreakfast/classnote/model/Test.java new file mode 100644 index 0000000..f882049 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/model/Test.java @@ -0,0 +1,10 @@ +package com.hellabreakfast.classnote.model; + +import java.util.Date; + +public class Test extends GradedWork { + + public Test(String name, String description, Boolean isRead, Date dueDate, double pointsEarned, double pointsPossible, double overallScore, double percentageOfFinal ) { + super(name, description, isRead, dueDate, pointsEarned, pointsPossible, overallScore, percentageOfFinal ); + } +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/AddAssignmentFragment.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AddAssignmentFragment.java new file mode 100644 index 0000000..2189435 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AddAssignmentFragment.java @@ -0,0 +1,73 @@ +package com.hellabreakfast.classnote.ui; + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TimePicker; + +import com.hellabreakfast.classnote.model.Assignment; +import com.hellabreakfast.classnote.model.Course; +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +public class AddAssignmentFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + public static final String ARG_SECTION_NUMBER = "section_number"; + + private Spinner courseSpinner; + private EditText titleField, descField; + private DatePicker datePicker; + private TimePicker timePicker; + + + public AddAssignmentFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_add_assignment, container, false); + + courseSpinner = (Spinner)rootView.findViewById(R.id.courseSpinner); + courseSpinner.setAdapter(new ArrayAdapter(getActivity().getApplicationContext(), android.R.layout.simple_spinner_item, Datamart.getInstance().getCourseTitles())); + + titleField = (EditText)rootView.findViewById(R.id.titleField); + descField = (EditText)rootView.findViewById(R.id.descField); + datePicker = (DatePicker)rootView.findViewById(R.id.datePicker); + timePicker = (TimePicker)rootView.findViewById(R.id.timePicker); + + Button saveButton = (Button)rootView.findViewById(R.id.saveAssignmentButton); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Calendar date = new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), timePicker.getCurrentHour(), timePicker.getCurrentMinute()); + Course c = Datamart.getInstance().getCourseByTitle((String)courseSpinner.getSelectedItem()); + Assignment assignment = new Assignment(null, titleField.getText().toString(), descField.getText().toString(), true, date.getTime()); + c.addAssignment(assignment); + + InputMethodManager imm = (InputMethodManager)getActivity().getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(descField.getWindowToken(), 0); + + ((MainActivity) getActivity() ).onNavigationDrawerItemSelected(1); + } + }); + + return rootView; + } +} \ No newline at end of file diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementAdapter.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementAdapter.java new file mode 100644 index 0000000..33ca620 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementAdapter.java @@ -0,0 +1,74 @@ +package com.hellabreakfast.classnote.ui; + +import android.app.Activity; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.hellabreakfast.classnote.model.Announcement; +import com.hellabreakfast.classnote.R; + +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.List; + +/** + * This class takes in a list of Announcements and uses it to populate a ListView + */ +public class AnnouncementAdapter extends BaseAdapter { + private List list; + private Activity activity; + private SimpleDateFormat dateFormat; + + public AnnouncementAdapter(List list, Activity activity) { + this.setList(list); + this.activity = activity; + dateFormat = new SimpleDateFormat("MMMM dd h:mm a"); + } + + /** + * Sets the list to use for the ListView, sorting it in reverse order (by posted date). + * @param list + */ + public void setList(List list) { + Collections.sort(list); + Collections.reverse(list); + this.list = list; + } + + @Override + public int getCount() { + return list.size(); + } + + @Override + public Object getItem(int i) { + return list.get(i); + } + + @Override + public long getItemId(int i) { + return 0; + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + if (view == null) { + LayoutInflater vi; + vi = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = vi.inflate(R.layout.list_item_announcement, null); + } + + Announcement announcement = (Announcement) getItem(i); + TextView courseTitleText = (TextView) view.findViewById(R.id.courseTitle); + TextView titleText = (TextView) view.findViewById(R.id.assignmentTitle); + TextView dueDateText = (TextView) view.findViewById(R.id.assignmentDueDate); + courseTitleText.setText(announcement.getCourse().getTitle()); + titleText.setText(announcement.getName()); + dueDateText.setText(dateFormat.format(announcement.getDueDate())); + return view; + } +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementDetailActivity.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementDetailActivity.java new file mode 100644 index 0000000..5b252e4 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementDetailActivity.java @@ -0,0 +1,36 @@ +package com.hellabreakfast.classnote.ui; + +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.widget.TextView; + +import com.hellabreakfast.classnote.model.Announcement; +import com.hellabreakfast.classnote.R; + +import java.text.SimpleDateFormat; + +/** + * Activity to display all details about an announcement + */ +public class AnnouncementDetailActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_announcement_details); + setTitle("Announcement"); + Announcement a = (Announcement)getIntent().getSerializableExtra("ANNOUNCEMENT"); + TextView title = (TextView)findViewById(R.id.announcement_details_title); + TextView author = (TextView)findViewById(R.id.announcement_details_author); + TextView courseName = (TextView)findViewById(R.id.announcement_details_class); + TextView description = (TextView)findViewById(R.id.announcement_details_description); + TextView dueDate = (TextView)findViewById(R.id.announcement_details_date); + title.setText(a.getName()); + author.setText("By "+a.getAuthor()); + courseName.setText(a.getCourse().getTitle()); + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM d h:mm a"); + dueDate.setText("Posted: "+dateFormat.format(a.getDueDate())+"\n"); + description.setText(a.getDescription()); + } + +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementListFragment.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementListFragment.java new file mode 100644 index 0000000..39b6188 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AnnouncementListFragment.java @@ -0,0 +1,58 @@ +package com.hellabreakfast.classnote.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +import com.hellabreakfast.classnote.model.Announcement; +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; + +import java.util.Observable; +import java.util.Observer; + +public class AnnouncementListFragment extends ListFragment implements Observer { + /** + * The fragment argument representing the section number for this + * fragment. + */ + public static final String ARG_SECTION_NUMBER = "section_number"; + + public AnnouncementListFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_announcement_list, container, false); + + setListAdapter(new AnnouncementAdapter(Datamart.getInstance().getAllAnnouncements(), getActivity())); + return rootView; + } + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Datamart.getInstance().addObserver(this); + } + + public void onDestroy() { + super.onDestroy(); + Datamart.getInstance().deleteObserver(this); + } + + public void onListItemClick(ListView l, View v, int position, long id) { + AnnouncementAdapter adapter = (AnnouncementAdapter)getListAdapter(); + Announcement a = (Announcement)adapter.getItem(position); + Intent i = new Intent(this.getActivity(), AnnouncementDetailActivity.class); + i.putExtra("ANNOUNCEMENT", a); + startActivity(i); + } + + public void update(Observable observable, Object data) { + setListAdapter(new AnnouncementAdapter(Datamart.getInstance().getAllAnnouncements(), getActivity())); + } + +} \ No newline at end of file diff --git a/src/com/rumbleworks/classnote/AssignmentAdapter.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AssignmentAdapter.java similarity index 72% rename from src/com/rumbleworks/classnote/AssignmentAdapter.java rename to classnote/src/main/java/com/hellabreakfast/classnote/ui/AssignmentAdapter.java index c9f2592..2a57638 100644 --- a/src/com/rumbleworks/classnote/AssignmentAdapter.java +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AssignmentAdapter.java @@ -1,4 +1,4 @@ -package com.rumbleworks.classnote; +package com.hellabreakfast.classnote.ui; import android.app.Activity; import android.content.Context; @@ -8,27 +8,34 @@ import android.widget.BaseAdapter; import android.widget.TextView; -import org.w3c.dom.Text; +import com.hellabreakfast.classnote.model.Assignment; +import com.hellabreakfast.classnote.R; -import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Collection; import java.util.Collections; import java.util.List; +/** + * This class takes in a list of Assignments and uses it to populate a ListView + */ public class AssignmentAdapter extends BaseAdapter { private List list; private Activity activity; private SimpleDateFormat dateFormat; public AssignmentAdapter(List list, Activity activity) { - this.list = list; + this.setList(list); this.activity = activity; - dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm"); + dateFormat = new SimpleDateFormat("MMMM d h:mm a"); } + /** + * Sets the list to use for the ListView, sorting it in order (by due date). + * @param list + */ public void setList(List list) { Collections.sort(list); + //Collections.reverse(list); this.list = list; } @@ -56,8 +63,10 @@ public View getView(int i, View view, ViewGroup viewGroup) { } Assignment assignment = (Assignment) getItem(i); + TextView courseTitleText = (TextView) view.findViewById(R.id.courseTitle); TextView titleText = (TextView) view.findViewById(R.id.assignmentTitle); TextView dueDateText = (TextView) view.findViewById(R.id.assignmentDueDate); + courseTitleText.setText(assignment.getCourse().getTitle()); titleText.setText(assignment.getName()); dueDateText.setText(dateFormat.format(assignment.getDueDate())); return view; diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/AssignmentDetailActivity.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AssignmentDetailActivity.java new file mode 100644 index 0000000..c249e6e --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/AssignmentDetailActivity.java @@ -0,0 +1,35 @@ +package com.hellabreakfast.classnote.ui; + +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.widget.TextView; + +import com.hellabreakfast.classnote.model.Assignment; +import com.hellabreakfast.classnote.R; + +import java.text.SimpleDateFormat; + +/** + * Activity to display all details about an assignment + */ + +public class AssignmentDetailActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_assignment_details); + setTitle("Assignment"); + Assignment a = (Assignment) getIntent().getSerializableExtra("ASSIGNMENT"); + TextView courseName = (TextView)findViewById(R.id.assignment_details_class); + TextView title = (TextView)findViewById(R.id.assignment_details_title); + TextView description = (TextView)findViewById(R.id.assignment_details_description); + TextView dueDate = (TextView)findViewById(R.id.assignment_details_date); + courseName.setText(a.getCourse().getTitle()); + title.setText(a.getName()); + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM d h:mm a"); + dueDate.setText("Due: "+dateFormat.format(a.getDueDate())+"\n"); + description.setText(a.getDescription()); + } + +} diff --git a/src/com/rumbleworks/classnote/ClassNoteApp.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/ClassNoteApp.java similarity index 59% rename from src/com/rumbleworks/classnote/ClassNoteApp.java rename to classnote/src/main/java/com/hellabreakfast/classnote/ui/ClassNoteApp.java index ae5bbb4..67f0d04 100644 --- a/src/com/rumbleworks/classnote/ClassNoteApp.java +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/ClassNoteApp.java @@ -1,7 +1,10 @@ -package com.rumbleworks.classnote; +package com.hellabreakfast.classnote.ui; import android.app.Application; -import android.content.Context; + +/** + * This class subclasses the android Application class and makes it into a singleton class so we can access it from anywhere in our code. + */ public class ClassNoteApp extends Application { @@ -14,5 +17,4 @@ public ClassNoteApp() { public static ClassNoteApp getApplication() { return instance; } - } diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/CurrentAssignmentListFragment.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/CurrentAssignmentListFragment.java new file mode 100644 index 0000000..6291f19 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/CurrentAssignmentListFragment.java @@ -0,0 +1,68 @@ +package com.hellabreakfast.classnote.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +import com.hellabreakfast.classnote.model.Assignment; +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; + +import java.util.Observable; +import java.util.Observer; + +/** + * The fragment for displaying current assignments (i.e. the ones with a due date in the future). + * This class is an observer of the Datamart and updates its content when the Datamart updates. + */ +public class CurrentAssignmentListFragment extends ListFragment implements Observer { + + @Override + public void onResume() { + super.onResume(); + AssignmentAdapter assignmentAdapter = (AssignmentAdapter)this.getListAdapter(); + assignmentAdapter.setList(Datamart.getInstance().getUpcomingAssignments()); + assignmentAdapter.notifyDataSetChanged(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_assignment_list, container, false); + + this.setListAdapter(new AssignmentAdapter(Datamart.getInstance().getUpcomingAssignments(), this.getActivity())); + + return rootView; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Datamart.getInstance().addObserver(this); + } + + @Override + public void onDestroy() { + super.onDestroy(); + Datamart.getInstance().deleteObserver(this); + } + + @Override + public void update(Observable observable, Object data) { + this.setListAdapter(new AssignmentAdapter(Datamart.getInstance().getUpcomingAssignments(), this.getActivity())); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + AssignmentAdapter adapter = (AssignmentAdapter)getListAdapter(); + Assignment a = (Assignment)adapter.getItem(position); + Intent i = new Intent(this.getActivity(), AssignmentDetailActivity.class); + i.putExtra("ASSIGNMENT", a); + startActivity(i); + } + +} \ No newline at end of file diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/HelpOverlayActivity.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/HelpOverlayActivity.java new file mode 100644 index 0000000..aa6f1af --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/HelpOverlayActivity.java @@ -0,0 +1,51 @@ +package com.hellabreakfast.classnote.ui; + +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; + +/** + * This activity shows the help overlay for the current screen in a transparent view over the screen. + */ +public class HelpOverlayActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_help_overlay); + + String title = getIntent().getStringExtra("title"); + if (title != null) setTitle(title); + + int currentScreen = Datamart.getInstance().getCurrentScreen(); + + TextView textView1 = (TextView) findViewById(R.id.textView1); + TextView textView2 = (TextView) findViewById(R.id.textView2); + TextView textView3 = (TextView) findViewById(R.id.textView3); + TextView textView4 = (TextView) findViewById(R.id.textView4); + TextView textView5 = (TextView) findViewById(R.id.textView5); + + String[][] helpArray = { + getResources().getStringArray(R.array.help_items_announcements), + getResources().getStringArray(R.array.help_items_assignments), + getResources().getStringArray(R.array.help_items_assignments), + getResources().getStringArray(R.array.help_items_add_assignment) + }; + textView1.setText( helpArray[currentScreen][0] ); + textView2.setText( helpArray[currentScreen][1] ); + textView3.setText( helpArray[currentScreen][2] ); + textView4.setText( helpArray[currentScreen][3] ); + textView5.setText( helpArray[currentScreen][4] ); + } + + /** + * The user tapped to dismiss, so finish the activity. + */ + public void understood(View view){ + finish(); + } +} \ No newline at end of file diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/LoginActivity.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/LoginActivity.java new file mode 100644 index 0000000..114e4ef --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/LoginActivity.java @@ -0,0 +1,82 @@ +package com.hellabreakfast.classnote.ui; + +import android.accounts.Account; +import android.accounts.AccountAuthenticatorActivity; +import android.accounts.AccountManager; +import android.os.Bundle; +import android.content.Intent; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import com.hellabreakfast.classnote.model.AsyncResultHandler; +import com.hellabreakfast.classnote.R; +import com.hellabreakfast.classnote.model.TSquareAPI; +import com.hellabreakfast.classnote.auth.GatechAccountAuthenticator; + +/** + * The activity that accepts the user's username and password and allows them to get to the + * main application if the login is correct. + */ +public class LoginActivity extends AccountAuthenticatorActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + } + + /** + * This method is called when the login button is clicked. It attempts login, and either + * starts the MainActivity or displays an error based on the result. + * @param view + */ + public void login(View view) { + EditText usernameField = (EditText)findViewById(R.id.usernameField); + EditText passwordField = (EditText)findViewById(R.id.passwordField); + final String username = usernameField.getText().toString(); + final String password = passwordField.getText().toString(); + + + TSquareAPI.login(usernameField.getText().toString(), passwordField.getText().toString(), new AsyncResultHandler() { + @Override + public void onSuccess() { + + String accountType = GatechAccountAuthenticator.ACCOUNT_TYPE; + AccountManager accMgr = AccountManager.get(LoginActivity.this); + final Account account = new Account(username, accountType); + accMgr.addAccountExplicitly(account, password, null); + + // Now we tell our caller, could be the Android Account Manager or even our own application + // that the process was successful + + final Intent intent = new Intent(); + intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, username); + intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType); + intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType); + LoginActivity.this.setAccountAuthenticatorResult(intent.getExtras()); + LoginActivity.this.setResult(RESULT_OK, intent); + + + Intent mainIntent = new Intent(); + mainIntent.setClass(LoginActivity.this, MainActivity.class); + + startActivity(mainIntent); + finish(); + } + + @Override + public void onFailure() { + LoginActivity.this.runOnUiThread(new Runnable() { + @Override + public void run() { + Toast toast = Toast.makeText(LoginActivity.this, "Invalid Username or Password", Toast.LENGTH_LONG); + toast.show(); + } + }); + } + }); + + } + +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/MainActivity.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/MainActivity.java new file mode 100644 index 0000000..f8dc3d4 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/MainActivity.java @@ -0,0 +1,163 @@ +package com.hellabreakfast.classnote.ui; + +import android.content.Intent; +import android.support.v4.app.Fragment; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.ActionBar; +import android.support.v4.app.FragmentManager; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.support.v4.widget.DrawerLayout; + +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; +import com.hellabreakfast.classnote.model.TSquareAPI; + +import java.util.Date; + + +/** + * This activity holds all of the primary fragments and the navigation drawer. + */ +public class MainActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { + + /** + * Fragment managing the behaviors, interactions and presentation of the navigation drawer. + */ + private NavigationDrawerFragment mNavigationDrawerFragment; + + /** + * Used to store the last screen title. For use in {@link #restoreActionBar()}. + */ + private CharSequence mTitle; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mNavigationDrawerFragment = (NavigationDrawerFragment) + getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); + + // Set up the drawer. + mNavigationDrawerFragment.setUp( + R.id.navigation_drawer, + (DrawerLayout) findViewById(R.id.drawer_layout)); + this.requireLogin(); + } + + /** + * Checks to see if the user is logged in, and if not, start up the LoginActivity. + */ + private void requireLogin() { + if (!Datamart.isLoggedIn()) { + finish(); + Intent intent = new Intent(); + intent.setClass(MainActivity.this, LoginActivity.class); + + startActivity(intent); + finish(); + } + } + + @Override + protected void onResume() { + super.onResume(); + Date now = new Date(); + Date lastRefreshed = Datamart.getInstance().getLastRefreshed(); + if (!Datamart.getInstance().isOffline() && (lastRefreshed == null || lastRefreshed.before(new Date(now.getTime()-1000*60*15)))) { // if more than 15 mins ago + TSquareAPI.refreshAll(); + } + } + + @Override + public void onNavigationDrawerItemSelected(int position) { + // update the main content by replacing fragments + FragmentManager fragmentManager = getSupportFragmentManager(); + + Fragment fragment = null; + switch (position) { + case 0: + fragment = new AnnouncementListFragment(); + mTitle = "Announcements"; + break; + case 1: + fragment = new CurrentAssignmentListFragment(); + mTitle = "Current Assignments"; + break; + case 2: + fragment = new PastAssignmentListFragment(); + mTitle = "Past Assignments"; + break; + case 3: + fragment = new AddAssignmentFragment(); + mTitle = "New Assignment"; + break; + } + if (fragment == null) return; + fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); + Datamart.getInstance().setCurrentScreen(position); + if (Datamart.getInstance().getVisited()[position] == false) { + this.showHelp(); + } + } + + /** + * Put the action bar back after selecting an item from the navigation drawer. + */ + public void restoreActionBar() { + ActionBar actionBar = getSupportActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(mTitle); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + if (!mNavigationDrawerFragment.isDrawerOpen()) { + // Only show items in the action bar relevant to this screen + // if the drawer is not showing. Otherwise, let the drawer + // decide what to show in the action bar. + getMenuInflater().inflate(R.menu.main, menu); + restoreActionBar(); + return true; + } + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_refresh) { + TSquareAPI.refreshAll(); + return true; + } + if (id == R.id.action_help) { + this.showHelp(); + return true; + } + if (id == R.id.action_logout) { + Datamart.clearInstance(); + this.requireLogin(); + return true; + } + return super.onOptionsItemSelected(item); + } + + /** + * Loads up the help activity for the current screen + */ + public void showHelp() { + Datamart.getInstance().setVisited(Datamart.getInstance().getCurrentScreen(), true); + Intent intent = new Intent(); + intent.setClass(this, HelpOverlayActivity.class); + intent.putExtra("title", getSupportActionBar().getTitle()); + startActivity(intent); + } + +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/NavigationDrawerFragment.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/NavigationDrawerFragment.java new file mode 100644 index 0000000..4dba81d --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/NavigationDrawerFragment.java @@ -0,0 +1,278 @@ +package com.hellabreakfast.classnote.ui; + +import android.support.v7.app.ActionBarActivity; +import android.app.Activity; +import android.support.v7.app.ActionBar; +import android.support.v4.app.Fragment; +import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +import com.hellabreakfast.classnote.R; + +/** + * Fragment used for managing interactions for and presentation of a navigation drawer. + * See the + * design guidelines for a complete explanation of the behaviors implemented here. + */ +public class NavigationDrawerFragment extends Fragment { + + /** + * Remember the position of the selected item. + */ + private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; + + /** + * Per the design guidelines, you should show the drawer on launch until the user manually + * expands it. This shared preference tracks this. + */ + private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; + + /** + * A pointer to the current callbacks instance (the Activity). + */ + private NavigationDrawerCallbacks mCallbacks; + + /** + * Helper component that ties the action bar to the navigation drawer. + */ + private ActionBarDrawerToggle mDrawerToggle; + + private DrawerLayout mDrawerLayout; + private ListView mDrawerListView; + private View mFragmentContainerView; + + private int mCurrentSelectedPosition = 0; + private boolean mFromSavedInstanceState; + private boolean mUserLearnedDrawer; + + public NavigationDrawerFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Read in the flag indicating whether or not the user has demonstrated awareness of the + // drawer. See PREF_USER_LEARNED_DRAWER for details. + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); + + if (savedInstanceState != null) { + mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); + mFromSavedInstanceState = true; + } + + // Select either the default item (0) or the last selected item. + selectItem(mCurrentSelectedPosition); + } + + @Override + public void onActivityCreated (Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + // Indicate that this fragment would like to influence the set of actions in the action bar. + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerListView = (ListView) inflater.inflate( + R.layout.fragment_navigation_drawer, container, false); + mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(position); + } + }); + mDrawerListView.setAdapter(new ArrayAdapter( + getActionBar().getThemedContext(), + android.R.layout.simple_list_item_1, + android.R.id.text1, + new String[]{ + "Announcements", + "Current Assignments", + "Past Assignments", + "New Assignment" + })); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + return mDrawerListView; + } + + public boolean isDrawerOpen() { + return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + } + + /** + * Users of this fragment must call this method to set up the navigation drawer interactions. + * + * @param fragmentId The android:id of this fragment in its activity's layout. + * @param drawerLayout The DrawerLayout containing this fragment's UI. + */ + public void setUp(int fragmentId, DrawerLayout drawerLayout) { + mFragmentContainerView = getActivity().findViewById(fragmentId); + mDrawerLayout = drawerLayout; + + // set a custom shadow that overlays the main content when the drawer opens + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + // set up the drawer's list view with items and click listener + + ActionBar actionBar = getActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + + // ActionBarDrawerToggle ties together the the proper interactions + // between the navigation drawer and the action bar app icon. + mDrawerToggle = new ActionBarDrawerToggle( + getActivity(), /* host Activity */ + mDrawerLayout, /* DrawerLayout object */ + R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ + R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ + R.string.navigation_drawer_close /* "close drawer" description for accessibility */ + ) { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + if (!isAdded()) { + return; + } + + getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + if (!isAdded()) { + return; + } + + if (!mUserLearnedDrawer) { + // The user manually opened the drawer; store this flag to prevent auto-showing + // the navigation drawer automatically in the future. + mUserLearnedDrawer = true; + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit(); + } + + getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + }; + + // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, + // per the navigation drawer design guidelines. + if (!mUserLearnedDrawer && !mFromSavedInstanceState) { + mDrawerLayout.openDrawer(mFragmentContainerView); + } + + // Defer code dependent on restoration of previous instance state. + mDrawerLayout.post(new Runnable() { + @Override + public void run() { + mDrawerToggle.syncState(); + } + }); + + mDrawerLayout.setDrawerListener(mDrawerToggle); + } + + private void selectItem(int position) { + mCurrentSelectedPosition = position; + if (mDrawerListView != null) { + mDrawerListView.setItemChecked(position, true); + } + if (mDrawerLayout != null) { + mDrawerLayout.closeDrawer(mFragmentContainerView); + } + if (mCallbacks != null) { + mCallbacks.onNavigationDrawerItemSelected(position); + } + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + mCallbacks = (NavigationDrawerCallbacks) activity; + } catch (ClassCastException e) { + throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + // Forward the new configuration the drawer toggle component. + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + // If the drawer is open, show the global app actions in the action bar. See also + // showGlobalContextActionBar, which controls the top-left area of the action bar. + if (mDrawerLayout != null && isDrawerOpen()) { + inflater.inflate(R.menu.main, menu); + showGlobalContextActionBar(); + } + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + return super.onOptionsItemSelected(item); + } + + /** + * Per the navigation drawer design guidelines, updates the action bar to show the global app + * 'context', rather than just what's in the current screen. + */ + private void showGlobalContextActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + actionBar.setTitle(R.string.app_name); + } + + private ActionBar getActionBar() { + return ((ActionBarActivity) getActivity()).getSupportActionBar(); + } + + /** + * Callbacks interface that all activities using this fragment must implement. + */ + public static interface NavigationDrawerCallbacks { + /** + * Called when an item in the navigation drawer is selected. + */ + void onNavigationDrawerItemSelected(int position); + } +} diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/PastAssignmentListFragment.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/PastAssignmentListFragment.java new file mode 100644 index 0000000..0b189e0 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/PastAssignmentListFragment.java @@ -0,0 +1,68 @@ +package com.hellabreakfast.classnote.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +import com.hellabreakfast.classnote.model.Assignment; +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; + +import java.util.Observable; +import java.util.Observer; + +/** + * The fragment for displaying past assignments (i.e. the ones with a due date in the past). + * This class is an observer of the Datamart and updates its content when the Datamart updates. + */ +public class PastAssignmentListFragment extends ListFragment implements Observer { + + @Override + public void onResume() { + super.onResume(); + AssignmentAdapter assignmentAdapter = (AssignmentAdapter)this.getListAdapter(); + assignmentAdapter.setList(Datamart.getInstance().getPastAssignments()); + assignmentAdapter.notifyDataSetChanged(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_assignment_list, container, false); + + this.setListAdapter(new AssignmentAdapter(Datamart.getInstance().getPastAssignments(), this.getActivity())); + + return rootView; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Datamart.getInstance().addObserver(this); + } + + @Override + public void onDestroy() { + super.onDestroy(); + Datamart.getInstance().deleteObserver(this); + } + + @Override + public void update(Observable observable, Object data) { + this.setListAdapter(new AssignmentAdapter(Datamart.getInstance().getPastAssignments(), this.getActivity())); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + AssignmentAdapter adapter = (AssignmentAdapter)getListAdapter(); + Assignment a = (Assignment)adapter.getItem(position); + Intent i = new Intent(this.getActivity(), AssignmentDetailActivity.class); + i.putExtra("ASSIGNMENT", a); + startActivity(i); + } + +} \ No newline at end of file diff --git a/classnote/src/main/java/com/hellabreakfast/classnote/ui/UpdatePasswordActivity.java b/classnote/src/main/java/com/hellabreakfast/classnote/ui/UpdatePasswordActivity.java new file mode 100644 index 0000000..e604921 --- /dev/null +++ b/classnote/src/main/java/com/hellabreakfast/classnote/ui/UpdatePasswordActivity.java @@ -0,0 +1,101 @@ +package com.hellabreakfast.classnote.ui; + +import android.accounts.Account; +import android.accounts.AccountAuthenticatorActivity; +import android.accounts.AccountManager; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.text.InputType; +import android.widget.EditText; +import android.widget.Toast; + +import com.hellabreakfast.classnote.model.AsyncResultHandler; +import com.hellabreakfast.classnote.model.Datamart; +import com.hellabreakfast.classnote.R; +import com.hellabreakfast.classnote.model.TSquareAPI; +import com.hellabreakfast.classnote.auth.GatechAccountAuthenticator; + +/** + * This activity is used for the user to update their password, when it is changed on their GT account. + */ +public class UpdatePasswordActivity extends AccountAuthenticatorActivity { + private EditText passwordField; + private ProgressDialog progressDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_update_password); + passwordField = new EditText(this); + passwordField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + passwordField.setHint("Password"); + AlertDialog dialog = new AlertDialog.Builder(this) + .setTitle("T-Square Password Invalid") + .setMessage("Enter your correct T-Square password to refresh") + .setView(passwordField) + .setPositiveButton("Refresh", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + attemptLogin(); + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + }) + .create(); + dialog.show(); + } + + /** + * Attempts to login with the entered password. On success, dismiss this activity. Otherwise, + * display an error and ask for the password again. + */ + public void attemptLogin() { + progressDialog = ProgressDialog.show(this, "Verifying Password", null, true, true, new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + progressDialog.dismiss(); + Datamart.getInstance().setOffline(true); + finish(); + } + }); + final String username = Datamart.getInstance().getUsername(); + final String password = passwordField.getText().toString(); + + TSquareAPI.login(username, password, new AsyncResultHandler() { + @Override + public void onSuccess() { + + String accountType = GatechAccountAuthenticator.ACCOUNT_TYPE; + AccountManager accMgr = AccountManager.get(UpdatePasswordActivity.this); + final Account account = new Account(username, accountType); + accMgr.setPassword(account, password); + + final Intent intent = new Intent(); + intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, username); + intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType); + intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType); + UpdatePasswordActivity.this.setAccountAuthenticatorResult(intent.getExtras()); + UpdatePasswordActivity.this.setResult(RESULT_OK, intent); + + finish(); + } + + @Override + public void onFailure() { + progressDialog.dismiss(); + Toast toast = Toast.makeText(UpdatePasswordActivity.this, "Invalid Username or Password", Toast.LENGTH_LONG); + toast.show(); + } + }); + + } + +} diff --git a/classnote/src/main/res/drawable-hdpi/drawer_shadow.9.png b/classnote/src/main/res/drawable-hdpi/drawer_shadow.9.png new file mode 100644 index 0000000..236bff5 Binary files /dev/null and b/classnote/src/main/res/drawable-hdpi/drawer_shadow.9.png differ diff --git a/classnote/src/main/res/drawable-hdpi/ic_drawer.png b/classnote/src/main/res/drawable-hdpi/ic_drawer.png new file mode 100644 index 0000000..c59f601 Binary files /dev/null and b/classnote/src/main/res/drawable-hdpi/ic_drawer.png differ diff --git a/classnote/src/main/res/drawable-hdpi/ic_launcher.png b/classnote/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..f0659b1 Binary files /dev/null and b/classnote/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/res/drawable-hdpi/ic_launcher.png b/classnote/src/main/res/drawable-hdpi/ic_launcher2.png similarity index 100% rename from res/drawable-hdpi/ic_launcher.png rename to classnote/src/main/res/drawable-hdpi/ic_launcher2.png diff --git a/classnote/src/main/res/drawable-mdpi/drawer_shadow.9.png b/classnote/src/main/res/drawable-mdpi/drawer_shadow.9.png new file mode 100644 index 0000000..ffe3a28 Binary files /dev/null and b/classnote/src/main/res/drawable-mdpi/drawer_shadow.9.png differ diff --git a/classnote/src/main/res/drawable-mdpi/ic_drawer.png b/classnote/src/main/res/drawable-mdpi/ic_drawer.png new file mode 100644 index 0000000..1ed2c56 Binary files /dev/null and b/classnote/src/main/res/drawable-mdpi/ic_drawer.png differ diff --git a/classnote/src/main/res/drawable-mdpi/ic_launcher.png b/classnote/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..5b8d5d6 Binary files /dev/null and b/classnote/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/res/drawable-mdpi/ic_launcher.png b/classnote/src/main/res/drawable-mdpi/ic_launcher2.png similarity index 100% rename from res/drawable-mdpi/ic_launcher.png rename to classnote/src/main/res/drawable-mdpi/ic_launcher2.png diff --git a/classnote/src/main/res/drawable-xhdpi/drawer_shadow.9.png b/classnote/src/main/res/drawable-xhdpi/drawer_shadow.9.png new file mode 100644 index 0000000..fabe9d9 Binary files /dev/null and b/classnote/src/main/res/drawable-xhdpi/drawer_shadow.9.png differ diff --git a/classnote/src/main/res/drawable-xhdpi/ic_drawer.png b/classnote/src/main/res/drawable-xhdpi/ic_drawer.png new file mode 100644 index 0000000..a5fa74d Binary files /dev/null and b/classnote/src/main/res/drawable-xhdpi/ic_drawer.png differ diff --git a/classnote/src/main/res/drawable-xhdpi/ic_launcher.png b/classnote/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..45443dc Binary files /dev/null and b/classnote/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/res/drawable-xhdpi/ic_launcher.png b/classnote/src/main/res/drawable-xhdpi/ic_launcher2.png similarity index 100% rename from res/drawable-xhdpi/ic_launcher.png rename to classnote/src/main/res/drawable-xhdpi/ic_launcher2.png diff --git a/classnote/src/main/res/drawable-xxhdpi/drawer_shadow.9.png b/classnote/src/main/res/drawable-xxhdpi/drawer_shadow.9.png new file mode 100644 index 0000000..b91e9d7 Binary files /dev/null and b/classnote/src/main/res/drawable-xxhdpi/drawer_shadow.9.png differ diff --git a/classnote/src/main/res/drawable-xxhdpi/ic_drawer.png b/classnote/src/main/res/drawable-xxhdpi/ic_drawer.png new file mode 100644 index 0000000..9c4685d Binary files /dev/null and b/classnote/src/main/res/drawable-xxhdpi/ic_drawer.png differ diff --git a/classnote/src/main/res/drawable-xxhdpi/ic_launcher.png b/classnote/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..a2f06c5 Binary files /dev/null and b/classnote/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/res/drawable-xxhdpi/ic_launcher.png b/classnote/src/main/res/drawable-xxhdpi/ic_launcher2.png similarity index 100% rename from res/drawable-xxhdpi/ic_launcher.png rename to classnote/src/main/res/drawable-xxhdpi/ic_launcher2.png diff --git a/classnote/src/main/res/layout/activity_announcement_details.xml b/classnote/src/main/res/layout/activity_announcement_details.xml new file mode 100644 index 0000000..999a223 --- /dev/null +++ b/classnote/src/main/res/layout/activity_announcement_details.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + diff --git a/classnote/src/main/res/layout/activity_assignment_details.xml b/classnote/src/main/res/layout/activity_assignment_details.xml new file mode 100644 index 0000000..f8da9f5 --- /dev/null +++ b/classnote/src/main/res/layout/activity_assignment_details.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + diff --git a/classnote/src/main/res/layout/activity_help_overlay.xml b/classnote/src/main/res/layout/activity_help_overlay.xml new file mode 100644 index 0000000..72a1db2 --- /dev/null +++ b/classnote/src/main/res/layout/activity_help_overlay.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + diff --git a/classnote/src/main/res/layout/activity_login.xml b/classnote/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..283faed --- /dev/null +++ b/classnote/src/main/res/layout/activity_login.xml @@ -0,0 +1,37 @@ + + + + + + + + +