mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 21:43:38 +00:00
Design menu layout, build adapters and activities
This commit is contained in:
parent
927bcce764
commit
cd7fd5d51a
@ -132,6 +132,9 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.thoughtcrime.securesms.loki.activities.CreateClosedGroupActivity"
|
android:name="org.thoughtcrime.securesms.loki.activities.CreateClosedGroupActivity"
|
||||||
android:screenOrientation="portrait" />
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name="org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivity"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.thoughtcrime.securesms.loki.activities.JoinPublicChatActivity"
|
android:name="org.thoughtcrime.securesms.loki.activities.JoinPublicChatActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
|
121
res/layout/activity_edit_closed_group.xml
Normal file
121
res/layout/activity_edit_closed_group.xml
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/displayNameContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="@dimen/large_spacing"
|
||||||
|
android:layout_marginTop="@dimen/small_spacing"
|
||||||
|
android:layout_marginRight="@dimen/large_spacing">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
style="@style/SessionEditText"
|
||||||
|
android:id="@+id/displayNameEditText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:hint="@string/activity_settings_display_name_edit_text_hint" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/displayNameTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="@dimen/very_large_font_size"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawableStart="@drawable/ic_edit_white_24dp"
|
||||||
|
android:gravity="right"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="@dimen/large_spacing"
|
||||||
|
android:layout_marginTop="@dimen/medium_spacing"
|
||||||
|
android:layout_marginRight="@dimen/large_spacing"
|
||||||
|
android:layout_marginBottom="@dimen/medium_spacing"
|
||||||
|
android:textSize="@dimen/small_font_size"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:text="@string/activity_edit_closed_group_explanation" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1px"
|
||||||
|
android:background="@color/separator" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="@dimen/large_spacing"
|
||||||
|
android:layout_marginTop="@dimen/small_spacing"
|
||||||
|
android:layout_marginRight="@dimen/massive_spacing"
|
||||||
|
android:layout_marginBottom="@dimen/small_spacing"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:text="@string/activity_edit_closed_group_edit_members"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="@dimen/medium_font_size" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/addMembersClosedGroupButton"
|
||||||
|
style="@style/MediumProminentOutlineButton"
|
||||||
|
android:layout_width="135dp"
|
||||||
|
android:layout_height="@dimen/small_button_height"
|
||||||
|
android:layout_marginTop="@dimen/small_spacing"
|
||||||
|
android:layout_marginRight="@dimen/large_spacing"
|
||||||
|
android:layout_marginLeft="@dimen/very_large_spacing"
|
||||||
|
android:layout_marginBottom="@dimen/small_spacing"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/activity_edit_closed_group_add_members" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<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">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
28
res/layout/fragment_group_edit_bottom_sheet.xml
Normal file
28
res/layout/fragment_group_edit_bottom_sheet.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
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"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:behavior_hideable="true"
|
||||||
|
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
|
||||||
|
android:background="@color/dialog_background">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/removeFromGroup"
|
||||||
|
style="@style/ActionItem"
|
||||||
|
android:drawableStart="@drawable/ic_phonelink_erase_white_24dp"
|
||||||
|
android:textSize="@dimen/medium_font_size"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:text="@string/fragment_edit_group_bottom_sheet_remove"/>
|
||||||
|
|
||||||
|
<!-- <TextView-->
|
||||||
|
<!-- android:id="@+id/makeAdministrator"-->
|
||||||
|
<!-- style="@style/ActionItem"-->
|
||||||
|
<!-- android:drawableStart="@drawable/ic_edit_white_24dp"-->
|
||||||
|
<!-- android:textSize="@dimen/medium_font_size"-->
|
||||||
|
<!-- android:textColor="@color/text"-->
|
||||||
|
<!-- android:text="@string/fragment_edit_group_bottom_sheet_admin" />-->
|
||||||
|
|
||||||
|
</LinearLayout>
|
10
res/menu/menu_edit_closed_group.xml
Normal file
10
res/menu/menu_edit_closed_group.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?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="Done"
|
||||||
|
android:id="@+id/editClosedGroupButton"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
</menu>
|
@ -1769,6 +1769,22 @@
|
|||||||
<string name="activity_create_closed_group_too_many_group_members_error">A closed group cannot have more than 10 members</string>
|
<string name="activity_create_closed_group_too_many_group_members_error">A closed group cannot have more than 10 members</string>
|
||||||
<string name="activity_create_closed_group_invalid_session_id_error">One of the members of your group has an invalid Session ID</string>
|
<string name="activity_create_closed_group_invalid_session_id_error">One of the members of your group has an invalid Session ID</string>
|
||||||
|
|
||||||
|
<string name="activity_edit_closed_group_title">Edit Closed Group</string>
|
||||||
|
<string name="activity_edit_closed_group_edit_text_hint">Enter a new group name (optional)</string>
|
||||||
|
<string name="activity_edit_closed_group_explanation">Closed groups support up to 10 members and provide the same privacy protections as one-on-one sessions.</string>
|
||||||
|
<string name="activity_edit_closed_group_edit_members">Edit members</string>
|
||||||
|
<string name="activity_edit_closed_group_add_members">Add members</string>
|
||||||
|
<string name="activity_edit_closed_group_group_name_missing_error">Group name can\'t be empty</string>
|
||||||
|
<string name="activity_edit_closed_group_group_name_too_long_error">Please enter a shorter group name</string>
|
||||||
|
<string name="activity_edit_closed_group_not_enough_group_members_error">Groups must have at least 2 group members</string>
|
||||||
|
<string name="activity_edit_closed_group_too_many_group_members_error">A closed group cannot have more than 10 members</string>
|
||||||
|
<string name="activity_edit_closed_group_invalid_session_id_error">One of the members of your group has an invalid Session ID</string>
|
||||||
|
<string name="activity_edit_closed_group_confirm_removal">Are you sure you want to remove this user?</string>
|
||||||
|
<string name="activity_edit_closed_group_member_removed">User removed from group</string>
|
||||||
|
|
||||||
|
<string name="fragment_edit_group_bottom_sheet_remove">Remove user from group</string>
|
||||||
|
<string name="fragment_edit_group_bottom_sheet_admin">Make this user a group admin</string>
|
||||||
|
|
||||||
<string name="activity_join_public_chat_title">Join Open Group</string>
|
<string name="activity_join_public_chat_title">Join Open Group</string>
|
||||||
<string name="activity_join_public_chat_error">Couldn\'t join group</string>
|
<string name="activity_join_public_chat_error">Couldn\'t join group</string>
|
||||||
<string name="activity_join_public_chat_enter_group_url_tab_title">Open Group URL</string>
|
<string name="activity_join_public_chat_enter_group_url_tab_title">Open Group URL</string>
|
||||||
|
@ -154,6 +154,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
|||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
import org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivity;
|
||||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase;
|
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase;
|
||||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabaseDelegate;
|
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabaseDelegate;
|
||||||
@ -1162,10 +1163,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleEditPushGroup() {
|
private void handleEditPushGroup() {
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
Intent intent = new Intent(this, EditClosedGroupActivity.class);
|
||||||
alert.setMessage("The ability to add members to a closed group is coming soon.");
|
startActivity(intent);
|
||||||
alert.setPositiveButton("OK", (dialog, which) -> dialog.dismiss());
|
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
alert.create().show();
|
// alert.setMessage("The ability to add members to a closed group is coming soon.");
|
||||||
|
// alert.setPositiveButton("OK", (dialog, which) -> dialog.dismiss());
|
||||||
|
// alert.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDistributionBroadcastEnabled(MenuItem item) {
|
private void handleDistributionBroadcastEnabled(MenuItem item) {
|
||||||
|
@ -43,8 +43,3 @@ class CreateClosedGroupAdapter(private val context: Context) : RecyclerView.Adap
|
|||||||
notifyItemChanged(index)
|
notifyItemChanged(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MemberClickListener {
|
|
||||||
|
|
||||||
fun onMemberClick(member: String)
|
|
||||||
}
|
|
@ -0,0 +1,184 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.os.AsyncTask
|
||||||
|
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 android.widget.Toast
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_closed_group.*
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_closed_group.emptyStateContainer
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_closed_group.mainContentContainer
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_closed_group.nameEditText
|
||||||
|
import kotlinx.android.synthetic.main.activity_edit_closed_group.*
|
||||||
|
import kotlinx.android.synthetic.main.activity_edit_closed_group.displayNameContainer
|
||||||
|
import kotlinx.android.synthetic.main.activity_edit_closed_group.displayNameTextView
|
||||||
|
import kotlinx.android.synthetic.main.activity_linked_devices.recyclerView
|
||||||
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
import network.loki.messenger.R
|
||||||
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
|
import org.thoughtcrime.securesms.conversation.ConversationActivity
|
||||||
|
import org.thoughtcrime.securesms.database.Address
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
|
import org.thoughtcrime.securesms.database.ThreadDatabase
|
||||||
|
import org.thoughtcrime.securesms.groups.GroupManager
|
||||||
|
import org.thoughtcrime.securesms.loki.dialogs.GroupEditingOptionsBottomSheet
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
|
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, LoaderManager.LoaderCallbacks<List<String>> {
|
||||||
|
private var members = listOf<String>()
|
||||||
|
set(value) { field = value; editClosedGroupAdapter.members = value }
|
||||||
|
|
||||||
|
private val editClosedGroupAdapter by lazy {
|
||||||
|
val result = EditClosedGroupAdapter(this)
|
||||||
|
result.glide = GlideApp.with(this)
|
||||||
|
result.memberClickListener = this
|
||||||
|
result
|
||||||
|
}
|
||||||
|
private var isEditingDisplayName = false
|
||||||
|
private val selectedMembers: Set<String>
|
||||||
|
get() { return editClosedGroupAdapter.selectedMembers }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
public val createNewPrivateChatResultCode = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// region Lifecycle
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||||
|
super.onCreate(savedInstanceState, isReady)
|
||||||
|
setContentView(R.layout.activity_edit_closed_group)
|
||||||
|
supportActionBar!!.title = resources.getString(R.string.activity_edit_closed_group_title)
|
||||||
|
displayNameContainer.setOnClickListener { showEditDisplayNameUI() }
|
||||||
|
displayNameTextView.text = "Get Group Name"
|
||||||
|
recyclerView.adapter = editClosedGroupAdapter
|
||||||
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
addMembersClosedGroupButton.setOnClickListener { createNewPrivateChat() }
|
||||||
|
LoaderManager.getInstance(this).initLoader(0, null, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.menu_edit_closed_group, menu)
|
||||||
|
return members.isNotEmpty()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Updating
|
||||||
|
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
||||||
|
return CreateClosedGroupLoader(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.editClosedGroupButton -> modifyClosedGroup()
|
||||||
|
else -> { /* Do nothing */ }
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createNewPrivateChat() {
|
||||||
|
setResult(createNewPrivateChatResultCode)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
private fun showEditDisplayNameUI() {
|
||||||
|
isEditingDisplayName = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMemberClick(member: String) {
|
||||||
|
val bottomSheet = GroupEditingOptionsBottomSheet()
|
||||||
|
bottomSheet.onRemoveTapped = {
|
||||||
|
bottomSheet.dismiss()
|
||||||
|
}
|
||||||
|
// bottomSheet.onAdminTapped = {
|
||||||
|
// bottomSheet.dismiss()
|
||||||
|
// }
|
||||||
|
bottomSheet.show(supportFragmentManager, "closeBottomSheet")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun modifyClosedGroup() {
|
||||||
|
val name = nameEditText.text.trim()
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_missing_error, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
if (name.length >= 64) {
|
||||||
|
return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_too_long_error, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedMembers.count() < 2) {
|
||||||
|
return Toast.makeText(this, R.string.activity_edit_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
if (selectedMembers.count() > 10) {
|
||||||
|
return Toast.makeText(this, R.string.activity_edit_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
val recipients = selectedMembers.map {
|
||||||
|
Recipient.from(this, Address.fromSerialized(it), false)
|
||||||
|
}.toSet()
|
||||||
|
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this) ?: TextSecurePreferences.getLocalNumber(this)
|
||||||
|
val admin = Recipient.from(this, Address.fromSerialized(masterHexEncodedPublicKey), false)
|
||||||
|
CreateClosedGroupTask(WeakReference(this), null, name.toString(), recipients, setOf( admin )).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleOpenConversation(threadId: Long, recipient: Recipient) {
|
||||||
|
val intent = Intent(this, ConversationActivity::class.java)
|
||||||
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId)
|
||||||
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT)
|
||||||
|
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.address)
|
||||||
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Tasks
|
||||||
|
internal class CreateClosedGroupTask(
|
||||||
|
private val activity: WeakReference<EditClosedGroupActivity>,
|
||||||
|
private val profilePicture: Bitmap?,
|
||||||
|
private val name: String?,
|
||||||
|
private val members: Set<Recipient>,
|
||||||
|
private val admins: Set<Recipient>
|
||||||
|
) : AsyncTask<Void, Void, Optional<GroupManager.GroupActionResult>>() {
|
||||||
|
|
||||||
|
override fun doInBackground(vararg params: Void?): Optional<GroupManager.GroupActionResult> {
|
||||||
|
val activity = activity.get() ?: return Optional.absent()
|
||||||
|
return Optional.of(GroupManager.createGroup(activity, members, profilePicture, name, false, admins))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPostExecute(result: Optional<GroupManager.GroupActionResult>) {
|
||||||
|
val activity = activity.get() ?: return super.onPostExecute(result)
|
||||||
|
if (result.isPresent && result.get().threadId > -1) {
|
||||||
|
if (!activity.isFinishing) {
|
||||||
|
activity.handleOpenConversation(result.get().threadId, result.get().groupRecipient)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onPostExecute(result)
|
||||||
|
Toast.makeText(activity.applicationContext, R.string.activity_create_closed_group_invalid_session_id_error, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.R
|
||||||
|
import android.app.PendingIntent.getActivity
|
||||||
|
import android.content.Context
|
||||||
|
import android.support.v7.app.AlertDialog
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import org.thoughtcrime.securesms.DeviceListItem
|
||||||
|
import org.thoughtcrime.securesms.database.Address
|
||||||
|
import org.thoughtcrime.securesms.loki.dialogs.DeviceEditingOptionsBottomSheet
|
||||||
|
import org.thoughtcrime.securesms.loki.dialogs.GroupEditingOptionsBottomSheet
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||||
|
import org.thoughtcrime.securesms.loki.views.UserView
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
|
class EditClosedGroupAdapter(private val context: Context) : RecyclerView.Adapter<EditClosedGroupAdapter.ViewHolder>() {
|
||||||
|
lateinit var glide: GlideRequests
|
||||||
|
val selectedMembers = mutableSetOf<String>()
|
||||||
|
var members = listOf<String>()
|
||||||
|
set(value) {
|
||||||
|
field = value; notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
var memberClickListener: MemberClickListener? = null
|
||||||
|
|
||||||
|
class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return members.size
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val view = UserView(context)
|
||||||
|
return ViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||||
|
val member = members[position]
|
||||||
|
viewHolder.view.setOnClickListener { memberClickListener?.onMemberClick(member) }
|
||||||
|
val isSelected = selectedMembers.contains(member)
|
||||||
|
viewHolder.view.bind(Recipient.from(context, Address.fromSerialized(member), false), isSelected, glide)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.ContactUtilities
|
||||||
|
import org.thoughtcrime.securesms.util.AsyncLoader
|
||||||
|
|
||||||
|
class EditClosedGroupLoader(context: Context) : AsyncLoader<List<String>>(context) {
|
||||||
|
|
||||||
|
override fun loadInBackground(): List<String> {
|
||||||
|
val contacts = ContactUtilities.getAllContacts(context)
|
||||||
|
// Only show the master devices of the users we are friends with
|
||||||
|
return contacts.filter { contact ->
|
||||||
|
!contact.recipient.isGroupRecipient && contact.isFriend && !contact.isOurDevice && !contact.isSlave
|
||||||
|
}.map {
|
||||||
|
it.recipient.address.toPhoneString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
interface MemberClickListener {
|
||||||
|
fun onMemberClick(member: String)
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.dialogs
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.design.widget.BottomSheetDialogFragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import kotlinx.android.synthetic.main.fragment_group_edit_bottom_sheet.*
|
||||||
|
import network.loki.messenger.R
|
||||||
|
|
||||||
|
public class GroupEditingOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||||
|
var onRemoveTapped: (() -> Unit)? = null
|
||||||
|
// var onAdminTapped: (() -> Unit)? = null
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
return inflater.inflate(R.layout.fragment_group_edit_bottom_sheet, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
removeFromGroup.setOnClickListener { onRemoveTapped?.invoke() }
|
||||||
|
// makeAdministrator.setOnClickListener { onAdminTapped?.invoke() }
|
||||||
|
}
|
||||||
|
}
|
@ -53,7 +53,8 @@ class UserView : LinearLayout {
|
|||||||
profilePictureView.isRSSFeed = true
|
profilePictureView.isRSSFeed = true
|
||||||
} else {
|
} else {
|
||||||
val threadID = GroupManager.getThreadIDFromGroupID(address, context)
|
val threadID = GroupManager.getThreadIDFromGroupID(address, context)
|
||||||
val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toList() ?: listOf()
|
val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toList()
|
||||||
|
?: listOf()
|
||||||
val randomUsers = users.sorted() // Sort to provide a level of stability
|
val randomUsers = users.sorted() // Sort to provide a level of stability
|
||||||
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
|
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
|
||||||
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
|
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
|
||||||
@ -67,7 +68,12 @@ class UserView : LinearLayout {
|
|||||||
profilePictureView.glide = glide
|
profilePictureView.glide = glide
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
nameTextView.text = user.name ?: "Unknown Contact"
|
nameTextView.text = user.name ?: "Unknown Contact"
|
||||||
tickImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
|
if (user.isGroupRecipient) {
|
||||||
|
// this doesnt work, find out how to work out if the user is a part of the group)
|
||||||
|
tickImageView.setImageResource(R.drawable.ic_edit_white_24dp)
|
||||||
|
} else {
|
||||||
|
tickImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user