forked from upstream-mirrors/quik
use kotlin android extensions for viewbinding in activity and fragment
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'realm-android' // Realm needs to be before Kotlin or the build will fail
|
apply plugin: 'realm-android' // Realm needs to be before Kotlin or the build will fail
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 26
|
compileSdkVersion 26
|
||||||
|
|||||||
@@ -35,6 +35,6 @@ class MainActivity : QkActivity() {
|
|||||||
})
|
})
|
||||||
.check()
|
.check()
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.content_frame, ConversationListFragment()).commit()
|
supportFragmentManager.beginTransaction().replace(R.id.contentFrame, ConversationListFragment()).commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,17 @@ package com.moez.QKSMS.ui.conversations
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.RecyclerView
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.ProgressBar
|
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.data.sync.SyncManager
|
import com.moez.QKSMS.data.sync.SyncManager
|
||||||
import com.moez.QKSMS.ui.base.QkFragment
|
import com.moez.QKSMS.ui.base.QkFragment
|
||||||
|
import kotlinx.android.synthetic.main.conversation_list_fragment.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ConversationListFragment : QkFragment() {
|
class ConversationListFragment : QkFragment() {
|
||||||
|
|
||||||
@Inject lateinit var viewModel: ConversationListViewModel
|
@Inject lateinit var viewModel: ConversationListViewModel
|
||||||
|
|
||||||
private var progress: ProgressBar? = null
|
|
||||||
private var conversationList: RecyclerView? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
getAppComponent()?.inject(this)
|
getAppComponent()?.inject(this)
|
||||||
@@ -26,11 +22,8 @@ class ConversationListFragment : QkFragment() {
|
|||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
val view = inflater.inflate(R.layout.conversation_list_fragment, container, false)
|
val view = inflater.inflate(R.layout.conversation_list_fragment, container, false)
|
||||||
|
|
||||||
progress = view.findViewById(R.id.conversation_progress)
|
conversationList.layoutManager = LinearLayoutManager(context)
|
||||||
|
conversationList.adapter = ConversationAdapter(context, viewModel.conversations)
|
||||||
conversationList = view.findViewById(R.id.conversation_list)
|
|
||||||
conversationList?.layoutManager = LinearLayoutManager(context)
|
|
||||||
conversationList?.adapter = ConversationAdapter(context, viewModel.conversations)
|
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
@@ -43,9 +36,9 @@ class ConversationListFragment : QkFragment() {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.load_conversations -> { // TODO: This is for testing, remove this
|
R.id.load_conversations -> { // TODO: This is for testing, remove this
|
||||||
progress?.visibility = View.VISIBLE
|
progress.visibility = View.VISIBLE
|
||||||
SyncManager.copyToRealm(context) {
|
SyncManager.copyToRealm(context) {
|
||||||
progress?.visibility = View.GONE
|
progress.visibility = View.GONE
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.moez.QKSMS.R
|
|||||||
|
|
||||||
class ConversationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
class ConversationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
val title: TextView = view.findViewById(R.id.conversation_title)
|
val title: TextView = view.findViewById(R.id.title)
|
||||||
val snippet: TextView = view.findViewById(R.id.conversation_snippet)
|
val snippet: TextView = view.findViewById(R.id.snippet)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class MessageListActivity : QkActivity() {
|
|||||||
val fragment = MessageListFragment()
|
val fragment = MessageListFragment()
|
||||||
messagesComponent.inject(fragment)
|
messagesComponent.inject(fragment)
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit()
|
supportFragmentManager.beginTransaction().replace(R.id.contentFrame, fragment).commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,16 @@ package com.moez.QKSMS.ui.messages
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.RecyclerView
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.ui.base.QkFragment
|
import com.moez.QKSMS.ui.base.QkFragment
|
||||||
|
import kotlinx.android.synthetic.main.message_list_fragment.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MessageListFragment : QkFragment() {
|
class MessageListFragment : QkFragment() {
|
||||||
|
|
||||||
@Inject lateinit var viewModel: MessageListViewModel
|
@Inject lateinit var viewModel: MessageListViewModel
|
||||||
|
|
||||||
private var messageList: RecyclerView? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
@@ -22,12 +20,10 @@ class MessageListFragment : QkFragment() {
|
|||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
val view = inflater.inflate(R.layout.message_list_fragment, container, false)
|
val view = inflater.inflate(R.layout.message_list_fragment, container, false)
|
||||||
|
|
||||||
messageList = view.findViewById(R.id.message_list)
|
|
||||||
|
|
||||||
val layoutManager = LinearLayoutManager(context)
|
val layoutManager = LinearLayoutManager(context)
|
||||||
layoutManager.stackFromEnd = true
|
layoutManager.stackFromEnd = true
|
||||||
messageList?.layoutManager = layoutManager
|
messageList.layoutManager = layoutManager
|
||||||
messageList?.adapter = MessageAdapter(context, viewModel.messages)
|
messageList.adapter = MessageAdapter(context, viewModel.messages)
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import com.moez.QKSMS.R
|
|||||||
|
|
||||||
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
val body: TextView = view.findViewById(R.id.message_body)
|
val body: TextView = view.findViewById(R.id.body)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
tools:context="com.moez.QKSMS.MainActivity">
|
tools:context="com.moez.QKSMS.MainActivity">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/content_frame"
|
android:id="@+id/contentFrame"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/conversation_progress"
|
android:id="@+id/progress"
|
||||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/conversation_list"
|
android:id="@+id/conversationList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
|||||||
@@ -10,19 +10,19 @@
|
|||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/conversation_title"
|
android:id="@+id/title"
|
||||||
style="@style/TextPrimary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Moez Bhatti" />
|
tools:text="Moez Bhatti" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/conversation_snippet"
|
android:id="@+id/snippet"
|
||||||
style="@style/TextSecondary"
|
style="@style/TextSecondary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/conversation_title"
|
app:layout_constraintTop_toBottomOf="@+id/title"
|
||||||
tools:text="Hey! How's it going?" />
|
tools:text="Hey! How's it going?" />
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/message_list"
|
android:id="@+id/messageList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:clipChildren="false"
|
android:clipChildren="false"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message_body"
|
android:id="@+id/body"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:layout_marginEnd="56dp"
|
android:layout_marginEnd="56dp"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message_body"
|
android:id="@+id/body"
|
||||||
style="@style/TextPrimary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user