Skip to content

Commit daee22b

Browse files
committed
added audit changes #2
1 parent acf5f84 commit daee22b

File tree

16 files changed

+263
-299
lines changed

16 files changed

+263
-299
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,77 @@
11
package com.esri.arcgismaps.kotlin.sampleviewer.model
22

3+
import com.esri.arcgismaps.kotlin.sampleviewer.R
4+
35
/**
46
* This data class is used to hold information in each CardItem in home screen
57
*/
68
data class Category(
79
val title: SampleCategory,
810
val icon: Int,
9-
val backgroundImage: Int,
10-
)
11+
val backgroundImage: Int
12+
) {
13+
companion object {
14+
val SAMPLE_CATEGORIES = listOf(
15+
Category(
16+
SampleCategory.ANALYSIS,
17+
R.drawable.ic_analysis,
18+
R.drawable.analysis_background,
19+
),
20+
Category(
21+
SampleCategory.AUGMENTED_REALITY,
22+
R.drawable.ic_augmented_reality,
23+
R.drawable.augmented_reality_background,
24+
),
25+
Category(
26+
SampleCategory.CLOUD_AND_PORTAL,
27+
R.drawable.ic_cloud,
28+
R.drawable.cloud_background,
29+
),
30+
Category(
31+
SampleCategory.EDIT_AND_MANAGE_DATA,
32+
R.drawable.ic_manage_data,
33+
R.drawable.manage_data_background,
34+
),
35+
Category(
36+
SampleCategory.LAYERS,
37+
R.drawable.ic_layers,
38+
R.drawable.layers_background,
39+
),
40+
Category(
41+
SampleCategory.MAPS,
42+
R.drawable.ic_map,
43+
R.drawable.maps_and_scenes_background,
44+
),
45+
Category(
46+
SampleCategory.ROUTING_AND_LOGISTICS,
47+
R.drawable.ic_routing_and_logistics,
48+
R.drawable.routing_and_logistics_background,
49+
),
50+
Category(
51+
SampleCategory.SCENES,
52+
R.drawable.ic_scenes,
53+
R.drawable.scenes_background,
54+
),
55+
Category(
56+
SampleCategory.SEARCH_AND_QUERY,
57+
R.drawable.ic_search_and_query,
58+
R.drawable.search_and_query_background,
59+
),
60+
Category(
61+
SampleCategory.UTILITY_NETWORKS,
62+
R.drawable.ic_utility,
63+
R.drawable.utility_background,
64+
),
65+
Category(
66+
SampleCategory.VISUALIZATION,
67+
R.drawable.ic_visualization,
68+
R.drawable.visualization_background,
69+
),
70+
Category(
71+
SampleCategory.FAVORITES,
72+
R.drawable.ic_favorite_selected,
73+
R.drawable.maps_and_scenes_background,
74+
),
75+
)
76+
}
77+
}

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/model/Sample.kt

+26-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,32 @@ data class Sample(
2121
val metadata: SampleMetadata,
2222
val isFavorite: Boolean = false,
2323
var score: Double = 0.0
24-
)
24+
) {
25+
companion object {
26+
val PREVIEW_INSTANCE = Sample(
27+
name = "Analyze hotspots",
28+
codeFiles = listOf(CodeFile("", "")),
29+
url = "",
30+
readMe = "",
31+
screenshotURL = "",
32+
metadata = SampleMetadata(
33+
description = "",
34+
formalName = "Analyze hotspots",
35+
ignore = false,
36+
imagePaths = listOf(""),
37+
keywords = listOf(""),
38+
language = "",
39+
redirectFrom = listOf(""),
40+
relevantApis = listOf(""),
41+
sampleCategory = SampleCategory.ANALYSIS,
42+
snippets = listOf(""),
43+
title = "Analyze hotspots"
44+
),
45+
isFavorite = false,
46+
mainActivity = ""
47+
)
48+
}
49+
}
2550

2651
fun Sample.startSample(context: Context) {
2752
val className = Class.forName(mainActivity) as Class<*>

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/model/SampleInfoRepository.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ interface SampleInfoRepository {
1212
fun getSampleByName(sampleName: String): Sample
1313

1414
fun getAllSamples(): List<Sample>
15-
}
15+
}

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/model/SampleMetadata.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
44
import kotlinx.serialization.Serializable
55

66
/**
7-
* A data class to hold detailed information about the sample
7+
* A data class to hold detailed information about the [Sample]
88
*/
99
@Serializable
1010
data class SampleMetadata(
@@ -20,4 +20,4 @@ data class SampleMetadata(
2020
val language: String?,
2121
val snippets: List<String>,
2222
val title: String
23-
)
23+
)

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/model/room/Converters.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Converters {
3434
return relevantApiJsonString.let { json.decodeFromString(it) }
3535
}
3636

37-
// Converts Sample to SampleEntity in order to select certain relevant fields
37+
// Converts Sample to SampleEntity in order to select relevant fields
3838
fun convertToEntity(sample: Sample): SampleEntity {
3939
return SampleEntity(
4040
sampleName = sample.name,

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/model/room/OkapiBM25.kt

+8-9
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,25 @@ import kotlin.math.log
2828
class OkapiBM25 {
2929

3030
companion object {
31-
32-
fun score(matchinfo: Array<Int>, column: Int, b: Double = 0.75, k1: Double = 1.2): Double {
31+
fun score(matchInfo: Array<Int>, column: Int, b: Double = 0.75, k1: Double = 1.2): Double {
3332

3433
val pOffset = 0
3534
val cOffset = 1
3635
val nOffset = 2
3736
val aOffset = 3
3837

3938
// the number of matchable phrases in the query
40-
val termCount = matchinfo[pOffset]
39+
val termCount = matchInfo[pOffset]
4140
// the number of user defined columns in the FTS table
42-
val colCount = matchinfo[cOffset]
41+
val colCount = matchInfo[cOffset]
4342

4443
val lOffset = aOffset + colCount
4544
val xOffset = lOffset + colCount
4645

4746
// the number of rows in the FTS4 table
48-
val totalDocs = matchinfo[nOffset].toDouble()
49-
val avgLength = matchinfo[aOffset + column].toDouble()
50-
val docLength = matchinfo[lOffset + column].toDouble()
47+
val totalDocs = matchInfo[nOffset].toDouble()
48+
val avgLength = matchInfo[aOffset + column].toDouble()
49+
val docLength = matchInfo[lOffset + column].toDouble()
5150

5251
var score = 0.0
5352

@@ -56,9 +55,9 @@ class OkapiBM25 {
5655
val currentX = xOffset + (3 * (column + i * colCount))
5756

5857
// in the current row, the number of times the phrase appears in the column
59-
val termFrequency = matchinfo[currentX].toDouble()
58+
val termFrequency = matchInfo[currentX].toDouble()
6059
// the total number of rows in the FTS table for which the column contains at least one instance of the phrase.
61-
val docsWithTerm = matchinfo[currentX + 2].toDouble()
60+
val docsWithTerm = matchInfo[currentX + 2].toDouble()
6261

6362
val p = totalDocs - docsWithTerm + 0.5
6463
val q = docsWithTerm + 0.5

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/model/room/SampleDao.kt

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import androidx.room.OnConflictStrategy
77
import androidx.room.Query
88
import kotlinx.coroutines.flow.Flow
99

10-
1110
/**
1211
* Holds all operations that uses Room
1312
*/

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/ui/components/CategoryCard.kt

+15-21
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,28 @@ import com.esri.arcgismaps.kotlin.sampleviewer.ui.theme.SampleAppTheme
3838
@Composable
3939
fun CardItem(
4040
category: Category,
41-
onClick: () -> Unit,
41+
onClick: () -> Unit
4242
) {
4343
ElevatedCard(
44-
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp),
4544
modifier = Modifier
4645
.size(width = 175.dp, height = 175.dp)
4746
.clickable { onClick() },
47+
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp),
4848
shape = MaterialTheme.shapes.medium
4949
) {
5050
Box {
51-
Box {
52-
BackgroundImageBox(category)
53-
}
51+
BackgroundImageBox(category)
5452
Column(
5553
modifier = Modifier.fillMaxSize(),
5654
horizontalAlignment = Alignment.CenterHorizontally,
57-
verticalArrangement = Arrangement.spacedBy(12.dp,Alignment.CenterVertically)
55+
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterVertically)
5856
) {
5957
IconWithBackgroundCircle(category)
6058
Text(
59+
modifier = Modifier.wrapContentSize(Alignment.Center),
6160
text = category.title.text,
6261
color = Color.White,
6362
textAlign = TextAlign.Center,
64-
modifier = Modifier.wrapContentSize(Alignment.Center),
6563
style = MaterialTheme.typography.titleMedium
6664
)
6765
}
@@ -74,16 +72,16 @@ private fun IconWithBackgroundCircle(item: Category) {
7472
Box(
7573
Modifier
7674
.background(
77-
Color.Black.copy(alpha = 0.8f),
75+
color = Color.Black.copy(alpha = 0.8f),
7876
shape = CircleShape
7977
)
8078
.padding(8.dp)
8179
) {
8280
Icon(
83-
painter = painterResource(item.icon),
84-
contentDescription = null,
8581
modifier = Modifier
8682
.size(30.dp),
83+
painter = painterResource(item.icon),
84+
contentDescription = "Category Icon",
8785
tint = Color.White
8886
)
8987
}
@@ -92,10 +90,10 @@ private fun IconWithBackgroundCircle(item: Category) {
9290
@Composable
9391
private fun BackgroundImageBox(item: Category) {
9492
Image(
93+
modifier = Modifier.fillMaxSize(),
9594
painter = painterResource(item.backgroundImage),
9695
contentDescription = item.title.text,
97-
modifier = Modifier.fillMaxSize(),
98-
contentScale = ContentScale.Crop,
96+
contentScale = ContentScale.Crop
9997
)
10098
Box(
10199
modifier = Modifier
@@ -109,16 +107,12 @@ private fun BackgroundImageBox(item: Category) {
109107
@Composable
110108
fun PreviewCategoryCardItem() {
111109
SampleAppTheme {
112-
val navController = rememberNavController()
113-
114110
CardItem(
115111
Category(
116-
SampleCategory.ANALYSIS,
117-
R.drawable.ic_analysis,
118-
R.drawable.analysis_background
112+
title = SampleCategory.ANALYSIS,
113+
icon = R.drawable.ic_analysis,
114+
backgroundImage = R.drawable.analysis_background
119115
),
120-
) {
121-
navController.navigate("${R.string.sampleList_section}/${SampleCategory.ANALYSIS.text}")
122-
}
116+
) { }
123117
}
124-
}
118+
}

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/ui/components/SampleCard.kt

+12-34
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ import androidx.compose.ui.res.painterResource
3838
import androidx.compose.ui.text.style.TextAlign
3939
import androidx.compose.ui.tooling.preview.Preview
4040
import androidx.compose.ui.unit.dp
41-
import com.esri.arcgismaps.kotlin.sampleviewer.model.CodeFile
4241
import com.esri.arcgismaps.kotlin.sampleviewer.model.Sample
43-
import com.esri.arcgismaps.kotlin.sampleviewer.model.SampleCategory
44-
import com.esri.arcgismaps.kotlin.sampleviewer.model.SampleMetadata
4542
import com.esri.arcgismaps.kotlin.sampleviewer.model.startSample
4643
import com.esri.arcgismaps.kotlin.sampleviewer.ui.screens.sampleList.DropdownItemData
4744
import com.esri.arcgismaps.kotlin.sampleviewer.ui.theme.SampleAppTheme
@@ -70,12 +67,12 @@ private fun TitleAndIconsRow(
7067
var expandedDescription by rememberSaveable { mutableStateOf(false) }
7168

7269
Row(
73-
verticalAlignment = Alignment.CenterVertically,
74-
horizontalArrangement = Arrangement.SpaceBetween,
7570
modifier = Modifier
7671
.fillMaxWidth()
7772
.background(MaterialTheme.colorScheme.surfaceContainer)
78-
.padding(start = 16.dp)
73+
.padding(start = 16.dp),
74+
verticalAlignment = Alignment.CenterVertically,
75+
horizontalArrangement = Arrangement.SpaceBetween
7976
) {
8077
Column(
8178
modifier = Modifier
@@ -125,7 +122,7 @@ private fun TitleAndIconsRow(
125122
) {
126123
Icon(
127124
painter = painterResource(id = option.icon),
128-
contentDescription = null,
125+
contentDescription = "${option.title} Icon",
129126
tint = MaterialTheme.colorScheme.onSurface
130127
)
131128
Text(
@@ -139,7 +136,7 @@ private fun TitleAndIconsRow(
139136
expandedMenu = option.title.lowercase().contains("favorite")
140137
option.onClick()
141138
},
142-
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
139+
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding
143140
)
144141
}
145142
}
@@ -158,15 +155,17 @@ private fun ExpandedDescriptionAnimation(
158155
exit = shrinkVertically()
159156
) {
160157
Row(
158+
modifier = Modifier
159+
.fillMaxWidth()
160+
.padding(vertical = 8.dp),
161161
verticalAlignment = Alignment.CenterVertically,
162-
horizontalArrangement = Arrangement.Start,
163-
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp)
162+
horizontalArrangement = Arrangement.Start
164163
) {
165164
Text(
166165
text = sample.metadata.description,
167166
textAlign = TextAlign.Start,
168167
style = MaterialTheme.typography.bodyMedium,
169-
color = Color.Gray,
168+
color = Color.Gray
170169
)
171170
}
172171
}
@@ -179,29 +178,8 @@ fun PreviewSampleCardItem() {
179178
SampleAppTheme {
180179
val dropdownItemData = listOf<DropdownItemData>()
181180
SampleCardItem(
182-
Sample(
183-
name = "Analyze hotspots",
184-
codeFiles = listOf(CodeFile("", "")),
185-
url = "",
186-
readMe = "",
187-
screenshotURL = "",
188-
metadata = SampleMetadata(
189-
description = "",
190-
formalName = "Analyze hotspots",
191-
ignore = false,
192-
imagePaths = listOf(""),
193-
keywords = listOf(""),
194-
language = "",
195-
redirectFrom = listOf(""),
196-
relevantApis = listOf(""),
197-
sampleCategory = SampleCategory.ANALYSIS,
198-
snippets = listOf(""),
199-
title = "Analyze hotspots"
200-
),
201-
isFavorite = false,
202-
mainActivity = ""
203-
),
204-
dropdownItemData
181+
sample = Sample.PREVIEW_INSTANCE,
182+
dropdownSampleItems = dropdownItemData
205183
)
206184
}
207185
}

app/src/main/java/com/esri/arcgismaps/kotlin/sampleviewer/ui/components/SampleViewerTopAppBar.kt

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import androidx.compose.runtime.Composable
1313
import androidx.compose.ui.res.stringResource
1414
import com.esri.arcgismaps.kotlin.sampleviewer.R
1515

16+
/**
17+
* The common [TopAppBar] used to display screen title and the back button for all screens.
18+
*/
1619
@Composable
1720
@OptIn(ExperimentalMaterial3Api::class)
1821
fun SampleViewerTopAppBar(

0 commit comments

Comments
 (0)