Skip to content

Commit

Permalink
Merge pull request #136 from ergoplatform/release/2.0.x
Browse files Browse the repository at this point in the history
Release 2.0.2214
  • Loading branch information
MrStahlfelge authored Aug 12, 2022
2 parents 2072cfc + cb9c8b0 commit 7952095
Show file tree
Hide file tree
Showing 70 changed files with 2,841 additions and 418 deletions.
2 changes: 1 addition & 1 deletion android/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
### Create the APK
* Clone this repo
* Download and install Android SDK (not necessary when you installed Android Studio)
* Set up OpenJDK8 (not necessary when you installed Android Studio)
* Set up OpenJDK11 (not necessary when you installed Android Studio)
* Run `./gradlew assembleDebug`
21 changes: 19 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ android {
applicationId "org.ergoplatform.android"
minSdkVersion 24
targetSdkVersion 31
versionCode 2213
versionName "1.10.2213"
versionCode 2214
versionName "2.0.2214"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
compose true
}

buildTypes {
release {
minifyEnabled true
Expand Down Expand Up @@ -59,6 +63,11 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}

composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion kotlin_version
}
}

dependencies {
Expand Down Expand Up @@ -101,6 +110,14 @@ dependencies {
// work around guava duplicate classes with guava 20.0 (fixed in 27+ but not usable)
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

// Compose
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.foundation:foundation-layout:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "com.github.MrStahlfelge.mosaik:common-compose:$mosaik_version"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
8 changes: 7 additions & 1 deletion android/src/main/java/org/ergoplatform/android/App.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.ergoplatform.android

import StageConstants
import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import org.ergoplatform.WalletStateSyncManager
import org.ergoplatform.appkit.NetworkType
import org.ergoplatform.isErgoMainNet
import org.ergoplatform.mosaik.MosaikLogger
import org.ergoplatform.utils.LogUtils

class App : Application() {
Expand All @@ -19,9 +21,13 @@ class App : Application() {
isErgoMainNet = (StageConstants.NETWORK_TYPE == NetworkType.MAINNET)
val preferences = Preferences(applicationContext)
AppCompatDelegate.setDefaultNightMode(preferences.dayNightMode)
WalletStateSyncManager.getInstance().loadPreferenceValues(preferences, AppDatabase.getInstance(applicationContext))
WalletStateSyncManager.getInstance()
.loadPreferenceValues(preferences, AppDatabase.getInstance(applicationContext))

LogUtils.stackTraceLogger = { lastStackTrace = it }
LogUtils.logDebug = BuildConfig.DEBUG
MosaikLogger.logger = { severity, msg, throwable ->
LogUtils.logDebug("Mosaik", "$severity: $msg", throwable)
}
}
}
50 changes: 48 additions & 2 deletions android/src/main/java/org/ergoplatform/android/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import androidx.room.withTransaction
import androidx.sqlite.db.SupportSQLiteDatabase
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import org.ergoplatform.android.mosaik.MosaikAppDbEntity
import org.ergoplatform.android.mosaik.MosaikDbDao
import org.ergoplatform.android.mosaik.MosaikHostDbEntity
import org.ergoplatform.android.mosaik.toDbEntity
import org.ergoplatform.android.tokens.TokenDbDao
import org.ergoplatform.android.tokens.TokenInformationDbEntity
import org.ergoplatform.android.tokens.TokenPriceDbEntity
Expand All @@ -18,6 +22,9 @@ import org.ergoplatform.android.transactions.AddressTransactionTokenDbEntity
import org.ergoplatform.android.transactions.TransactionDbDao
import org.ergoplatform.android.transactions.toDbEntity
import org.ergoplatform.android.wallet.*
import org.ergoplatform.mosaik.MosaikAppEntry
import org.ergoplatform.mosaik.MosaikAppHost
import org.ergoplatform.mosaik.MosaikDbProvider
import org.ergoplatform.persistance.*

@Database(
Expand All @@ -29,15 +36,18 @@ import org.ergoplatform.persistance.*
AddressTransactionDbEntity::class,
AddressTransactionTokenDbEntity::class,
TokenPriceDbEntity::class,
TokenInformationDbEntity::class
TokenInformationDbEntity::class,
MosaikAppDbEntity::class,
MosaikHostDbEntity::class,
],
version = 7,
version = 8,
exportSchema = false
)
abstract class AppDatabase : RoomDatabase(), IAppDatabase {
abstract fun walletDao(): WalletDbDao
abstract fun tokenDao(): TokenDbDao
abstract fun transactionDao(): TransactionDbDao
abstract fun mosaikDao(): MosaikDbDao

companion object {

Expand All @@ -59,6 +69,7 @@ abstract class AppDatabase : RoomDatabase(), IAppDatabase {
.addMigrations(MIGRATION_4_5)
.addMigrations(MIGRATION_5_6)
.addMigrations(MIGRATION_6_7)
.addMigrations(MIGRATION_7_8)
.build()
}

Expand Down Expand Up @@ -116,12 +127,23 @@ abstract class AppDatabase : RoomDatabase(), IAppDatabase {
database.execSQL("CREATE INDEX IF NOT EXISTS `index_address_transaction_token_address_tx_id` ON `address_transaction_token` (`address`, `tx_id`)")
}
}

private val MIGRATION_7_8 = object : Migration(7, 8) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `mosaik_app` (`url` TEXT NOT NULL, `name` TEXT NOT NULL, `description` TEXT, `iconFile` TEXT, `last_visited` INTEGER NOT NULL, `favorite` INTEGER NOT NULL, PRIMARY KEY(`url`))")
database.execSQL("CREATE INDEX IF NOT EXISTS `index_mosaik_app_favorite_name` ON `mosaik_app` (`favorite`, `name`)")
database.execSQL("CREATE TABLE IF NOT EXISTS `mosaik_host` (`hostName` TEXT NOT NULL, `guid` TEXT NOT NULL, PRIMARY KEY(`hostName`))")
}
}

}

override val tokenDbProvider get() = RoomTokenDbProvider(this)
override val walletDbProvider get() = RoomWalletDbProvider(this)
override val transactionDbProvider: TransactionDbProvider
get() = RoomTransactionDbProvider(this)
override val mosaikDbProvider: MosaikDbProvider
get() = RoomMosaikDbProvider(this)
}

class RoomWalletDbProvider(private val database: AppDatabase) : WalletDbProvider {
Expand Down Expand Up @@ -288,4 +310,28 @@ class RoomTransactionDbProvider(private val database: AppDatabase) : Transaction
.map { it.toModel() }
}

}

class RoomMosaikDbProvider(private val database: AppDatabase) : MosaikDbProvider {
override suspend fun loadAppEntry(url: String): MosaikAppEntry? =
database.mosaikDao().loadAppEntry(url)?.toModel()

override suspend fun insertOrUpdateAppEntry(mosaikApp: MosaikAppEntry) =
database.mosaikDao().insertOrUpdateAppEntry(mosaikApp.toDbEntity())

override fun getAllAppFavoritesByLastVisited(): Flow<List<MosaikAppEntry>> =
database.mosaikDao().getAppFavoritesByLastVisited().map { it.map { it.toModel() } }

override fun getAllAppsByLastVisited(limit: Int): Flow<List<MosaikAppEntry>> =
database.mosaikDao().getAllAppsByLastVisited(limit).map { it.map { it.toModel() } }

override suspend fun deleteAppsNotFavoriteVisitedBefore(timestamp: Long) =
database.mosaikDao().deleteAppsNotFavoriteVisitedBefore(timestamp)

override suspend fun insertOrUpdateAppHost(mosaikApp: MosaikAppHost) =
database.mosaikDao().insertOrUpdateAppHost(mosaikApp.toDbEntity())

override suspend fun getMosaikHostInfo(hostname: String): MosaikAppHost? =
database.mosaikDao().getMosaikHostInfo(hostname)?.toModel()

}
10 changes: 9 additions & 1 deletion android/src/main/java/org/ergoplatform/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class MainActivity : AppCompatActivity() {
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_wallet, R.id.navigation_settings
R.id.navigation_wallet,
R.id.navigation_mosaik,
R.id.navigation_settings
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
Expand All @@ -46,6 +48,12 @@ class MainActivity : AppCompatActivity() {
if (savedInstanceState == null) {
handleIntent(navController)
}

setMosaikButtonVisibility(navView)
}

fun setMosaikButtonVisibility(navView: BottomNavigationView = findViewById(R.id.nav_view)) {
navView.menu.findItem(R.id.navigation_mosaik).isVisible = Preferences(this).mosaikEnabled
}

fun scanQrCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
Expand Down Expand Up @@ -56,9 +57,14 @@ class ErgoAuthenticationFragment : AbstractAuthenticationFragment(), WalletChoos
binding.layoutAuthenticate.visibility =
if (state == ErgoAuthUiLogic.State.WAIT_FOR_AUTH) View.VISIBLE else View.GONE

if (state == ErgoAuthUiLogic.State.DONE)
if (state == ErgoAuthUiLogic.State.DONE) {
refreshDoneScreen()
else if (state == ErgoAuthUiLogic.State.WAIT_FOR_AUTH)
parentFragmentManager.setFragmentResult(
ergoAuthActionRequestKey, bundleOf(
ergoAuthActionCompletedBundleKey to true
)
)
} else if (state == ErgoAuthUiLogic.State.WAIT_FOR_AUTH)
refreshAuthPrompt()
}

Expand Down Expand Up @@ -96,16 +102,15 @@ class ErgoAuthenticationFragment : AbstractAuthenticationFragment(), WalletChoos
private fun refreshAuthPrompt() {
refreshWalletLabel()
val uiLogic = viewModel.uiLogic
binding.layoutAuthMessage.visibility = uiLogic.ergAuthRequest?.userMessage?.let {
binding.tvAuthMessage.text = getString(R.string.label_message_from_dapp, it)
val severityResId =
(uiLogic.ergAuthRequest?.messageSeverity
?: MessageSeverity.NONE).getSeverityDrawableResId()
binding.imageAuthMessage.setImageResource(severityResId)
binding.imageAuthMessage.visibility =
if (severityResId == 0) View.GONE else View.VISIBLE
View.VISIBLE
} ?: View.GONE
binding.layoutAuthMessage.visibility = View.VISIBLE
binding.tvAuthMessage.text =
uiLogic.getAuthenticationMessage(AndroidStringProvider(requireContext()))
val severityResId =
(uiLogic.ergAuthRequest?.messageSeverity
?: MessageSeverity.NONE).getSeverityDrawableResId()
binding.imageAuthMessage.setImageResource(severityResId)
binding.imageAuthMessage.visibility =
if (severityResId == 0) View.GONE else View.VISIBLE

}

Expand All @@ -131,4 +136,9 @@ class ErgoAuthenticationFragment : AbstractAuthenticationFragment(), WalletChoos
super.onDestroyView()
_binding = null
}

companion object {
val ergoAuthActionRequestKey = "KEY_ERGOAUTH_FRAGMENT"
val ergoAuthActionCompletedBundleKey = "KEY_ERGOAUTH_COMPLETED"
}
}
Loading

0 comments on commit 7952095

Please sign in to comment.