Skip to content

Commit

Permalink
Added Contacts Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
wajahatkarim3 committed Apr 25, 2019
1 parent f1a7ac3 commit 2a2b23d
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 53 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
Expand Down
30 changes: 17 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wajahatkarim3.chaty">
package="com.wajahatkarim3.chaty">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Chaty">
<activity android:name=".LoginActivity">
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Chaty">
<activity
android:name=".LoginActivity"
android:theme="@style/Theme.Chaty.NoToolbar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
<activity
android:name=".ContactsActivity"
android:label="Contacts"></activity>
</application>

</manifest>
99 changes: 99 additions & 0 deletions app/src/main/java/com/wajahatkarim3/chaty/ContactsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.wajahatkarim3.chaty

import android.content.Context
import android.graphics.Color
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.amulyakhare.textdrawable.TextDrawable
import com.amulyakhare.textdrawable.util.ColorGenerator
import com.bumptech.glide.Glide

class ContactsActivity : AppCompatActivity() {

lateinit var recyclerContacts: RecyclerView
lateinit var layoutManager: LinearLayoutManager
lateinit var recyclerAdapter: ContactsRecyclerAdapter
var contactsList = arrayListOf<UserModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_contacts)

setupViews()
loadDummyData()
}

fun setupViews()
{
// RecyclerView
recyclerContacts = findViewById(R.id.recyclerContacts)
layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
recyclerContacts.layoutManager = layoutManager
recyclerAdapter = ContactsRecyclerAdapter(this)
recyclerContacts.adapter = recyclerAdapter
}

fun loadDummyData()
{
contactsList.add(UserModel("John Doe", "Online", "https://cdn.pixabay.com/photo/2013/07/13/10/07/man-156584_960_720.png"))
contactsList.add(UserModel("Alexa Johnson", "Offline", "https://previews.123rf.com/images/juliasart/juliasart1704/juliasart170400022/75406270-vector-girl-icon-woman-avatar-face-icon-cartoon-style-.jpg"))
contactsList.add(UserModel("Robert Smith", "Online", "https://i.pinimg.com/originals/a7/0e/16/a70e1675c7bc001f1578aa76bb0a7819.png"))
contactsList.add(UserModel("Steve Boam", "Online", "https://cdn1.iconfinder.com/data/icons/people-faces-2/512/11-512.png"))
recyclerAdapter.notifyDataSetChanged()
}

inner class ContactsRecyclerAdapter(val context: Context) : RecyclerView.Adapter<ContactsRecyclerAdapter.ContactViewHolder>()
{
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ContactViewHolder {
return ContactViewHolder(LayoutInflater.from(this@ContactsActivity).inflate(R.layout.contact_item_layout, parent, false))
}

override fun getItemCount(): Int = contactsList.size

override fun onBindViewHolder(holder: ContactViewHolder, position: Int) {
holder.bindItem(contactsList[position])
}

inner class ContactViewHolder : RecyclerView.ViewHolder
{
var txtUsername: AppCompatTextView
var txtStatus: AppCompatTextView
var imgContactPhoto: AppCompatImageView

constructor(itemView: View) : super(itemView)
{
txtUsername = itemView.findViewById(R.id.txtUsername)
txtStatus = itemView.findViewById(R.id.txtStatus)
imgContactPhoto = itemView.findViewById(R.id.imgContactPhoto)
}

fun bindItem(userModel: UserModel)
{
txtUsername.text = userModel.name
txtStatus.text = userModel.status
setAvatarImage(userModel.name[0].toString())
if (userModel.status.equals("Online"))
txtStatus.setTextColor(context.resources.getColor(R.color.colorOnline))
else
txtStatus.setTextColor(context.resources.getColor(R.color.colorOffline))
}

fun setAvatarImage(letter: String)
{
var generator = ColorGenerator.MATERIAL
var color = generator.randomColor

var drawable = TextDrawable.builder().buildRect(letter, color)
imgContactPhoto.setImageDrawable(drawable)
}
}
}
}
35 changes: 34 additions & 1 deletion app/src/main/java/com/wajahatkarim3/chaty/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
package com.wajahatkarim3.chaty

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout

class LoginActivity : AppCompatActivity() {
class LoginActivity : AppCompatActivity()
{
lateinit var inputUsername: TextInputLayout
lateinit var txtUsername: TextInputEditText
lateinit var btnLogin: MaterialButton

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)

setupViews()
}

fun setupViews()
{
inputUsername = findViewById(R.id.inputUsername)
txtUsername = findViewById(R.id.txtUsername)
btnLogin = findViewById(R.id.btnLogin)

btnLogin.setOnClickListener {
// Clear previous errors if any
inputUsername.error = null

// Username Validation
if (txtUsername.text.toString().isEmpty())
{
inputUsername.error = "Username cannot be empty!"
return@setOnClickListener
}

// Go to Contacts screen
var intent = Intent(this, ContactsActivity::class.java)
startActivity(intent)
}
}
}
12 changes: 0 additions & 12 deletions app/src/main/java/com/wajahatkarim3/chaty/MainActivity.kt

This file was deleted.

7 changes: 7 additions & 0 deletions app/src/main/java/com/wajahatkarim3/chaty/UserModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wajahatkarim3.chaty

data class UserModel (
val name: String = "",
val status: String = "",
val photoUrl: String = ""
)
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_contacts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ContactsActivity"
android:background="@color/colorWindowBackground">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerContacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
tools:listitem="@layout/contact_item_layout"/>

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
android:layout_marginRight="20dp"
android:hint="Username"
android:focusedByDefault="false"
android:defaultFocusHighlightEnabled="false"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/imgLogo"
Expand All @@ -38,6 +37,7 @@
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
Expand Down
19 changes: 0 additions & 19 deletions app/src/main/res/layout/activity_main.xml

This file was deleted.

54 changes: 54 additions & 0 deletions app/src/main/res/layout/contact_item_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="?attr/selectableItemBackground"
android:clickable="true">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imgContactPhoto"
android:layout_width="60dp"
android:layout_height="60dp"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/avatars"
/>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txtUsername"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="@tools:sample/full_names"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/imgContactPhoto"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/txtStatus"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginLeft="20dp"/>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txtStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="Online"
app:layout_constraintTop_toBottomOf="@id/txtUsername"
app:layout_constraintLeft_toRightOf="@id/imgContactPhoto"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@id/imgContactPhoto"
android:textSize="17sp"
android:layout_marginLeft="20dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>
4 changes: 4 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<color name="textColorPrimary">#222322</color>
<color name="textColorSecondary">#FFFFFF</color>
<color name="colorControlActivated">#c84241</color>
<color name="colorControlDefault">#444444</color>
<color name="colorWindowBackground">#eeeeee</color>
<color name="colorOnline">#149214</color>
<color name="colorOffline">#7E7D7D</color>
</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">

<!-- Base application theme. -->
<style name="Theme.Chaty" parent="Theme.MaterialComponents.Light.NoActionBar">
<style name="Theme.Chaty" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand All @@ -11,6 +11,11 @@
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="android:statusBarColor">@color/colorPrimary</item>
</style>

<style name="Theme.Chaty.NoToolbar" parent="Theme.Chaty">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="Widget.Chaty.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ buildscript {
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -19,7 +18,9 @@ allprojects {
repositories {
google()
jcenter()

maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Apr 21 18:30:37 PKT 2019
#Thu Apr 25 18:14:34 PKT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit 2a2b23d

Please sign in to comment.