mirror of https://github.com/M66B/FairEmail.git
Added inline answer button configuration
This commit is contained in:
parent
2bd86fb978
commit
3a576bdef9
|
@ -9,6 +9,7 @@ For support you can use [the contact form](https://contact.faircode.eu/?product=
|
|||
### Next version
|
||||
|
||||
* Added option to configure number of widget subject lines
|
||||
* Added remembering last used folder for contacts
|
||||
* Small improvements and minor bug fixes
|
||||
* Updated [translations](https://crowdin.com/project/open-source-email)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,6 +9,7 @@ For support you can use [the contact form](https://contact.faircode.eu/?product=
|
|||
### Next version
|
||||
|
||||
* Added option to configure number of widget subject lines
|
||||
* Added remembering last used folder for contacts
|
||||
* Small improvements and minor bug fixes
|
||||
* Updated [translations](https://crowdin.com/project/open-source-email)
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 274,
|
||||
version = 275,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -2781,6 +2781,12 @@ public abstract class DB extends RoomDatabase {
|
|||
db.execSQL("ALTER TABLE `answer` ADD COLUMN `label` TEXT");
|
||||
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_answer_label` ON `answer` (`label`)");
|
||||
}
|
||||
}).addMigrations(new Migration(274, 275) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("ALTER TABLE `contact` ADD COLUMN `folder` INTEGER");
|
||||
}
|
||||
}).addMigrations(new Migration(998, 999) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
|
|
|
@ -105,6 +105,12 @@ public interface DaoContact {
|
|||
@Update
|
||||
int updateContact(EntityContact contact);
|
||||
|
||||
@Query("UPDATE contact SET folder = :folder WHERE id=:id")
|
||||
int setContactFolder(long id, Long folder);
|
||||
|
||||
@Query("UPDATE contact SET folder = NULL")
|
||||
int clearContactFolders();
|
||||
|
||||
@Query("DELETE FROM contact WHERE id = :id")
|
||||
int deleteContact(long id);
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ public class EntityContact implements Serializable {
|
|||
@NonNull
|
||||
public Long account;
|
||||
public Long identity; // no foreign key, no index
|
||||
public Long folder; // last used
|
||||
@NonNull
|
||||
public int type;
|
||||
@NonNull
|
||||
|
|
|
@ -47,6 +47,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
@Entity(
|
||||
tableName = EntityOperation.TABLE_NAME,
|
||||
foreignKeys = {
|
||||
|
@ -230,6 +232,16 @@ public class EntityOperation {
|
|||
if (source == null || target == null || source.id.equals(target.id))
|
||||
return;
|
||||
|
||||
if (message.from != null && message.from.length == 1 &&
|
||||
EntityFolder.USER.equals(target.type)) {
|
||||
String email = ((InternetAddress) message.from[0]).getAddress();
|
||||
if (!TextUtils.isEmpty(email)) {
|
||||
EntityContact contact = db.contact().getContact(target.account, EntityContact.TYPE_FROM, email);
|
||||
if (contact != null)
|
||||
db.contact().setContactFolder(contact.id, target.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (EntityFolder.JUNK.equals(target.type) &&
|
||||
Objects.equals(source.account, target.account)) {
|
||||
Boolean noblock = (Boolean) jargs.opt(3);
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail 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.
|
||||
|
||||
FairEmail 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 FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2023 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
public class FragmentDialogAnswerButton extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
final Context context = getContext();
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
final String[] values = getResources().getStringArray(R.array.answerValues);
|
||||
|
||||
final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_answer_button, null);
|
||||
Spinner spAnswerActionSingle = dview.findViewById(R.id.spAnswerActionSingle);
|
||||
Spinner spAnswerActionLong = dview.findViewById(R.id.spAnswerActionLong);
|
||||
TextView tvAnswerActionWarning = dview.findViewById(R.id.tvAnswerActionWarning);
|
||||
|
||||
AdapterView.OnItemSelectedListener onSelected = new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
String s = values[spAnswerActionSingle.getSelectedItemPosition()];
|
||||
String l = values[spAnswerActionLong.getSelectedItemPosition()];
|
||||
tvAnswerActionWarning.setVisibility(
|
||||
"menu".equals(s) || "menu".equals(l)
|
||||
? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Do nothing
|
||||
}
|
||||
};
|
||||
|
||||
spAnswerActionSingle.setOnItemSelectedListener(onSelected);
|
||||
spAnswerActionLong.setOnItemSelectedListener(onSelected);
|
||||
|
||||
String answer_default = prefs.getString("answer_single", "menu");
|
||||
for (int pos = 0; pos < values.length; pos++)
|
||||
if (values[pos].equals(answer_default)) {
|
||||
spAnswerActionSingle.setSelection(pos);
|
||||
break;
|
||||
}
|
||||
|
||||
boolean reply_all = prefs.getBoolean("reply_all", false);
|
||||
String answer_action = prefs.getString("answer_action", reply_all ? "reply_all" : "reply");
|
||||
for (int pos = 0; pos < values.length; pos++)
|
||||
if (values[pos].equals(answer_action)) {
|
||||
spAnswerActionLong.setSelection(pos);
|
||||
break;
|
||||
}
|
||||
|
||||
tvAnswerActionWarning.setVisibility(View.GONE);
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(dview)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString("answer_single", values[spAnswerActionSingle.getSelectedItemPosition()]).apply();
|
||||
editor.putString("answer_action", values[spAnswerActionLong.getSelectedItemPosition()]).apply();
|
||||
sendResult(Activity.RESULT_OK);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
sendResult(Activity.RESULT_CANCELED);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
}
|
||||
}
|
|
@ -63,8 +63,12 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
private int result = 0;
|
||||
|
@ -84,6 +88,12 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
final long[] disabled = aargs.getLongArray("disabled");
|
||||
final boolean cancopy = aargs.getBoolean("cancopy");
|
||||
|
||||
long[] messages = null;
|
||||
if (aargs.containsKey("message"))
|
||||
messages = new long[]{aargs.getLong("message")};
|
||||
else if (aargs.containsKey("messages"))
|
||||
messages = aargs.getLongArray("messages");
|
||||
|
||||
final Context context = getContext();
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final InputMethodManager imm = Helper.getSystemService(context, InputMethodManager.class);
|
||||
|
@ -220,6 +230,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
public void run() {
|
||||
try {
|
||||
db.folder().resetSelectedCount(account);
|
||||
db.contact().clearContactFolders();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
@ -305,6 +316,8 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
Bundle args = new Bundle();
|
||||
args.putLong("account", account);
|
||||
args.putLongArray("disabled", disabled);
|
||||
if (messages != null)
|
||||
args.putLongArray("messages", messages);
|
||||
|
||||
new SimpleTask<Data>() {
|
||||
@Override
|
||||
|
@ -323,13 +336,58 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
protected Data onExecute(Context context, Bundle args) {
|
||||
long account = args.getLong("account");
|
||||
long[] disabled = args.getLongArray("disabled");
|
||||
long[] messages = args.getLongArray("messages");
|
||||
|
||||
List<EntityFolder> favorites = new ArrayList<>();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean suggest_received = prefs.getBoolean("suggest_received", false);
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
Map<Long, Integer> frequency = new HashMap<>();
|
||||
if (suggest_received &&
|
||||
messages != null && messages.length < 100) {
|
||||
for (Long id : messages) {
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message != null && message.from != null && message.from[0] != null) {
|
||||
String email = ((InternetAddress) message.from[0]).getAddress();
|
||||
if (!TextUtils.isEmpty(email)) {
|
||||
EntityContact contact =
|
||||
db.contact().getContact(message.account, EntityContact.TYPE_FROM, email);
|
||||
if (contact != null && contact.folder != null) {
|
||||
Integer freq = frequency.get(contact.folder);
|
||||
freq = (freq == null ? 1 : freq + 1);
|
||||
frequency.put(contact.folder, freq);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Long> fs = new ArrayList<>(frequency.keySet());
|
||||
Collections.sort(fs, new Comparator<Long>() {
|
||||
@Override
|
||||
public int compare(Long f1, Long f2) {
|
||||
return -Integer.compare(frequency.get(f1), frequency.get(f2));
|
||||
}
|
||||
});
|
||||
for (long fid : fs) {
|
||||
EntityFolder f = db.folder().getFolder(fid);
|
||||
if (f != null)
|
||||
favorites.add(f);
|
||||
}
|
||||
|
||||
List<EntityFolder> ffolders = db.folder().getFavoriteFolders(account, 3, disabled);
|
||||
if (ffolders != null)
|
||||
for (EntityFolder folder : ffolders)
|
||||
if (!frequency.containsKey(folder.id))
|
||||
favorites.add(folder);
|
||||
|
||||
Data data = new Data();
|
||||
data.account = db.account().getAccount(account);
|
||||
data.folders = db.folder().getFoldersEx(account);
|
||||
data.favorites = db.folder().getFavoriteFolders(account, 3, disabled);
|
||||
data.favorites = favorites;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -3588,6 +3588,9 @@ public class FragmentMessages extends FragmentBase
|
|||
} else if (itemId == R.id.menu_reply_answer) {
|
||||
onMenuAnswer(message);
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_settings) {
|
||||
onMenuAnswerSettings();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -3728,6 +3731,11 @@ public class FragmentMessages extends FragmentBase
|
|||
}.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "message:answer");
|
||||
}
|
||||
|
||||
private void onMenuAnswerSettings() {
|
||||
FragmentDialogAnswerButton fragment = new FragmentDialogAnswerButton();
|
||||
fragment.show(getParentFragmentManager(), "dialog:answer");
|
||||
}
|
||||
|
||||
private void onMore() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLongArray("ids", getSelection());
|
||||
|
@ -4404,6 +4412,7 @@ public class FragmentMessages extends FragmentBase
|
|||
args.putBoolean("copy", copy);
|
||||
args.putBoolean("cancopy", true);
|
||||
args.putLongArray("disabled", Helper.toLongArray(disabled));
|
||||
args.putLongArray("messages", getSelection());
|
||||
|
||||
FragmentDialogFolder fragment = new FragmentDialogFolder();
|
||||
fragment.setArguments(args);
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<eu.faircode.email.ScrollViewEx 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="match_parent"
|
||||
android:fadeScrollbars="false"
|
||||
android:padding="24dp"
|
||||
android:scrollbarStyle="outsideOverlay">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCaption"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableStart="@drawable/twotone_settings_24"
|
||||
android:drawablePadding="6dp"
|
||||
android:text="@string/title_advanced_answer_caption"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAnswerActionSingle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_advanced_answer_default"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvCaption" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spAnswerActionSingle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:entries="@array/answerNames"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAnswerActionSingle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAnswerActionLong"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_advanced_answer_action"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/spAnswerActionSingle" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spAnswerActionLong"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:entries="@array/answerNames"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAnswerActionLong" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAnswerActionWarning"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_advanced_answer_warning"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spAnswerActionLong" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAnswerActionHint"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_advanced_answer_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvAnswerActionWarning" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ScrollViewEx>
|
|
@ -56,4 +56,11 @@
|
|||
android:title="@string/title_reply_template">
|
||||
<menu />
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_settings"
|
||||
android:icon="@drawable/twotone_settings_24"
|
||||
android:title="@string/menu_setup">
|
||||
<menu />
|
||||
</item>
|
||||
</menu>
|
|
@ -441,8 +441,11 @@
|
|||
<string name="title_advanced_send_reminders">Show reminders</string>
|
||||
<string name="title_advanced_send_delayed">Delay sending messages</string>
|
||||
<string name="title_advanced_attach_new">Add shared files to a new draft</string>
|
||||
<string name="title_advanced_answer_caption">Answer button settings</string>
|
||||
<string name="title_advanced_answer_default">Short pressing on the answer button will:</string>
|
||||
<string name="title_advanced_answer_action">Long pressing on the answer button will:</string>
|
||||
<string name="title_advanced_answer_hint">The answer button actions can also be configured in the send settings tab page</string>
|
||||
<string name="title_advanced_answer_warning">Not all actions are possible without a selection menu!</string>
|
||||
<string name="title_advanced_send_pending">Show non-obtrusive send delayed icon</string>
|
||||
|
||||
<string name="title_advanced_auto_save_paragraph">Automatically save a draft after every paragraph</string>
|
||||
|
|
|
@ -9,6 +9,7 @@ Rahonavis
|
|||
Next version
|
||||
|
||||
* Added option to configure number of widget subject lines
|
||||
* Added remembering last used folder for contacts
|
||||
* Small improvements and minor bug fixes
|
||||
* Updated translations
|
||||
|
||||
|
|
Loading…
Reference in New Issue