diff --git a/Week2/.gitignore b/Week2/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/Week2/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/Week2/app/.gitignore b/Week2/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/Week2/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Week2/app/build.gradle.kts b/Week2/app/build.gradle.kts new file mode 100644 index 0000000..8707c64 --- /dev/null +++ b/Week2/app/build.gradle.kts @@ -0,0 +1,53 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.week2" + compileSdk { + version = release(36) { + minorApiLevel = 1 + } + } + + defaultConfig { + applicationId = "com.example.week2" + minSdk = 24 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + buildFeatures { + viewBinding = true + } +} + +dependencies { + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(libs.androidx.activity) + implementation(libs.androidx.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + implementation(libs.androidx.navigation.fragment.ktx) + implementation(libs.androidx.navigation.ui.ktx) +} \ No newline at end of file diff --git a/Week2/app/proguard-rules.pro b/Week2/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/Week2/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Week2/app/src/androidTest/java/com/example/week2/ExampleInstrumentedTest.kt b/Week2/app/src/androidTest/java/com/example/week2/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..e20abc4 --- /dev/null +++ b/Week2/app/src/androidTest/java/com/example/week2/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.week2 + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.week2", appContext.packageName) + } +} \ No newline at end of file diff --git a/Week2/app/src/main/AndroidManifest.xml b/Week2/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8a17b4a --- /dev/null +++ b/Week2/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/BuyAllFragment.kt b/Week2/app/src/main/java/com/example/week2/BuyAllFragment.kt new file mode 100644 index 0000000..79ed64b --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/BuyAllFragment.kt @@ -0,0 +1,23 @@ +package com.example.week2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class BuyAllFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return inflater.inflate(R.layout.fragment_buy_all, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/BuyFragment.kt b/Week2/app/src/main/java/com/example/week2/BuyFragment.kt new file mode 100644 index 0000000..155d22f --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/BuyFragment.kt @@ -0,0 +1,71 @@ +package com.example.week2 + +import android.graphics.Typeface +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.fragment.app.Fragment +import com.example.week2.databinding.FragmentBuyBinding +import com.google.android.material.tabs.TabLayout + +class BuyFragment : Fragment(R.layout.fragment_buy) { + + private var _binding: FragmentBuyBinding? = null + private val binding get() = _binding!! + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + _binding = FragmentBuyBinding.bind(view) + + setupTabs() + } + + private fun setupTabs() { + binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all))) + binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.Shirts))) + binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.Shoes))) + + replaceTabFragment(BuyAllFragment()) + + binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + updateTabStyle(tab, true) + + when (tab?.position) { + 0 -> replaceTabFragment(BuyAllFragment()) + 1 -> replaceTabFragment(BuyTopsFragment()) + 2 -> replaceTabFragment(BuyShoesFragment()) + } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + updateTabStyle(tab, false) + } + + override fun onTabReselected(tab: TabLayout.Tab?) {} + }) + + updateTabStyle(binding.tabLayout.getTabAt(0), true) + } + + private fun replaceTabFragment(fragment: Fragment) { + childFragmentManager.beginTransaction() + .replace(R.id.tabContent, fragment) + .commit() + } + + private fun updateTabStyle(tab: TabLayout.Tab?, isBold: Boolean) { + val tabView = (binding.tabLayout.getChildAt(0) as ViewGroup).getChildAt(tab?.position ?: 0) as ViewGroup + val textView = tabView.getChildAt(1) as? TextView + + textView?.let { + it.typeface = if (isBold) Typeface.DEFAULT_BOLD else Typeface.DEFAULT + } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/BuyShoesFragment.kt b/Week2/app/src/main/java/com/example/week2/BuyShoesFragment.kt new file mode 100644 index 0000000..d818d30 --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/BuyShoesFragment.kt @@ -0,0 +1,23 @@ +package com.example.week2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class BuyShoesFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return inflater.inflate(R.layout.fragment_buy_shoes, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/BuyTopsFragment.kt b/Week2/app/src/main/java/com/example/week2/BuyTopsFragment.kt new file mode 100644 index 0000000..27357fe --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/BuyTopsFragment.kt @@ -0,0 +1,23 @@ +package com.example.week2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class BuyTopsFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return inflater.inflate(R.layout.fragment_buy_tops, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/HomeFragment.kt b/Week2/app/src/main/java/com/example/week2/HomeFragment.kt new file mode 100644 index 0000000..6035368 --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/HomeFragment.kt @@ -0,0 +1,23 @@ +package com.example.week2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class HomeFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return inflater.inflate(R.layout.fragment_home, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/MainActivity.kt b/Week2/app/src/main/java/com/example/week2/MainActivity.kt new file mode 100644 index 0000000..88f176a --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/MainActivity.kt @@ -0,0 +1,62 @@ +package com.example.week2 +import com.example.week2.databinding.ActivityMainBinding + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import android.util.Log +import androidx.fragment.app.Fragment +import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.setupWithNavController + +class MainActivity : AppCompatActivity() { + private val TAG = "LIFE_QUIZ" + private lateinit var binding: ActivityMainBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + Log.d(TAG, "onCreate") + + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + + val navHostFragment = supportFragmentManager + .findFragmentById(R.id.nav_host_fragment) as NavHostFragment + val navController = navHostFragment.navController + binding.bottomBarInclude.bottomNav.setupWithNavController(navController) + + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, 0) + insets + } + } + + override fun onStart() { + super.onStart() + Log.d(TAG, "onStart") + } + override fun onResume() { + super.onResume() + Log.d(TAG, "onResume") + } + override fun onPause() { + super.onPause() + Log.d(TAG, "onPause") + } + override fun onStop() { + super.onStop() + Log.d(TAG, "onStop") + } + override fun onDestroy() { + super.onDestroy() + Log.d(TAG, "onDestroy") + } + override fun onRestart() { + super.onRestart() + Log.d(TAG, "onRestart") + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/ProfileFragment.kt b/Week2/app/src/main/java/com/example/week2/ProfileFragment.kt new file mode 100644 index 0000000..3124d89 --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/ProfileFragment.kt @@ -0,0 +1,23 @@ +package com.example.week2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class ProfileFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return inflater.inflate(R.layout.fragment_profile, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + } +} \ No newline at end of file diff --git a/Week2/app/src/main/java/com/example/week2/ShoppingcartFragment.kt b/Week2/app/src/main/java/com/example/week2/ShoppingcartFragment.kt new file mode 100644 index 0000000..4b3f85e --- /dev/null +++ b/Week2/app/src/main/java/com/example/week2/ShoppingcartFragment.kt @@ -0,0 +1,37 @@ +package com.example.week2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import android.widget.Button +import androidx.navigation.fragment.findNavController +import androidx.navigation.NavOptions + +class ShoppingcartFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + + ): View { + return inflater.inflate(R.layout.fragment_shoppingcart, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val button = view.findViewById