Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
ADFA-2443 | Move file I/O operations off the main thread#771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
81b4384d143be09481149a3e135ee1417623c2b86291a478d343d283fd3f2722fc5cb9f194bf22157501066f25d9faa8e0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ import android.net.Uri | ||
| import android.os.Bundle | ||
| import android.os.Handler | ||
| import android.os.Looper | ||
| import android.util.Log | ||
| import android.view.Menu | ||
| import android.view.MenuItem | ||
| import android.view.View | ||
| @@ -50,6 +51,7 @@ import org.appdevforall.codeonthego.layouteditor.editor.DeviceSize | ||
| import org.appdevforall.codeonthego.layouteditor.editor.convert.ConvertImportedXml | ||
| import org.appdevforall.codeonthego.layouteditor.managers.DrawableManager | ||
| import org.appdevforall.codeonthego.layouteditor.managers.IdManager.clear | ||
| import org.appdevforall.codeonthego.layouteditor.managers.PreferencesManager | ||
| import org.appdevforall.codeonthego.layouteditor.managers.ProjectManager | ||
| import org.appdevforall.codeonthego.layouteditor.managers.UndoRedoManager | ||
| import org.appdevforall.codeonthego.layouteditor.tools.XmlLayoutGenerator | ||
| @@ -147,31 +149,38 @@ class EditorActivity : BaseActivity() { | ||
| val createdAt = getCreatedTime(filePath).toString() | ||
| val modifiedAt = getLastModifiedTime(filePath).toString() | ||
| projectManager.openProject( | ||
| ProjectFile( | ||
| filePath, | ||
| createdAt, | ||
| modifiedAt, | ||
| this@EditorActivity, | ||
| mainLayoutName = fileName | ||
| try { | ||
| projectManager.openProject( | ||
| ProjectFile( | ||
| filePath, | ||
| createdAt, | ||
| modifiedAt, | ||
| this@EditorActivity, | ||
| mainLayoutName = fileName | ||
| ) | ||
| ) | ||
| project = projectManager.openedProject!! | ||
| invalidateOptionsMenu() | ||
| androidToDesignConversion( | ||
| Uri.fromFile(File(projectManager.openedProject?.mainLayout?.path ?: "")), | ||
| ) | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| project = projectManager.openedProject!! | ||
| invalidateOptionsMenu() | ||
| androidToDesignConversion( | ||
| Uri.fromFile(File(projectManager.openedProject?.mainLayout?.path ?: "")), | ||
| ) | ||
| supportActionBar?.title = project.name | ||
| layoutAdapter = LayoutListAdapter(project) | ||
| supportActionBar?.title = project.name | ||
| layoutAdapter = LayoutListAdapter(project) | ||
| binding.editorLayout.setBackgroundColor( | ||
| Utils.getSurfaceColor(this@EditorActivity) | ||
| ) | ||
| } catch (e: Exception) { | ||
| Log.e("EditorActivity", "Error loading project", e) | ||
| Toast.makeText( | ||
| this@EditorActivity, | ||
| getString(string.msg_error_opening_project), | ||
| Toast.LENGTH_SHORT | ||
| ).show() | ||
| finish() | ||
| } | ||
| } | ||
| } ?: showNothingDialog() | ||
| binding.editorLayout.setBackgroundColor( | ||
| Utils.getSurfaceColor( | ||
| this, | ||
| ), | ||
| ) | ||
| } | ||
| private fun defineXmlPicker() { | ||
| @@ -724,23 +733,30 @@ class EditorActivity : BaseActivity() { | ||
| } | ||
| } | ||
| private fun openLayout(layoutFile: LayoutFile) { | ||
| originalProductionXml = layoutFile.readLayoutFile() | ||
| originalDesignXml = layoutFile.readDesignFile() | ||
| private suspend fun openLayout(layoutFile: LayoutFile) { | ||
| val (production, design, layoutName) = withContext(Dispatchers.IO) { | ||
| val production = layoutFile.readLayoutFile() | ||
| var design = layoutFile.readDesignFile() | ||
| var contentToParse = layoutFile.readDesignFile() | ||
| if (design.isNullOrBlank() && !production.isNullOrBlank()) { | ||
| val converted = withContext(Dispatchers.Default) { | ||
| ConvertImportedXml(production).getXmlConverted(this@EditorActivity) | ||
| } | ||
| if (!converted.isNullOrBlank()) { | ||
| layoutFile.saveDesignFile(converted) | ||
| design = converted | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Triple(production, design, layoutFile.name) | ||
| } | ||
| originalProductionXml = production | ||
| originalDesignXml = design | ||
| if (contentToParse.isNullOrBlank()) { | ||
| val productionContent = layoutFile.readLayoutFile() | ||
| if (!productionContent.isNullOrBlank()) { | ||
| contentToParse = ConvertImportedXml(productionContent).getXmlConverted(this) | ||
| contentToParse?.let { layoutFile.saveDesignFile(it) } | ||
| } | ||
| } | ||
| binding.editorLayout.loadLayoutFromParser(design) | ||
| binding.editorLayout.loadLayoutFromParser(contentToParse) | ||
| project.currentLayout = layoutFile | ||
| supportActionBar!!.subtitle = layoutFile.name | ||
| supportActionBar?.subtitle = layoutName | ||
| if (drawerLayout.isDrawerOpen(GravityCompat.START)) { | ||
| drawerLayout.closeDrawer(GravityCompat.START) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.