XML shows a white screen - android

I'm trying to do a login and create account pages for my app in Kotlin. The problem is that I added the create account page on AndroidManifest to be the first page when you open the app and it only shows a white screen. I noticed that in Android Studio there's a Design tab and the page shows exactly like I want it. Can you help me?
This is my XML
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_background">
<TextView
android:id="#+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/create_account"
android:textSize="30sp"
android:textColor="#color/white"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.132" />
<androidx.cardview.widget.CardView
android:id="#+id/myCardView"
android:layout_width="393dp"
android:layout_height="451dp"
android:layout_gravity="center"
android:layout_margin="4dp"
app:cardBackgroundColor="#color/cardsColor"
app:cardCornerRadius="12dp"
app:cardElevation="0dp"
app:cardUseCompatPadding="true"
app:contentPadding="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="361dp"
android:layout_height="426dp"
android:orientation="vertical"
android:padding="16dp"
android:paddingStart="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:weightSum="5.5">
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginBottom="10dp"
android:background="#drawable/edit_text_stroke"
android:gravity="center"
android:hint="#string/email"
android:minLines="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.213"
android:importantForAutofill="no" />
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginBottom="10dp"
android:background="#drawable/edit_text_stroke"
android:gravity="center"
android:hint="#string/password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.3"
android:importantForAutofill="no" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="#+id/register_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/button_round_corners"
android:gravity="center"
android:padding="12dp"
android:text="#string/create_account"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.164"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/myCardView"
app:layout_constraintVertical_bias="0.535" />
<Button
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_round_corners"
android:padding="12dp"
android:text="#string/login"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.81"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/myCardView"
app:layout_constraintVertical_bias="0.535" />
</androidx.constraintlayout.widget.ConstraintLayout>
and my kotlin class
package projeto.a43796.dashboard
import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.text.TextUtils
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import kotlinx.android.synthetic.main.activity_create_account.*
class CreateAccount : AppCompatActivity() {
lateinit var registerButton: Button
lateinit var email: EditText
lateinit var password: EditText
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
setContentView(R.layout.activity_create_account)
registerButton = findViewById(R.id.register_button)
email = findViewById(R.id.email)
password = findViewById(R.id.password)
registerButton.setOnClickListener(){
when{
TextUtils.isEmpty(email.text.toString().trim{it <= ' '}) -> {
Toast.makeText(
this#CreateAccount,
"Please enter your e-mail",
Toast.LENGTH_SHORT
).show()
}
TextUtils.isEmpty(password.text.toString().trim{it <= ' '}) -> {
Toast.makeText(
this#CreateAccount,
"Please enter your password",
Toast.LENGTH_SHORT
).show()
}
else -> {
val email: String = email.text.toString().trim{it <= ' '}
val passord: String = password.text.toString().trim{it <= ' '}
FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, passord)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val firebaseUser: FirebaseUser = task.result!!.user!!
Toast.makeText(
this#CreateAccount,
"Account Created",
Toast.LENGTH_SHORT
).show()
val intent =
Intent(this#CreateAccount, Dashboard::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
intent.putExtra("user_id", firebaseUser.uid)
intent.putExtra("email_user", email)
startActivity(intent)
finish()
}
else{
Toast.makeText(
this#CreateAccount,
task.exception!!.message.toString(),
Toast.LENGTH_SHORT
).show()
}
}
}
}
}
}
}

Related

signInWithEmailAndPassword Firebase, Android Studio, kotlin not working properly

I am attempting to use Firebase to store my emails and passwords. On my Sign-Up page, maybe 5% of the time, the code will run smoothly with no problems. However, when it does run, I have to wait a decent amount of time before it will register the new user within Firebase (about 3-5 minutes). All of my Toast messages go through except for the "Sign up success" and "it.exception.toString()" because it rarely completes the process. I assume the problem lies within the "firebaseAuth.createUserWithEmailAndPassword..." block, but I am not able to fix the problem.
xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:scrollbars="none"
android:background="#color/grey"
tools:context=".LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginStart="22dp"
android:layout_marginEnd="22dp">
<ImageView
android:id="#+id/blueCFSLogo"
android:layout_marginTop="32dp"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.01"
app:srcCompat="#drawable/blue_cfs_logo" />
<TextView
android:id="#+id/signUpTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:fontFamily="#font/lobster_regular"
android:letterSpacing=".05"
android:text="Sign Up"
android:textColor="#color/orange"
android:textSize="34sp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/blueCFSLogo"
app:layout_constraintVertical_bias="0.514" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/emailLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColorHint="#color/grey"
app:boxBackgroundColor="#color/white"
app:boxCornerRadiusBottomEnd="10dp"
app:boxCornerRadiusBottomStart="10dp"
app:boxCornerRadiusTopEnd="10dp"
app:boxCornerRadiusTopStart="10dp"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" >
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_semibold"
android:inputType="textEmailAddress"
android:singleLine="true"
android:hint="#string/email"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/edtPasswordPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColorHint="#color/grey"
app:boxBackgroundColor="#color/white"
app:boxCornerRadiusBottomEnd="10dp"
app:boxCornerRadiusBottomStart="10dp"
app:boxCornerRadiusTopEnd="10dp"
app:boxCornerRadiusTopStart="10dp"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/passwordEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_semibold"
android:hint="#string/password"
android:inputType="textPassword"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/edtConfirmPasswordTil"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColorHint="#color/grey"
app:boxBackgroundColor="#color/white"
app:boxCornerRadiusBottomEnd="10dp"
app:boxCornerRadiusBottomStart="10dp"
app:boxCornerRadiusTopEnd="10dp"
app:boxCornerRadiusTopStart="10dp"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/confirmPasswordEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_semibold"
android:hint="Confirm Password"
android:inputType="textPassword"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/signUpBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
app:cornerRadius="20dp"
app:backgroundTint="#color/blue"
android:fontFamily="#font/nunito_bold"
android:textSize="16sp"
android:text="Sign Up"
android:textColor="#color/grey" >
</androidx.appcompat.widget.AppCompatButton>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center">
<TextView
android:id="#+id/alreadyHaveAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_semibold"
android:letterSpacing=".05"
android:text="Already have an account?"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="13sp" />
<TextView
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="#font/nunito_bolditalic"
android:letterSpacing=".05"
android:text="Login"
android:textColor="#color/orange"
android:textSize="13sp"
android:textAlignment="center"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
.kt file:
package com.countdownfantasysports.app
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import com.countdownfantasysports.app.databinding.ActivitySignUpBinding
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import kotlinx.android.synthetic.main.activity_sign_up.*
class SignUpActivity : AppCompatActivity() {
private lateinit var binding: ActivitySignUpBinding
private lateinit var firebaseAuth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySignUpBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.login.setOnClickListener {
val loginIntent = Intent(this, LoginActivity::class.java)
startActivity(loginIntent)
}
firebaseAuth = FirebaseAuth.getInstance()
binding.signUpBtn.setOnClickListener{
val email = binding.emailEditText.text.toString()
val password = binding.passwordEt.text.toString()
val confirmPassword = binding.confirmPasswordEt.text.toString()
if (email.isNotEmpty() && password.isNotEmpty() && confirmPassword.isNotEmpty()) {
if (password == confirmPassword){
firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener{
if (it.isSuccessful) {
// If successful, start MainActivity
val mainIntent = Intent(this, MainActivity::class.java)
startActivity(mainIntent)
// If successful, display message for user
Toast.makeText(
this,
"Sign up success",
Toast.LENGTH_SHORT).show()
// If successful, log success
Log.d("Isaac", "createUserWithEmail:success")
} else {
// If failure, display message for user
Toast.makeText(
this,
it.exception.toString(),
Toast.LENGTH_SHORT).show()
// If failure, log failure
Log.w("Isaac", "createUserWithEmail:failure")
}
}
} else {
// If passwords do not match, display message to user
Toast.makeText(
this,
"Password does not match",
Toast.LENGTH_SHORT).show()
}
} else {
// If empty fields, display message for user
Toast.makeText(
this,
"Empty fields are not allowed",
Toast.LENGTH_SHORT).show()
}
}
// Start LoginActivity
binding.login.setOnClickListener {
val loginIntent = Intent(this, LoginActivity::class.java)
startActivity(loginIntent)
}
}
}```
I have tried mulitple builds, but this seems to be the only on that completes 5% of the time. Help would be appreciated. Thanks!

Progressbar databinding can't change the visibility

I have a progressbar in my layout in Android and i want to change its visibility inside the viewmodel. But application only gets the first state of progressbar. Whenever i try to change it nothing happen. Here is my layout file ;
<?xml version="1.0" encoding="utf-8"?>
<layout
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"
>
<data>
<import type="android.view.View"></import>
<variable
name="viewmodel"
type="com.tolgahantutar.bexworkfloww.ui.auth.AuthViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="24dp"
android:paddingTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="154dp"
android:layout_height="154dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="48dp"
android:src="#drawable/bexfalogo"
android:contentDescription="#string/bexlogo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="132dp"
android:textAllCaps="true"
android:textSize="16dp" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="#string/hint_username">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#={viewmodel.userName}"
>
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="#string/hint_password"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:text="#={viewmodel.password}"
/>
</com.google.android.material.textfield.TextInputLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="#+id/button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="#string/button_login"
android:onClick="#{viewmodel::onClickUserLogin}"
/>
<com.google.android.material.button.MaterialButton
android:id="#+id/button_cancel"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_toStartOf="#id/button_login"
android:layout_toLeftOf="#id/button_login"
android:text="#string/button_cancel" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="#{viewmodel.isLoading ? View.VISIBLE : View.GONE}" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
and my viewmodel looks like this
package com.tolgahantutar.bexworkfloww.ui.auth
import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import androidx.databinding.ObservableBoolean
import androidx.databinding.library.baseAdapters.BR
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.tolgahantutar.bexworkfloww.data.network.repositories.AuthorizeSessionRepository
import com.tolgahantutar.bexworkfloww.ui.home.HomeActivity
import com.tolgahantutar.bexworkfloww.util.ApiException
import com.tolgahantutar.bexworkfloww.util.NoInternetException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.internal.notify
class AuthViewModel (
private val repository: AuthorizeSessionRepository
):ViewModel() {
var userName: String?=null
var password: String?=null
val isLoading = MutableLiveData<Boolean>(true)
fun onClickUserLogin(view: View){
isLoading.value = false
val sessionID = 0
val authorityID = 0
val loginType = "System"
viewModelScope.launch {
if(!(userName==null||password==null)){
try{
val authResponse = userLogin(sessionID,authorityID,userName!!,password!!,loginType)
if(authResponse.Result){
isLoading.value=false
Toast.makeText(view.context, "Login Successfull", Toast.LENGTH_LONG).show()
val intent = Intent(view.context,HomeActivity::class.java)
view.context.startActivity(intent)
}else{
//isLoading.value=false
Toast.makeText(view.context, "Login Failed!!", Toast.LENGTH_LONG).show()
}
}catch (e: ApiException){
e.printStackTrace()
}catch (e: NoInternetException){
e.printStackTrace()
}}
else{
Toast.makeText(view.context, "Kullanıcı adı ve şifre boş bırakılamaz!!", Toast.LENGTH_SHORT).show()
}
}
}
suspend fun userLogin(
SessionID : Int,
AuthorityID: Int,
UserName: String,
Password : String,
LoginType: String
)= withContext(Dispatchers.IO){repository.userLogin(SessionID, AuthorityID, UserName, Password, LoginType)}
}
As i mentioned it is just get the first state but when i click the button nothing changes..

CalendarView doesn't show when visabilty is initally set to GONE

UPDATE: I added my whole code after I fixed it as I stated in my answer
hello guys I am having a weird bug. I have a calendar view that's initially set to GONE and I try to change it to VISIBLE and GONE when the user clicks on an icon.
it doesn't show.
but, when I set it initially to VISIBLE it works as expected.
I tried debugging and it enters both branches of the when statement, but it doesn't change the visibility
any idea what I am doing wrong here?
calendar_icon.setOnClickListener {
when (calendarView.visibility) {
View.GONE -> {
calendarView.visibility = View.VISIBLE
}
else -> { calendarView.visibility = View.GONE
}
}
}
XML code
<?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:id="#+id/per_day_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/brighter_white">
<androidx.cardview.widget.CardView
android:id="#+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:cardBackgroundColor="#color/brighter_white"
app:cardCornerRadius="12dp"
app:cardElevation="12dp"
app:contentPadding="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/per_day_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="4"
android:background="#android:color/transparent"
android:hint="#string/search"
android:textColorHint="#color/silver"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageView11"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.6" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="#drawable/rounded_corner_azure_bg"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_search_line" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/rounded_corner_lavendar_bg"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/calendarView"
app:layout_goneMarginTop="16dp">
<TextView
android:id="#+id/per_day_current_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="4"
android:fontFamily="#font/montserrat_medium"
android:text="TextView"
android:textColor="#color/charcoal"
android:textSize="15sp" />
<ImageView
android:id="#+id/calendar_icon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_calendar" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<TextView
android:id="#+id/report_item_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="#color/periwinkle"
android:fontFamily="#font/montserrat_medium"
android:gravity="center"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:paddingBottom="16dp"
android:text="#string/user_name"
android:textColor="#color/charcoal"
android:textStyle="bold" />
<TextView
android:id="#+id/report_item_attend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="#color/platinum"
android:fontFamily="#font/montserrat_medium"
android:gravity="center"
android:maxLines="2"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:paddingBottom="16dp"
android:text="#string/attend_time"
android:textColor="#color/charcoal"
android:textStyle="bold" />
<TextView
android:id="#+id/report_item_leave"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="#color/misty_rose"
android:fontFamily="#font/montserrat_medium"
android:gravity="center"
android:maxLines="2"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:paddingBottom="16dp"
android:text="#string/leave_time"
android:textColor="#color/charcoal"
android:textStyle="bold" />
<TextView
android:id="#+id/report_item_lost_points"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="#color/magnolia"
android:ellipsize="end"
android:fontFamily="#font/montserrat_medium"
android:gravity="center"
android:maxLines="2"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:paddingBottom="16dp"
android:text="#string/lostPoints"
android:textColor="#color/charcoal"
android:textStyle="bold" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/report_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout5" />
<CalendarView
android:id="#+id/calendarView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView2"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment code
package iti.intake40.mawgood_admin.reports.per_day
import android.app.DatePickerDialog
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import iti.intake40.mawgood_admin.R
import iti.intake40.mawgood_admin.core.DateUtilities
import iti.intake40.mawgood_admin.models.Report
import kotlinx.android.synthetic.main.fragment_reports.*
class ReportsFragment : Fragment(), ReportPerDayContract.IView {
private val TAG = ReportsFragment::class.java.simpleName
private lateinit var presenter: ReportPerDayPresenter
private lateinit var adapter: ReportPerDayAdapter
private val reportList = ArrayList<Report>()
private var rootView: View? = null
private var mDatePickerDialog: DatePickerDialog? = null
private var per_day_current_date: TextView? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.fragment_reports, container, false)
per_day_current_date = root.findViewById(R.id.per_day_current_date)
presenter = ReportPerDayPresenter(context!!, this)
return root
}
#RequiresApi(Build.VERSION_CODES.O)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
rootView = view.findViewById(R.id.per_day_root)
presenter.getOrganizationCreationDate()
calendarView.maxDate = System.currentTimeMillis()
calendarView.visibility = View.GONE
calendar_icon.setOnClickListener {
when (calendarView.visibility) {
View.GONE -> {
calendarView.visibility = View.VISIBLE
}
View.VISIBLE -> {
calendarView.visibility = View.GONE
}
}
}
calendarView.setOnDateChangeListener { view, year, month, dayOfMonth ->
calendarView.visibility = View.GONE
val date = "$dayOfMonth-${month + 1}-$year"
Log.d(TAG, date)
val dayInUnix = DateUtilities.convertDateToTimestamp(date)
presenter.listenForChanges(dayInUnix.toString())
}
}
#RequiresApi(Build.VERSION_CODES.O)
override fun onStart() {
super.onStart()
activity!!.title = "Reports"
search()
per_day_current_date?.text = DateUtilities.getTodayInDate()
val today = DateUtilities.getTodayInUnix().toString()
presenter.listenForChanges(today)
}
private fun search() {
per_day_search.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
adapter.filter.filter(s)
}
})
}
override fun onStop() {
super.onStop()
presenter.detachListeners()
}
override fun displayNoData() {
// per_day_empty_iv.visibility = View.VISIBLE
// per_day_empty_tv.visibility = View.VISIBLE
report_rv.visibility = View.INVISIBLE
}
override fun hideNoData() {
// per_day_empty_iv.visibility = View.INVISIBLE
// per_day_empty_tv.visibility = View.INVISIBLE
report_rv.visibility = View.VISIBLE
}
override fun updateRecyclerView(reports: List<Report>) {
reportList.clear()
reportList.addAll(reports)
adapter = ReportPerDayAdapter(reportList)
report_rv.setHasFixedSize(true)
report_rv.layoutManager = LinearLayoutManager(context)
report_rv.adapter = adapter
adapter.notifyDataSetChanged()
}
override fun updateDayView(date: String) {
per_day_current_date?.text = date
}
override fun showConnectionError() {
Snackbar.make(rootView!!, R.string.no_connection_show_cache, Snackbar.LENGTH_LONG)
.show()
}
override fun setCalendarStartDate(creationDateUnix: Long) {
calendarView.minDate = creationDateUnix
Log.d(TAG, creationDateUnix.toString())
}
}
it seems like a bug. I was able to fix this by removing the visibility attribute from XML.
and set the visibility programmatically in onViewCreated like this: calendarView.visibility = View.GONE

Android (Kotlin): text now showing after I set it

Playing around with Android and following this simple introduction but I can't get the line resultsTextView.text = rand.toString() to trigger. Not sure what I'm missing.
The main Kotlin code looks like this (MainActivity.kt):
package io.github.ovid.randomizer
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.SeekBar
import android.widget.TextView
import kotlin.random.Random
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rollButton = findViewById<Button>(R.id.rollButton)
val resultsTextView = findViewById<TextView>(R.id.resultsTextView)
val seekBar = findViewById<SeekBar>(R.id.seekBar)
rollButton.setOnContextClickListener {
val rand = Random.nextInt(seekBar.progress) + 1
resultsTextView.text = rand.toString()
true
}
}
}
And my activity_main.xml:
<?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=".MainActivity" >
<Button
android:id="#+id/rollButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="96dp"
android:layout_marginLeft="96dp"
android:layout_marginEnd="96dp"
android:layout_marginRight="96dp"
android:layout_marginBottom="24dp"
android:text="Roll"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<SeekBar
android:id="#+id/seekBar"
style="#style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="24dp"
android:max="10"
android:progress="3"
app:layout_constraintBottom_toTopOf="#+id/rollButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginBottom="16dp"
android:text="How Many"
app:layout_constraintBottom_toTopOf="#+id/seekBar"
app:layout_constraintStart_toStartOf="parent" />
<View
android:id="#+id/divider"
android:layout_width="409dp"
android:layout_height="1dp"
android:layout_marginBottom="16dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toTopOf="#+id/textView"
tools:layout_editor_absoluteX="1dp" />
<TextView
android:id="#+id/resultsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="0dp"
android:layout_marginLeft="0dp"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textSize="144sp"
app:layout_constraintBottom_toTopOf="#+id/divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Everything on the layout in the emulator looks correct, but pressing the "Roll" button shows I clicked the button, but no text shows up in the resultsTextView.
D'oh! It was setOnClickListener, not setOnContextClickListener. Made the change and removed the true at the end and it worked fine. Sorry for the noise.
Just replace the event method from setOnContextClickListener to setOnClickListener, an it will work fine. Just like this:
rollButton.setOnClickListener {
val rand = Random.nextInt(seekBar.progress) + 1
resultsTextView.text = rand.toString()
}

RecyclerView cells deform when keyboard opened

I am implementing a chat inside my app, and the recycler view behave in wired way when the keyboard opened, the cards expands by itself
I tried to disable the recycling ,change the way I build the layout but nothing works,I need to understand why this happened and how to fix it.
The XML layout for the view
<LinearLayout 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"
android:background="#android:color/white"
android:orientation="vertical"
tools:context="io.thed.cuju.ChatDetailsFragment">
<LinearLayout
android:id="#+id/linearLayout22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/chat_image"
android:layout_width="32dp"
android:layout_height="32dp"
tools:src="#drawable/avatar" />
<TextView
android:id="#+id/name_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
tools:text="Bradley Anderson" />
</LinearLayout>
<include
android:id="#+id/say_hi"
layout="#layout/say_hi_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<android.support.constraint.ConstraintLayout
android:id="#+id/chat_list_and_input_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/chat_details_recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="#+id/linearLayout5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/space2"
app:reverseLayout="true"
tools:listitem="#layout/recived_chat_box_item" />
<TextView
android:id="#+id/space2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/Gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ProgressBar
android:id="#+id/progressBar12"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/linearLayout5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<EditText
android:id="#+id/to_be_sent_chat"
style="#style/cujuEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:ems="10"
android:hint="Type a message"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/chat_extra"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/send_chat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/to_be_sent_chat"
app:layout_constraintTop_toTopOf="#+id/to_be_sent_chat" />
<ImageView
android:id="#+id/chat_extra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="#drawable/add_media_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
The Adapter
package io.thed.cuju.adapters
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.google.gson.Gson
import com.pddstudio.preferences.encrypted.EncryptedPreferences
import com.squareup.picasso.Picasso
import io.thed.cuju.R
import io.thed.cuju.beans.MessageBean
import io.thed.cuju.beans.UserBean
import io.thed.cuju.constants.*
import io.thed.cuju.customsViews.ZoomImageFragment
import java.text.SimpleDateFormat
import java.util.*
class ChatDetailsAdapter// Provide a suitable constructor (depends on the kind of dataset)
(private val chatList: List<MessageBean>, internal var context: Context) : RecyclerView.Adapter<ChatDetailsAdapter.ViewHolder>() {
internal var token: String? = null
internal var user: UserBean? = null
val SENT_CHAT = 1
val RECIVED_CHAT = 2
override fun getItemViewType(position: Int): Int {
val current: MessageBean = chatList[position]
val encryptedPreferences = EncryptedPreferences.Builder(context).withEncryptionPassword(PASSWORD).build()
var token: String = encryptedPreferences.getString(USER_PREF_TOKEN_KEY, NO_TOKEN)
tokenForImage = "?x-access-token=" + token
user = Gson().fromJson(encryptedPreferences!!.getString(USER_PREF_KEY, ""), UserBean::class.java)
if (user!!._id != current.from) {
return RECIVED_CHAT
} else {
return SENT_CHAT
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChatDetailsAdapter.ViewHolder {
val v: View?
if (viewType == SENT_CHAT) {
v = LayoutInflater.from(parent.context).inflate(R.layout.send_chat_box_item, parent, false)
} else {
v = LayoutInflater.from(parent.context).inflate(R.layout.recived_chat_box_item, parent, false)
}
return ViewHolder(v)
}
// set the view's size, margins, paddings and layout parameters
lateinit var tokenForImage: String
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val current = chatList[position]
holder.setIsRecyclable(false)
if (current.data.text != null) {
holder.chat_text.text = current.data.text
}
if (current.data.type == "picture") {
val url = BASE_URL + current.data.media!!.thumbnail + tokenForImage
Picasso.with(context).load(Uri.parse(url)).fit().placeholder(context.resources.getDrawable(R.drawable.placeholder)).into(holder.chat_image)
holder.chat_image.visibility = View.VISIBLE
holder.chat_play.visibility = View.GONE
holder.chat_image.setOnClickListener {
ZoomImageFragment.newInstance(url).show((context as Activity).fragmentManager, "")
}
} else if (current.data.type == "video") {
val url = BASE_URL + current.data.media!!.thumbnail + tokenForImage
Picasso.with(context).load(Uri.parse(url)).fit().placeholder(context.resources.getDrawable(R.drawable.placeholder)).into(holder.chat_image)
holder.chat_image.visibility = View.VISIBLE
holder.chat_play.visibility = View.VISIBLE
holder.chat_image.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(BASE_URL + current.data.media.link + tokenForImage))
ContextCompat.startActivity(context, intent, null)
}
} else {
holder.chat_image.visibility = View.GONE
holder.chat_play.visibility = View.GONE
}
val formatter = SimpleDateFormat(DATE_FORMAT)
formatter.timeZone = TimeZone.getTimeZone("GMT")
try {
val dateToBeParsed = DateUtils.getRelativeTimeSpanString(formatter.parse(current.created_at).time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS)
holder.chat_time.text = dateToBeParsed
} catch (e: Exception) {
println(e.message)
holder.chat_time.text = current.created_at
}
if (holder.itemViewType == SENT_CHAT) {
if (current.failed) {
holder.chat_status!!.setImageResource(R.drawable.message_seen)
} else if (current.seen) {
holder.chat_status!!.setImageResource(R.drawable.message_seen)
} else if (current.received) {
holder.chat_status!!.setImageResource(R.drawable.message_recived_not_seen)
} else if (current.sent) {
holder.chat_status!!.setImageResource(R.drawable.message_sent_to_server)
}
}
}
override fun getItemCount(): Int {
return chatList.size
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val chat_image: ImageView = v.findViewById(R.id.chat_image)
val chat_play: ImageView = v.findViewById(R.id.chat_play)
val chat_text: TextView = v.findViewById(R.id.chat_text)
val chat_time: TextView = v.findViewById(R.id.chat_time)
val chat_status: ImageView? = v.findViewById(R.id.chat_status)
}
}
reviced_chat_box_item.xml (sorry for the typo)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="12dp"
app:cardBackgroundColor="#color/recivedChat"
app:cardCornerRadius="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="#+id/chat_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chat_text"
tools:srcCompat="#drawable/content_image" />
<ImageView
android:id="#+id/chat_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#+id/chat_image"
app:layout_constraintEnd_toEndOf="#+id/chat_image"
app:layout_constraintStart_toStartOf="#+id/chat_image"
app:layout_constraintTop_toTopOf="#+id/chat_image"
app:srcCompat="#drawable/play" />
<TextView
android:id="#+id/chat_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:layout_marginEnd="2dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="2dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Hello buddy, gonna go for a training today?"
android:textColor="#color/chat_color"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/chat_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:text="12 mins ago"
android:textColor="#color/time_ago"
android:textSize="13sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView2" />
</android.support.constraint.ConstraintLayout>
send_chat_box_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginStart="8dp"
app:cardCornerRadius="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="#+id/chat_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chat_text"
tools:srcCompat="#drawable/content_image" />
<ImageView
android:id="#+id/chat_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#+id/chat_image"
app:layout_constraintEnd_toEndOf="#+id/chat_image"
app:layout_constraintStart_toStartOf="#+id/chat_image"
app:layout_constraintTop_toTopOf="#+id/chat_image"
app:srcCompat="#drawable/play" />
<TextView
android:id="#+id/chat_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="16dp"
android:layout_marginStart="2dp"
android:layout_marginTop="8dp"
android:text="Hello buddy, gonna go for a training today?"
android:textColor="#color/chat_color"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/chat_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="4dp"
android:text="12 mins ago"
android:textColor="#color/time_ago"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView2" />
<ImageView
android:id="#+id/chat_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/chat_time"
app:layout_constraintEnd_toStartOf="#+id/chat_time"
app:layout_constraintTop_toTopOf="#+id/chat_time"
app:srcCompat="#drawable/message_seen" />
</android.support.constraint.ConstraintLayout>

Categories

Resources