mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Fix several issues with chatcolors.
This commit is contained in:
committed by
Cody Henthorne
parent
e5b0941d30
commit
18133e2a10
@@ -25,6 +25,7 @@ import org.thoughtcrime.securesms.conversation.colors.ChatColorsPalette;
|
||||
import org.thoughtcrime.securesms.conversation.colors.NameColor;
|
||||
import org.thoughtcrime.securesms.database.DatabaseObserver;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.thoughtcrime.securesms.groups.LiveGroup;
|
||||
import org.thoughtcrime.securesms.groups.ui.GroupMemberEntry;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
@@ -32,11 +33,14 @@ import org.thoughtcrime.securesms.mediasend.MediaRepository;
|
||||
import org.thoughtcrime.securesms.ratelimit.RecaptchaRequiredEvent;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
import org.thoughtcrime.securesms.util.SingleLiveEvent;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -203,9 +207,13 @@ public class ConversationViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
@NonNull LiveData<Map<RecipientId, NameColor>> getNameColorsMap() {
|
||||
LiveData<Recipient> recipient = Transformations.switchMap(recipientId, r -> Recipient.live(r).getLiveData());
|
||||
LiveData<Recipient> groupRecipients = LiveDataUtil.filter(recipient, Recipient::isGroup);
|
||||
LiveData<List<GroupMemberEntry.FullMember>> groupMembers = Transformations.switchMap(groupRecipients, r -> new LiveGroup(r.getGroupId().get()).getFullMembers());
|
||||
LiveData<Recipient> recipient = Transformations.switchMap(recipientId, r -> Recipient.live(r).getLiveData());
|
||||
LiveData<Optional<GroupId>> group = Transformations.map(recipient, Recipient::getGroupId);
|
||||
LiveData<List<GroupMemberEntry.FullMember>> groupMembers = Transformations.switchMap(group, g -> {
|
||||
//noinspection CodeBlock2Expr
|
||||
return g.transform(id -> new LiveGroup(id).getFullMembers())
|
||||
.or(() -> new DefaultValueLiveData<>(Collections.emptyList()));
|
||||
});
|
||||
|
||||
return Transformations.map(groupMembers, members -> {
|
||||
List<GroupMemberEntry.FullMember> sorted = Stream.of(members)
|
||||
|
||||
@@ -25,9 +25,9 @@ sealed class ChatColorSelectionRepository(context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getUsageCount(chatColors: ChatColors, consumer: (Int) -> Unit) {
|
||||
fun getUsageCount(chatColorsId: ChatColors.Id, consumer: (Int) -> Unit) {
|
||||
SignalExecutors.BOUNDED.execute {
|
||||
consumer(DatabaseFactory.getRecipientDatabase(context).getColorUsageCount(chatColors))
|
||||
consumer(DatabaseFactory.getRecipientDatabase(context).getColorUsageCount(chatColorsId))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class ChatColorSelectionViewModel(private val repository: ChatColorSelectionRepo
|
||||
}
|
||||
|
||||
fun startDeletion(chatColors: ChatColors) {
|
||||
repository.getUsageCount(chatColors) {
|
||||
repository.getUsageCount(chatColors.id) {
|
||||
if (it > 0) {
|
||||
internalEvents.postValue(Event.ConfirmDeletion(it, chatColors))
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ScrollView
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.Dimension
|
||||
@@ -60,11 +61,20 @@ class CustomChatColorCreatorPageFragment :
|
||||
|
||||
val gradientTool: CustomChatColorGradientToolView = view.findViewById(R.id.gradient_tool)
|
||||
val save: View = view.findViewById(R.id.save)
|
||||
val scrollView: ScrollView = view.findViewById(R.id.scroll_view)
|
||||
|
||||
if (page == SINGLE_PAGE) {
|
||||
gradientTool.visibility = View.GONE
|
||||
} else {
|
||||
gradientTool.setListener(object : CustomChatColorGradientToolView.Listener {
|
||||
override fun onGestureStarted() {
|
||||
scrollView.requestDisallowInterceptTouchEvent(true)
|
||||
}
|
||||
|
||||
override fun onGestureFinished() {
|
||||
scrollView.requestDisallowInterceptTouchEvent(false)
|
||||
}
|
||||
|
||||
override fun onDegreesChanged(degrees: Float) {
|
||||
viewModel.setDegrees(degrees)
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ class CustomChatColorCreatorRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getUsageCount(chatColors: ChatColors, consumer: (Int) -> Unit) {
|
||||
fun getUsageCount(chatColorsId: ChatColors.Id, consumer: (Int) -> Unit) {
|
||||
SignalExecutors.BOUNDED.execute {
|
||||
val recipientsDatabase = DatabaseFactory.getRecipientDatabase(context)
|
||||
|
||||
consumer(recipientsDatabase.getColorUsageCount(chatColors))
|
||||
consumer(recipientsDatabase.getColorUsageCount(chatColorsId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ class CustomChatColorCreatorViewModel(
|
||||
}
|
||||
|
||||
fun startSave(chatColors: ChatColors) {
|
||||
if (chatColors.id is ChatColors.Id.Custom) {
|
||||
repository.getUsageCount(chatColors) {
|
||||
if (chatColorsId is ChatColors.Id.Custom) {
|
||||
repository.getUsageCount(chatColorsId) {
|
||||
if (it > 0) {
|
||||
internalEvents.postValue(Event.Warn(it, chatColors))
|
||||
} else {
|
||||
|
||||
@@ -103,7 +103,8 @@ class CustomChatColorGradientToolView @JvmOverloads constructor(
|
||||
color = ContextCompat.getColor(context, R.color.signal_inverse_transparent_10)
|
||||
}
|
||||
|
||||
val gestureDetectorCompat = GestureDetectorCompat(context, GestureListener())
|
||||
private val gestureListener = GestureListener()
|
||||
private val gestureDetectorCompat = GestureDetectorCompat(context, gestureListener)
|
||||
|
||||
fun setTopColor(@ColorInt color: Int) {
|
||||
topColorPaint.color = color
|
||||
@@ -147,7 +148,14 @@ class CustomChatColorGradientToolView @JvmOverloads constructor(
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean {
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
|
||||
if (event.action == MotionEvent.ACTION_CANCEL || event.action == MotionEvent.ACTION_UP) {
|
||||
listener?.onGestureFinished()
|
||||
} else if (event.action == MotionEvent.ACTION_DOWN) {
|
||||
listener?.onGestureStarted()
|
||||
}
|
||||
|
||||
return gestureDetectorCompat.onTouchEvent(event)
|
||||
}
|
||||
|
||||
@@ -303,6 +311,8 @@ class CustomChatColorGradientToolView @JvmOverloads constructor(
|
||||
private fun Float.rotate(degrees: Float): Float = (this + degrees + 360f) % 360f
|
||||
|
||||
interface Listener {
|
||||
fun onGestureStarted()
|
||||
fun onGestureFinished()
|
||||
fun onDegreesChanged(degrees: Float)
|
||||
fun onSelectedEdgeChanged(edge: CustomChatColorEdge)
|
||||
}
|
||||
|
||||
@@ -1411,11 +1411,11 @@ public class RecipientDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
public int getColorUsageCount(@NotNull ChatColors chatColors) {
|
||||
public int getColorUsageCount(@NotNull ChatColors.Id chatColorsId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String[] projection = SqlUtil.buildArgs("COUNT(*)");
|
||||
String where = CUSTOM_CHAT_COLORS_ID + " = ?";
|
||||
String[] args = SqlUtil.buildArgs(chatColors.getId().getLongValue());
|
||||
String[] args = SqlUtil.buildArgs(chatColorsId.getLongValue());
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, projection, where, args, null, null, null)) {
|
||||
if (cursor == null) {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.thoughtcrime.securesms.components.TypingIndicatorView
|
||||
app:typingIndicator_tint="@color/signal_inverse_primary"
|
||||
android:id="@+id/typing_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?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"
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
Reference in New Issue
Block a user