Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Small fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadec committed Dec 27, 2018
1 parent 137d827 commit d806554
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 108 deletions.
7 changes: 0 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="@string/import_gyia">
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/hu/kfg/naplo/AbsencesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.text.Spanned;
import android.util.Log;
import android.view.Display;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
Expand Down Expand Up @@ -79,7 +80,6 @@ private void updateViews() {
}
TableLayout table = findViewById(R.id.absencestable);
table.removeAllViews();
table.setMeasureWithLargestChildEnabled(true);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
Expand All @@ -92,13 +92,14 @@ private void updateViews() {
background.setStroke(3, strokeColor);
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{background});
layerDrawable.setLayerInset(0, -3, -3, -3, 0);
for (Date date : dates) {
for (int i = 0; i < dates.size(); i++) {
Date date = dates.get(i);
List<Absence> absences = db.getAbsencesOnDay(date);
final TableRow row2 = new TableRow(AbsencesActivity.this);
row2.setLayoutParams(lp);
TextView lView2 = new TextView(AbsencesActivity.this);
lView2.setMinWidth((int) (size.x / 1.1));
lView2.setText(Html.fromHtml("<big><u><b>" + this.date.format(date)));
lView2.setText(Html.fromHtml((i > 0 ? "<br/>" : "") + "<div style=\"text-align:center;\"><big><big><u><b>" + this.date.format(date) + "</b></u></big></big>"));
row2.addView(lView2);
table.addView(row2);
for (Absence absence : absences) {
Expand All @@ -112,6 +113,7 @@ private void updateViews() {
table.addView(row);
}
}
Log.e("Test", "" + ((ScrollView) findViewById(R.id.absences_scrollview)).getChildCount());
if (dates == null || dates.size() == 0) {
final TableRow row = new TableRow(AbsencesActivity.this);
row.setLayoutParams(lp);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/hu/kfg/naplo/AbsencesDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ boolean insertAbsence(Absence absence) {
ArrayList<Date> getDates() {
ArrayList<Date> array_list = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("SELECT DISTINCT " + ABSENCES_COLUMN_ABSENCE + " FROM " + ABSENCES_TABLE_NAME + " ORDER BY " + ABSENCES_COLUMN_ABSENCE, null);
Cursor res = db.rawQuery("SELECT DISTINCT " + ABSENCES_COLUMN_ABSENCE + " FROM " + ABSENCES_TABLE_NAME + " ORDER BY " + ABSENCES_COLUMN_ABSENCE + " DESC", null);
res.moveToFirst();

while (!res.isAfterLast()) {
Expand Down
29 changes: 6 additions & 23 deletions app/src/main/java/hu/kfg/naplo/ChangeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@

import android.net.*;
import android.os.*;
import android.service.notification.StatusBarNotification;
import android.text.Html;
import android.util.*;

import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.security.MessageDigest;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjuster;
import java.util.*;
import java.io.*;

import android.widget.*;
import android.app.*;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -224,7 +218,6 @@ public void run() {
} catch (Exception e) {
e.printStackTrace();
}
Log.i(TAG, ilessons.size() + " <-- size of ignore");
int day = 0;
List<Substitution> subs = new ArrayList<>();
String tomorrowFormat = "";
Expand Down Expand Up @@ -266,7 +259,6 @@ public void run() {
try {
period = Integer.valueOf(line.substring(line.indexOf(">") + 1, line.lastIndexOf("<")));
} catch (Exception e) {
Log.d(TAG, "No lesson specified");
}
sub.setTime(period, day == 1);
}
Expand All @@ -275,7 +267,6 @@ public void run() {
try {
room = Integer.valueOf(line.substring(line.indexOf(">") + 1, line.lastIndexOf("<")));
} catch (Exception e) {
Log.d(TAG, "No room specified!");
}
sub.setRoom(room);
}
Expand Down Expand Up @@ -337,8 +328,6 @@ public int compare(Substitution o1, Substitution o2) {
if (!autoignore || isRelevant(sub, sub.isToday() ? lessonsToday : lessonsTomorrow)) {
text.append("\n");
text.append(sub.toString("PPDD. SS: TE C9 RR, GG"));
} else {
Log.i(TAG, "Irrelevant substitution");
}
//Log.d(TAG, sub.toString("PPDD. SS: TE C9 RR, GG"));
numoflessons++;
Expand Down Expand Up @@ -369,7 +358,7 @@ public void run() {

private static boolean isRelevant(Substitution substitution, List<Lesson> lessons) {
try {
Log.i(TAG, substitution.toString("DDPP-SS:MT->TE C9"));
//Log.i(TAG, substitution.toString("DDPP-SS:MT->TE C9"));
if (lessons == null || lessons.size() == 0) {
Log.i(TAG, "No lessons on day: ?");
return true; //Since we don't know if an error occurred, or no lessons
Expand Down Expand Up @@ -571,7 +560,6 @@ public void handleMessage(Message message) {
Log.d(TAG, "Absences: " + rawAbsences.length());
for (int i = 0; i < rawAbsences.length(); i++) {
JSONObject currentItem = rawAbsences.getJSONObject(i);
Log.e(TAG, currentItem.toString());
String mode = currentItem.getString("ModeName");
String subject = currentItem.getString("Subject");
String teacher = currentItem.getString("Teacher");
Expand Down Expand Up @@ -610,15 +598,14 @@ public void handleMessage(Message message) {
e.printStackTrace();
}
if (mygrades.size() < 1) {
new DBHelper(context).cleanDatabase();
new GradesDB(context).cleanDatabase();
return DB_EMPTY;
}
if (new DBHelper(context).upgradeDatabase(mygrades)) return UPGRADE_DONE;
if (new GradesDB(context).upgradeDatabase(mygrades)) return UPGRADE_DONE;
else return UPGRADE_FAILED;
}
try {
if (resultStuff.toString().length() < 300) {
Log.w(TAG, rawGrades.toString());
throw new Exception("Content too small \nLength: " + resultStuff.toString().length());
}
if (mygrades.size() == 0) throw new IndexOutOfBoundsException("No grades!");
Expand All @@ -632,7 +619,7 @@ public void run() {
}
});
}
new DBHelper(context).cleanDatabase();
new GradesDB(context).cleanDatabase();
return DB_EMPTY;
} catch (Exception e) {
Log.e(TAG, e.getMessage());
Expand All @@ -659,7 +646,7 @@ public void run() {
if (rawGrades.length() - numofnotes > 0 && !SHA512(notes).equals(pref.getString("lastSHA", "ABCD"))) {
int i = rawGrades.length() - numofnotes;
StringBuilder text = new StringBuilder();
DBHelper db1 = new DBHelper(context);
GradesDB db1 = new GradesDB(context);
for (int i2 = 0; i2 < i; i2++) {
text.append(mygrades.get(i2).getNotificationFormat());
text.append(", \n");
Expand All @@ -676,7 +663,7 @@ public void run() {
AppNotificationManager.notifyIfChanged(new int[]{0, pref.getBoolean("vibrate", false) ? 1 : 0, pref.getBoolean("flash", false) ? 1 : 0}, context, eURL, context.getString(R.string.unknown_change));
//If a grade was modified, it's easier to update the whole DB
try {
if (new DBHelper(context).upgradeDatabase(mygrades)) return UPGRADE_DONE;
if (new GradesDB(context).upgradeDatabase(mygrades)) return UPGRADE_DONE;
} catch (Exception e) {
Log.e(TAG, "Automatically initiated update failed");
e.printStackTrace();
Expand Down Expand Up @@ -750,8 +737,6 @@ static int getTimetable(Context context, Date from, Date to, boolean removeExist
return UNKNOWN_ERROR;
}

//List<Lesson> mylessons = new ArrayList<>();
Log.d(TAG, resultStuff.toString());
TimetableDB db = new TimetableDB(context);
if (removeExisting) db.cleanDatabase();
try {
Expand Down Expand Up @@ -814,7 +799,6 @@ static List<Event> doEventsCheck(final Context context, Date date) {
//NOTE the special space (nbsp??) between month & day!!!
SimpleDateFormat monthDay = new SimpleDateFormat("yyyy-MMMM dd", new Locale("hu"));
SimpleDateFormat time = new SimpleDateFormat("HH:mm", Locale.getDefault());
Log.i(TAG, "Reading from output");
while ((line = reader.readLine()) != null) {
sb.append(line);
if (!line.contains("Date")) {
Expand All @@ -838,7 +822,6 @@ static List<Event> doEventsCheck(final Context context, Date date) {
endDate = startDate;
}
events.add(new Event(tempInfo, startDate, endDate));
Log.i(TAG, "Event added");

}
reader.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
public class GradesDB extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "Grades.db";
private static final String GRADES_TABLE_NAME= "grades";
Expand All @@ -24,7 +24,7 @@ public class DBHelper extends SQLiteOpenHelper {
private static final String GRADES_COLUMN_TEACHER = "teacher";
private static final String GRADES_COLUMN_WEIGHTED = "weighted";

DBHelper(Context context) {
GradesDB(Context context) {
super(context, DATABASE_NAME, null, 1);
}

Expand Down
41 changes: 30 additions & 11 deletions app/src/main/java/hu/kfg/naplo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void onCreate(Bundle savedInstanceState) {


if (prefs.getString("url", null) != null) {
new DBHelper(MainActivity.this).cleanDatabase();
new GradesDB(MainActivity.this).cleanDatabase();
prefs.edit().remove("url").commit();
}

Expand Down Expand Up @@ -270,7 +270,7 @@ public boolean onPreferenceClick(Preference preference) {
} else {
classField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
classField.setFilters(new InputFilter[]{classFilter, new InputFilter.LengthFilter(5)});
classField.setHint("9.AK / 12.IB");
classField.setHint("9.AK / 12.IB / 11.D");
}
classField.setText(prefs.getString("class", ""));
d.setOnShowListener(new DialogInterface.OnShowListener() {
Expand Down Expand Up @@ -300,10 +300,20 @@ public void onClick(View v) {
final String cls = classField.getText().toString();
final String uname = usernameField.getText().toString();
final String pwd = passwordField.getText().toString();
if ((cls.length() < CLASS_MIN_LENGTH || !cls.contains(".")) && !notification_mode.getValue().equals(ChangeListener.MODE_TEACHER)) {
if (notification_mode.getValue().equals(ChangeListener.MODE_TEACHER)) {
if (cls.length() > 3) {
prefs.edit().putString("class", cls).commit();
} else {
Toast t = Toast.makeText(MainActivity.this, R.string.teacher_hint, Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
return;
}
if ((cls.length() < CLASS_MIN_LENGTH || !cls.contains("."))) {
Toast.makeText(MainActivity.this, R.string.incorrect_class, Toast.LENGTH_SHORT).show();
return;
} else if ((uname.length() < 3 || pwd.length() < 3) && !notification_mode.getValue().equals(ChangeListener.MODE_TEACHER)) {
} else if ((uname.length() < 3 || pwd.length() < 3)) {
Toast.makeText(MainActivity.this, R.string.incorrect_credentials, Toast.LENGTH_SHORT).show();
return;
}
Expand Down Expand Up @@ -348,6 +358,9 @@ public void run() {
t.show();
}
});
new AbsencesDB(MainActivity.this).cleanDatabase();
new GradesDB(MainActivity.this).cleanDatabase();
new TimetableDB(MainActivity.this).cleanDatabase();
}
});
t.start();
Expand All @@ -357,13 +370,19 @@ public void run() {
}
});
d.show();
AlertDialog.Builder warnPw = new AlertDialog.Builder(MainActivity.this);
warnPw.setMessage(R.string.change_password);
warnPw.setIcon(android.R.drawable.ic_dialog_alert);
warnPw.setTitle(R.string.warning);
warnPw.setPositiveButton("OK", null);
warnPw.setCancelable(false);
warnPw.show();
if (notification_mode.getValue().equals(ChangeListener.MODE_TEACHER)) {
Toast t = Toast.makeText(MainActivity.this, R.string.teacher_hint, Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
} else {
AlertDialog.Builder warnPw = new AlertDialog.Builder(MainActivity.this);
warnPw.setMessage(R.string.change_password);
warnPw.setIcon(android.R.drawable.ic_dialog_alert);
warnPw.setTitle(R.string.warning);
warnPw.setPositiveButton("OK", null);
warnPw.setCancelable(false);
warnPw.show();
}
return false;
}
});
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/hu/kfg/naplo/TableViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.text.Html;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
Expand All @@ -42,7 +41,7 @@

public class TableViewActivity extends Activity implements View.OnClickListener {

DBHelper db;
GradesDB db;
int upgraderesult = 0;
int VIEW_HEIGHT = 30;
boolean lightmode = false;
Expand All @@ -57,15 +56,15 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_view);
getActionBar().setDisplayHomeAsUpEnabled(true);
db = new DBHelper(TableViewActivity.this);
db = new GradesDB(TableViewActivity.this);
if (db.numberOfRows() < 1) {
updateDatabase(db);
} else {
doStuff(db);
}
}

void doStuff(final DBHelper db) {
void doStuff(final GradesDB db) {
final TableLayout table = findViewById(R.id.table);
runOnUiThread(new Runnable() {
@Override
Expand Down Expand Up @@ -227,7 +226,7 @@ public void run() {

}

void updateDatabase(final DBHelper db) {
void updateDatabase(final GradesDB db) {
if (PreferenceManager.getDefaultSharedPreferences(TableViewActivity.this).getString("password2", "").length() <= 1) {
Toast t = Toast.makeText(TableViewActivity.this, R.string.incorrect_credentials, Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/res/layout/activity_absences.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp"
tools:context="hu.kfg.naplo.AbsencesActivity"
android:id="@+id/absences_scrollview"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">

<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">

<TableLayout
android:id="@+id/absencestable"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
</HorizontalScrollView>
<TableLayout
android:id="@+id/absencestable"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
Loading

0 comments on commit d806554

Please sign in to comment.