mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 03:12:15 +00:00
Add: The new repositories fragment
This commit is contained in:
parent
fc6331c3a1
commit
fe59f50e36
@ -2,6 +2,7 @@ package com.looker.droidify.database
|
||||
|
||||
import android.database.Cursor
|
||||
import android.os.CancellationSignal
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.paging.DataSource
|
||||
import androidx.room.*
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
@ -55,6 +56,9 @@ interface RepositoryDao : BaseDao<Repository> {
|
||||
@get:Query("SELECT * FROM repository WHERE deleted == 0 ORDER BY _id ASC")
|
||||
val all: List<Repository>
|
||||
|
||||
@get:Query("SELECT * FROM repository WHERE deleted == 0 ORDER BY _id ASC")
|
||||
val allLive: LiveData<List<Repository>>
|
||||
|
||||
@get:Query("SELECT * FROM repository WHERE deleted == 0 ORDER BY _id ASC")
|
||||
val allFlowable: Flowable<List<Repository>>
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.looker.droidify.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.looker.droidify.databinding.FragmentRepositoriesXBinding
|
||||
import com.looker.droidify.service.Connection
|
||||
import com.looker.droidify.service.SyncService
|
||||
import com.looker.droidify.ui.activities.PrefsActivityX
|
||||
import com.looker.droidify.ui.items.RepoItem
|
||||
import com.looker.droidify.ui.viewmodels.RepositoriesViewModelX
|
||||
import com.mikepenz.fastadapter.FastAdapter
|
||||
import com.mikepenz.fastadapter.adapters.ItemAdapter
|
||||
|
||||
class PrefsRepositoriesFragment : BaseNavFragment() {
|
||||
private lateinit var binding: FragmentRepositoriesXBinding
|
||||
private val reposItemAdapter = ItemAdapter<RepoItem>()
|
||||
private var reposFastAdapter: FastAdapter<RepoItem>? = null
|
||||
val viewModel: RepositoriesViewModelX by viewModels {
|
||||
RepositoriesViewModelX.Factory(prefsActivityX.db)
|
||||
}
|
||||
|
||||
private val prefsActivityX: PrefsActivityX
|
||||
get() = requireActivity() as PrefsActivityX
|
||||
|
||||
private val syncConnection = Connection(SyncService::class.java)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = FragmentRepositoriesXBinding.inflate(inflater, container, false)
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun setupAdapters() {
|
||||
syncConnection.bind(requireContext())
|
||||
|
||||
reposFastAdapter = FastAdapter.with(reposItemAdapter)
|
||||
reposFastAdapter?.setHasStableIds(false)
|
||||
|
||||
binding.recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
adapter = reposFastAdapter
|
||||
}
|
||||
}
|
||||
|
||||
override fun setupLayout() {
|
||||
viewModel.productsList.observe(requireActivity()) {
|
||||
reposItemAdapter.set(
|
||||
it.mapNotNull { dbRepo ->
|
||||
dbRepo.trueData?.let { repo ->
|
||||
RepoItem(repo)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
syncConnection.unbind(requireContext())
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.looker.droidify.ui.viewmodels
|
||||
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.looker.droidify.database.DatabaseX
|
||||
import com.looker.droidify.database.Repository
|
||||
|
||||
class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
||||
|
||||
val productsList = MediatorLiveData<List<Repository>>()
|
||||
|
||||
init {
|
||||
productsList.addSource(db.repositoryDao.allLive, productsList::setValue)
|
||||
}
|
||||
|
||||
class Factory(val db: DatabaseX) : ViewModelProvider.Factory {
|
||||
@Suppress("unchecked_cast")
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(RepositoriesViewModelX::class.java)) {
|
||||
return RepositoriesViewModelX(db) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
}
|
||||
}
|
46
src/main/res/layout/fragment_repositories_x.xml
Normal file
46
src/main/res/layout/fragment_repositories_x.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ OAndBackupX: open-source apps backup and restore app.
|
||||
~ Copyright (C) 2020 Antonios Hazim
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU Affero General Public License as
|
||||
~ published by the Free Software Foundation, either version 3 of the
|
||||
~ License, or (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU Affero General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU Affero General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
</data>
|
||||
|
||||
<com.google.android.material.circularreveal.CircularRevealFrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/scrollLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="top"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
tools:listitem="@layout/item_repository_x" />
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
|
||||
</layout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user