mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 19:52:46 +01:00
Add cookies database and remake grade dialog (#18)
* Add cookies database * Remake dialog fragment * Add selectable to textview in dialog
This commit is contained in:
parent
add96d37dc
commit
15260b58f3
@ -41,6 +41,7 @@ dependencies {
|
|||||||
compile 'org.apache.commons:commons-collections4:4.1'
|
compile 'org.apache.commons:commons-collections4:4.1'
|
||||||
compile 'com.thoughtbot:expandablerecyclerview:1.3'
|
compile 'com.thoughtbot:expandablerecyclerview:1.3'
|
||||||
compile 'com.android.support:cardview-v7:25.3.1'
|
compile 'com.android.support:cardview-v7:25.3.1'
|
||||||
|
compile 'com.google.code.gson:gson:2.8.1'
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile 'org.mockito:mockito-core:2.9.0'
|
testCompile 'org.mockito:mockito-core:2.9.0'
|
||||||
|
@ -36,9 +36,9 @@ public class GradesDialogFragment extends DialogFragment {
|
|||||||
TextView colorText = (TextView) view.findViewById(R.id.color_dialog_text_value);
|
TextView colorText = (TextView) view.findViewById(R.id.color_dialog_text_value);
|
||||||
TextView okTextClick = (TextView) view.findViewById(R.id.OK_dialog);
|
TextView okTextClick = (TextView) view.findViewById(R.id.OK_dialog);
|
||||||
|
|
||||||
|
subjectText.setText(grade.getSubject());
|
||||||
gradeText.setText(grade.getValue());
|
gradeText.setText(grade.getValue());
|
||||||
gradeText.setBackgroundResource(grade.getValueColor());
|
gradeText.setBackgroundResource(grade.getValueColor());
|
||||||
subjectText.setText(grade.getSubject());
|
|
||||||
weightText.setText(grade.getWeight());
|
weightText.setText(grade.getWeight());
|
||||||
dateText.setText(grade.getDate());
|
dateText.setText(grade.getDate());
|
||||||
colorText.setText(colorHexToColorName(grade.getColor()));
|
colorText.setText(colorHexToColorName(grade.getColor()));
|
||||||
|
@ -10,9 +10,11 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import com.google.gson.Gson;
|
||||||
import java.io.ObjectInputStream;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -24,6 +26,7 @@ import io.github.wulkanowy.api.grades.Subject;
|
|||||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||||
import io.github.wulkanowy.database.accounts.Account;
|
import io.github.wulkanowy.database.accounts.Account;
|
||||||
import io.github.wulkanowy.database.accounts.AccountsDatabase;
|
import io.github.wulkanowy.database.accounts.AccountsDatabase;
|
||||||
|
import io.github.wulkanowy.database.cookies.CookiesDatabase;
|
||||||
import io.github.wulkanowy.database.grades.GradesDatabase;
|
import io.github.wulkanowy.database.grades.GradesDatabase;
|
||||||
import io.github.wulkanowy.database.subjects.SubjectsDatabase;
|
import io.github.wulkanowy.database.subjects.SubjectsDatabase;
|
||||||
|
|
||||||
@ -61,7 +64,8 @@ public class GradesFragment extends Fragment {
|
|||||||
public class MarksTask extends AsyncTask<Void, Void, Void> {
|
public class MarksTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Map<String, String> loginCookies;
|
|
||||||
|
private Map<String, String> loginCookies = new HashMap<>();
|
||||||
|
|
||||||
MarksTask(Context context) {
|
MarksTask(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@ -69,12 +73,15 @@ public class GradesFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
String cookiesPath = mContext.getFilesDir().getPath() + "/cookies.txt";
|
long userId = mContext.getSharedPreferences("LoginData", Context.MODE_PRIVATE).getLong("isLogin", 0);
|
||||||
long userId = mContext.getSharedPreferences("LoginData", mContext.MODE_PRIVATE).getLong("isLogin", 0);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(cookiesPath));
|
Gson gson = new GsonBuilder().enableComplexMapKeySerialization()
|
||||||
loginCookies = (Map<String, String>) ois.readObject();
|
.setPrettyPrinting().create();
|
||||||
|
CookiesDatabase cookiesDatabase = new CookiesDatabase(mContext);
|
||||||
|
cookiesDatabase.open();
|
||||||
|
loginCookies = gson.fromJson(cookiesDatabase.getCookies(), loginCookies.getClass());
|
||||||
|
cookiesDatabase.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -102,7 +109,7 @@ public class GradesFragment extends Fragment {
|
|||||||
gradesDatabase.open();
|
gradesDatabase.open();
|
||||||
gradesDatabase.put(gradesList.getAll());
|
gradesDatabase.put(gradesList.getAll());
|
||||||
|
|
||||||
for (Subject subject : subjectsList.getAll()) {
|
for (Subject subject : subjectsDatabase.getAllSubjectsNames()) {
|
||||||
List<GradeItem> gradeItems = gradesDatabase.getSubjectGrades(userId, SubjectsDatabase.getSubjectId(subject.getName()));
|
List<GradeItem> gradeItems = gradesDatabase.getSubjectGrades(userId, SubjectsDatabase.getSubjectId(subject.getName()));
|
||||||
if (gradeItems.size() > 0) {
|
if (gradeItems.size() > 0) {
|
||||||
subjectWithGradesList.add(new SubjectWithGrades(subject.getName(), gradeItems));
|
subjectWithGradesList.add(new SubjectWithGrades(subject.getName(), gradeItems));
|
||||||
|
@ -8,9 +8,10 @@ import android.database.SQLException;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.activity.dashboard.DashboardActivity;
|
import io.github.wulkanowy.activity.dashboard.DashboardActivity;
|
||||||
@ -24,6 +25,7 @@ import io.github.wulkanowy.api.user.BasicInformation;
|
|||||||
import io.github.wulkanowy.api.user.PersonalData;
|
import io.github.wulkanowy.api.user.PersonalData;
|
||||||
import io.github.wulkanowy.database.accounts.Account;
|
import io.github.wulkanowy.database.accounts.Account;
|
||||||
import io.github.wulkanowy.database.accounts.AccountsDatabase;
|
import io.github.wulkanowy.database.accounts.AccountsDatabase;
|
||||||
|
import io.github.wulkanowy.database.cookies.CookiesDatabase;
|
||||||
import io.github.wulkanowy.security.CryptoException;
|
import io.github.wulkanowy.security.CryptoException;
|
||||||
import io.github.wulkanowy.security.Safety;
|
import io.github.wulkanowy.security.Safety;
|
||||||
|
|
||||||
@ -67,12 +69,13 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
|
|||||||
return R.string.login_denied_text;
|
return R.string.login_denied_text;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String cookiesPath = activity.getFilesDir().getPath() + "/cookies.txt";
|
Gson gson = new GsonBuilder().enableComplexMapKeySerialization()
|
||||||
FileOutputStream out = new FileOutputStream(cookiesPath);
|
.setPrettyPrinting().create();
|
||||||
ObjectOutputStream outputStream = new ObjectOutputStream(out);
|
CookiesDatabase cookiesDatabase = new CookiesDatabase(activity);
|
||||||
outputStream.writeObject(login.getCookies());
|
cookiesDatabase.open();
|
||||||
outputStream.flush();
|
cookiesDatabase.put(gson.toJson(login.getCookies()));
|
||||||
} catch (IOException e) {
|
cookiesDatabase.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
return R.string.login_cookies_save_failed_text;
|
return R.string.login_cookies_save_failed_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
|||||||
AccountsDatabase accountsDatabase = new AccountsDatabase(activity);
|
AccountsDatabase accountsDatabase = new AccountsDatabase(activity);
|
||||||
accountsDatabase.open();
|
accountsDatabase.open();
|
||||||
|
|
||||||
if (accountsDatabase.checkExist("accounts", null, null)) {
|
if (accountsDatabase.checkExist("accounts")) {
|
||||||
try {
|
try {
|
||||||
Account account = accountsDatabase.getAccount(activity.getSharedPreferences("LoginData", activity.MODE_PRIVATE).getLong("isLogin", 0));
|
Account account = accountsDatabase.getAccount(activity.getSharedPreferences("LoginData", activity.MODE_PRIVATE).getLong("isLogin", 0));
|
||||||
accountsDatabase.close();
|
accountsDatabase.close();
|
||||||
|
@ -9,9 +9,13 @@ import android.util.Log;
|
|||||||
public class DatabaseAdapter {
|
public class DatabaseAdapter {
|
||||||
|
|
||||||
private final String DATABASE_NAME = "accountdatabase.db";
|
private final String DATABASE_NAME = "accountdatabase.db";
|
||||||
private final int DATABASE_VERSION = 2;
|
|
||||||
|
private final int DATABASE_VERSION = 3;
|
||||||
|
|
||||||
public static SQLiteDatabase database;
|
public static SQLiteDatabase database;
|
||||||
|
|
||||||
private DatabaseHelper databaseHelper;
|
private DatabaseHelper databaseHelper;
|
||||||
|
|
||||||
public Context context;
|
public Context context;
|
||||||
|
|
||||||
public DatabaseAdapter(Context context) {
|
public DatabaseAdapter(Context context) {
|
||||||
@ -69,12 +73,17 @@ public class DatabaseAdapter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkExist(String tableName) {
|
||||||
|
return checkExist(tableName, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteAndCreate(String tableName) {
|
public void deleteAndCreate(String tableName) {
|
||||||
|
|
||||||
database.execSQL(databaseHelper.DROP_TABLE + tableName);
|
database.execSQL(databaseHelper.DROP_TABLE + tableName);
|
||||||
database.execSQL(databaseHelper.SUBJECT_TABLE);
|
database.execSQL(databaseHelper.SUBJECT_TABLE);
|
||||||
database.execSQL(databaseHelper.ACCOUNT_TABLE);
|
database.execSQL(databaseHelper.ACCOUNT_TABLE);
|
||||||
database.execSQL(databaseHelper.GRADE_TABLE);
|
database.execSQL(databaseHelper.GRADE_TABLE);
|
||||||
|
database.execSQL(databaseHelper.COOKIES_TABLE);
|
||||||
|
|
||||||
Log.d(DatabaseHelper.DEBUG_TAG, "Recreate table " + tableName);
|
Log.d(DatabaseHelper.DEBUG_TAG, "Recreate table " + tableName);
|
||||||
|
|
||||||
|
@ -9,12 +9,14 @@ import android.util.Log;
|
|||||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public final static String DEBUG_TAG = "SQLiteWulkanowyDatabase";
|
public final static String DEBUG_TAG = "SQLiteWulkanowyDatabase";
|
||||||
|
|
||||||
public final String ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts( " +
|
public final String ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts( " +
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
"name TEXT, " +
|
"name TEXT, " +
|
||||||
"email TEXT," +
|
"email TEXT," +
|
||||||
"password TEXT, " +
|
"password TEXT, " +
|
||||||
"county TEXT );";
|
"county TEXT );";
|
||||||
|
|
||||||
public final String SUBJECT_TABLE = "CREATE TABLE IF NOT EXISTS subjects( " +
|
public final String SUBJECT_TABLE = "CREATE TABLE IF NOT EXISTS subjects( " +
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
"name TEXT, " +
|
"name TEXT, " +
|
||||||
@ -22,6 +24,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
"finalRating1 TEXT, " +
|
"finalRating1 TEXT, " +
|
||||||
"predictedRating2 TEXT, " +
|
"predictedRating2 TEXT, " +
|
||||||
"finalRating2 TEXT );";
|
"finalRating2 TEXT );";
|
||||||
|
|
||||||
public final String GRADE_TABLE = "CREATE TABLE IF NOT EXISTS grades( " +
|
public final String GRADE_TABLE = "CREATE TABLE IF NOT EXISTS grades( " +
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
"userID INTEGER, " +
|
"userID INTEGER, " +
|
||||||
@ -37,6 +40,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
"semester INTEGER, " +
|
"semester INTEGER, " +
|
||||||
"isNew INTEGER );";
|
"isNew INTEGER );";
|
||||||
|
|
||||||
|
public final String COOKIES_TABLE = "CREATE TABLE IF NOT EXISTS cookies( " +
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
|
"cookies TEXT );";
|
||||||
|
|
||||||
public final String DROP_TABLE = "DROP TABLE IF EXISTS ";
|
public final String DROP_TABLE = "DROP TABLE IF EXISTS ";
|
||||||
|
|
||||||
public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
|
public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
|
||||||
@ -48,6 +55,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL(ACCOUNT_TABLE);
|
db.execSQL(ACCOUNT_TABLE);
|
||||||
db.execSQL(SUBJECT_TABLE);
|
db.execSQL(SUBJECT_TABLE);
|
||||||
db.execSQL(GRADE_TABLE);
|
db.execSQL(GRADE_TABLE);
|
||||||
|
db.execSQL(COOKIES_TABLE);
|
||||||
Log.d(DEBUG_TAG, "Create database");
|
Log.d(DEBUG_TAG, "Create database");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +64,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL(DROP_TABLE + "accounts");
|
db.execSQL(DROP_TABLE + "accounts");
|
||||||
db.execSQL(DROP_TABLE + "subjects");
|
db.execSQL(DROP_TABLE + "subjects");
|
||||||
db.execSQL(DROP_TABLE + "grades");
|
db.execSQL(DROP_TABLE + "grades");
|
||||||
|
db.execSQL(DROP_TABLE + "cookies");
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
Log.d(DEBUG_TAG, "Database upgrade from ver." + oldVersion + " to ver." + newVersion);
|
Log.d(DEBUG_TAG, "Database upgrade from ver." + oldVersion + " to ver." + newVersion);
|
||||||
}
|
}
|
||||||
|
@ -41,25 +41,6 @@ public class AccountsDatabase extends DatabaseAdapter {
|
|||||||
throw new SQLException("Attempt to write on read-only database");
|
throw new SQLException("Attempt to write on read-only database");
|
||||||
}
|
}
|
||||||
|
|
||||||
public long update(Account account) throws SQLException {
|
|
||||||
|
|
||||||
ContentValues updateAccount = new ContentValues();
|
|
||||||
updateAccount.put(name, account.getName());
|
|
||||||
updateAccount.put(email, account.getEmail());
|
|
||||||
updateAccount.put(password, account.getPassword());
|
|
||||||
updateAccount.put(county, account.getCounty());
|
|
||||||
String args[] = {account.getId() + ""};
|
|
||||||
|
|
||||||
if (!database.isReadOnly()) {
|
|
||||||
long updateId = database.update(accounts, updateAccount, "id=?", args);
|
|
||||||
Log.d(DatabaseHelper.DEBUG_TAG, "Update account " + updateId + " into database");
|
|
||||||
return updateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.e(DatabaseHelper.DEBUG_TAG, "Attempt to write on read-only database");
|
|
||||||
throw new SQLException("Attempt to write on read-only database");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Account getAccount(long id) throws SQLException {
|
public Account getAccount(long id) throws SQLException {
|
||||||
|
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package io.github.wulkanowy.database.cookies;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.SQLException;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.database.DatabaseAdapter;
|
||||||
|
import io.github.wulkanowy.database.DatabaseHelper;
|
||||||
|
|
||||||
|
public class CookiesDatabase extends DatabaseAdapter {
|
||||||
|
|
||||||
|
private String cookies = "cookies";
|
||||||
|
|
||||||
|
public CookiesDatabase(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long put(String serializableCookiesMap) {
|
||||||
|
|
||||||
|
ContentValues newCookie = new ContentValues();
|
||||||
|
newCookie.put(cookies, serializableCookiesMap);
|
||||||
|
|
||||||
|
if (!database.isReadOnly()) {
|
||||||
|
if (!checkExist(cookies)) {
|
||||||
|
long newId = database.insertOrThrow(cookies, null, newCookie);
|
||||||
|
Log.d(DatabaseHelper.DEBUG_TAG, "Put cookies into database");
|
||||||
|
return newId;
|
||||||
|
} else {
|
||||||
|
deleteAndCreate(cookies);
|
||||||
|
long newId = database.insertOrThrow(cookies, null, newCookie);
|
||||||
|
Log.d(DatabaseHelper.DEBUG_TAG, "Put cookies into database");
|
||||||
|
return newId;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(DatabaseHelper.DEBUG_TAG, "Attempt to write on read-only database");
|
||||||
|
throw new SQLException("Attempt to write on read-only database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookies() {
|
||||||
|
|
||||||
|
String exec = "SELECT " + cookies + " FROM " + cookies;
|
||||||
|
|
||||||
|
Cursor cursor = database.rawQuery(exec, null);
|
||||||
|
|
||||||
|
cursor.moveToFirst();
|
||||||
|
|
||||||
|
String cookie = cursor.getString(0);
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
|
Log.d(DatabaseHelper.DEBUG_TAG, "Extract cookies from database");
|
||||||
|
|
||||||
|
return cookie;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,6 @@ package io.github.wulkanowy.database.grades;
|
|||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.CursorIndexOutOfBoundsException;
|
|
||||||
import android.database.SQLException;
|
import android.database.SQLException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -20,7 +19,6 @@ import io.github.wulkanowy.database.subjects.SubjectsDatabase;
|
|||||||
|
|
||||||
public class GradesDatabase extends DatabaseAdapter {
|
public class GradesDatabase extends DatabaseAdapter {
|
||||||
|
|
||||||
private String idText = "id";
|
|
||||||
private String userIdText = "userID";
|
private String userIdText = "userID";
|
||||||
private String subjectIdText = "subjectID";
|
private String subjectIdText = "subjectID";
|
||||||
private String subject = "subject";
|
private String subject = "subject";
|
||||||
@ -70,7 +68,7 @@ public class GradesDatabase extends DatabaseAdapter {
|
|||||||
List<Long> newIdList = new ArrayList<>();
|
List<Long> newIdList = new ArrayList<>();
|
||||||
List<Grade> preparedList;
|
List<Grade> preparedList;
|
||||||
|
|
||||||
if (checkExist(grades, null, null)) {
|
if (checkExist(grades)) {
|
||||||
preparedList = DatabaseComparer.compareGradesLists(gradeList, getAllUserGrades());
|
preparedList = DatabaseComparer.compareGradesLists(gradeList, getAllUserGrades());
|
||||||
deleteAndCreate(grades);
|
deleteAndCreate(grades);
|
||||||
} else {
|
} else {
|
||||||
@ -84,75 +82,6 @@ public class GradesDatabase extends DatabaseAdapter {
|
|||||||
return newIdList;
|
return newIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long update(Grade grade) throws SQLException {
|
|
||||||
|
|
||||||
ContentValues updateGrade = new ContentValues();
|
|
||||||
updateGrade.put(userIdText, grade.getUserID());
|
|
||||||
updateGrade.put(subjectIdText, grade.getSubjectID());
|
|
||||||
updateGrade.put(subject, grade.getSubject());
|
|
||||||
updateGrade.put(value, grade.getValue());
|
|
||||||
updateGrade.put(color, grade.getColor());
|
|
||||||
updateGrade.put(symbol, grade.getSymbol());
|
|
||||||
updateGrade.put(description, grade.getDescription());
|
|
||||||
updateGrade.put(weight, grade.getWeight());
|
|
||||||
updateGrade.put(date, grade.getDate());
|
|
||||||
updateGrade.put(teacher, grade.getTeacher());
|
|
||||||
updateGrade.put(semester, grade.getSemester());
|
|
||||||
updateGrade.put(isNew, grade.isNew() ? 1 : 0);
|
|
||||||
String args[] = {grade.getId() + ""};
|
|
||||||
|
|
||||||
if (!database.isReadOnly()) {
|
|
||||||
long updateId = database.update(grades, updateGrade, "id=?", args);
|
|
||||||
Log.d(DatabaseHelper.DEBUG_TAG, "Update grade " + updateId + " into database");
|
|
||||||
return updateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.e(DatabaseHelper.DEBUG_TAG, "Attempt to write on read-only database");
|
|
||||||
throw new SQLException("Attempt to write on read-only database");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Grade getGrade(long id) throws SQLException {
|
|
||||||
|
|
||||||
Grade grade = new Grade();
|
|
||||||
|
|
||||||
String[] columns = {idText, userIdText, subjectIdText, value, color, description, weight, date, teacher};
|
|
||||||
String args[] = {id + ""};
|
|
||||||
|
|
||||||
try {
|
|
||||||
Cursor cursor = database.query(grades, columns, "id=?", args, null, null, null, null);
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.moveToFirst();
|
|
||||||
grade.setId(cursor.getInt(0));
|
|
||||||
grade.setUserID(cursor.getInt(1));
|
|
||||||
grade.setSubjectID(cursor.getInt(2));
|
|
||||||
grade.setSubject(cursor.getString(3));
|
|
||||||
grade.setValue(cursor.getString(4));
|
|
||||||
grade.setColor(cursor.getString(5));
|
|
||||||
grade.setSymbol(cursor.getString(6));
|
|
||||||
grade.setDescription(cursor.getString(7));
|
|
||||||
grade.setWeight(cursor.getString(8));
|
|
||||||
grade.setDate(cursor.getString(9));
|
|
||||||
grade.setTeacher(cursor.getString(10));
|
|
||||||
grade.setSemester(cursor.getString(11));
|
|
||||||
grade.setIsNew(cursor.getInt(12) != 0);
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
|
|
||||||
Log.e(DatabaseHelper.DEBUG_TAG, e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (CursorIndexOutOfBoundsException e) {
|
|
||||||
|
|
||||||
Log.e(DatabaseHelper.DEBUG_TAG, e.getMessage());
|
|
||||||
throw new SQLException(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d(DatabaseHelper.DEBUG_TAG, "Extract grade " + id + " from database");
|
|
||||||
|
|
||||||
return grade;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<GradeItem> getSubjectGrades(long userId, long subjectId) throws SQLException {
|
public List<GradeItem> getSubjectGrades(long userId, long subjectId) throws SQLException {
|
||||||
|
|
||||||
String whereExec = "SELECT * FROM " + grades + " WHERE " + userIdText + "=? AND " + subjectIdText + "=?";
|
String whereExec = "SELECT * FROM " + grades + " WHERE " + userIdText + "=? AND " + subjectIdText + "=?";
|
||||||
|
@ -1,67 +1,67 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView 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_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="15dp"
|
android:minHeight="450dp"
|
||||||
android:minHeight="350dp"
|
android:minWidth="325dp"
|
||||||
android:minWidth="300dp"
|
android:orientation="vertical">
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="20dp">
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:minHeight="450dp"
|
||||||
|
android:padding="20dp"
|
||||||
|
tools:ignore="UselessParent">
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/dialog_grade_text"
|
android:id="@+id/dialog_grade_text"
|
||||||
android:layout_width="70dp"
|
android:layout_width="80dp"
|
||||||
android:layout_height="70dp"
|
android:layout_height="80dp"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_gravity="end"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/app_name"
|
android:text="@string/app_name"
|
||||||
android:textSize="30sp" />
|
android:textSize="30sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subject_dialog_text"
|
android:id="@+id/subject_dialog_text_value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_marginEnd="80dp"
|
android:layout_gravity="start"
|
||||||
android:layout_marginRight="80dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:text="@string/dialog_subject_text"
|
android:layout_marginEnd="90dp"
|
||||||
android:textSize="17sp" />
|
android:layout_marginRight="90dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
<TextView
|
android:maxLines="5"
|
||||||
android:id="@+id/subject_dialog_text_value"
|
android:minHeight="80dp"
|
||||||
android:layout_width="wrap_content"
|
android:minLines="2"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_below="@+id/subject_dialog_text"
|
|
||||||
android:layout_marginEnd="80dp"
|
|
||||||
android:layout_marginRight="80dp"
|
|
||||||
android:layout_marginTop="3dp"
|
|
||||||
android:text="@string/grades_text"
|
android:text="@string/grades_text"
|
||||||
android:textSize="12sp" />
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/description_dialog_text"
|
android:id="@+id/description_dialog_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/dialog_description_text"
|
|
||||||
android:textSize="17sp"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:layout_below="@+id/subject_dialog_text_value"
|
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true" />
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/subject_dialog_text_value"
|
||||||
|
android:text="@string/dialog_description_text"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="17sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/description_dialog_text_value"
|
android:id="@+id/description_dialog_text_value"
|
||||||
@ -70,11 +70,9 @@
|
|||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/description_dialog_text"
|
android:layout_below="@+id/description_dialog_text"
|
||||||
android:layout_marginEnd="80dp"
|
|
||||||
android:layout_marginRight="80dp"
|
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:maxLines="3"
|
|
||||||
android:text="@string/noDescription_text"
|
android:text="@string/noDescription_text"
|
||||||
|
android:textIsSelectable="true"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -84,8 +82,6 @@
|
|||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/description_dialog_text_value"
|
android:layout_below="@+id/description_dialog_text_value"
|
||||||
android:layout_marginEnd="80dp"
|
|
||||||
android:layout_marginRight="80dp"
|
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/dialog_weight_text"
|
android:text="@string/dialog_weight_text"
|
||||||
android:textSize="17sp" />
|
android:textSize="17sp" />
|
||||||
@ -94,22 +90,21 @@
|
|||||||
android:id="@+id/weight_dialog_text_value"
|
android:id="@+id/weight_dialog_text_value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/weight_dialog_text"
|
android:layout_below="@+id/weight_dialog_text"
|
||||||
android:layout_marginEnd="80dp"
|
|
||||||
android:layout_marginRight="80dp"
|
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:text="@string/grades_text"
|
android:text="@string/grades_text"
|
||||||
|
android:textIsSelectable="true"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/teacher_dialog_text"
|
android:id="@+id/teacher_dialog_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/weight_dialog_text_value"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/dialog_teacher_text"
|
android:text="@string/dialog_teacher_text"
|
||||||
android:textSize="17sp" />
|
android:textSize="17sp" />
|
||||||
@ -118,14 +113,21 @@
|
|||||||
android:id="@+id/teacher_dialog_text_value"
|
android:id="@+id/teacher_dialog_text_value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/teacher_dialog_text"
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:text="@string/grades_text"
|
android:text="@string/dialog_teacher_text"
|
||||||
|
android:textIsSelectable="true"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/color_dialog_text"
|
android:id="@+id/color_dialog_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/teacher_dialog_text_value"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/dialog_color_text"
|
android:text="@string/dialog_color_text"
|
||||||
android:textSize="17sp" />
|
android:textSize="17sp" />
|
||||||
@ -134,14 +136,21 @@
|
|||||||
android:id="@+id/color_dialog_text_value"
|
android:id="@+id/color_dialog_text_value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/color_dialog_text"
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:text="@string/grades_text"
|
android:text="@string/dialog_color_text"
|
||||||
|
android:textIsSelectable="true"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/date_dialog_text"
|
android:id="@+id/date_dialog_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/color_dialog_text_value"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/dialog_date_text"
|
android:text="@string/dialog_date_text"
|
||||||
android:textSize="17sp" />
|
android:textSize="17sp" />
|
||||||
@ -150,16 +159,14 @@
|
|||||||
android:id="@+id/date_dialog_text_value"
|
android:id="@+id/date_dialog_text_value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@+id/date_dialog_text"
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:text="@string/grades_text"
|
android:text="@string/dialog_date_text"
|
||||||
|
android:textIsSelectable="true"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:layout_marginTop="19dp">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/OK_dialog"
|
android:id="@+id/OK_dialog"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
@ -167,8 +174,9 @@
|
|||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_marginEnd="20dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:layout_marginRight="20dp"
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user