Skip to content

Commit

Permalink
Merge pull request #22 from viethua99/issue/crash_when_generating
Browse files Browse the repository at this point in the history
Update-theme-and-hot-fix-crash
  • Loading branch information
viethua99 committed Oct 15, 2023
2 parents 417ac07 + 1291f6b commit fe9363c
Show file tree
Hide file tree
Showing 83 changed files with 1,121 additions and 443 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Android-Text-to-Image](https://socialify.git.ci/viethua99/Android-Text-to-Image/image?description=1&descriptionEditable=%F0%9F%9A%80%20Instantly%20generate%20high-quality%20images%20based%20on%20your%20text%20prompt%20%F0%9F%9A%80&font=Inter&logo=https%3A%2F%2Ftabris.com%2Fwp-content%2Fuploads%2F2021%2F06%2Fjetpack-compose-icon_RGB.png&name=1&pattern=Brick%20Wall&theme=Dark)
<p align="center">
<a href="https://github.com/viethua99">
<a href="https://github.com/viethua99/Android-Text-to-Image/releases">
<img src="https://img.shields.io/github/downloads/viethua99/Android-Text-to-Image/total?color=3BB143" alt="Github - viethua99">
</a>

Expand All @@ -18,7 +18,7 @@
## Download
Go to the [Releases](https://github.com/viethua99/Android-Text-to-Image/releases) to download the latest APK.

<img src="docs/images/showcase_v1.gif" align="right" width="280"/>
<img src="docs/images/showcase_v2.gif" align="right" width="280"/>

## Features

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
dependencies {

implementation(project(":feature:generate"))
implementation(project(":feature:explore"))
implementation(project(":feature:gallery"))
implementation(project(":feature:settings"))
implementation(project(":feature:loading"))
implementation(project(":feature:result"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.junit.Rule
import org.junit.Test
import kotlin.properties.ReadOnlyProperty
import com.vproject.texttoimage.feature.generate.R as generateR
import com.vproject.texttoimage.feature.explore.R as exploreR
import com.vproject.texttoimage.feature.gallery.R as galleryR

@HiltAndroidTest
class NavigationTest {
Expand All @@ -46,7 +46,7 @@ class NavigationTest {
// The strings used for matching in these tests
private val appName by composeTestRule.stringResource(R.string.app_name)
private val generate by composeTestRule.stringResource(generateR.string.generate)
private val explore by composeTestRule.stringResource(exploreR.string.explore)
private val gallery by composeTestRule.stringResource(galleryR.string.gallery)

@Test
fun whenAppStarted_thenFirstScreenIsGenerate() {
Expand All @@ -60,31 +60,31 @@ class NavigationTest {
composeTestRule.apply {
onNodeWithContentDescription("settings").assertExists()

onNodeWithText(explore).performClick()
onNodeWithText(gallery).performClick()
onNodeWithContentDescription("settings").assertExists()
}
}

@Test(expected = NoActivityResumedException::class)
fun givenAppStarted_whenPressingBackButton_thenQuittingApp() {
composeTestRule.apply {
onNodeWithText(explore).performClick()
onNodeWithText(gallery).performClick()
onNodeWithText(generate).performClick()
Espresso.pressBack()
}
}

@Test
fun whenSelectingExploreTab_thenShowExploreNavigationTab() {
fun whenSelectingGalleryTab_thenShowGalleryNavigationTab() {
composeTestRule.apply {
// Verify that the top bar contains the app name on the first screen.
onNodeWithText(appName).assertExists()

// Go to the explore tab, verify that the top bar contains "Explore". This means
// we'll have 2 elements with the text "Explore" on screen. One in the top bar, and
// Go to the gallery tab, verify that the top bar contains "Gallery". This means
// we'll have 2 elements with the text "Gallery" on screen. One in the top bar, and
// one in the bottom navigation.
onNodeWithText(explore).performClick()
onAllNodesWithText(explore).assertCountEquals(2)
onNodeWithText(gallery).performClick()
onAllNodesWithText(gallery).assertCountEquals(2)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class TextToImageAppStateTest {

currentDestination = SUT.currentDestination?.route

// Navigate to test explore destination
// Navigate to test gallery destination
LaunchedEffect(Unit) {
testNavController.setCurrentDestination("test_explore")
testNavController.setCurrentDestination("test_gallery")
}
}
assertEquals("test_explore", currentDestination)
assertEquals("test_gallery", currentDestination)
}

@Test
Expand All @@ -81,7 +81,7 @@ class TextToImageAppStateTest {

assertEquals(2, SUT.topLevelDestinations.size)
assertTrue(SUT.topLevelDestinations[0].name.contains("generate", true))
assertTrue(SUT.topLevelDestinations[1].name.contains("explore", true))
assertTrue(SUT.topLevelDestinations[1].name.contains("gallery", true))
}

private fun getCompactWindowClass() = WindowSizeClass.calculateFromSize(DpSize(500.dp, 300.dp))
Expand All @@ -95,7 +95,7 @@ private fun rememberTestNavController(): TestNavHostController {
navigatorProvider.addNavigator(ComposeNavigator())
graph = createGraph(startDestination = "test_generate") {
composable("test_generate") { }
composable("test_explore") { }
composable("test_gallery") { }
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".TextToImageApplication"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.vproject.texttoimage.navigation

import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.compose.NavHost
import com.vproject.texttoimage.feature.explore.navigation.exploreScreen
import com.vproject.texttoimage.feature.gallery.navigation.galleryScreen
import com.vproject.texttoimage.feature.generate.navigation.generateRoute
import com.vproject.texttoimage.feature.generate.navigation.generateScreen
import com.vproject.texttoimage.feature.generate.navigation.navigateToGenerate
import com.vproject.texttoimage.feature.loading.navigation.loadingScreen
import com.vproject.texttoimage.feature.loading.navigation.navigateToLoading
import com.vproject.texttoimage.feature.result.navigation.navigateToResult
Expand All @@ -20,6 +23,8 @@ fun TextToImageNavHost(
startDestination: String = generateRoute,
) {
val navController = appState.navController
val context = LocalContext.current

NavHost(
navController = navController,
startDestination = startDestination,
Expand All @@ -30,13 +35,21 @@ fun TextToImageNavHost(
navController.navigateToLoading(prompt, styleId)
}
)
exploreScreen()
galleryScreen(onPromptItemClick = { promptContent, imageUrl ->
navController.navigateToResult(imageUrl, promptContent,"1")
})
settingsScreen(
onBackClick = navController::popBackStack,
)
loadingScreen(
onImageGenerated = navController::navigateToResult
onImageGenerated = navController::navigateToResult,
onError = {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
navController.navigateToGenerate()
}
)
resultScreen(
onBackClick = navController::popBackStack
)
resultScreen()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vproject.texttoimage.navigation

import androidx.compose.ui.graphics.vector.ImageVector
import com.vproject.texttoimage.R
import com.vproject.texttoimage.feature.gallery.R as galleryR
import com.vproject.texttoimage.core.designsystem.icon.TextToImageIcons
import com.vproject.texttoimage.feature.generate.R as generateR

Expand All @@ -18,15 +19,15 @@ enum class TopLevelDestination(
) {
GENERATE(
selectedIcon = TextToImageIcons.RoundedAutoFixNormal,
unselectedIcon = TextToImageIcons.OutlinedAutoFixNormal,
unselectedIcon = TextToImageIcons.RoundedAutoFixNormal,
iconTextId = generateR.string.generate,
titleTextId = R.string.app_name,
),
EXPLORE(
selectedIcon = TextToImageIcons.RoundedLanguage,
unselectedIcon = TextToImageIcons.OutlinedLanguage,
iconTextId = R.string.explore,
titleTextId = R.string.explore,
GALLERY(
selectedIcon = TextToImageIcons.PhotoLibrary,
unselectedIcon = TextToImageIcons.PhotoLibrary,
iconTextId = galleryR.string.gallery,
titleTextId = R.string.app_name,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.vproject.texttoimage.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand All @@ -13,6 +15,7 @@ import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.modifier.modifierLocalConsumer
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavDestination
Expand Down Expand Up @@ -49,7 +52,7 @@ fun TextToImageApp(
}
}
) { paddingValues ->
Column(Modifier.fillMaxSize()) {
Column(Modifier.fillMaxSize().padding(paddingValues)) {
// Show the top app bar on top level destinations.
val topLevelDestination = appState.currentTopLevelDestination
topLevelDestination?.let { nonNullTopLevelDestination ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.vproject.texttoimage.core.ui.TrackDisposableJank
import com.vproject.texttoimage.feature.explore.navigation.exploreRoute
import com.vproject.texttoimage.feature.explore.navigation.navigateToExplore
import com.vproject.texttoimage.feature.gallery.navigation.galleryRoute
import com.vproject.texttoimage.feature.gallery.navigation.navigateToGallery
import com.vproject.texttoimage.feature.generate.navigation.generateRoute
import com.vproject.texttoimage.feature.generate.navigation.navigateToGenerate
import com.vproject.texttoimage.feature.settings.navigation.navigateToSettings
import com.vproject.texttoimage.navigation.TopLevelDestination
import com.vproject.texttoimage.navigation.TopLevelDestination.GENERATE
import com.vproject.texttoimage.navigation.TopLevelDestination.EXPLORE
import com.vproject.texttoimage.navigation.TopLevelDestination.GALLERY

@Composable
fun rememberTextToImageAppState(
Expand Down Expand Up @@ -49,20 +49,20 @@ class TextToImageAppState(
val currentTopLevelDestination: TopLevelDestination?
@Composable get() = when (currentDestination?.route) {
generateRoute -> GENERATE
exploreRoute -> EXPLORE
galleryRoute -> GALLERY
else -> null
}

val shouldShowBottomBar: Boolean
@Composable get() = windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact &&
(currentTopLevelDestination == GENERATE || currentTopLevelDestination == EXPLORE)
(currentTopLevelDestination == GENERATE || currentTopLevelDestination == GALLERY)


/**
* Map of top level destinations to be used in the TopBar, BottomBar. The key is the
* route.
*/
val topLevelDestinations: List<TopLevelDestination> = TopLevelDestination.values().asList().filter { it.name == GENERATE.name }
val topLevelDestinations: List<TopLevelDestination> = TopLevelDestination.values().asList()


/**
Expand All @@ -88,7 +88,7 @@ class TextToImageAppState(

when (topLevelDestination) {
GENERATE -> navController.navigateToGenerate(topLevelNavOptions)
EXPLORE -> navController.navigateToExplore(topLevelNavOptions)
GALLERY -> navController.navigateToGallery(topLevelNavOptions)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<string name="app_name">Text To Image</string>

<!-- TEMPORARY -->
<string name="explore">Explore</string>
<string name="gallery">Gallery</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.vproject.texttoimage.core.data.repository.image

import com.vproject.texttoimage.core.model.data.PromptData
import kotlinx.coroutines.flow.Flow

interface ImageRepository {
suspend fun generateImage(prompt: String) : Flow<String>
suspend fun generateImage(prompt: String, negativePrompt: String) : Flow<PromptData>
suspend fun fetchQueuedImage(id: Long) : Flow<PromptData>
fun getGeneratedPromptList() : Flow<List<PromptData>>
fun getTopTrendingPromptList() : Flow<List<PromptData>>
}
Loading

0 comments on commit fe9363c

Please sign in to comment.