Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Fix crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed May 18, 2018
1 parent f8ea502 commit 38779ea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LogsFilterFragment : DialogFragment(), DialogInterface.OnClickListener, Di
val data = Intent()
data.putExtra(Constants.Bundle.LOGS_GROUPS, selectedItems)

this.targetFragment?.onActivityResult(this.targetRequestCode, Activity.RESULT_OK, data)
this.parentFragment?.onActivityResult(LogsFragment.REQUEST_CODE_FILTER, Activity.RESULT_OK, data)

dialog?.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ class LogsFragment : Fragment(), Callback<Logs>, RealmChangeListener<RealmResult
}

private fun handleLogsGroupFilter() {
val fragment = LogsFilterFragment.newInstance(this.groups)
fragment.setTargetFragment(this, REQUEST_CODE_FILTER)
fragment.show(this.childFragmentManager, "logs_filter")
LogsFilterFragment.newInstance(this.groups)
.show(this.childFragmentManager, "logs_filter")
}

private fun handleLogsLevelSelection(item: MenuItem?): Boolean {
Expand Down Expand Up @@ -256,8 +255,9 @@ class LogsFragment : Fragment(), Callback<Logs>, RealmChangeListener<RealmResult
}

companion object {
const val REQUEST_CODE_FILTER = 1

private const val AUTO_UPDATE_JOB_TAG = "logs-auto-update-tag"
private const val REQUEST_CODE_FILTER = 1
private const val TOLERANCE_RATIO = 0.1

internal fun getLogLevelForMenuId(menuId: Int?) = when (menuId) {
Expand Down
33 changes: 26 additions & 7 deletions app/src/main/kotlin/com/mgaetan89/showsrage/helper/Migration.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.mgaetan89.showsrage.helper

import com.mgaetan89.showsrage.model.Episode
import com.mgaetan89.showsrage.model.History
import com.mgaetan89.showsrage.model.LogEntry
import com.mgaetan89.showsrage.model.RealmString
import com.mgaetan89.showsrage.model.RootDir
import com.mgaetan89.showsrage.model.Schedule
import com.mgaetan89.showsrage.model.Show
import io.realm.DynamicRealm
import io.realm.RealmMigration
import io.realm.RealmSchema
Expand Down Expand Up @@ -54,6 +59,12 @@ class Migration : RealmMigration {

localOldVersion++
}

if (localOldVersion == 7L) {
this.updateToV8(schema)

localOldVersion++
}
}

override fun equals(other: Any?) = other is Migration
Expand Down Expand Up @@ -91,24 +102,27 @@ class Migration : RealmMigration {
}

private fun updateToV7(schema: RealmSchema) {
schema.get("Episode")
schema.get(Episode::class.java.simpleName)
?.setRequired("airDate", true)
?.setRequired("id", true)
?.setRequired("name", true)
?.setRequired("quality", true)
?.setRequired("subtitles", true)

schema.get("History")?.setRequired("id", true)
schema.get(History::class.java.simpleName)
?.setRequired("id", true)

schema.get("LogEntry")
schema.get(LogEntry::class.java.simpleName)
?.setRequired("dateTime", true)
?.setRequired("message", true)

schema.get("RealmString")?.setRequired("value", true)
schema.get(RealmString::class.java.simpleName)
?.setRequired("value", true)

schema.get("RootDir")?.setRequired("location", true)
schema.get(RootDir::class.java.simpleName)
?.setRequired("location", true)

schema.get("Schedule")
schema.get(Schedule::class.java.simpleName)
?.setRequired("airDate", true)
?.setRequired("airs", true)
?.setRequired("episodeName", true)
Expand All @@ -120,10 +134,15 @@ class Migration : RealmMigration {
?.setRequired("showName", true)
?.setRequired("showStatus", true)

schema.get("Show")
schema.get(Show::class.java.simpleName)
?.setRequired("network", true)
?.setRequired("nextEpisodeAirDate", true)
?.setRequired("quality", true)
?.setRequired("tvRageName", true)
}

private fun updateToV8(schema: RealmSchema) {
schema.get(Schedule::class.java.simpleName)
?.setRequired("episodePlot", false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.realm.Realm
import io.realm.RealmConfiguration

object Utils {
private const val DATABASE_VERSION = 7L
private const val DATABASE_VERSION = 8L

fun createRealmConfiguration(assetFile: String?): RealmConfiguration {
return RealmConfiguration.Builder().let {
Expand Down

0 comments on commit 38779ea

Please sign in to comment.