Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,14 @@ object FileIO {
var workspaceReturnValue: WorkspaceReturnValue? = null
if (temporaryFilePath != null) {
try {
val stream = FileInputStream(temporaryFilePath)
workspaceReturnValue = commandSerializer.readFromInternalMemory(stream)
FileInputStream(temporaryFilePath).use { stream ->
workspaceReturnValue = commandSerializer.readFromInternalMemory(stream)
}
} catch (e: IOException) {
Log.e("Cannot read", "Can't read from stream", e)
} catch (e: RuntimeException){
Log.e("Paintroid", "Temporary file corrupted", e)
deleteTempFile(File(temporaryFilePath))
}
}
return workspaceReturnValue
Expand Down
31 changes: 20 additions & 11 deletions Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,18 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
presenterMain.initializeFromCleanState(picturePath, pictureName)

if (!model.isOpenedFromCatroid && presenterMain.checkForTemporaryFile() && (!isRunningEspressoTests || isTemporaryFileSavingTest)) {
val workspaceReturnValue = presenterMain.openTemporaryFile()
commandManager.loadCommandsCatrobatImage(workspaceReturnValue?.commandManagerModel)
model.colorHistory = workspaceReturnValue?.colorHistory ?: ColorHistory()
model.colorHistory.colors.lastOrNull()?.let {
toolReference.tool?.changePaintColor(it)
presenterMain.setBottomNavigationColor(it)
try{
val workspaceReturnValue = presenterMain.openTemporaryFile()
commandManager.loadCommandsCatrobatImage(workspaceReturnValue?.commandManagerModel)
model.colorHistory = workspaceReturnValue?.colorHistory ?: ColorHistory()
model.colorHistory.colors.lastOrNull()?.let {
toolReference.tool?.changePaintColor(it)
presenterMain.setBottomNavigationColor(it)
}
}
catch(e: Exception){
Log.e("Paintroid", "Temporary file Corrupted Error: ", e)
presenterMain.initializeFromCleanState(null, null)
}
}
workspace.perspective.setBitmapDimensions(layerModel.width, layerModel.height)
Expand Down Expand Up @@ -407,12 +413,15 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
}

private fun getAppFragment() {
supportFragmentManager.findFragmentByTag(APP_FRAGMENT_KEY)?.let { fragment ->
appFragment = fragment as PaintroidApplicationFragment
}
if (!this::appFragment.isInitialized) {
val existing = supportFragmentManager.findFragmentByTag(APP_FRAGMENT_KEY)

if (existing is PaintroidApplicationFragment) {
appFragment = existing
} else {
appFragment = PaintroidApplicationFragment()
supportFragmentManager.beginTransaction().add(appFragment, APP_FRAGMENT_KEY).commit()
supportFragmentManager.beginTransaction()
.add(appFragment, APP_FRAGMENT_KEY)
.commitNow()
}
}

Expand Down