Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a9586ac authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch '5520-redesign_send_as_popup' into 'main'

5520-redesign_send_as_popup

See merge request !99
parents 4baa9f70 311fe18c
Loading
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022  E FOUNDATION
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation, either version 3 of the License, or
     (at your option) any later version.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/color_dialog_backgronund" />
    <corners android:radius="4dp" />
</shape>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
    </style>

    <style name="Theme.k9.Dialog.Base" parent="Theme.MaterialComponents.Dialog.Alert">
        <item name="android:windowBackground">@color/color_dialog_backgronund</item>
        <item name="android:windowBackground">@drawable/dialog_background</item>
        <item name="android:colorAccent">@color/color_default_accent</item>
        <item name="android:textColorPrimary">@color/color_default_secondary_text</item>
        <item name="android:textColorSecondary">@color/color_default_secondary_text</item>
+2 −0
Original line number Diff line number Diff line
@@ -1195,11 +1195,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                builder = new AlertDialog.Builder(context);
                builder.setTitle(R.string.send_as);
                final IdentityAdapter adapter = new IdentityAdapter(context);
                adapter.setCurrentIdentity(identity);
                builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        IdentityContainer container = (IdentityContainer) adapter.getItem(which);
                        onAccountChosen(container.account, container.identity);
                        adapter.setCurrentIdentity(identity); // this needs to be called because, adapter is not initialize everytime. So it needs to be updated for next time
                    }
                });

+61 −7
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.fsck.k9.Account;
@@ -26,6 +27,7 @@ import java.util.List;
public class IdentityAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private List<Object> mItems;
    private Identity currentIdentity;

    public IdentityAdapter(Context context) {
        mLayoutInflater = (LayoutInflater) context.getSystemService(
@@ -33,17 +35,28 @@ public class IdentityAdapter extends BaseAdapter {

        List<Object> items = new ArrayList<>();
        Preferences prefs = Preferences.getPreferences(context.getApplicationContext());
        Collection<Account> accounts = prefs.getAccounts();
        for (Account account : accounts) {
        List<Account> accounts = prefs.getAccounts();

        for (int i = 0; i < accounts.size(); i++) {
            Account account = accounts.get(i);
            items.add(account);
            List<Identity> identities = account.getIdentities();

            for (Identity identity : identities) {
                items.add(new IdentityContainer(identity, account));
            }

            if (i < accounts.size() - 1) { // not the last item, so can add divider
                items.add(new DividerContainer());
            }
        }
        mItems = items;
    }

    public void setCurrentIdentity(Identity currentIdentity) {
        this.currentIdentity = currentIdentity;
    }

    @Override
    public int getCount() {
        return mItems.size();
@@ -51,12 +64,22 @@ public class IdentityAdapter extends BaseAdapter {

    @Override
    public int getViewTypeCount() {
        return 2;
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        return (mItems.get(position) instanceof Account) ? 0 : 1;
        Object item = mItems.get(position);

        if (item instanceof Account) {
            return 0;
        }

        if (item instanceof IdentityContainer) {
            return 1;
        }

        return 2;
    }

    @Override
@@ -82,8 +105,8 @@ public class IdentityAdapter extends BaseAdapter {
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Object item = mItems.get(position);

        View view = null;

        if (item instanceof Account) {
            if (convertView != null && convertView.getTag() instanceof AccountHolder) {
                view = convertView;
@@ -99,7 +122,9 @@ public class IdentityAdapter extends BaseAdapter {
            AccountHolder holder = (AccountHolder) view.getTag();
            holder.name.setText(account.getDisplayName());
            holder.chip.setBackgroundColor(account.getChipColor());
        } else if (item instanceof IdentityContainer) {
        }

        else if (item instanceof IdentityContainer) {
            if (convertView != null && convertView.getTag() instanceof IdentityHolder) {
                view = convertView;
            } else {
@@ -107,6 +132,7 @@ public class IdentityAdapter extends BaseAdapter {
                IdentityHolder holder = new IdentityHolder();
                holder.name = view.findViewById(R.id.name);
                holder.description = view.findViewById(R.id.description);
                holder.selected = view.findViewById(R.id.selected);
                view.setTag(holder);
            }

@@ -115,13 +141,37 @@ public class IdentityAdapter extends BaseAdapter {
            IdentityHolder holder = (IdentityHolder) view.getTag();
            holder.name.setText(identity.getDescription());
            holder.description.setText(getIdentityDescription(identity));
            holder.selected.setChecked(identity.equals(currentIdentity));
        }

        else if (item instanceof DividerContainer) {
            if (convertView != null && convertView.getTag() instanceof DividerContainer) {
                view = convertView;
            } else {
                view = mLayoutInflater.inflate(R.layout.choose_account_divider, parent, false);
                DividerContainer holder = new DividerContainer();
                view.setTag(holder);
            }
        }

        return view;
    }

    private static String getIdentityDescription(Identity identity) {
        return String.format("%s <%s>", identity.getName(), identity.getEmail());
        StringBuilder stringBuilder = new StringBuilder();

        if (identity.getName() != null && !identity.getName().trim().isEmpty()) {
            stringBuilder.append(identity.getName())
                    .append(" ");
        }

        if (identity.getEmail() != null && !identity.getEmail().trim().isEmpty()) {
            stringBuilder.append("<")
                    .append(identity.getEmail())
                    .append(">");
        }

        return stringBuilder.toString();
    }

    /**
@@ -139,6 +189,9 @@ public class IdentityAdapter extends BaseAdapter {
        }
    }

    private static class DividerContainer {
    }

    static class AccountHolder {
        public TextView name;
        public View chip;
@@ -147,5 +200,6 @@ public class IdentityAdapter extends BaseAdapter {
    static class IdentityHolder {
        public TextView name;
        public TextView description;
        public RadioButton selected;
    }
}
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022  E FOUNDATION
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation, either version 3 of the License, or
     (at your option) any later version.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="7dp">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="15dp"
        android:background="@color/color_choose_account_divider" />
</LinearLayout>
 No newline at end of file
Loading