Skip to content

Commit

Permalink
Merge pull request thunderbird#4891 from k9mail/update_tokenautocomplete
Browse files Browse the repository at this point in the history
Update TokenAutoComplete
  • Loading branch information
cketti authored Jul 29, 2020
2 parents cd446f3 + 97619c0 commit 6e611a5
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 147 deletions.
2 changes: 1 addition & 1 deletion app/ui/legacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "com.google.android.material:material:${versions.materialComponents}"
implementation "de.cketti.library.changelog:ckchangelog:1.2.1"
implementation "com.splitwise:tokenautocomplete:2.0.7"
implementation "com.splitwise:tokenautocomplete:4.0.0-beta01"
implementation "de.cketti.safecontentresolver:safe-content-resolver-v21:1.0.0"
implementation "com.xwray:groupie:2.8.0"
implementation "com.xwray:groupie-kotlin-android-extensions:2.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
import com.fsck.k9.view.RecipientSelectView.TokenListener;
import com.fsck.k9.view.ToolableViewAnimator;

import static com.fsck.k9.FontSizes.FONT_10SP;
import static com.fsck.k9.FontSizes.FONT_12SP;
import static com.fsck.k9.FontSizes.FONT_16SP;
import static com.fsck.k9.FontSizes.FONT_20SP;
import static com.fsck.k9.FontSizes.FONT_DEFAULT;
import static com.fsck.k9.FontSizes.LARGE;
import static com.fsck.k9.FontSizes.MEDIUM;
import static com.fsck.k9.FontSizes.SMALL;


public class RecipientMvpView implements OnFocusChangeListener, OnClickListener {
private static final int VIEW_INDEX_HIDDEN = -1;
Expand Down Expand Up @@ -112,6 +121,11 @@ public void onTokenRemoved(Recipient recipient) {
public void onTokenChanged(Recipient recipient) {
presenter.onToTokenChanged();
}

@Override
public void onTokenIgnored(Recipient token) {
// Do nothing
}
});

ccView.setTokenListener(new TokenListener<Recipient>() {
Expand All @@ -129,6 +143,11 @@ public void onTokenRemoved(Recipient recipient) {
public void onTokenChanged(Recipient recipient) {
presenter.onCcTokenChanged();
}

@Override
public void onTokenIgnored(Recipient token) {
// Do nothing
}
});

bccView.setTokenListener(new TokenListener<Recipient>() {
Expand All @@ -146,6 +165,11 @@ public void onTokenRemoved(Recipient recipient) {
public void onTokenChanged(Recipient recipient) {
presenter.onBccTokenChanged();
}

@Override
public void onTokenIgnored(Recipient token) {
// Do nothing
}
});
}

Expand Down Expand Up @@ -195,11 +219,28 @@ public void requestFocusOnBccField() {
}

public void setFontSizes(FontSizes fontSizes, int fontSize) {
int tokenTextSize = getTokenTextSize(fontSize);
toView.setTokenTextSize(tokenTextSize);
ccView.setTokenTextSize(tokenTextSize);
bccView.setTokenTextSize(tokenTextSize);
fontSizes.setViewTextSize(toView, fontSize);
fontSizes.setViewTextSize(ccView, fontSize);
fontSizes.setViewTextSize(bccView, fontSize);
}

private int getTokenTextSize(int fontSize) {
switch (fontSize) {
case FONT_10SP: return FONT_10SP;
case FONT_12SP: return FONT_12SP;
case SMALL: return SMALL;
case FONT_16SP: return 15;
case MEDIUM: return FONT_16SP;
case FONT_20SP: return MEDIUM;
case LARGE: return FONT_20SP;
default: return FONT_DEFAULT;
}
}

public void addRecipients(RecipientType recipientType, Recipient... recipients) {
switch (recipientType) {
case TO: {
Expand All @@ -220,11 +261,9 @@ public void addRecipients(RecipientType recipientType, Recipient... recipients)
public void silentlyAddBccAddresses(Recipient... recipients) {
removeAllTextChangedListeners(bccView);

// The actual modification of the view is deferred via View.post()…
bccView.addRecipients(recipients);

// … so we do the same to add back the listeners.
bccView.post(() -> addAllTextChangedListeners(bccView));
addAllTextChangedListeners(bccView);
}

public void silentlyRemoveBccAddresses(Address[] addressesToRemove) {
Expand All @@ -238,13 +277,11 @@ public void silentlyRemoveBccAddresses(Address[] addressesToRemove) {

for (Address address : addressesToRemove) {
if (recipient.address.equals(address)) {
// The actual modification of the view is deferred via View.post()…
bccView.removeObject(recipient);
bccView.removeObjectSync(recipient);
}
}

// … so we do the same to add back the listeners.
bccView.post(() -> addAllTextChangedListeners(bccView));
addAllTextChangedListeners(bccView);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fsck.k9.ui.compose

import android.content.Context
import android.util.AttributeSet
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout

/**
* Custom [ConstraintLayout] that returns an appropriate baseline value for our recipient token layout.
*/
class RecipientTokenConstraintLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private lateinit var textView: TextView

override fun onFinishInflate() {
super.onFinishInflate()
textView = findViewById(android.R.id.text1)
}

override fun getBaseline(): Int {
return textView.top + textView.baseline
}
}
Loading

0 comments on commit 6e611a5

Please sign in to comment.