-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1a7ac3
commit 2a2b23d
Showing
14 changed files
with
249 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
99
app/src/main/java/com/wajahatkarim3/chaty/ContactsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |