Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Commit bbc8fdf

Browse files
committed
Move libraries list to new activity
1 parent 3fd2799 commit bbc8fdf

9 files changed

Lines changed: 77 additions & 80 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ dependencies {
4747
// Room
4848
implementation deps.roomRuntime
4949
implementation deps.roomRxJava
50+
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
51+
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
5052
kapt deps.roomCompiler
5153

5254
// Rx

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
android:name=".ui.about.AboutActivity"
6161
android:theme="@style/AppThemeNoBar" />
6262
<activity android:name=".ui.previousOrder.PreviousOrderActivity" />
63+
<activity
64+
android:name=".ui.libraries.LibrariesActivity"
65+
android:parentActivityName=".ui.about.AboutActivity" />
6366

6467
<service android:name=".data.network.MyFirebaseMessagingService">
6568
<intent-filter>
@@ -76,11 +79,9 @@
7679
<meta-data
7780
android:name="preloaded_fonts"
7881
android:resource="@array/preloaded_fonts" />
79-
8082
<meta-data
8183
android:name="firebase_crashlytics_collection_enabled"
8284
android:value="false" />
83-
8485
</application>
8586

8687
</manifest>

app/src/main/java/com/marknkamau/justjava/data/models/Library.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ data class Library(val name: String, val author: String, val license: Int, val l
1313
}
1414

1515
val licenseText: String
16-
get() {
17-
return when(license){
18-
MIT -> "MIT"
19-
APACHE2 -> "Apache-2.0"
20-
else -> "Unknown"
21-
}
16+
get() = when (license) {
17+
MIT -> "MIT"
18+
APACHE2 -> "Apache-2.0"
19+
else -> "Unknown"
2220
}
23-
2421
}

app/src/main/java/com/marknkamau/justjava/ui/about/AboutActivity.kt

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import android.content.Intent
44
import android.net.Uri
55
import android.os.Bundle
66
import androidx.appcompat.app.AppCompatActivity
7-
import androidx.recyclerview.widget.DividerItemDecoration
8-
import androidx.recyclerview.widget.LinearLayoutManager
97
import android.view.View
10-
import android.widget.LinearLayout
118
import com.marknkamau.justjava.BuildConfig
129
import com.marknkamau.justjava.R
13-
import com.marknkamau.justjava.data.models.Library
10+
import com.marknkamau.justjava.ui.libraries.LibrariesActivity
1411
import kotlinx.android.synthetic.main.activity_about.*
1512

1613
class AboutActivity : AppCompatActivity(), View.OnClickListener {
@@ -21,39 +18,14 @@ class AboutActivity : AppCompatActivity(), View.OnClickListener {
2118

2219
tvVersion.text = "v${BuildConfig.VERSION_NAME}"
2320

24-
val libraries = mutableListOf(
25-
Library("Retrofit", "Square", Library.APACHE2, "http://square.github.io/retrofit/"),
26-
Library("Gson", "Google", Library.APACHE2, "https://github.com/google/gson"),
27-
Library("RxJava", "ReactiveX", Library.APACHE2, "https://github.com/ReactiveX/RxJava"),
28-
Library("RxAndroid", "ReactiveX", Library.APACHE2, "https://github.com/ReactiveX/RxAndroid"),
29-
Library("RxKotlin", "ReactiveX", Library.APACHE2, "https://github.com/ReactiveX/RxKotlin"),
30-
Library("Picasso", "Square", Library.APACHE2, "http://square.github.io/picasso/"),
31-
Library("Timber", "Jake Wharton", Library.APACHE2, "https://github.com/JakeWharton/timber"),
32-
Library("Mockito", "Mockito", Library.MIT, "https://github.com/mockito/mockito"),
33-
Library("Mockito-Kotlin", "Niek Haarman", Library.MIT, "https://github.com/nhaarman/mockito-kotlin")
34-
).sortedBy { it.name }
35-
36-
rvLibraries.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this, LinearLayout.VERTICAL, false)
37-
rvLibraries.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(this, LinearLayout.VERTICAL))
38-
val librariesAdapter = LibrariesAdapter { library ->
39-
openUrl(library.link)
40-
}
41-
rvLibraries.adapter = librariesAdapter
42-
librariesAdapter.setItems(libraries)
43-
4421
tvSource.setOnClickListener(this)
4522
imgBack.setOnClickListener(this)
4623
imgMail.setOnClickListener(this)
4724
imgLinkedin.setOnClickListener(this)
4825
imgGithub.setOnClickListener(this)
4926
imgWebsite.setOnClickListener(this)
5027
tvPrivacyPolicy.setOnClickListener(this)
51-
52-
scrollView.post{
53-
Runnable {
54-
scrollView.scrollTo(0, scrollView.top)
55-
}.run()
56-
}
28+
tvLibraries.setOnClickListener { startActivity(Intent(this, LibrariesActivity::class.java)) }
5729
}
5830

5931
override fun onClick(view: View) {
@@ -70,7 +42,6 @@ class AboutActivity : AppCompatActivity(), View.OnClickListener {
7042

7143
private fun openUrl(url: String) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
7244

73-
7445
private fun sendEmail() {
7546
val addresses = arrayOf("mark.kamau@outlook.com") //Has to be String array or it will ignore
7647
val intent = Intent(Intent.ACTION_SENDTO)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.marknkamau.justjava.ui.libraries
2+
3+
import android.content.Intent
4+
import android.net.Uri
5+
import androidx.appcompat.app.AppCompatActivity
6+
import android.os.Bundle
7+
import android.widget.LinearLayout
8+
import androidx.recyclerview.widget.RecyclerView
9+
import com.marknkamau.justjava.R
10+
import com.marknkamau.justjava.data.models.Library
11+
import kotlinx.android.synthetic.main.activity_libraries.*
12+
13+
class LibrariesActivity : AppCompatActivity() {
14+
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
super.onCreate(savedInstanceState)
17+
setContentView(R.layout.activity_libraries)
18+
19+
val libraries = mutableListOf(
20+
Library("Retrofit", "Square", Library.APACHE2, "http://square.github.io/retrofit/"),
21+
Library("Gson", "Google", Library.APACHE2, "https://github.com/google/gson"),
22+
Library("RxJava", "ReactiveX", Library.APACHE2, "https://github.com/ReactiveX/RxJava"),
23+
Library("RxAndroid", "ReactiveX", Library.APACHE2, "https://github.com/ReactiveX/RxAndroid"),
24+
Library("RxKotlin", "ReactiveX", Library.APACHE2, "https://github.com/ReactiveX/RxKotlin"),
25+
Library("Picasso", "Square", Library.APACHE2, "http://square.github.io/picasso/"),
26+
Library("Timber", "Jake Wharton", Library.APACHE2, "https://github.com/JakeWharton/timber"),
27+
Library("Mockito", "Mockito", Library.MIT, "https://github.com/mockito/mockito"),
28+
Library("Mockito-Kotlin", "Niek Haarman", Library.MIT, "https://github.com/nhaarman/mockito-kotlin")
29+
).sortedBy { it.name }
30+
31+
rvLibraries.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this, RecyclerView.VERTICAL, false)
32+
rvLibraries.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(this, LinearLayout.VERTICAL))
33+
rvLibraries.adapter = LibrariesAdapter(libraries) { library ->
34+
openUrl(library.link)
35+
}
36+
}
37+
38+
private fun openUrl(url: String) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
39+
}

app/src/main/java/com/marknkamau/justjava/ui/about/LibrariesAdapter.kt renamed to app/src/main/java/com/marknkamau/justjava/ui/libraries/LibrariesAdapter.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.marknkamau.justjava.ui.about
1+
package com.marknkamau.justjava.ui.libraries
22

3-
import androidx.recyclerview.widget.RecyclerView
43
import android.view.LayoutInflater
54
import android.view.View
65
import android.view.ViewGroup
@@ -15,23 +14,14 @@ import java.util.*
1514
* https://github.com/MarkNjunge
1615
*/
1716

18-
class LibrariesAdapter(private val onClick: (Library) -> Unit) : androidx.recyclerview.widget.RecyclerView.Adapter<LibrariesAdapter.ViewHolder>() {
17+
class LibrariesAdapter(private val data: List<Library>, private val onClick: (Library) -> Unit) : androidx.recyclerview.widget.RecyclerView.Adapter<LibrariesAdapter.ViewHolder>() {
1918

20-
private var data: List<Library> = ArrayList()
21-
22-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
23-
return ViewHolder(
24-
LayoutInflater.from(parent.context).inflate(R.layout.item_library, parent, false)
25-
)
26-
}
19+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_library, parent, false))
2720

2821
override fun getItemCount() = data.size
2922

30-
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(data[position], onClick)
31-
32-
fun setItems(data: List<Library>) {
33-
this.data = data
34-
notifyDataSetChanged()
23+
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
24+
holder.bind(data[position], onClick)
3525
}
3626

3727
class ViewHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {

app/src/main/res/layout/activity_about.xml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,42 +196,32 @@
196196
app:layout_constraintTop_toBottomOf="@+id/textView18" />
197197

198198
<TextView
199-
android:id="@+id/tvLicenses"
200-
android:layout_width="0dp"
199+
android:id="@+id/tvPrivacyPolicy"
200+
android:layout_width="wrap_content"
201201
android:layout_height="wrap_content"
202202
android:layout_marginStart="8dp"
203203
android:layout_marginTop="8dp"
204-
android:text="Open Source Libraries"
204+
android:paddingTop="8dp"
205+
android:paddingBottom="8dp"
206+
android:text="Privacy Policy"
205207
android:textColor="@color/colorAccent"
206208
android:textSize="17sp"
207209
app:layout_constraintStart_toStartOf="parent"
208-
app:layout_constraintTop_toBottomOf="@+id/tvPrivacyPolicy" />
209-
210-
<androidx.recyclerview.widget.RecyclerView
211-
android:id="@+id/rvLibraries"
212-
android:layout_width="0dp"
213-
android:layout_height="wrap_content"
214-
android:nestedScrollingEnabled="false"
215-
app:layout_constraintBottom_toBottomOf="parent"
216-
app:layout_constraintEnd_toEndOf="parent"
217-
app:layout_constraintStart_toStartOf="parent"
218-
app:layout_constraintTop_toBottomOf="@+id/tvLicenses"
219-
tools:itemCount="2"
220-
tools:listitem="@layout/item_library" />
210+
app:layout_constraintTop_toBottomOf="@+id/textView19" />
221211

222212
<TextView
223-
android:id="@+id/tvPrivacyPolicy"
213+
android:id="@+id/tvLibraries"
224214
android:layout_width="wrap_content"
225215
android:layout_height="wrap_content"
226216
android:layout_marginStart="8dp"
227217
android:layout_marginTop="8dp"
228-
android:paddingBottom="8dp"
229218
android:paddingTop="8dp"
230-
android:text="Privacy Policy"
219+
android:paddingBottom="8dp"
220+
android:text="Open Source Libraries"
231221
android:textColor="@color/colorAccent"
232222
android:textSize="17sp"
233223
app:layout_constraintStart_toStartOf="parent"
234-
app:layout_constraintTop_toBottomOf="@+id/textView19" />
224+
app:layout_constraintTop_toBottomOf="@+id/tvPrivacyPolicy" />
235225

236226
</androidx.constraintlayout.widget.ConstraintLayout>
237227
</ScrollView>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/rvLibraries"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context=".ui.libraries.LibrariesActivity" />

app/src/main/res/layout/item_library.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/rootLayout"
66
android:layout_width="match_parent"
7-
android:layout_height="wrap_content"
8-
android:background="@color/colorPrimaryDark">
7+
android:layout_height="wrap_content">
98

109
<TextView
1110
android:id="@+id/tvName"
@@ -14,7 +13,7 @@
1413
android:layout_marginStart="8dp"
1514
android:layout_marginTop="8dp"
1615
android:text="Library name"
17-
android:textColor="@android:color/white"
16+
android:textColor="#000000"
1817
app:layout_constraintStart_toStartOf="parent"
1918
app:layout_constraintTop_toTopOf="parent" />
2019

@@ -25,7 +24,7 @@
2524
android:layout_marginStart="8dp"
2625
android:alpha=".54"
2726
android:text="Author"
28-
android:textColor="@android:color/white"
27+
android:textColor="#000000"
2928
app:layout_constraintStart_toStartOf="parent"
3029
app:layout_constraintTop_toBottomOf="@+id/tvName" />
3130

@@ -36,7 +35,7 @@
3635
android:layout_marginBottom="8dp"
3736
android:layout_marginStart="8dp"
3837
android:alpha=".54"
39-
android:textColor="@android:color/white"
38+
android:textColor="#000000"
4039
app:layout_constraintBottom_toBottomOf="parent"
4140
app:layout_constraintStart_toStartOf="parent"
4241
app:layout_constraintTop_toBottomOf="@+id/tvAuthor"

0 commit comments

Comments
 (0)