Skip to content

Commit 54b2745

Browse files
committed
πŸ‘• code refactor
1 parent 9077264 commit 54b2745

19 files changed

Lines changed: 139 additions & 79 deletions

β€Žsrc/main/kotlin/com/theapache64/stackzy/App.ktβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package com.theapache64.stackzy
22

33
import com.theapache64.cyclone.core.Application
44
import com.theapache64.stackzy.ui.feature.MainActivity
5-
import com.theapache64.stackzy.util.CommandExecutor
65
import com.toxicbakery.logging.Arbor
76
import com.toxicbakery.logging.Seedling
8-
import java.io.File
97

108
class App : Application() {
119
override fun onCreate() {
@@ -17,6 +15,9 @@ class App : Application() {
1715
}
1816
}
1917

18+
/**
19+
* The magic beings here
20+
*/
2021
fun main() {
2122
App().onCreate()
2223
}

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/common/AlphabetCircle.ktβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.ui.graphics.Brush
1313
import androidx.compose.ui.text.font.FontWeight
1414
import com.theapache64.stackzy.ui.util.Preview
1515

16+
/*
1617
fun main() {
1718
Preview {
1819
LazyRow {
@@ -22,6 +23,7 @@ fun main() {
2223
}
2324
}
2425
}
26+
*/
2527

2628

2729
@Composable

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/common/CustomScaffold.ktβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import androidx.compose.ui.unit.dp
1414
import com.theapache64.stackzy.util.R
1515

1616
/**
17-
* To show a basic content page with title
17+
* To show a basic content page
1818
*/
1919
const val CONTENT_PADDING_VERTICAL = 15
2020
const val CONTENT_PADDING_HORIZONTAL = 30
@@ -39,12 +39,14 @@ fun CustomScaffold(
3939
)
4040
) {
4141

42+
// Header
4243
Row(
4344
modifier = Modifier
4445
.height(60.dp),
4546
verticalAlignment = Alignment.CenterVertically
4647
) {
4748

49+
// Back button
4850
if (onBackClicked != null) {
4951
IconButton(
5052
onClick = onBackClicked,
@@ -56,6 +58,7 @@ fun CustomScaffold(
5658
}
5759
}
5860

61+
// Title and Subtitle
5962
Column {
6063
Text(
6164
text = title,
@@ -71,6 +74,7 @@ fun CustomScaffold(
7174
}
7275
}
7376

77+
// Right slot (Search, Icons etc)
7478
if (topRightSlot != null) {
7579
Box(
7680
modifier = Modifier.fillMaxWidth(),
@@ -85,6 +89,7 @@ fun CustomScaffold(
8589
modifier = Modifier.height(20.dp)
8690
)
8791

92+
// Content slot
8893
content()
8994
}
9095

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/MainActivity.ktβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MainActivity : Activity() {
2929
StackzyTheme(
3030
title = R.string.app_name
3131
) {
32+
// Igniting navigation
3233
rootComponent(factory = ::NavHostComponent)
3334
.render()
3435
}

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/appdetail/AppDetailScreen.ktβ€Ž

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fun AppDetailScreen(
3838
report!!.appName!!
3939
}
4040

41+
// Calculating item width based on screen width
4142
val appItemWidth = (LocalAppWindow.current.width - (CONTENT_PADDING_HORIZONTAL * 2)) / GRID_SIZE
4243

4344
CustomScaffold(
@@ -52,46 +53,14 @@ fun AppDetailScreen(
5253
)
5354
} else {
5455
if (loadingMessage != null) {
55-
56-
var enabled by remember { mutableStateOf(true) }
57-
58-
val alpha = if (enabled) {
59-
0f
60-
} else {
61-
360f
62-
}
63-
64-
val animatedValue by animateFloatAsState(
65-
targetValue = alpha,
66-
animationSpec = tween(200),
67-
finishedListener = {
68-
enabled = !enabled
69-
}
70-
)
71-
72-
Box(
73-
modifier = Modifier.fillMaxSize()
74-
) {
75-
Image(
76-
modifier = Modifier
77-
.rotate(animatedValue)
78-
.align(Alignment.Center)
79-
.size(50.dp),
80-
colorFilter = ColorFilter.tint(MaterialTheme.colors.primary),
81-
bitmap = imageResource("drawables/loading.png"),
82-
contentDescription = ""
83-
)
84-
85-
LoadingText(
86-
modifier = Modifier.align(Alignment.BottomCenter),
87-
message = loadingMessage!!
88-
)
89-
}
56+
LoadingAnimation(loadingMessage!!)
9057
} else if (report != null) {
9158

9259
if (report!!.libraries.isEmpty()) {
60+
// No libraries found
9361
val platform = report!!.platform
9462
if (platform is Platform.NativeKotlin || platform is Platform.NativeJava) {
63+
// native platform with libs
9564
FullScreenError(
9665
title = "We couldn't find any libraries",
9766
message = "But don't worry, we're improving our dictionary strength. Please try later",
@@ -146,5 +115,44 @@ fun AppDetailScreen(
146115
}
147116

148117

118+
}
119+
}
120+
121+
@Composable
122+
private fun LoadingAnimation(loadingMessage: String) {
123+
124+
var enabled by remember { mutableStateOf(true) }
125+
126+
val alpha = if (enabled) {
127+
0f
128+
} else {
129+
360f
130+
}
131+
132+
val animatedValue by animateFloatAsState(
133+
targetValue = alpha,
134+
animationSpec = tween(200),
135+
finishedListener = {
136+
enabled = !enabled
137+
}
138+
)
139+
140+
Box(
141+
modifier = Modifier.fillMaxSize()
142+
) {
143+
Image(
144+
modifier = Modifier
145+
.rotate(animatedValue)
146+
.align(Alignment.Center)
147+
.size(50.dp),
148+
colorFilter = ColorFilter.tint(MaterialTheme.colors.primary),
149+
bitmap = imageResource("drawables/loading.png"),
150+
contentDescription = ""
151+
)
152+
153+
LoadingText(
154+
modifier = Modifier.align(Alignment.BottomCenter),
155+
message = loadingMessage!!
156+
)
149157
}
150158
}

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/appdetail/AppDetailViewModel.ktβ€Ž

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.StateFlow
1313
import kotlinx.coroutines.flow.collect
1414
import kotlinx.coroutines.flow.distinctUntilChanged
1515
import kotlinx.coroutines.launch
16+
import java.io.File
1617
import javax.inject.Inject
1718

1819

@@ -24,7 +25,6 @@ class AppDetailViewModel @Inject constructor(
2425
private val untrackedLibsRepo: UntrackedLibsRepo
2526
) {
2627

27-
2828
private val _fatalError = MutableStateFlow<String?>(null)
2929
val fatalError: StateFlow<String?> = _fatalError
3030

@@ -50,8 +50,6 @@ class AppDetailViewModel @Inject constructor(
5050
suffix = ".apk"
5151
).toFile()
5252

53-
println("Path is ${destinationFile.absolutePath}")
54-
5553
adbRepo.pullFile(
5654
androidDevice,
5755
apkRemotePath,
@@ -61,21 +59,7 @@ class AppDetailViewModel @Inject constructor(
6159
_loadingMessage.value = "Pulling APK $downloadPercentage% ..."
6260
try {
6361
if (downloadPercentage == 100) {
64-
// Now let's decompile
65-
_loadingMessage.value = R.string.app_detail_loading_decompiling
66-
val decompiledDir = apkToolRepo.decompile(destinationFile)
67-
68-
// Analyse
69-
_loadingMessage.value = R.string.app_detail_loading_analysing
70-
val allLibraries = librariesRepo.getCachedLibraries()
71-
require(allLibraries != null) { "Cached libraries are null" }
72-
73-
// Report
74-
val report = apkAnalyzerRepo.analyze(decompiledDir, allLibraries)
75-
76-
77-
_analysisReport.value = report
78-
_loadingMessage.value = null
62+
onApkPulled(destinationFile)
7963
}
8064
} catch (e: Exception) {
8165
e.printStackTrace()
@@ -88,6 +72,23 @@ class AppDetailViewModel @Inject constructor(
8872
}
8973
}
9074

75+
private fun onApkPulled(destinationFile: File) {
76+
// Now let's decompile
77+
_loadingMessage.value = R.string.app_detail_loading_decompiling
78+
val decompiledDir = apkToolRepo.decompile(destinationFile)
79+
80+
// Analyse
81+
_loadingMessage.value = R.string.app_detail_loading_analysing
82+
val allLibraries = librariesRepo.getCachedLibraries()
83+
require(allLibraries != null) { "Cached libraries are null" }
84+
85+
// Report
86+
val report = apkAnalyzerRepo.analyze(decompiledDir, allLibraries)
87+
88+
_analysisReport.value = report
89+
_loadingMessage.value = null
90+
}
91+
9192
/**
9293
* TODO:
9394
*/

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/selectapp/SelectAppScreen.ktβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import com.theapache64.stackzy.util.R
2626

2727
private const val GRID_SIZE = 3
2828

29+
/**
30+
* To select an application from the selected device
31+
*/
2932
@Composable
3033
fun SelectAppScreen(
3134
selectAppViewModel: SelectAppViewModel,
@@ -35,8 +38,9 @@ fun SelectAppScreen(
3538

3639
val searchKeyword by selectAppViewModel.searchKeyword.collectAsState()
3740
val apps by selectAppViewModel.apps.collectAsState()
41+
42+
// Calculating item width based on screen width
3843
val appItemWidth = (LocalAppWindow.current.width - (CONTENT_PADDING_HORIZONTAL * 2)) / GRID_SIZE
39-
println("Width is $appItemWidth")
4044

4145
CustomScaffold(
4246
title = R.string.select_app_title,

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/selectapp/SelectAppViewModel.ktβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ class SelectAppViewModel @Inject constructor(
1313
val adbRepo: AdbRepo
1414
) {
1515

16+
/**
17+
* To store all apps instaled in the device (used for search filtering)
18+
*/
1619
private var fullApps: List<AndroidApp>? = null
1720
private val _searchKeyword = MutableStateFlow("")
1821
val searchKeyword: StateFlow<String> = _searchKeyword
1922

23+
/**
24+
* Filtered apps
25+
*/
2026
private val _apps = MutableStateFlow(listOf<AndroidApp>())
2127
val apps: StateFlow<List<AndroidApp>> = _apps
2228

@@ -29,6 +35,8 @@ class SelectAppViewModel @Inject constructor(
2935

3036
fun onSearchKeywordChanged(newKeyword: String) {
3137
_searchKeyword.value = newKeyword
38+
39+
// Filtering apps
3240
_apps.value = fullApps!!.filter { it.appPackage.name.toLowerCase().contains(newKeyword, ignoreCase = true) }
3341
}
3442
}

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/selectdevice/SelectDeviceScreen.ktβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import com.theapache64.stackzy.ui.common.FullScreenError
1515
import com.theapache64.stackzy.ui.common.Selectable
1616
import com.theapache64.stackzy.util.R
1717

18+
/**
19+
* To select a device from connected devices
20+
*/
1821
@Composable
1922
fun SelectDeviceScreen(
2023
selectDeviceViewModel: SelectDeviceViewModel,
@@ -48,6 +51,7 @@ fun Content(
4851
image = imageResource("drawables/no_device.png")
4952
)
5053
} else {
54+
// Content
5155
CustomScaffold(
5256
title = R.string.device_select_the_device
5357
) {

β€Žsrc/main/kotlin/com/theapache64/stackzy/ui/feature/selectdevice/SelectDeviceScreenComponent.ktβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.theapache64.stackzy.ui.navigation.Component
88
import javax.inject.Inject
99

1010
class SelectDeviceScreenComponent(
11-
appComponent : AppComponent,
11+
appComponent: AppComponent,
1212
private val componentContext: ComponentContext,
1313
private val onDeviceSelected: (AndroidDevice) -> Unit
1414
) : Component, ComponentContext by componentContext {
@@ -22,13 +22,13 @@ class SelectDeviceScreenComponent(
2222

2323
@Composable
2424
override fun render() {
25-
// Start watching
25+
// Start watching devices
2626
selectDeviceViewModel.watchConnectedDevices()
2727

2828
SelectDeviceScreen(
2929
selectDeviceViewModel,
3030
onDeviceSelected = {
31-
// Stop watching
31+
// Stop watching devices
3232
selectDeviceViewModel.removeConnectionWatcher()
3333

3434
onDeviceSelected(it)

0 commit comments

Comments
Β (0)