Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "#41 Profile enhancement and My Orders Section addition " #56

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ android {
}

dependencies {
implementation(libs.coil.compose.v222)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand All @@ -67,7 +67,6 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.webkit)
// implementation(libs.androidx.core.splashscreen)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application

android:name=".MyApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -17,15 +15,6 @@
android:supportsRtl="true"
android:theme="@style/Theme.MySplashScreen"
tools:targetApi="31">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.rememberNavController
import com.yuvrajsinghgmx.shopsmart.api.API
import com.yuvrajsinghgmx.shopsmart.navigation.Navigation
import com.yuvrajsinghgmx.shopsmart.screens.HomeScreen
import com.yuvrajsinghgmx.shopsmart.ui.theme.ShopSmartTheme
import com.yuvrajsinghgmx.shopsmart.viewmodel.ShoppingListViewModel
import dagger.hilt.android.AndroidEntryPoint
import retrofit2.Retrofit
import retrofit2.converter.scalars.ScalarsConverterFactory
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -26,10 +29,10 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()
setContent {
ShopSmartTheme {
val viewModel: ShoppingListViewModel = hiltViewModel()
val viewModel : ShoppingListViewModel = hiltViewModel()
val navController = rememberNavController()
Navigation(viewModel = viewModel, navController = navController)
Navigation(navController ,viewModel)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import com.yuvrajsinghgmx.shopsmart.screens.HomeScreen
import com.yuvrajsinghgmx.shopsmart.screens.Profile
import com.yuvrajsinghgmx.shopsmart.screens.ShopSmartNavBar
import com.yuvrajsinghgmx.shopsmart.screens.Upcoming
import com.yuvrajsinghgmx.shopsmart.screens.MyOrders
import com.yuvrajsinghgmx.shopsmart.viewmodel.ShoppingListViewModel

@Composable
fun Navigation(viewModel: ShoppingListViewModel, navController: NavHostController) {
fun Navigation(navController: NavHostController, viewModel: ShoppingListViewModel) {
Scaffold(
bottomBar = { ShopSmartNavBar(navController) }
) { innerPadding ->
Expand All @@ -24,18 +23,9 @@ fun Navigation(viewModel: ShoppingListViewModel, navController: NavHostControlle
startDestination = "Home",
modifier = Modifier.padding(innerPadding)
) {
composable("Home") {
HomeScreen(viewModel = viewModel, navController = navController)
}
composable("UpComing") {
Upcoming()
}
composable("Profile") {
Profile(navController = navController)
}
composable("MyOrders") {
MyOrders(navController = navController)
}
composable("Home") { HomeScreen(viewModel, navController) }
composable("UpComing") { Upcoming() }
composable("Profile") { Profile() }
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
Expand All @@ -25,12 +26,15 @@ import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
Expand All @@ -47,33 +51,21 @@ import coil.compose.AsyncImage
import com.yuvrajsinghgmx.shopsmart.R
import com.yuvrajsinghgmx.shopsmart.datastore.Poduct
import com.yuvrajsinghgmx.shopsmart.datastore.saveItems
import com.yuvrajsinghgmx.shopsmart.utils.SharedPrefsHelper
import com.yuvrajsinghgmx.shopsmart.viewmodel.ShoppingListViewModel
import kotlinx.coroutines.launch

data class Product(val name: String, val amount: Int, val imageUrl: String? = null)

private fun saveOrdersToSharedPreferences(context: Context, items: List<Product>) {
try {
val orders = items.map { Poduct(it.name, it.amount, it.imageUrl) }
if (orders.isNotEmpty()) {
SharedPrefsHelper.saveOrders(context, orders)
Log.d("HomeScreen", "Orders saved: ${orders.size}")
Toast.makeText(context, "Orders saved successfully", Toast.LENGTH_SHORT).show()
} else {
// If the order list is empty, clear the orders in SharedPreferences
SharedPrefsHelper.saveOrders(context, emptyList())
Log.d("HomeScreen", "No orders to save, cleared existing orders")
Toast.makeText(context, "Cart is empty", Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
Log.e("HomeScreen", "Error saving orders", e)
Toast.makeText(context, "Error saving orders", Toast.LENGTH_SHORT).show()
}
}
data class ButtonNavigationItem(
val title: String,
val selectedIcon: ImageVector,
val unselectedIcon: ImageVector
)


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController: NavController) {
fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(),navController: NavController) {
val context = LocalContext.current
val items = viewModel.items.collectAsState(initial = emptyList())
var newItem by remember { mutableStateOf("") }
Expand All @@ -84,6 +76,7 @@ fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController
var showDialog by remember { mutableStateOf(false) }
var isLoading by remember { mutableStateOf(false) }


LaunchedEffect(viewModel) {
viewModel.loadItems(context)
}
Expand Down Expand Up @@ -112,7 +105,8 @@ fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController
}) {
Icon(
Icons.Default.Delete,
contentDescription = "Delete Selected"
contentDescription = "Delete Selected",
// tint = Color(primaryColor.value)
)
}
}
Expand All @@ -138,40 +132,6 @@ fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp)
) {

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
"Total:",
style = TextStyle(
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
)
)
val total = subtotal + deliveryFee - discount
Text(
"₹$total",
style = TextStyle(
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
)
)
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = {
saveOrdersToSharedPreferences(context, items.value)
navController.navigate("MyOrders")
},
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
shape = RoundedCornerShape(8.dp),
) {
Text("Checkout", fontSize = 18.sp)
}
}
}
}
}
Expand Down Expand Up @@ -229,8 +189,12 @@ fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController
.fillMaxWidth()
.padding(bottom = 10.dp)
.clip(RoundedCornerShape(16.dp))
.border(2.dp, color = MaterialTheme.colorScheme.outline, RoundedCornerShape(16.dp)),
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp),
.border(
BorderStroke(1.dp, Color(0xFF332D25)),
RoundedCornerShape(16.dp)
),
elevation = CardDefaults.cardElevation(defaultElevation = 5.dp),
colors = CardDefaults.cardColors(containerColor = Color(rgb(234, 235, 230)))

) {
Row(
Expand Down Expand Up @@ -453,6 +417,7 @@ fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController
isLoading = false
showDialog = false
}

}
}
) {
Expand All @@ -463,4 +428,4 @@ fun HomeScreen(viewModel: ShoppingListViewModel = hiltViewModel(), navController
}
}
}
}
}
Loading