Commit c0321853 authored by Mark Murphy's avatar Mark Murphy
Browse files

updates for v1.1

parent ba8d2863
......@@ -35,7 +35,7 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
......@@ -22,16 +22,12 @@ import android.view.MenuItem
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.commonsware.jetpack.sampler.actionbar.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private val vmFactory: ViewModelProvider.Factory
by lazy { SavedStateViewModelFactory(application, this) }
private val vm: ColorViewModel by viewModels { vmFactory }
private val vm: ColorViewModel by viewModels()
private lateinit var colorAdapter: ColorAdapter
override fun onCreate(savedInstanceState: Bundle?) {
......
......@@ -37,7 +37,7 @@ android {
dependencies {
implementation "androidx.activity:activity-ktx:1.1.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
/*
Copyright (c) 2019-2020 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
Covered in detail in the book _Elements of Android Jetpack_
https://commonsware.com/Jetpack
*/
package com.commonsware.jetpack.bookmarker
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import org.jsoup.Jsoup
import java.net.URI
......@@ -35,10 +51,10 @@ object BookmarkRepository {
BookmarkModel(entity)
}
fun load(context: Context): LiveData<List<BookmarkModel>> {
fun load(context: Context): Flow<List<BookmarkModel>> {
val db: BookmarkDatabase = BookmarkDatabase[context]
return Transformations.map(db.bookmarkStore().all()) { entities ->
return db.bookmarkStore().all().map { entities ->
entities.map { BookmarkModel(it) }
}
}
......
/*
Copyright (c) 2019 CommonsWare, LLC
Copyright (c) 2019-2020 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
......@@ -16,16 +16,16 @@
package com.commonsware.jetpack.bookmarker
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
@Dao
interface BookmarkStore {
@Query("SELECT * FROM BookmarkEntity ORDER BY title")
fun all(): LiveData<List<BookmarkEntity>>
fun all(): Flow<List<BookmarkEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun save(entity: BookmarkEntity)
......
/*
Copyright (c) 2019 CommonsWare, LLC
Copyright (c) 2019-2020 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
......@@ -19,8 +19,8 @@ package com.commonsware.jetpack.bookmarker
import android.app.Application
import androidx.lifecycle.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import java.util.*
class MainMotor(application: Application) : AndroidViewModel(application) {
private val _saveEvents = MutableLiveData<Event<BookmarkResult>>()
......@@ -28,16 +28,9 @@ class MainMotor(application: Application) : AndroidViewModel(application) {
val states: LiveData<MainViewState>
init {
states =
Transformations.map(BookmarkRepository.load(getApplication())) { models ->
val content = ArrayList<RowState>()
for (model in models) {
content.add(RowState(model))
}
MainViewState.Content(content)
}
states = BookmarkRepository.load(getApplication())
.map { models -> MainViewState.Content(models.map { RowState(it) }) }
.asLiveData()
}
fun save(pageUrl: String) {
......
......@@ -28,6 +28,7 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.activity:activity:1.1.0"
}
......@@ -24,6 +24,7 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.activity:activity:1.1.0"
}
......@@ -35,7 +35,7 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
......
......@@ -23,16 +23,12 @@ import android.provider.ContactsContract
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModelProvider
import com.commonsware.jetpack.sampler.contact.databinding.ActivityMainBinding
private const val REQUEST_PICK = 1337
class MainActivity : AppCompatActivity() {
private val vmFactory: ViewModelProvider.Factory
by lazy { SavedStateViewModelFactory(application, this) }
private val vm: ContactViewModel by viewModels { vmFactory }
private val vm: ContactViewModel by viewModels()
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
......
......@@ -36,7 +36,7 @@ android {
dependencies {
implementation "androidx.activity:activity-ktx:1.1.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
......
......@@ -29,17 +29,13 @@ android {
jvmTarget = "1.8"
}
androidExtensions {
experimental = true
}
viewBinding {
enabled = true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
......@@ -19,8 +19,6 @@ package com.commonsware.jetpack.sampler.style
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.commonsware.jetpack.sampler.style.databinding.ActivityMainBinding
......@@ -29,9 +27,7 @@ import kotlin.collections.ArrayList
class MainActivity : AppCompatActivity() {
private lateinit var adapter: EventAdapter
private val vmFactory: ViewModelProvider.Factory
by lazy { SavedStateViewModelFactory(application, this) }
private val vm: EventViewModel by viewModels { vmFactory }
private val vm: EventViewModel by viewModels()
private val id = Random().nextInt()
override fun onCreate(savedInstanceState: Bundle?) {
......
......@@ -35,7 +35,7 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
......@@ -19,10 +19,6 @@ package com.commonsware.jetpack.sampler.theme
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.get
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.commonsware.jetpack.sampler.theme.databinding.ActivityMainBinding
......@@ -31,9 +27,7 @@ import kotlin.collections.ArrayList
class MainActivity : AppCompatActivity() {
private lateinit var adapter: EventAdapter
private val vmFactory: ViewModelProvider.Factory
by lazy { SavedStateViewModelFactory(application, this) }
private val vm: EventViewModel by viewModels { vmFactory }
private val vm: EventViewModel by viewModels()
private val id = Random().nextInt()
override fun onCreate(savedInstanceState: Bundle?) {
......
......@@ -30,17 +30,13 @@ android {
jvmTarget = "1.8"
}
androidExtensions {
experimental = true
}
dataBinding {
enabled = true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
......@@ -20,8 +20,6 @@ import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.commonsware.jetpack.sampler.databind.databinding.ActivityMainBinding
......@@ -30,9 +28,7 @@ import kotlin.collections.ArrayList
class MainActivity : AppCompatActivity() {
private lateinit var adapter: EventAdapter
private val vmFactory: ViewModelProvider.Factory
by lazy { SavedStateViewModelFactory(application, this) }
private val vm: EventViewModel by viewModels { vmFactory }
private val vm: EventViewModel by viewModels()
private val id = Random().nextInt()
override fun onCreate(savedInstanceState: Bundle?) {
......
......@@ -35,7 +35,7 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
......@@ -36,7 +36,7 @@ android {
dependencies {
implementation "androidx.activity:activity-ktx:1.1.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
......@@ -36,7 +36,7 @@ android {
dependencies {
implementation "androidx.activity:activity-ktx:1.1.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment