forked from ikromovmirzokhid/JobTop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bab458a
commit e253d2c
Showing
25 changed files
with
810 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/imb/jobtop/adapter/CategoryAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.imb.jobtop.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.imb.jobtop.R | ||
import com.imb.jobtop.databinding.ListItemCategoryBinding | ||
import com.imb.jobtop.model.Category | ||
import kotlinx.android.synthetic.main.list_item_category.view.* | ||
|
||
class CategoryAdapter(private val onclickListener: OnCategoryClickListener) : | ||
ListAdapter<Category, CategoryViewHolder>(CategoryDiffCallback()) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder = | ||
CategoryViewHolder.from(parent) | ||
|
||
|
||
override fun onBindViewHolder(holder: CategoryViewHolder, position: Int) = | ||
holder.bind(getItem(position), onclickListener) | ||
} | ||
|
||
class CategoryViewHolder(private val binding: ListItemCategoryBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(item: Category, onclickListener: OnCategoryClickListener) { | ||
binding.category = item | ||
binding.categoryIcon.setImageBitmap(item.icon) | ||
binding.root.setOnClickListener { onclickListener.onClick(item) } | ||
} | ||
|
||
companion object { | ||
fun from(parent: ViewGroup): CategoryViewHolder { | ||
val binding = DataBindingUtil.inflate<ListItemCategoryBinding>( | ||
LayoutInflater.from(parent.context), | ||
R.layout.list_item_job, | ||
parent, | ||
false | ||
) | ||
return CategoryViewHolder(binding) | ||
} | ||
} | ||
} | ||
|
||
class CategoryDiffCallback : DiffUtil.ItemCallback<Category>() { | ||
override fun areItemsTheSame(oldItem: Category, newItem: Category): Boolean = | ||
oldItem.id == newItem.id | ||
|
||
override fun areContentsTheSame(oldItem: Category, newItem: Category): Boolean = | ||
oldItem.title == oldItem.title && oldItem.jobCount == newItem.jobCount | ||
} | ||
|
||
class OnCategoryClickListener(val onclickListener: (cat: Category) -> Unit) { | ||
fun onClick(cat: Category) { | ||
onclickListener(cat) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.imb.jobtop.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.imb.jobtop.R | ||
import com.imb.jobtop.databinding.ListItemJobBinding | ||
import com.imb.jobtop.model.JobMinimal | ||
|
||
class JobAdapter(private val onclickListener: OnJobClickListener) : | ||
ListAdapter<JobMinimal, JobViewHolder>(JobDiffCallback()) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): JobViewHolder = | ||
JobViewHolder.from(parent) | ||
|
||
|
||
override fun onBindViewHolder(holder: JobViewHolder, position: Int) = | ||
holder.bind(getItem(position), onclickListener) | ||
|
||
} | ||
|
||
class JobViewHolder(private val binding: ListItemJobBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(item: JobMinimal, onclickListener: OnJobClickListener) { | ||
binding.job = item | ||
binding.postedTimeText.text = item.time.toString() | ||
binding.root.setOnClickListener { onclickListener.onClick(item) } | ||
binding.favoriteBtn.setOnClickListener { onclickListener.onFavorClick(item) } | ||
} | ||
|
||
companion object { | ||
fun from(parent: ViewGroup): JobViewHolder { | ||
val binding = DataBindingUtil.inflate<ListItemJobBinding>( | ||
LayoutInflater.from(parent.context), | ||
R.layout.list_item_job, | ||
parent, | ||
false | ||
) | ||
return JobViewHolder(binding) | ||
} | ||
} | ||
} | ||
|
||
class JobDiffCallback : DiffUtil.ItemCallback<JobMinimal>() { | ||
override fun areItemsTheSame(oldItem: JobMinimal, newItem: JobMinimal): Boolean = | ||
oldItem.id == newItem.id | ||
|
||
override fun areContentsTheSame(oldItem: JobMinimal, newItem: JobMinimal): Boolean = | ||
oldItem.title == newItem.title && oldItem.location == newItem.location && oldItem.isFavorite == newItem.isFavorite | ||
} | ||
|
||
class OnJobClickListener( | ||
val onclickListener: (job: JobMinimal) -> Unit, | ||
val onFavoriteClickListener: (job: JobMinimal) -> Unit | ||
) { | ||
fun onClick(job: JobMinimal) { | ||
onclickListener(job) | ||
} | ||
|
||
fun onFavorClick(job: JobMinimal) { | ||
onFavoriteClickListener(job) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.imb.jobtop.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.viewModels | ||
import com.imb.jobtop.R | ||
import com.imb.jobtop.adapter.CategoryAdapter | ||
import com.imb.jobtop.adapter.JobAdapter | ||
import com.imb.jobtop.databinding.FragmentJobBinding | ||
import com.imb.jobtop.databinding.FragmentMainVacancyBinding | ||
import com.imb.jobtop.di.components.MainComponent | ||
import com.imb.jobtop.fragments.base.BaseFragment | ||
import com.imb.jobtop.viewmodel.JobViewModel | ||
import com.imb.jobtop.viewmodel.VacancyViewModel | ||
|
||
class JobFragment : BaseFragment(R.layout.fragment_job) { | ||
|
||
private val component by lazy { | ||
MainComponent.create() | ||
} | ||
|
||
private val viewModel by viewModels<JobViewModel> { component.viewModelFactory() } | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val binding = FragmentJobBinding.inflate(layoutInflater) | ||
|
||
viewModel.submit.observe(viewLifecycleOwner, { | ||
if (it) { | ||
|
||
viewModel.submitCompleted() | ||
} | ||
}) | ||
|
||
binding.viewModel = viewModel | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.imb.jobtop.model | ||
|
||
import android.graphics.Bitmap | ||
|
||
data class Job( | ||
var id: Long, | ||
var title: String, | ||
var employer: String, | ||
var info: String, | ||
var salary: String, | ||
var isFavorite: Boolean, | ||
var location: String, | ||
var time: Long, | ||
var requirements: List<String> | ||
) | ||
|
||
data class JobMinimal( | ||
var id: Long, | ||
var title: String, | ||
var employer: String, | ||
var salary: String, | ||
var isFavorite: Boolean, | ||
var location: String, | ||
var time: Long, | ||
) | ||
|
||
data class Category( | ||
var id: Long, | ||
var icon: Bitmap, | ||
var title: String, | ||
var jobCount: Int, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/imb/jobtop/viewmodel/JobViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.imb.jobtop.viewmodel | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.imb.jobtop.model.Job | ||
import com.imb.jobtop.network.api.VacancyApi | ||
import com.imb.jobtop.viewmodel.base.BaseViewModel | ||
import javax.inject.Inject | ||
|
||
class JobViewModel @Inject constructor( | ||
private val api: VacancyApi, | ||
datasetID: Long, | ||
vacancyID: Long | ||
) : | ||
BaseViewModel() { | ||
lateinit var job: Job | ||
|
||
private val _submit = MutableLiveData<Boolean>() | ||
val submit: LiveData<Boolean> | ||
get() = _submit | ||
|
||
fun submitClicked() { | ||
_submit.value = true | ||
} | ||
|
||
fun submitCompleted() { | ||
_submit.value = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="@color/blue" /> | ||
<corners android:radius="10dp" /> | ||
</shape> |
10 changes: 10 additions & 0 deletions
10
app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="#1565C0" | ||
android:pathData="M8.59,16.59L13.17,12 8.59,7.41 10,6l6,6 -6,6 -1.41,-1.41z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/> | ||
</vector> |
Oops, something went wrong.