Add 'add members' functionality and cleanup, refactor
parent
50799d9d90
commit
91af472d3b
@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/default_session_background" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/mainContentContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/emptyStateContainer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_centerInParent="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="@dimen/medium_font_size"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:text="@string/activity_create_closed_group_empty_state_message" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/MediumProminentOutlineButton"
|
||||||
|
android:id="@+id/createNewPrivateChatButton"
|
||||||
|
android:layout_width="196dp"
|
||||||
|
android:layout_height="@dimen/medium_button_height"
|
||||||
|
android:layout_marginTop="@dimen/medium_spacing"
|
||||||
|
android:text="@string/activity_create_closed_group_empty_state_button_title" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item android:title="@string/GroupCreateActivity_menu_apply_button"
|
|
||||||
android:id="@+id/menu_create_group"
|
|
||||||
android:icon="?menu_accept_icon"
|
|
||||||
app:showAsAction="always|withText"/>
|
|
||||||
|
|
||||||
</menu>
|
|
@ -0,0 +1,101 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v4.app.LoaderManager
|
||||||
|
import android.support.v4.content.Loader
|
||||||
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_closed_group.*
|
||||||
|
import kotlinx.android.synthetic.main.activity_linked_devices.recyclerView
|
||||||
|
import network.loki.messenger.R
|
||||||
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
|
|
||||||
|
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, LoaderManager.LoaderCallbacks<List<String>> {
|
||||||
|
private var members = listOf<String>()
|
||||||
|
set(value) { field = value; selectContactsAdapter.members = value }
|
||||||
|
|
||||||
|
private val selectContactsAdapter by lazy {
|
||||||
|
val result = SelectContactsAdapter(this)
|
||||||
|
result.glide = GlideApp.with(this)
|
||||||
|
result.memberClickListener = this
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
private val selectedMembers: Set<String>
|
||||||
|
get() { return selectContactsAdapter.selectedMembers }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
public val createNewPrivateChatResultCode = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// region Lifecycle
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||||
|
super.onCreate(savedInstanceState, isReady)
|
||||||
|
setContentView(R.layout.activity_select_contacts)
|
||||||
|
supportActionBar!!.title = resources.getString(R.string.activity_select_contacts_title)
|
||||||
|
recyclerView.adapter = selectContactsAdapter
|
||||||
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
createNewPrivateChatButton.setOnClickListener { createNewPrivateChat() }
|
||||||
|
LoaderManager.getInstance(this).initLoader(0, null, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.menu_done, menu)
|
||||||
|
return members.isNotEmpty()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Updating
|
||||||
|
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
||||||
|
return SelectContactsLoader(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {
|
||||||
|
update(members)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoaderReset(loader: Loader<List<String>>) {
|
||||||
|
update(listOf())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun update(members: List<String>) {
|
||||||
|
this.members = members
|
||||||
|
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
||||||
|
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Interaction
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
val id = item.itemId
|
||||||
|
when(id) {
|
||||||
|
R.id.doneButton -> returnContacts()
|
||||||
|
else -> { /* Do nothing */ }
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createNewPrivateChat() {
|
||||||
|
setResult(createNewPrivateChatResultCode)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMemberClick(member: String) {
|
||||||
|
selectContactsAdapter.onMemberClick(member)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun returnContacts() {
|
||||||
|
val selectedMembers = this.selectedMembers
|
||||||
|
val selectedContacts = selectedMembers.toTypedArray()
|
||||||
|
val data = Intent()
|
||||||
|
data.putExtra("Selected Contacts Result", selectedContacts)
|
||||||
|
setResult(Activity.RESULT_OK, data)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue