diff --git a/app/src/main/java/app/sunstreak/yourpisd/AppRater.java b/app/src/main/java/app/sunstreak/yourpisd/AppRater.java index 5180d1f..b4b4724 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/AppRater.java +++ b/app/src/main/java/app/sunstreak/yourpisd/AppRater.java @@ -57,8 +57,12 @@ public static void showRateDialog(final Context mContext, final SharedPreference dialog.setButton(DialogInterface.BUTTON_POSITIVE, RATE_YOUR_PISD, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { - mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME))); + if (editor != null) { + editor.putBoolean("dontshowagain", true); + editor.commit(); + } dialog.dismiss(); + mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME))); } }); @@ -81,7 +85,6 @@ public void onClick(DialogInterface dialog, int id) { } }); - //TODO: change this - //dialog.show(); + dialog.show(); } } \ No newline at end of file diff --git a/app/src/main/java/app/sunstreak/yourpisd/ClassSwipeActivity.java b/app/src/main/java/app/sunstreak/yourpisd/ClassSwipeActivity.java index 7d23c59..f698d4f 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/ClassSwipeActivity.java +++ b/app/src/main/java/app/sunstreak/yourpisd/ClassSwipeActivity.java @@ -53,9 +53,7 @@ public class ClassSwipeActivity extends ActionBarActivity { static ViewPager mViewPager; static int studentIndex; - static int classesMade = 0; static int termNum; - static boolean doneMakingClasses; static Session session; static Student student; @@ -85,6 +83,11 @@ protected void onCreate(Bundle savedInstanceState) { setTitle(TermFinder.Term.values()[termNum].name); session = ((YPApplication) getApplication()).session; + if (session == null) + { + logout(false); + return; + } session.studentIndex = studentIndex; student = session.getCurrentStudent(); classesForTerm = student.getClassesForTerm(termNum); @@ -171,23 +174,50 @@ else if (termNum == ClassReport.NUM_TERMS - 1) } @Override - public boolean onOptionsItemSelected(MenuItem item) { - Intent intent; - // Handle item selection - switch (item.getItemId()) { - case R.id.log_out: - MainActivity.UserLogoutTask logout = new MainActivity.UserLogoutTask(); - ((YPApplication) getApplication()).session = session = null; - logout.execute(session); + protected void onRestart() { + super.onRestart(); + logout(false); + } - //TODO: logout on MainActivity instead - SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit(); + @Override + protected void onDestroy() { + super.onDestroy(); + logout(false); + } + + private void logout(boolean userIntervention) + { + if (session != null) + { + MainActivity.UserLogoutTask logout = new MainActivity.UserLogoutTask(); + logout.execute(session); + ((YPApplication) getApplication()).session = session = null; + + if (userIntervention) + { + SharedPreferences.Editor editor = getSharedPreferences( + "LoginActivity", Context.MODE_PRIVATE).edit(); editor.putBoolean("auto_login", false); editor.commit(); - intent = new Intent(this, LoginActivity.class); - // Clear all activities between this and LoginActivity - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); + } + } + + SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit(); + editor.putBoolean("auto_login", false); + editor.commit(); + Intent intent = new Intent(this, LoginActivity.class); + // Clear all activities between this and LoginActivity + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle item selection + switch (item.getItemId()) { + case R.id.log_out: //TODO: add logout button + logout(true); return true; /* case R.id.refresh: @@ -198,7 +228,7 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; */ case R.id.previous_term: - intent = new Intent(this, ClassSwipeActivity.class); + Intent intent = new Intent(this, ClassSwipeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("studentIndex", studentIndex); intent.putExtra("classIndex", mViewPager.getCurrentItem()); @@ -358,6 +388,7 @@ public void onClick(View arg0) { StringBuilder msg = new StringBuilder(); msg.append(view.getCategory() == null ? "No category" : view.getCategory().getType()) + .append("\nMax Grade: " + String.format("%.1f", view.getMaxGrade())) .append("\nDue Date: " + DateHelper.daysRelative(view.getDueDate())) .append("\nWeight: x" + String.format("%.1f", view.getWeight())); try { diff --git a/app/src/main/java/app/sunstreak/yourpisd/MainActivity.java b/app/src/main/java/app/sunstreak/yourpisd/MainActivity.java index 02816f9..e954555 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/MainActivity.java +++ b/app/src/main/java/app/sunstreak/yourpisd/MainActivity.java @@ -108,6 +108,18 @@ public class MainActivity extends ActionBarActivity { public SlidingTabLayout slidingTabLayout; public Toolbar toolbar; + @Override + protected void onRestart() { + super.onRestart(); + logout(false); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + logout(false); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -126,11 +138,10 @@ protected void onCreate(Bundle savedInstanceState) { session = ((YPApplication) getApplication()).session; if (session == null) { - logout(); + logout(false); return; } - // Create the adapter that will return a fragment for each of the three // primary sections of the app. FragmentManager fm = getSupportFragmentManager(); @@ -278,7 +289,7 @@ public boolean onCreateOptionsMenu(Menu menu) { return super.onCreateOptionsMenu(menu); } - private void logout() + private void logout(boolean userIntervention) { if (session != null) { @@ -286,10 +297,13 @@ private void logout() logout.execute(session); ((YPApplication) getApplication()).session = session = null; - Editor editor = getSharedPreferences( - "LoginActivity", Context.MODE_PRIVATE).edit(); - editor.putBoolean("auto_login", false); - editor.commit(); + if (userIntervention) + { + Editor editor = getSharedPreferences( + "LoginActivity", Context.MODE_PRIVATE).edit(); + editor.putBoolean("auto_login", false); + editor.commit(); + } } // attendanceTask.cancel(true); // attendanceTask = null; @@ -310,7 +324,7 @@ public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.log_out: - logout(); + logout(true); return true; case R.id.credits: System.out.println("SHOWING CREDITS"); @@ -331,7 +345,8 @@ public static class UserLogoutTask extends AsyncTask { @Override protected Void doInBackground(Session... sessions) { - sessions[0].logout(); + if (sessions[0] != null) + sessions[0].logout(); return null; } } @@ -423,7 +438,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, public static class SummaryFragment extends YPMainFragment { public static final String ARG_SEMESTER_NUM = "semester_number"; - //TODO: change here. public static final String[][] COLUMN_HEADERS = { {"1st", "2nd", "Exam", "Avg"}, {"3rd", "4th", "Exam", "Avg"}}; diff --git a/app/src/main/java/app/sunstreak/yourpisd/TermFinder.java b/app/src/main/java/app/sunstreak/yourpisd/TermFinder.java index cd9df1f..b8e395c 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/TermFinder.java +++ b/app/src/main/java/app/sunstreak/yourpisd/TermFinder.java @@ -2,7 +2,6 @@ public class TermFinder { - // TODO Hardcoded for 2016-2017 school year public enum Term { TERM_0("1st Nine Weeks"), TERM_1("2nd Nine Weeks"), @@ -13,7 +12,7 @@ public enum Term { public final String name; - private Term(String name) { + Term(String name) { this.name = name; } } diff --git a/app/src/main/java/app/sunstreak/yourpisd/net/Parser.java b/app/src/main/java/app/sunstreak/yourpisd/net/Parser.java index f892ed1..f0f7982 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/net/Parser.java +++ b/app/src/main/java/app/sunstreak/yourpisd/net/Parser.java @@ -107,7 +107,7 @@ public static void parseTermReport(String html, TermReport report) { String temp = assignment.getElementsByClass("points").get(0).html(); if (temp.isEmpty()) - newAssignment.setGrade(-1); //TODO: Grade doesn't exist + newAssignment.setGrade(-1); else newAssignment.setGrade(Double.parseDouble(temp)); @@ -187,16 +187,19 @@ public static void parseGradeSummary(String html, Map clas //Add new class report as needed. ClassReport report; if (classes.containsKey(courseID)) + { report = classes.get(courseID); + report.setCourseName(name); + } else{ - // Teacher name - String teacher = courseMain.get(1).children().get(1).getElementsByClass("teacher").get(0).html(); report = new ClassReport(courseID, name); - report.setPeriodNum(Integer.parseInt(period)); - report.setTeacherName(teacher); classes.put(courseID, report); } + String teacher = courseMain.get(1).children().get(1).getElementsByClass("teacher").get(0).html(); + report.setPeriodNum(Integer.parseInt(period)); + report.setTeacherName(teacher); + //Create a new term as needed. TermReport termReport = report.getTerm(termNum); if (termReport == null) diff --git a/app/src/main/java/app/sunstreak/yourpisd/net/Testing.java b/app/src/main/java/app/sunstreak/yourpisd/net/Testing.java index d7f722f..f7a5377 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/net/Testing.java +++ b/app/src/main/java/app/sunstreak/yourpisd/net/Testing.java @@ -22,7 +22,7 @@ public class Testing { public static void main(String[] args) { /* for (String s : classes) - System.out.println(s + "\t\t" + Student.maxGPA(s)); + System.out.println(s + "\t\t" + Student.getMaxGPA(s)); */ /* diff --git a/app/src/main/java/app/sunstreak/yourpisd/net/data/ClassReport.java b/app/src/main/java/app/sunstreak/yourpisd/net/data/ClassReport.java index 6a69965..8c22252 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/net/data/ClassReport.java +++ b/app/src/main/java/app/sunstreak/yourpisd/net/data/ClassReport.java @@ -4,14 +4,12 @@ import app.sunstreak.yourpisd.Semester; public class ClassReport { - //TODO: teacher email public static int SEMESTER_TERMS = 3; public static int NUM_TERMS = SEMESTER_TERMS * 2; private final int classID; //Unique ID that identifies which class this is. private final TermReport terms[] = new TermReport[NUM_TERMS]; //Terms in this Class. private int periodNum; - private int average = -1; private String courseName; private String teacherName; @@ -52,24 +50,6 @@ public int calculateAverage(Semester sem){ return (int) Math.round(grade / weight); } - public double getMaxGPA() { - String className = getCourseName().toUpperCase(); - - if (className.contains("PHYS IB SL") - || className.contains("MATH STDY IB")) - return 4.5; - - String[] split = className.split("[\\s()\\d/]+"); - - for (int i = 0; i < split.length; i++) { - if (split[i].equals("AP") || split[i].equals("IB")) - return 5; - if (split[i].equals("H") || split[i].equals("IH")) - return 4.5; - } - return 4; - } - public void setTerm(int termNum, TermReport term) { terms[termNum] = term; } diff --git a/app/src/main/java/app/sunstreak/yourpisd/net/data/ParseException.java b/app/src/main/java/app/sunstreak/yourpisd/net/data/ParseException.java deleted file mode 100644 index 3daf6af..0000000 --- a/app/src/main/java/app/sunstreak/yourpisd/net/data/ParseException.java +++ /dev/null @@ -1,21 +0,0 @@ -package app.sunstreak.yourpisd.net.data; - -/** - * Thrown when a parse error occurs. - */ -public class ParseException extends Exception { - public ParseException() { - } - - public ParseException(String detailMessage) { - super(detailMessage); - } - - public ParseException(String detailMessage, Throwable throwable) { - super(detailMessage, throwable); - } - - public ParseException(Throwable throwable) { - super(throwable); - } -} diff --git a/app/src/main/java/app/sunstreak/yourpisd/net/data/Student.java b/app/src/main/java/app/sunstreak/yourpisd/net/data/Student.java index 842b54c..20d4596 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/net/data/Student.java +++ b/app/src/main/java/app/sunstreak/yourpisd/net/data/Student.java @@ -31,7 +31,7 @@ public class Student { Bitmap studentPictureBitmap; - public static double maxGPA(String className) { + public static double getMaxGPA(String className) { className = className.toUpperCase(); if (className.contains("PHYS IB SL") @@ -195,7 +195,7 @@ public double getGPA(Semester sem) { if (grade >= 70) { //Passing class. - double classGPA = maxGPA(report.getCourseName()) - gpaDifference(grade); + double classGPA = getMaxGPA(report.getCourseName()) - gpaDifference(grade); pointSum += classGPA; pointCount++; } diff --git a/app/src/main/java/app/sunstreak/yourpisd/net/data/TermReport.java b/app/src/main/java/app/sunstreak/yourpisd/net/data/TermReport.java index 005c1c7..63707b6 100644 --- a/app/src/main/java/app/sunstreak/yourpisd/net/data/TermReport.java +++ b/app/src/main/java/app/sunstreak/yourpisd/net/data/TermReport.java @@ -11,9 +11,6 @@ import app.sunstreak.yourpisd.net.Parser; import app.sunstreak.yourpisd.net.Session; -/** - * Created by Henry on 9/3/2016. - */ public class TermReport { private final Student student; private final ClassReport classGrades; @@ -55,10 +52,6 @@ public List getCategories() { return categories; } - public Student getStudent() { - return student; - } - public int getGrade() { return grade; }