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 f52fd4b commit 77b0852
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 58 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/com/imb/jobtop/database/JobDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ interface JobDao {
fun get(id: Long): Job?

@Query("SELECT * FROM Jobs ORDER BY time DESC")
fun getTexts(): LiveData<List<Job>>
fun getJobs(): List<Job>

@Query("SELECT * FROM Jobs WHERE isFavorite == 1")
fun getFavoriteJobs(): List<Job>

@Query("SELECT * FROM Jobs WHERE catId == :catID")
fun getJobsByCategory(catID: Long): List<Job>

@Query("SELECT * FROM Jobs WHERE location LIKE :location")
fun getJobsByLocation(location: String): List<Job>

@Query("DELETE FROM Jobs")
fun clear()
Expand Down
59 changes: 24 additions & 35 deletions app/src/main/java/com/imb/jobtop/fragments/FragmentMainVacancy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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.database.MyDatabase
import com.imb.jobtop.di.components.MainComponent
import com.imb.jobtop.fragments.base.BaseFragment
import com.imb.jobtop.utils.extensions.progressOff
Expand All @@ -33,69 +34,57 @@ class FragmentMainVacancy : BaseFragment(R.layout.fragment_main_vacancy) {
private lateinit var jobAdapter: JobAdapter
private lateinit var categoryAdapter: CategoryAdapter

private lateinit var db: MyDatabase
private val viewModel by viewModels<VacancyViewModel> { component.viewModelFactory() }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
db = MyDatabase.getInstance(requireContext())
initAdapters()
initSearchView()
initNavBar()

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

private fun initAdapters() {
categoryAdapter = CategoryAdapter(OnCategoryClickListener {
val b = Bundle()
b.putData("category_id", it)
b.putInt("type", 0)
findNavController().navigate(R.id.jobList, b)
})

jobAdapter = JobAdapter(OnJobClickListener({
val b = Bundle()
b.putData("job", it)
findNavController().navigate(R.id.jobDetailFragment, b)
}, {
TODO("favourite button")
it.isFavorite = !it.isFavorite
db.jodDao.update(it)
}))

initSearchView()
initBottomNavBar()

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

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

override fun onQueryTextChange(newText: String?): Boolean {
TODO("Not yet implemented")
val list = db.jodDao.getJobsByLocation(newText ?: "")
viewModel.searchJobs(list)
return true
}
})
}

private fun initBottomNavBar() {
bottomNavigation.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.homePage -> {
findNavController()
}
R.id.favPage -> {
val b = Bundle()
b.putInt("type", 1)
findNavController().navigate(R.id.jobListFragment, b)
}
R.id.userPage -> {

}
}
true
}
}

private fun initToolbar() {
private fun initNavBar() {
drawerBtn.setOnClickListener {
if (drawerLayout != null && navView != null)
drawerLayout.openDrawer(navView)//GravityCompat.START)
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/imb/jobtop/fragments/JobListFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.imb.jobtop.fragments
import android.os.Bundle
import android.view.View
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.imb.jobtop.R
import com.imb.jobtop.adapter.JobAdapter
import com.imb.jobtop.adapter.OnJobClickListener
Expand All @@ -11,22 +12,34 @@ import com.imb.jobtop.fragments.base.BaseFragment
import com.imb.jobtop.model.Job
import com.imb.jobtop.utils.extensions.getData
import com.imb.jobtop.utils.extensions.putData
import kotlinx.android.synthetic.main.fragment_job_list.*

class JobListFragment : BaseFragment(R.layout.fragment_job_list) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val type = arguments?.getInt("type")
val db = MyDatabase.getInstance(requireContext())
val list: MutableList<Job>?
when (type) {
0 -> list = db.jodDao.getJobs().toMutableList()

1 -> list = db.jodDao.getJobs().toMutableList()

2 -> list = db.jodDao.getJobs().toMutableList()
}


val jobAdapter = JobAdapter(OnJobClickListener({
val b = Bundle()
b.putData("job", it)
findNavController().navigate(R.id.jobDetailFragment, b)
}, {
TODO("favourite button")
it.isFavorite = !it.isFavorite
db.jodDao.update(it)
}))

jobList.adapter = jobAdapter
jobList.layoutManager = LinearLayoutManager(context)

}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/imb/jobtop/model/models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.room.PrimaryKey
data class Job(
@PrimaryKey(autoGenerate = true)
var id: Long,
var catId: Long,
var title: String,
var employer: String,
var info: String,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/imb/jobtop/network/api/VacancyApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface VacancyApi {
@GET("13645/version/10074?access_key=$accessKey")
suspend fun getEconomyVacancy(): Any

@GET("9035/version/29697?access_key=$accessKey")
suspend fun getTransportVacancy(): Any

@GET("{dataSet_id}/version/{vacancy_id}?access_key=$accessKey")
suspend fun getVacancy(
@Path("dataSet_id") dataSet_id: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface NetworkComponent {
abstract class NetworkModule {

companion object {
private const val BASE_URL = "https://data.gov.uz/uz/api/v1/json/"
private const val BASE_URL = "https://data.gov.uz/uz/api/v1/json/dataset/"

@Provides
@Singleton
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/imb/jobtop/viewmodel/VacancyViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.imb.jobtop.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.imb.jobtop.model.Job
import com.imb.jobtop.network.api.VacancyApi
import com.imb.jobtop.utils.resources.ResourceProvider
import com.imb.jobtop.viewmodel.base.BaseViewModel
Expand All @@ -16,23 +17,28 @@ class VacancyViewModel @Inject constructor(
private val api: VacancyApi
) : BaseViewModel() {

private var _data: MutableLiveData<Any>? = null
private val data: LiveData<Any>?
private var _data: MutableLiveData<List<Job>>? = null
private val data: LiveData<List<Job>>?
get() = _data

fun getVacancyFromSomeWhere(): LiveData<Any> {
fun getVacancyFromSomeWhere(): LiveData<List<Job>> {
_data = MutableLiveData()
viewModelScope.launch(Dispatchers.IO) {
try {
val response = api.getEconomyVacancy()
_data?.postValue(response)
// _data?.postValue(response)
} catch (error: HttpException) {

} catch (error: Throwable) {

}
}
return data!!

}

fun searchJobs(newList: List<Job>) {
_data?.postValue(newList)
}

}
1 change: 1 addition & 0 deletions app/src/main/res/drawable/bg_search_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F4F6F9"/>
<corners android:radius="20dp"/>
<stroke android:color="#F4F6F9" android:width="10dp"/>

</shape>
20 changes: 4 additions & 16 deletions app/src/main/res/layout/fragment_main_vacancy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
android:fitsSystemWindows="true">


<androidx.constraintlayout.widget.ConstraintLayout
Expand All @@ -22,10 +21,10 @@

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/drawerBtn"
android:padding="10dp"
android:background="@color/colorTransparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorTransparent"
android:padding="10dp"
android:src="@drawable/ic_round_menu_24" />


Expand Down Expand Up @@ -123,23 +122,12 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
app:layout_constraintBottom_toTopOf="@id/bottomNavigation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/headerText2"
tools:listitem="@layout/list_item_job" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:itemIconTint="@color/blue"
app:itemTextColor="@color/blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/jobList"
app:layout_constraintVertical_bias="1"
app:menu="@menu/bottom_navigation_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down

0 comments on commit 77b0852

Please sign in to comment.