Skip to content

Commit

Permalink
Add cathash image support for android client
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Nov 30, 2024
1 parent 218185e commit 3bb16a3
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network.bisq.mobile.client

import android.app.Application
import network.bisq.mobile.client.di.androidClientModule
import network.bisq.mobile.client.di.clientModule
import network.bisq.mobile.domain.di.domainModule
import network.bisq.mobile.presentation.di.presentationModule
Expand All @@ -14,7 +15,7 @@ class MainApplication: Application() {

startKoin {
androidContext(this@MainApplication)
modules(listOf(domainModule, presentationModule, clientModule))
modules(listOf(domainModule, presentationModule, clientModule, androidClientModule))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package network.bisq.mobile.client.di

import network.bisq.mobile.client.cathash.ClientCatHashService
import network.bisq.mobile.service.AndroidClientCatHashService
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.bind
import org.koin.dsl.module


val androidClientModule = module {
single {
val context = androidContext()
val filesDir = context.filesDir.absolutePath
AndroidClientCatHashService(context, filesDir)
} bind ClientCatHashService::class
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This iconFilePath is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package network.bisq.mobile.service

import android.content.Context
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.asImageBitmap
import network.bisq.mobile.client.cathash.ClientCatHashService
import network.bisq.mobile.utils.ImageUtil
import network.bisq.mobile.utils.ImageUtil.PATH_TO_DRAWABLE
import java.io.File

const val CAT_HASH_PATH = PATH_TO_DRAWABLE + "cathash/"

class AndroidClientCatHashService(private val context: Context, filesDir: String) :
ClientCatHashService<ImageBitmap>("$filesDir/Bisq2_mobile") {
override fun composeImage(paths: Array<String>, size: Int): ImageBitmap {
return ImageUtil.composeImage(
context,
CAT_HASH_PATH,
paths,
size,
size
).asImageBitmap()
}

override fun writeRawImage(image: ImageBitmap, iconFilePath: String) {
ImageUtil.writeRawImage(image.asAndroidBitmap(), File(iconFilePath))
}

override fun readRawImage(iconFilePath: String): ImageBitmap? {
return ImageUtil.readRawImage(File((iconFilePath)))?.asImageBitmap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ val clientModule = module {
single<MarketPriceServiceFacade> { ClientMarketPriceServiceFacade(get()) }

single { UserProfileApiGateway(get()) }
single<UserProfileServiceFacade> { ClientUserProfileServiceFacade(get()) }
single<UserProfileServiceFacade> { ClientUserProfileServiceFacade(get(), get()) }

single { OfferbookApiGateway(get()) }
single<OfferbookServiceFacade> { ClientOfferbookServiceFacade(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import network.bisq.mobile.client.offerbook.market.ClientMarketListItemService
import network.bisq.mobile.client.offerbook.market.ClientSelectedOfferbookMarketService
import network.bisq.mobile.client.offerbook.offer.ClientOfferbookListItemService
import network.bisq.mobile.client.offerbook.offer.OfferbookApiGateway
import network.bisq.mobile.domain.service.market_price.MarketPriceServiceFacade
import network.bisq.mobile.domain.data.model.OfferListItem
import network.bisq.mobile.domain.service.offerbook.OfferbookServiceFacade
import network.bisq.mobile.domain.data.model.MarketListItem
import network.bisq.mobile.domain.data.model.OfferListItem
import network.bisq.mobile.domain.data.model.OfferbookMarket
import network.bisq.mobile.domain.service.market_price.MarketPriceServiceFacade
import network.bisq.mobile.domain.service.offerbook.OfferbookServiceFacade
import network.bisq.mobile.utils.Logging

class ClientOfferbookServiceFacade(
Expand All @@ -24,8 +24,10 @@ class ClientOfferbookServiceFacade(
override val selectedOfferbookMarket: StateFlow<OfferbookMarket> get() = selectedOfferbookMarketService.selectedOfferbookMarket

// Misc
private val offerbookListItemService: ClientOfferbookListItemService = ClientOfferbookListItemService(apiGateway)
private val marketListItemService: ClientMarketListItemService = ClientMarketListItemService(apiGateway)
private val offerbookListItemService: ClientOfferbookListItemService =
ClientOfferbookListItemService(apiGateway)
private val marketListItemService: ClientMarketListItemService =
ClientMarketListItemService(apiGateway)
private val selectedOfferbookMarketService: ClientSelectedOfferbookMarketService =
ClientSelectedOfferbookMarketService(marketPriceServiceFacade)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ package network.bisq.mobile.client.user_profile

import kotlinx.coroutines.delay
import kotlinx.datetime.Clock
import network.bisq.mobile.client.cathash.ClientCatHashService
import network.bisq.mobile.client.replicated_model.user.identity.PreparedData
import network.bisq.mobile.client.replicated_model.user.profile.UserProfile
import network.bisq.mobile.domain.service.user_profile.UserProfileServiceFacade
import network.bisq.mobile.utils.Logging
import network.bisq.mobile.utils.hexToByteArray
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

class ClientUserProfileServiceFacade(private val apiGateway: UserProfileApiGateway) :
class ClientUserProfileServiceFacade(
private val apiGateway: UserProfileApiGateway,
private val clientCatHashService: ClientCatHashService<Any>
) :
UserProfileServiceFacade, Logging {

// Misc
Expand All @@ -26,8 +31,15 @@ class ClientUserProfileServiceFacade(private val apiGateway: UserProfileApiGatew
val ts = Clock.System.now().toEpochMilliseconds()
val preparedData = apiGateway.requestPreparedData()
createSimulatedDelay(Clock.System.now().toEpochMilliseconds() - ts)
//todo not impl yet
result(preparedData.id, preparedData.nym, null)
val pubKeyHash: ByteArray = preparedData.id.hexToByteArray()
val powSolution = preparedData.proofOfWork.solution
val image = clientCatHashService.getImage(
pubKeyHash,
powSolution,
0,
120
)
result(preparedData.id, preparedData.nym, image)
this.preparedData = preparedData
} catch (e: Exception) {
log.e { e.toString() }
Expand Down

0 comments on commit 3bb16a3

Please sign in to comment.