Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
otashjumaev committed Dec 5, 2020
1 parent bab458a commit e253d2c
Show file tree
Hide file tree
Showing 25 changed files with 810 additions and 23 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}


buildTypes {
release {
minifyEnabled false
Expand All @@ -33,6 +34,9 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding true
}
}

dependencies {
Expand Down
58 changes: 58 additions & 0 deletions app/src/main/java/com/imb/jobtop/adapter/CategoryAdapter.kt
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)
}
}
68 changes: 68 additions & 0 deletions app/src/main/java/com/imb/jobtop/adapter/JobAdapter.kt
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)
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.imb.jobtop.di.ViewModelFactory
import com.imb.jobtop.di.ViewModelKey
import com.imb.jobtop.network.api.VacancyApi
import com.imb.jobtop.utils.resources.ResourceProvider
import com.imb.jobtop.viewmodel.JobViewModel
import com.imb.jobtop.viewmodel.VacancyViewModel
import dagger.Binds
import dagger.BindsInstance
Expand Down Expand Up @@ -47,4 +48,9 @@ abstract class MainScreenModule {
@IntoMap
@ViewModelKey(VacancyViewModel::class)
abstract fun vacancyViewModel(viewModel: VacancyViewModel): ViewModel

@Binds
@IntoMap
@ViewModelKey(JobViewModel::class)
abstract fun vacancyViewModel(viewModel: JobViewModel): ViewModel
}
41 changes: 39 additions & 2 deletions app/src/main/java/com/imb/jobtop/fragments/FragmentMainVacancy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ package com.imb.jobtop.fragments

import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.SearchView
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.imb.jobtop.R
import com.imb.jobtop.adapter.CategoryAdapter
import com.imb.jobtop.adapter.JobAdapter
import com.imb.jobtop.adapter.OnCategoryClickListener
import com.imb.jobtop.adapter.OnJobClickListener
import com.imb.jobtop.databinding.FragmentMainVacancyBinding
import com.imb.jobtop.di.components.MainComponent
import com.imb.jobtop.fragments.base.BaseFragment
import com.imb.jobtop.utils.extensions.progressOff
Expand All @@ -16,19 +24,48 @@ class FragmentMainVacancy : BaseFragment(R.layout.fragment_main_vacancy) {
private val component by lazy {
MainComponent.create()
}
private lateinit var jobAdapter: JobAdapter
private lateinit var categoryAdapter: CategoryAdapter

private val viewModel by viewModels<VacancyViewModel> { component.viewModelFactory() }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val binding = FragmentMainVacancyBinding.inflate(layoutInflater)
categoryAdapter = CategoryAdapter(OnCategoryClickListener {

})

jobAdapter = JobAdapter(OnJobClickListener({

}, {

// loadVacancies()
}))

binding.searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
TODO("Not yet implemented")
}

override fun onQueryTextChange(newText: String?): Boolean {
TODO("Not yet implemented")
}
})

val jobManager = LinearLayoutManager(context)
val catManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
binding.jobList.adapter = jobAdapter
binding.jobList.layoutManager = jobManager
binding.categoryList.adapter = categoryAdapter
binding.categoryList.layoutManager = catManager
loadVacancies()
}

private fun loadVacancies() {
progressOn()
viewModel.getVacancyFromSomeWhere().observe(viewLifecycleOwner, Observer {
progressOff()

// jobAdapter.submitList(it)
})
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/imb/jobtop/fragments/JobFragment.kt
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import androidx.fragment.app.Fragment
import com.imb.jobtop.MainActivity


abstract class BaseFragment(
layoutId: Int
) :
Fragment(layoutId) {
abstract class BaseFragment(layoutId: Int) : Fragment(layoutId) {

var detached = true

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/imb/jobtop/model/models.kt
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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import okhttp3.OkHttpClient;

import static uz.infin.core.network.tls.TlsExtKt.enableTlsOnPreLollipop;
import static com.imb.jobtop.network.tls.TlsExtKt.enableTlsOnPreLollipop;

public class UnsafeOkHttpClient {
public static OkHttpClient.Builder getUnsafeOkHttpClient() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/imb/jobtop/network/tls/TlsExt.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uz.infin.core.network.tls
package com.imb.jobtop.network.tls

import android.os.Build
import android.util.Log
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/imb/jobtop/viewmodel/JobViewModel.kt
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
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/bg_btn_submit.xml
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 app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml
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>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_location_on_24.xml
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>
Loading

0 comments on commit e253d2c

Please sign in to comment.