diff --git a/app/src/main/java/com/root14/flashlightappsmarket/model/AppItem.kt b/app/src/main/java/com/root14/flashlightappsmarket/model/AppItem.kt index ae88a1e..9ad9b20 100644 --- a/app/src/main/java/com/root14/flashlightappsmarket/model/AppItem.kt +++ b/app/src/main/java/com/root14/flashlightappsmarket/model/AppItem.kt @@ -2,6 +2,10 @@ package com.root14.flashlightappsmarket.model import android.graphics.drawable.Drawable +/** + * Created by ilkay on 17,May, 2023 + */ + data class AppItem( val icon: Drawable?, val name: String, diff --git a/app/src/main/java/com/root14/flashlightappsmarket/model/CategoryItem.kt b/app/src/main/java/com/root14/flashlightappsmarket/model/CategoryItem.kt new file mode 100644 index 0000000..1a1ae78 --- /dev/null +++ b/app/src/main/java/com/root14/flashlightappsmarket/model/CategoryItem.kt @@ -0,0 +1,11 @@ +package com.root14.flashlightappsmarket.model + +import android.graphics.drawable.Drawable + +/** + * Created by ilkay on 17,May, 2023 + */ +data class CategoryItem( + val icon: Drawable?, + val name: String +) \ No newline at end of file diff --git a/app/src/main/java/com/root14/flashlightappsmarket/view/AppAdapter.kt b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/AppAdapter.kt similarity index 84% rename from app/src/main/java/com/root14/flashlightappsmarket/view/AppAdapter.kt rename to app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/AppAdapter.kt index 4086e73..60fc2b9 100644 --- a/app/src/main/java/com/root14/flashlightappsmarket/view/AppAdapter.kt +++ b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/AppAdapter.kt @@ -1,9 +1,12 @@ -package com.root14.flashlightappsmarket.view +package com.root14.flashlightappsmarket.view.ui.applicationFragment import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.root14.flashlightappsmarket.model.AppItem +/** + * Created by ilkay on 17,May, 2023 + */ class AppAdapter(private val appList: List) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder { diff --git a/app/src/main/java/com/root14/flashlightappsmarket/view/AppViewHolder.kt b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/AppViewHolder.kt similarity index 89% rename from app/src/main/java/com/root14/flashlightappsmarket/view/AppViewHolder.kt rename to app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/AppViewHolder.kt index 69899aa..f910a2f 100644 --- a/app/src/main/java/com/root14/flashlightappsmarket/view/AppViewHolder.kt +++ b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/AppViewHolder.kt @@ -1,11 +1,13 @@ -package com.root14.flashlightappsmarket.view +package com.root14.flashlightappsmarket.view.ui.applicationFragment import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.root14.flashlightappsmarket.databinding.ItemAppBinding import com.root14.flashlightappsmarket.model.AppItem - +/** + * Created by ilkay on 17,May, 2023 + */ class AppViewHolder(private val binding: ItemAppBinding) : RecyclerView.ViewHolder(binding.root) { fun bind(appItem: AppItem) { diff --git a/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/ApplicationFragment.kt b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/ApplicationFragment.kt index ff64a73..29e7aba 100644 --- a/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/ApplicationFragment.kt +++ b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/applicationFragment/ApplicationFragment.kt @@ -9,10 +9,10 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import com.root14.flashlightappsmarket.R import com.root14.flashlightappsmarket.databinding.FragmentApplicationBinding -import com.root14.flashlightappsmarket.databinding.FragmentMainBinding import com.root14.flashlightappsmarket.model.AppItem -import com.root14.flashlightappsmarket.view.AppAdapter - +/** + * Created by ilkay on 17,May, 2023 + */ /** * list applications diff --git a/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/CategoryAdapter.kt b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/CategoryAdapter.kt new file mode 100644 index 0000000..e7b0c37 --- /dev/null +++ b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/CategoryAdapter.kt @@ -0,0 +1,25 @@ +package com.root14.flashlightappsmarket.view.ui.mainfragment + +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.root14.flashlightappsmarket.model.CategoryItem + +/** + * Created by ilkay on 17,May, 2023 + */ +class CategoryAdapter(private val categoryItem: List) : + RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder { + return CategoryViewHolder.create(parent) + } + + override fun onBindViewHolder(holder: CategoryViewHolder, position: Int) { + val categoryItem = categoryItem[position] + holder.bind(categoryItem) + } + + override fun getItemCount(): Int { + return categoryItem.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/CategoryViewHolder.kt b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/CategoryViewHolder.kt new file mode 100644 index 0000000..965e52b --- /dev/null +++ b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/CategoryViewHolder.kt @@ -0,0 +1,29 @@ +package com.root14.flashlightappsmarket.view.ui.mainfragment + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.root14.flashlightappsmarket.databinding.ItemAppBinding +import com.root14.flashlightappsmarket.databinding.ListCategoriesBinding +import com.root14.flashlightappsmarket.model.AppItem +import com.root14.flashlightappsmarket.model.CategoryItem + +/** + * Created by ilkay on 17,May, 2023 + */ +class CategoryViewHolder(private val binding: ListCategoriesBinding) : + RecyclerView.ViewHolder(binding.root) { + + fun bind(categoryItem: CategoryItem) { + binding.imageViewIcon.setImageDrawable(categoryItem.icon) + binding.textViewCategoryName.text = categoryItem.name + } + + companion object { + fun create(parent: ViewGroup): CategoryViewHolder { + val inflater = LayoutInflater.from(parent.context) + val binding = ListCategoriesBinding.inflate(inflater, parent, false) + return CategoryViewHolder(binding) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/MainFragment.kt b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/MainFragment.kt index 84d0bda..da60ad9 100644 --- a/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/MainFragment.kt +++ b/app/src/main/java/com/root14/flashlightappsmarket/view/ui/mainfragment/MainFragment.kt @@ -8,16 +8,17 @@ import android.view.ViewGroup import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import com.root14.flashlightappsmarket.R +import com.root14.flashlightappsmarket.databinding.FragmentApplicationBinding import com.root14.flashlightappsmarket.databinding.FragmentMainBinding -import com.root14.flashlightappsmarket.model.AppItem -import com.root14.flashlightappsmarket.view.AppAdapter +import com.root14.flashlightappsmarket.model.CategoryItem +import com.root14.flashlightappsmarket.view.ui.applicationFragment.AppAdapter /** * main fragment listing categories */ class MainFragment : Fragment() { private lateinit var binding: FragmentMainBinding - private lateinit var appAdapter: AppAdapter + private lateinit var categoryAdapter: CategoryAdapter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } @@ -33,5 +34,25 @@ class MainFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val categoryList = createCategoryList() + categoryAdapter = CategoryAdapter(categoryList) + binding.rvCategories.layoutManager = LinearLayoutManager(requireContext()) + binding.rvCategories.adapter = categoryAdapter } + + //test + private fun createCategoryList() = listOf( + CategoryItem( + context?.let { ContextCompat.getDrawable(it, R.drawable.baseline_flashlight_on_24) }, + "Flashlights" + ), + CategoryItem( + context?.let { ContextCompat.getDrawable(it, R.drawable.baseline_light_mode_24) }, + "Colored Lights" + ), + CategoryItem( + context?.let { ContextCompat.getDrawable(it, R.drawable.baseline_sos_24) }, + "Sos Alerts" + ) + ) } \ No newline at end of file diff --git a/app/src/main/res/layout/list_categories.xml b/app/src/main/res/layout/list_categories.xml new file mode 100644 index 0000000..5c2f818 --- /dev/null +++ b/app/src/main/res/layout/list_categories.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b66028b..210e79b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,4 +9,5 @@ Flashlights Colored Lights SOS Alerts + Category Name \ No newline at end of file