mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 03:42:15 +00:00
Add: Add new repo button
This commit is contained in:
parent
7bbac86dd4
commit
14ae20e166
@ -28,7 +28,7 @@ class RepoItem(val item: Repository) :
|
||||
else
|
||||
context.getColorFromAttr(R.attr.colorOnBackground)
|
||||
|
||||
binding.repoName.text = item.name
|
||||
binding.repoName.text = item.name.ifEmpty { context.getString(R.string.new_repository) }
|
||||
binding.repoDescription.text = item.description.trim()
|
||||
|
||||
binding.repoItem.setCardBackgroundColor(
|
||||
|
@ -3,8 +3,13 @@ package com.looker.droidify.ui.viewmodels
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.looker.droidify.database.DatabaseX
|
||||
import com.looker.droidify.database.entity.Repository
|
||||
import com.looker.droidify.database.entity.Repository.Companion.newRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
||||
|
||||
@ -14,6 +19,16 @@ class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
||||
repositories.addSource(db.repositoryDao.allLive, repositories::setValue)
|
||||
}
|
||||
|
||||
fun addRepository() {
|
||||
viewModelScope.launch {
|
||||
addNewRepository()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun addNewRepository() {
|
||||
withContext(Dispatchers.IO) { db.repositoryDao.insert(newRepository()) }
|
||||
}
|
||||
|
||||
class Factory(val db: DatabaseX) : ViewModelProvider.Factory {
|
||||
@Suppress("unchecked_cast")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
|
@ -33,13 +33,29 @@
|
||||
android:layout_gravity="top"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
tools:listitem="@layout/item_repository_x" />
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/add_repository"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton.Icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:layout_margin="@dimen/shape_margin_medium"
|
||||
android:drawableEnd="@drawable/ic_add"
|
||||
android:drawableTint="?colorPrimary"
|
||||
android:text="@string/add_repository" />
|
||||
|
||||
<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.appcompat.widget.LinearLayoutCompat>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
|
||||
</layout>
|
||||
|
@ -185,4 +185,5 @@
|
||||
<string name="install_after_sync_summary">Automatically install app updates after syncing repositories</string>
|
||||
<string name="prefs_updated_apps">Number of updated apps to show</string>
|
||||
<string name="prefs_new_apps">Number of new apps to show</string>
|
||||
<string name="new_repository">New repository</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user