Search in sources :

Example 1 with MappingModel

use of org.thoughtcrime.securesms.util.adapter.mapping.MappingModel in project Signal-Android by WhisperSystems.

the class ChatWallpaperPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    dynamicTheme.onCreate(this);
    setContentView(R.layout.chat_wallpaper_preview_activity);
    adapter = new ChatWallpaperPreviewAdapter();
    colorizerView = findViewById(R.id.colorizer);
    bubble2 = findViewById(R.id.preview_bubble_2);
    viewPager = findViewById(R.id.preview_pager);
    View submit = findViewById(R.id.preview_set_wallpaper);
    ChatWallpaperRepository repository = new ChatWallpaperRepository();
    ChatWallpaper selected = getIntent().getParcelableExtra(EXTRA_CHAT_WALLPAPER);
    boolean dim = getIntent().getBooleanExtra(EXTRA_DIM_IN_DARK_MODE, false);
    Toolbar toolbar = findViewById(R.id.toolbar);
    TextView bubble2Text = findViewById(R.id.preview_bubble_2_text);
    toolbar.setNavigationOnClickListener(unused -> {
        finish();
    });
    viewPager.setAdapter(adapter);
    adapter.submitList(Collections.singletonList(new ChatWallpaperSelectionMappingModel(selected)));
    repository.getAllWallpaper(wallpapers -> adapter.submitList(Stream.of(wallpapers).map(wallpaper -> ChatWallpaperFactory.updateWithDimming(wallpaper, dim ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f)).<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new).toList()));
    submit.setOnClickListener(unused -> {
        ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(viewPager.getCurrentItem());
        setResult(RESULT_OK, new Intent().putExtra(EXTRA_CHAT_WALLPAPER, model.getWallpaper()));
        finish();
    });
    RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
    final ChatColors chatColors;
    if (recipientId != null && Recipient.live(recipientId).get().hasOwnChatColors()) {
        Recipient recipient = Recipient.live(recipientId).get();
        bubble2Text.setText(getString(R.string.ChatWallpaperPreviewActivity__set_wallpaper_for_s, recipient.getDisplayName(this)));
        chatColors = recipient.getChatColors();
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else if (SignalStore.chatColorsValues().hasChatColors()) {
        chatColors = Objects.requireNonNull(SignalStore.chatColorsValues().getChatColors());
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else {
        onPageChanged = new OnPageChanged();
        viewPager.registerOnPageChangeCallback(onPageChanged);
        bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selected.getAutoChatColors()));
    }
    new FullscreenHelper(this).showSystemUI();
    WindowUtil.setLightStatusBarFromTheme(this);
    WindowUtil.setLightNavigationBarFromTheme(this);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Objects(java.util.Objects) TextView(android.widget.TextView) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Toolbar(androidx.appcompat.widget.Toolbar) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Intent(android.content.Intent) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) TextView(android.widget.TextView) TextView(android.widget.TextView) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with MappingModel

use of org.thoughtcrime.securesms.util.adapter.mapping.MappingModel in project Signal-Android by signalapp.

the class ChatWallpaperPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    dynamicTheme.onCreate(this);
    setContentView(R.layout.chat_wallpaper_preview_activity);
    adapter = new ChatWallpaperPreviewAdapter();
    colorizerView = findViewById(R.id.colorizer);
    bubble2 = findViewById(R.id.preview_bubble_2);
    viewPager = findViewById(R.id.preview_pager);
    View submit = findViewById(R.id.preview_set_wallpaper);
    ChatWallpaperRepository repository = new ChatWallpaperRepository();
    ChatWallpaper selected = getIntent().getParcelableExtra(EXTRA_CHAT_WALLPAPER);
    boolean dim = getIntent().getBooleanExtra(EXTRA_DIM_IN_DARK_MODE, false);
    Toolbar toolbar = findViewById(R.id.toolbar);
    TextView bubble2Text = findViewById(R.id.preview_bubble_2_text);
    toolbar.setNavigationOnClickListener(unused -> {
        finish();
    });
    viewPager.setAdapter(adapter);
    adapter.submitList(Collections.singletonList(new ChatWallpaperSelectionMappingModel(selected)));
    repository.getAllWallpaper(wallpapers -> adapter.submitList(Stream.of(wallpapers).map(wallpaper -> ChatWallpaperFactory.updateWithDimming(wallpaper, dim ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f)).<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new).toList()));
    submit.setOnClickListener(unused -> {
        ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(viewPager.getCurrentItem());
        setResult(RESULT_OK, new Intent().putExtra(EXTRA_CHAT_WALLPAPER, model.getWallpaper()));
        finish();
    });
    RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
    final ChatColors chatColors;
    if (recipientId != null && Recipient.live(recipientId).get().hasOwnChatColors()) {
        Recipient recipient = Recipient.live(recipientId).get();
        bubble2Text.setText(getString(R.string.ChatWallpaperPreviewActivity__set_wallpaper_for_s, recipient.getDisplayName(this)));
        chatColors = recipient.getChatColors();
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else if (SignalStore.chatColorsValues().hasChatColors()) {
        chatColors = Objects.requireNonNull(SignalStore.chatColorsValues().getChatColors());
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else {
        onPageChanged = new OnPageChanged();
        viewPager.registerOnPageChangeCallback(onPageChanged);
        bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selected.getAutoChatColors()));
    }
    new FullscreenHelper(this).showSystemUI();
    WindowUtil.setLightStatusBarFromTheme(this);
    WindowUtil.setLightNavigationBarFromTheme(this);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Objects(java.util.Objects) TextView(android.widget.TextView) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Toolbar(androidx.appcompat.widget.Toolbar) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Intent(android.content.Intent) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) TextView(android.widget.TextView) TextView(android.widget.TextView) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Example 3 with MappingModel

use of org.thoughtcrime.securesms.util.adapter.mapping.MappingModel in project Signal-Android by WhisperSystems.

the class CallParticipantsListDialog method updateList.

private void updateList(@NonNull CallParticipantsState callParticipantsState) {
    List<MappingModel<?>> items = new ArrayList<>();
    boolean includeSelf = callParticipantsState.getGroupCallState() == WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED;
    OptionalLong headerCount = callParticipantsState.getParticipantCount();
    headerCount.executeIfPresent(count -> {
        items.add(new CallParticipantsListHeader((int) count));
        if (includeSelf) {
            items.add(new CallParticipantViewState(callParticipantsState.getLocalParticipant()));
        }
        for (CallParticipant callParticipant : callParticipantsState.getAllRemoteParticipants()) {
            items.add(new CallParticipantViewState(callParticipant));
        }
    });
    adapter.submitList(items);
}
Also used : CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) ArrayList(java.util.ArrayList) OptionalLong(com.annimon.stream.OptionalLong) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel)

Example 4 with MappingModel

use of org.thoughtcrime.securesms.util.adapter.mapping.MappingModel in project Signal-Android by signalapp.

the class CallParticipantsListDialog method updateList.

private void updateList(@NonNull CallParticipantsState callParticipantsState) {
    List<MappingModel<?>> items = new ArrayList<>();
    boolean includeSelf = callParticipantsState.getGroupCallState() == WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED;
    OptionalLong headerCount = callParticipantsState.getParticipantCount();
    headerCount.executeIfPresent(count -> {
        items.add(new CallParticipantsListHeader((int) count));
        if (includeSelf) {
            items.add(new CallParticipantViewState(callParticipantsState.getLocalParticipant()));
        }
        for (CallParticipant callParticipant : callParticipantsState.getAllRemoteParticipants()) {
            items.add(new CallParticipantViewState(callParticipant));
        }
    });
    adapter.submitList(items);
}
Also used : CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) ArrayList(java.util.ArrayList) OptionalLong(com.annimon.stream.OptionalLong) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel)

Aggregations

MappingModel (org.thoughtcrime.securesms.util.adapter.mapping.MappingModel)4 Context (android.content.Context)2 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Toolbar (androidx.appcompat.widget.Toolbar)2 ViewPager2 (androidx.viewpager2.widget.ViewPager2)2 OptionalLong (com.annimon.stream.OptionalLong)2 Stream (com.annimon.stream.Stream)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 PassphraseRequiredActivity (org.thoughtcrime.securesms.PassphraseRequiredActivity)2 R (org.thoughtcrime.securesms.R)2 ChatColors (org.thoughtcrime.securesms.conversation.colors.ChatColors)2 ColorizerView (org.thoughtcrime.securesms.conversation.colors.ColorizerView)2 CallParticipant (org.thoughtcrime.securesms.events.CallParticipant)2