Changed for newer Android version
This commit is contained in:
parent
840fc9c0b7
commit
f32b19e4f5
|
@ -2,8 +2,6 @@ apply plugin: 'com.android.application'
|
|||
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
// Create a variable called keystorePropertiesFile, and initialize it to your
|
||||
// keystore.properties file, in the rootProject folder.
|
||||
def keystorePropertiesFile = rootProject.file("keystore.properties")
|
||||
|
@ -24,12 +22,11 @@ android {
|
|||
storePassword keystoreProperties['storePassword']
|
||||
}
|
||||
}
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.1"
|
||||
compileSdk 32
|
||||
defaultConfig {
|
||||
applicationId "de.twomartens.troubleshooting"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
minSdk 29
|
||||
targetSdk 29
|
||||
versionCode 2
|
||||
versionName "0.1"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
@ -49,25 +46,28 @@ android {
|
|||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
def lifecycle_version = "2.1.0-rc01"
|
||||
def work_version = "2.1.0"
|
||||
def lifecycle_version = '2.2.0'
|
||||
def work_version = '2.7.1'
|
||||
apply plugin: "org.jetbrains.kotlin.kapt"
|
||||
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.core:core-ktx:1.0.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha08'
|
||||
implementation 'androidx.appcompat:appcompat:1.5.1'
|
||||
implementation 'androidx.core:core-ktx:1.8.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test:runner:1.5.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
implementation 'com.google.android.material:material:1.8.0-alpha03'
|
||||
implementation 'com.github.uDevel:widgetlab:0.9.7'
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
|
||||
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
|
||||
kapt "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
||||
implementation "androidx.work:work-runtime-ktx:$work_version"
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package de.twomartens.troubleshooting
|
||||
|
||||
import android.view.View
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.UNSET
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.message_sent.view.*
|
||||
import de.twomartens.troubleshooting.databinding.MessageBinding
|
||||
import java.text.DateFormat
|
||||
|
||||
const val VIEW_TYPE_MESSAGE_RECEIVED: Int = 1
|
||||
|
@ -13,13 +17,14 @@ class MessageListAdapter : RecyclerView.Adapter<MessageListAdapter.MessageHolder
|
|||
private var messages: ArrayList<Message> = ArrayList()
|
||||
val dateFormat: DateFormat = DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
|
||||
inner class MessageHolder(private val view: View) : RecyclerView.ViewHolder(view) {
|
||||
inner class MessageHolder(private val binding: MessageBinding)
|
||||
: RecyclerView.ViewHolder(binding.root) {
|
||||
private var message: Message? = null
|
||||
|
||||
fun bind(message: Message) {
|
||||
this.message = message
|
||||
view.text_message_body.text = message.message
|
||||
view.text_message_time.text = dateFormat.format(message.createdAt)
|
||||
binding.textMessageBody.text = message.message
|
||||
binding.textMessageTime.text = dateFormat.format(message.createdAt)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,19 +32,74 @@ class MessageListAdapter : RecyclerView.Adapter<MessageListAdapter.MessageHolder
|
|||
// Create new views (invoked by the layout manager)
|
||||
override fun onCreateViewHolder(parent: ViewGroup,
|
||||
viewType: Int): MessageHolder {
|
||||
|
||||
return when (viewType) {
|
||||
VIEW_TYPE_MESSAGE_RECEIVED -> {
|
||||
val view = parent.inflate(R.layout.message_reveived, false)
|
||||
MessageHolder(view)
|
||||
val binding = MessageBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.textMessageBody.setBackgroundResource(R.drawable.rounded_rectangle_secondary_color)
|
||||
binding.textMessageBody.setTextColor(parent.context.resources.getColor(R.color.color_on_secondary, null))
|
||||
|
||||
binding.textMessageTime.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
this.marginStart = 4
|
||||
this.marginEnd = UNSET
|
||||
}
|
||||
|
||||
binding.textMessageTime.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
this.startToEnd = binding.textMessageBody.id
|
||||
this.endToStart = UNSET
|
||||
}
|
||||
|
||||
binding.textMessageBody.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
this.startToStart = parent.id
|
||||
this.topToTop = parent.id
|
||||
this.endToEnd = UNSET
|
||||
}
|
||||
|
||||
MessageHolder(binding)
|
||||
}
|
||||
VIEW_TYPE_MESSAGE_SENT -> {
|
||||
val view = parent.inflate(R.layout.message_sent, false)
|
||||
MessageHolder(view)
|
||||
val binding = MessageBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.root.setPadding(parent.context.resources.getDimensionPixelSize(R.dimen.message_sent_padding))
|
||||
binding.textMessageBody.setBackgroundResource(R.drawable.rounded_rectangle_primary_color)
|
||||
binding.textMessageBody.setTextColor(parent.context.resources.getColor(R.color.color_on_primary, null))
|
||||
|
||||
binding.textMessageTime.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
this.marginEnd = 4
|
||||
this.marginStart = UNSET
|
||||
}
|
||||
|
||||
binding.textMessageTime.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
this.endToStart = binding.textMessageBody.id
|
||||
this.startToEnd = UNSET
|
||||
}
|
||||
|
||||
binding.textMessageBody.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
this.endToEnd = parent.id
|
||||
this.startToStart = UNSET
|
||||
}
|
||||
|
||||
MessageHolder(binding)
|
||||
}
|
||||
else -> {
|
||||
val view = parent.inflate(R.layout.message_reveived, false)
|
||||
MessageHolder(view)
|
||||
val binding = MessageBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.textMessageBody.setBackgroundResource(R.drawable.rounded_rectangle_secondary_color)
|
||||
binding.textMessageBody.setTextColor(parent.context.resources.getColor(R.color.color_on_secondary, null))
|
||||
|
||||
binding.textMessageTime.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
this.marginStart = 4
|
||||
this.marginEnd = UNSET
|
||||
}
|
||||
|
||||
binding.textMessageTime.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
this.startToEnd = binding.textMessageBody.id
|
||||
this.endToStart = UNSET
|
||||
}
|
||||
|
||||
binding.textMessageBody.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
this.startToStart = parent.id
|
||||
this.endToEnd = UNSET
|
||||
}
|
||||
|
||||
MessageHolder(binding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package de.twomartens.troubleshooting
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import de.twomartens.troubleshooting.databinding.ActivityMainBinding
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
val binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
}
|
||||
|
||||
fun startSession(view: View) {
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
package de.twomartens.troubleshooting
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Spinner
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.udevel.widgetlab.TypingIndicatorView
|
||||
import kotlinx.android.synthetic.main.activity_message_list.view.*
|
||||
import de.twomartens.troubleshooting.databinding.ActivityMessageListBinding
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class MessageListActivity : AppCompatActivity() {
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var binding: ActivityMessageListBinding
|
||||
private val viewAdapter: MessageListAdapter = MessageListAdapter()
|
||||
private lateinit var spinner: Spinner
|
||||
private lateinit var horizontalLayout: ConstraintLayout
|
||||
|
@ -31,12 +31,13 @@ class MessageListActivity : AppCompatActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_message_list)
|
||||
binding = ActivityMessageListBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
initVariables()
|
||||
adapter = initSpinner(model, spinner)
|
||||
bindMessageObserver(viewAdapter, model)
|
||||
initButton(horizontalLayout, ::step, spinner)
|
||||
initButton(::step, spinner)
|
||||
val messages = initFirstChoice(adapter, model, horizontalLayout)
|
||||
receiveMessages(messages, model, typingIndicator, recyclerView, horizontalLayout)
|
||||
}
|
||||
|
@ -46,15 +47,15 @@ class MessageListActivity : AppCompatActivity() {
|
|||
viewManager.stackFromEnd = true
|
||||
viewManager.reverseLayout = false
|
||||
|
||||
model = ViewModelProviders.of(this).get(MessageListViewModel::class.java)
|
||||
model = ViewModelProvider(this)[MessageListViewModel::class.java]
|
||||
|
||||
horizontalLayout = findViewById(R.id.layout_chatbox)
|
||||
typingIndicator = findViewById(R.id.indicator)
|
||||
horizontalLayout = binding.layoutChatbox
|
||||
typingIndicator = binding.indicator
|
||||
typingIndicator.visibility = View.GONE
|
||||
horizontalLayout.visibility = View.GONE
|
||||
spinner = findViewById(R.id.spinner)
|
||||
spinner = binding.spinner
|
||||
|
||||
recyclerView = findViewById<RecyclerView>(R.id.messageList).apply {
|
||||
recyclerView = binding.messageList.apply {
|
||||
// use this setting to improve performance if you know that changes
|
||||
// in content do not change the layout size of the RecyclerView
|
||||
setHasFixedSize(true)
|
||||
|
@ -91,8 +92,8 @@ class MessageListActivity : AppCompatActivity() {
|
|||
model.getMessages().observe(this, messageObserver)
|
||||
}
|
||||
|
||||
private fun initButton(horizontalLayout: ConstraintLayout, step: (SpinnerOption) -> Unit, spinner: Spinner) {
|
||||
horizontalLayout.button_send.setOnClickListener {
|
||||
private fun initButton(step: (SpinnerOption) -> Unit, spinner: Spinner) {
|
||||
binding.buttonSend.setOnClickListener {
|
||||
val option = spinner.selectedItem
|
||||
if (option is SpinnerOption) {
|
||||
step(option)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?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="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_message_body"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="@drawable/rounded_rectangle_secondary_color"
|
||||
android:maxWidth="240dp"
|
||||
android:padding="8dp"
|
||||
android:text="@string/test"
|
||||
android:textColor="@color/color_on_secondary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_message_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:text="@string/_11_40"
|
||||
android:textColor="@color/color_on_background"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/text_message_body"
|
||||
app:layout_constraintStart_toEndOf="@+id/text_message_body" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,7 +1,6 @@
|
|||
<?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="wrap_content"
|
||||
android:padding="8dp">
|
||||
|
@ -28,5 +27,5 @@
|
|||
android:textSize="12sp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/text_message_body"
|
||||
app:layout_constraintEnd_toStartOf="@+id/text_message_body"
|
||||
tools:textColor="@color/color_on_background" />
|
||||
android:textColor="@color/color_on_background" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="message_sent_padding">8dp</dimen>
|
||||
</resources>
|
|
@ -21,6 +21,8 @@
|
|||
<string name="tell_support">Please tell the support the following information.</string>
|
||||
<string name="who_are_you">Who are you?</string>
|
||||
<string name="gardner_second">I\'m Gardner Elliot from Mars. In my spare time I help people like you.</string>
|
||||
<string name="test">test</string>
|
||||
<string name="_11_40">11:40</string>
|
||||
|
||||
<string-array name="binary">
|
||||
<item>yes</item>
|
||||
|
|
|
@ -18,6 +18,17 @@
|
|||
<item name="colorOnBackground">@color/color_on_background</item>
|
||||
<item name="colorOnSurface">@color/color_on_surface</item>
|
||||
<item name="colorOnError">@color/color_on_error</item>
|
||||
<item name="actionBarStyle">@style/ActionBar</item>
|
||||
</style>
|
||||
|
||||
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
|
||||
<item name="background">@color/color_primary</item>
|
||||
<item name="android:titleTextStyle">@style/ActionBar.TitleTextStyle</item>
|
||||
<item name="titleTextStyle">@style/ActionBar.TitleTextStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
|
||||
<item name="android:textColor">@color/color_on_primary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
11
build.gradle
11
build.gradle
|
@ -1,14 +1,13 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.31'
|
||||
ext.kotlin_version = '1.6.21'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.2'
|
||||
classpath 'com.android.tools.build:gradle:7.1.3'
|
||||
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
|
||||
|
@ -16,13 +15,13 @@ buildscript {
|
|||
}
|
||||
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.kapt") version "1.3.41"
|
||||
id("org.jetbrains.kotlin.kapt") version "1.7.21"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Sun Jul 14 13:15:54 CEST 2019
|
||||
#Fri Mar 20 23:47:39 CET 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
|
||||
|
|
Loading…
Reference in New Issue