Skip to content

Commit

Permalink
File list fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bailuk committed Apr 28, 2024
1 parent 52f10e4 commit 325366d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class AndroidSyncTileBitmap : MapTileInterface {
return bitmap
}

val androidBitmap: android.graphics.Bitmap?
private val androidBitmap: android.graphics.Bitmap?
get() {
val b = bitmap
return if (b != null) {
AndroidGraphicFactory.getBitmap(b)
} else null
}

val androidCanvas: Canvas?
private val androidCanvas: Canvas?
get() {
val b = androidBitmap
return if (b != null) {
Expand All @@ -56,7 +56,8 @@ class AndroidSyncTileBitmap : MapTileInterface {

@Synchronized
override fun set(file: Foc, defaultTileSize: Int, transparent: Boolean) {
set(MapTileUtil.load(file, defaultTileSize, transparent))
free()
set(MapTileUtil.loadThrow(file, defaultTileSize, transparent))
}

@Throws(IOException::class)
Expand Down Expand Up @@ -93,6 +94,7 @@ class AndroidSyncTileBitmap : MapTileInterface {

@Synchronized
override fun set(defaultTileSize: Int, transparent: Boolean) {
free()
set(AndroidGraphicFactory.INSTANCE.createTileBitmap(defaultTileSize, transparent))
}

Expand Down Expand Up @@ -124,9 +126,7 @@ class AndroidSyncTileBitmap : MapTileInterface {

@Synchronized
override fun free() {
if (bitmap != null) {
bitmap!!.decrementRefCount()
}
bitmap?.apply { decrementRefCount() }
bitmap = null
size = Obj.MIN_SIZE.toLong()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class GtkSyncTileBitmap : MapTileInterface {

@Synchronized
override fun set(file: Foc, defaultTileSize: Int, transparent: Boolean) {
set(MapTileUtil.load(file, defaultTileSize, transparent))
free()
set(MapTileUtil.loadThrow(file, defaultTileSize, transparent))
}

@Synchronized
Expand Down
11 changes: 7 additions & 4 deletions aat-gtk/src/main/kotlin/ch/bailu/aat_gtk/view/list/FileList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import ch.bailu.gtk.gtk.MenuButton
import ch.bailu.gtk.gtk.Orientation
import ch.bailu.gtk.gtk.PopoverMenu
import ch.bailu.gtk.gtk.ScrolledWindow
import ch.bailu.gtk.gtk.Separator
import ch.bailu.gtk.gtk.SignalListItemFactory
import ch.bailu.gtk.gtk.Spinner
import ch.bailu.gtk.lib.bridge.ListIndex
import ch.bailu.gtk.lib.util.SizeLog
import ch.bailu.gtk.pango.EllipsizeMode
import ch.bailu.gtk.type.Str

class FileList(app: Application,
Expand Down Expand Up @@ -162,6 +162,7 @@ class FileList(app: Application,

onTeardown {
val item = ListItem(it.cast())
items[item]?.apply { teardown() }
items.remove(item)
logItems.log(items.size.toLong())
}
Expand Down Expand Up @@ -198,8 +199,9 @@ class FileList(app: Application,
append(menuButton)
addCssClass(Strings.linked)
})
append(Separator(Orientation.VERTICAL))
append(fileNameLabel)
append(fileNameLabel.apply {
ellipsize = EllipsizeMode.START
})
})

vbox.append(ScrolledWindow().apply {
Expand All @@ -220,7 +222,6 @@ class FileList(app: Application,
}
}


private fun selectAndFrame(index: Int) {
select(index)
if (isIndexValid(indexOfSelected)) {
Expand Down Expand Up @@ -265,9 +266,11 @@ class FileList(app: Application,
iteratorSimple.moveToPosition(indexOfSelected)
overlayMenu.setFile(iteratorSimple.info.file)
fileNameLabel.setLabel(iteratorSimple.info.file.name)
fileNameLabel.setTooltipText(iteratorSimple.info.file.toString())
menuButton.sensitive = true
} else {
fileNameLabel.label = Str.NULL
fileNameLabel.tooltipText = Str.NULL
menuButton.sensitive = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ class FileListItem(appContext: AppContext, listItem: ListItem, private val descr
labels[1].setText(infoText)
labels[2].setText(info.file.name)

previewImageView.setFilePath(info.file) // TODO error message if file does not exists
previewImageView.onAttached() // TODO memory management
previewImageView.setFilePath(info.file)
previewImageView.onAttached()
}

fun teardown() {
previewImageView.onDetached()
}
}
19 changes: 8 additions & 11 deletions aat-lib/src/main/java/ch/bailu/aat_lib/map/tile/MapTileUtil.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package ch.bailu.aat_lib.map.tile

import ch.bailu.aat_lib.app.AppGraphicFactory
import ch.bailu.aat_lib.logger.AppLog
import ch.bailu.foc.Foc
import org.mapsforge.core.graphics.TileBitmap
import java.io.IOException

object MapTileUtil {
fun load(file: Foc, size: Int, transparent: Boolean): TileBitmap? {
var result: TileBitmap? = null

try {
file.openR()?.use {
result = AppGraphicFactory.instance().createTileBitmap(it, size, transparent)
result?.timestamp = file.lastModified()
fun loadThrow(file: Foc, size: Int, transparent: Boolean): TileBitmap {
file.openR()?.use {
val result = AppGraphicFactory.instance().createTileBitmap(it, size, transparent)
if (result is TileBitmap) {
result.timestamp = file.lastModified()
return result
}
} catch (e: Exception) {
AppLog.e(this, e)
}
return result
throw IOException(file.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.bailu.aat_lib.service.cache

import ch.bailu.aat_lib.app.AppContext
import ch.bailu.aat_lib.dispatcher.AppBroadcaster
import ch.bailu.aat_lib.logger.AppLog
import ch.bailu.aat_lib.map.tile.MapTileInterface
import ch.bailu.aat_lib.map.tile.source.Source
import ch.bailu.aat_lib.preferences.map.SolidTileSize
Expand Down Expand Up @@ -89,7 +90,16 @@ open class ObjTileCacheOnly(id: String, sc: AppContext, private val tile: Tile,
object : OnObject(appContext, file.toString(), ObjTileCacheOnly::class.java) {
override fun run(handle: Obj) {
val tile = handle as ObjTileCacheOnly
tile.bitmap.set(file, SolidTileSize.DEFAULT_TILESIZE, tile.source.isTransparent)
try {
tile.bitmap.set(
file,
SolidTileSize.DEFAULT_TILESIZE,
tile.source.isTransparent
)
} catch (e : Exception) {
AppLog.e(this, e)
}

appContext.broadcaster.broadcast(
AppBroadcaster.FILE_CHANGED_INCACHE,
file.toString()
Expand Down

0 comments on commit 325366d

Please sign in to comment.