Commit 8d47aa52 authored by Filip Wiesner's avatar Filip Wiesner

Widget not updating, Teacher without username fix

parent 888c707d
{
"formatVersion": 1,
"database": {
"version": 10,
"identityHash": "c82af5ad9a4208e83145de4872eee9a2",
"entities": [
{
"tableName": "Event",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `sequenceNum` INTEGER NOT NULL, `startsAt` INTEGER NOT NULL, `endsAt` INTEGER NOT NULL, `deleted` INTEGER NOT NULL, `capacity` INTEGER NOT NULL, `occupied` INTEGER NOT NULL, `eventTypeRaw` TEXT NOT NULL, `parallel` TEXT NOT NULL, `cs` TEXT, `en` TEXT, `course` TEXT, `room` TEXT, `teachers` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "sequenceNum",
"columnName": "sequenceNum",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "startsAt",
"columnName": "startsAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "endsAt",
"columnName": "endsAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "deleted",
"columnName": "deleted",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "capacity",
"columnName": "capacity",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "occupied",
"columnName": "occupied",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "eventTypeRaw",
"columnName": "eventTypeRaw",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "parallel",
"columnName": "parallel",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "note.cs",
"columnName": "cs",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "note.en",
"columnName": "en",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linked.course",
"columnName": "course",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linked.room",
"columnName": "room",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linked.teachers",
"columnName": "teachers",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_Event_eventTypeRaw",
"unique": false,
"columnNames": [
"eventTypeRaw"
],
"createSql": "CREATE INDEX `index_Event_eventTypeRaw` ON `${TABLE_NAME}` (`eventTypeRaw`)"
}
],
"foreignKeys": []
},
{
"tableName": "EventNote",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`noteId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `eventId` INTEGER NOT NULL, `note` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "noteId",
"columnName": "noteId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "eventId",
"columnName": "eventId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "note",
"columnName": "note",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"noteId"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_EventNote_eventId",
"unique": true,
"columnNames": [
"eventId"
],
"createSql": "CREATE UNIQUE INDEX `index_EventNote_eventId` ON `${TABLE_NAME}` (`eventId`)"
}
],
"foreignKeys": []
},
{
"tableName": "Course",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`code` TEXT NOT NULL, `completion` TEXT NOT NULL, `credits` INTEGER NOT NULL, `department` TEXT NOT NULL, `homepage` TEXT, `name` TEXT NOT NULL, `range` TEXT NOT NULL, `season` TEXT NOT NULL, `state` TEXT NOT NULL, `studyForm` TEXT, PRIMARY KEY(`code`))",
"fields": [
{
"fieldPath": "code",
"columnName": "code",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "completion",
"columnName": "completion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "credits",
"columnName": "credits",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "department",
"columnName": "department",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "homepage",
"columnName": "homepage",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "range",
"columnName": "range",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "season",
"columnName": "season",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "state",
"columnName": "state",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "studyForm",
"columnName": "studyForm",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"code"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "Teacher",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`firstName` TEXT NOT NULL, `lastName` TEXT NOT NULL, `personalNumber` INTEGER NOT NULL, `titlesPost` TEXT, `titlesPre` TEXT, `username` TEXT, `division` TEXT NOT NULL, `email` TEXT NOT NULL, `extern` INTEGER NOT NULL, `phone` TEXT, PRIMARY KEY(`personalNumber`))",
"fields": [
{
"fieldPath": "firstName",
"columnName": "firstName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastName",
"columnName": "lastName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "personalNumber",
"columnName": "personalNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "titlesPost",
"columnName": "titlesPost",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "titlesPre",
"columnName": "titlesPre",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "division",
"columnName": "division",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "email",
"columnName": "email",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "extern",
"columnName": "extern",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "phone",
"columnName": "phone",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"personalNumber"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"c82af5ad9a4208e83145de4872eee9a2\")"
]
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 9,
"identityHash": "37125790ad99f4a37db3a5a5401a8f52",
"identityHash": "c82af5ad9a4208e83145de4872eee9a2",
"entities": [
{
"tableName": "Event",
......@@ -228,7 +228,7 @@
},
{
"tableName": "Teacher",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`firstName` TEXT NOT NULL, `lastName` TEXT NOT NULL, `personalNumber` INTEGER NOT NULL, `titlesPost` TEXT, `titlesPre` TEXT, `username` TEXT NOT NULL, `division` TEXT NOT NULL, `email` TEXT NOT NULL, `extern` INTEGER NOT NULL, `phone` TEXT, PRIMARY KEY(`username`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`firstName` TEXT NOT NULL, `lastName` TEXT NOT NULL, `personalNumber` INTEGER NOT NULL, `titlesPost` TEXT, `titlesPre` TEXT, `username` TEXT, `division` TEXT NOT NULL, `email` TEXT NOT NULL, `extern` INTEGER NOT NULL, `phone` TEXT, PRIMARY KEY(`personalNumber`))",
"fields": [
{
"fieldPath": "firstName",
......@@ -264,7 +264,7 @@
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": true
"notNull": false
},
{
"fieldPath": "division",
......@@ -293,7 +293,7 @@
],
"primaryKey": {
"columnNames": [
"username"
"personalNumber"
],
"autoGenerate": false
},
......@@ -301,9 +301,10 @@
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"37125790ad99f4a37db3a5a5401a8f52\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"c82af5ad9a4208e83145de4872eee9a2\")"
]
}
}
\ No newline at end of file
......@@ -53,12 +53,14 @@ class AuthFragment : Fragment() {
infoMessage.text = when (result) {
is Success -> {
onAuthFinished()
"Succesfully fetched"
"Successfully fetched"
}
is Failure -> {
UserInfo.username = ""
result.message
}
else -> "Loading"
}
}
......
......@@ -20,7 +20,7 @@ class AuthViewModel : BlackBirdVM() {
private val _authStatus = MutableLiveData<AuthResult>() withDefault AuthResult.NOT_YET
private val _authLoadingStatus = MutableLiveData<Boolean>() withDefault false
private val _userInitResult = MutableLiveData<Result<Unit>>() withDefault NotYet()
private val _userInitState = MutableLiveData<String>() withDefault "Didn't start yet"
private val _userInitState = MutableLiveData<String>() withDefault "Waiting for login"
val authStatus: LiveData<AuthResult> get() = _authStatus
val authLoadingStatus: LiveData<Boolean> get() = _authLoadingStatus
......
......@@ -5,9 +5,6 @@ import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Intent
import android.os.IBinder
import androidx.room.Room
import com.cvut.blackbird.model.database.BlackBirdDB
import org.jetbrains.anko.toast
class NextEventService : Service() {
......@@ -21,21 +18,6 @@ class NextEventService : Service() {
.getAppWidgetIds(ComponentName(this@NextEventService, NextEventWidget::class.java))
)
})
// val db: BlackBirdDB = Room
// .databaseBuilder(this, BlackBirdDB::class.java, "blackbird_DB")
// .fallbackToDestructiveMigration()
// .build()
//
// val appWidgetManager = AppWidgetManager.getInstance(this)
// val allWidgetIds = intent?.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)
//
// if (allWidgetIds != null) {
// for (appWidgetId in allWidgetIds) {
// NextEventWidget.updateAppWidget(this, appWidgetManager, appWidgetId, db)
// }
// }
// toast("next service RUNNING")
return super.onStartCommand(intent, flags, startId)
}
......
......@@ -6,6 +6,7 @@ import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.os.SystemClock
import android.widget.RemoteViews
import androidx.room.Room
import com.cvut.blackbird.R
......@@ -65,11 +66,6 @@ class NextEventWidget : AppWidgetProvider() {
).let {
PendingIntent.getService(context, 0, it, PendingIntent.FLAG_CANCEL_CURRENT)
}
private fun updateInMillis(millis: Long, pendingIntent: PendingIntent, context: Context) {
val alarm = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarm.set(AlarmManager.ELAPSED_REALTIME, millis, pendingIntent)
}
}
......@@ -84,26 +80,12 @@ class NextEventWidget : AppWidgetProvider() {
// There may be multiple widgets active, so update all of them
for (appWidgetId in appWidgetIds)
updateAppWidget(context, appWidgetManager, appWidgetId, db)
if (pendingIntent == null) pendingIntent = createPending(context)
updateInMillis(updateInterval, pendingIntent!!, context)
}
override fun onEnabled(context: Context) {
// if(pendingIntent == null)
// pendingIntent = createPending(context)
//
// val alarm = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
//
// alarm.setRepeating(
// AlarmManager.ELAPSED_REALTIME,
// SystemClock.elapsedRealtime() + updateInterval,
// updateInterval,
// pendingIntent
// )
// updateInMillis(5000, pendingIntent!!, context)
// alarm.setExact(AlarmManager.ELAPSED_REALTIME, 1000 * 5, pending)
if (pendingIntent == null) pendingIntent = createPending(context)
val alarm = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), updateInterval, pendingIntent)
}
override fun onDisabled(context: Context) {
......
......@@ -14,7 +14,7 @@ import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat
@Database(entities = [Event::class, EventNote::class, Course::class, Teacher::class], version = 9)
@Database(entities = [Event::class, EventNote::class, Course::class, Teacher::class], version = 10)
@TypeConverters(DBTypeConverters::class)
abstract class BlackBirdDB: RoomDatabase() {
abstract fun eventDao(): EventDao
......
......@@ -15,6 +15,7 @@ data class Teacher(
@Path("atom:content")
@PropertyElement val lastName: String,
@PrimaryKey
@Path("atom:content")
@PropertyElement val personalNumber: Int,
......@@ -24,9 +25,8 @@ data class Teacher(
@Path("atom:content")
@PropertyElement val titlesPre: String?,
@PrimaryKey
@Path("atom:content")
@PropertyElement val username: String,
@PropertyElement val username: String?,
@Path("atom:content")
@PropertyElement val division: String,
......
......@@ -4,7 +4,6 @@
android:initialLayout="@layout/next_event_widget"
android:minWidth="40dp"
android:minHeight="40dp"
android:previewImage="@drawable/example_appwidget_preview"
android:resizeMode="none"
android:updatePeriodMillis="1800"
android:updatePeriodMillis="-1"
android:widgetCategory="home_screen|keyguard"/>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment