Skip to content

Commit

Permalink
added google folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicalMeghan committed Nov 3, 2020
1 parent ec691ac commit 5e29458
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 17 deletions.
19 changes: 19 additions & 0 deletions RecyclerViewKotlin/.google/packaging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# GOOGLE SAMPLE PACKAGING DATA
#
# This file is used by Google as part of our samples packaging process.
# End users may safely ignore this file. It has no relevance to other systems.
---
status: PUBLISHED
technologies: [Android]
categories: [Views Widgets]
languages: [Kotlin]
solutions: [Mobile]
github: android/views-widgets
level: INTERMEDIATE
icon: screenshots/icon-web.png
apiRefs:
- androidx.recyclerview.widget.RecyclerView
- androidx.recyclerview.widget.RecyclerView.LayoutManager
- androidx.recyclerview.widget.RecyclerView.ViewHolder
license: apache2
51 changes: 49 additions & 2 deletions RecyclerViewKotlin/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
#RecyclerView Kotlin
Android RecyclerView Sample (Kotlin)
====================================

This application implements a RecyclerView in Kotlin with ListAdapter, onClickListener
and Headers. If you are looking for a simpler sample, look at the RecyclerViewSimple sample
in the directory.
in the directory.


Introduction
------------

Sample demonstrating the use of [RecyclerView][1] to layout elements with a
[LinearLayoutManager][2].

[RecyclerView][1] can display large datasets that can be scrolled
efficiently by recycling a limited number of views. [ListAdapter][3] is used to
efficiently compute diffs when items are added/removed from the list. Click listeners can be
defined when [ViewHolder][4] views are instantiated.


[1]: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView
[2]: https://developer.android.com/reference/androidx/recyclerview/widget/LinearLayoutManager
[3]: https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter
[4]: https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder

Pre-requisites
--------------

- Android SDK 27
- Android Gradle Plugin 3.0
- Android Support Repository

Screenshots
-------------

![image](https://user-images.githubusercontent.com/46006059/98028846-8b6df700-1dc3-11eb-9f0b-ad93569be189.png)

Getting Started
---------------

To build this project, use "Import Project" in Android Studio.

Support
-------

- Stack Overflow: http://stackoverflow.com/questions/tagged/android

If you've found an error in this sample, please file an issue:
https://github.com/android/views-widgets

Patches are encouraged, and may be submitted by forking this project and
submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
1 change: 0 additions & 1 deletion RecyclerViewKotlin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.example.recyclersample"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FlowersListActivity : AppCompatActivity() {
private fun adapterOnClick(flower: Flower) {
val intent = Intent(this, FlowerDetailActivity()::class.java)
intent.putExtra(FLOWER_ID, flower.id)
this.startActivity(intent)
startActivity(intent)
}

/* Adds flower to flowerList when FAB is clicked. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FlowersListViewModel(val dataSource: DataSource) : ViewModel() {

/* If the name and description are present, create new Flower and add it to the datasource */
fun insertFlower(flowerName: String?, flowerDescription: String?) {
if(flowerName == null || flowerDescription == null){
if (flowerName == null || flowerDescription == null) {
return
}

Expand Down
12 changes: 12 additions & 0 deletions RecyclerViewKotlin/app/src/main/res/drawable/ic_add_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<!--
Copyright (C) 2020 The Android Open Source Project
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
Expand Down
6 changes: 1 addition & 5 deletions RecyclerViewKotlin/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
android:contentDescription="@string/fab_content_description"
android:src="@drawable/ic_add_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9" />
app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<Button
android:id="@+id/done_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="250dp"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/done_button_text" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
android:id="@+id/flower_detail_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="50dp"
android:paddingBottom="20dp"
android:paddingTop="24dp"
android:paddingBottom="24dp"
android:text="@string/flower1_name"
android:textAlignment="center"
android:textAppearance="?attr/textAppearanceHeadline3" />

<ImageView
android:id="@+id/flower_detail_image"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_gravity="center"
android:contentDescription="@string/flower_image_content_description"
app:srcCompat="@drawable/rose" />
Expand All @@ -40,13 +40,13 @@
android:id="@+id/flower_detail_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:padding="16dp"
android:text="@string/flower1_description" />

<Button
android:id="@+id/remove_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="250dp"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove_this_flower" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2020 The Android Open Source Project
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.
-->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
Expand Down

0 comments on commit 5e29458

Please sign in to comment.