Added extra button to edit signature

pull/209/head
M66B 3 years ago
parent b37cde1c5a
commit 19a2c6ec38

@ -146,8 +146,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
static final int REQUEST_IMPORT_CERTIFICATE = 7;
static final int REQUEST_OAUTH = 8;
static final int REQUEST_STILL = 9;
static final int REQUEST_DELETE_ACCOUNT = 10;
static final int REQUEST_IMPORT_PROVIDERS = 11;
static final int REQUEST_SELECT_IDENTITY = 10;
static final int REQUEST_EDIT_SIGNATURE = 11;
static final int REQUEST_DELETE_ACCOUNT = 12;
static final int REQUEST_IMPORT_PROVIDERS = 13;
static final int PI_MISC = 1;

@ -304,14 +304,18 @@ public class ActivitySignature extends ActivityBase {
}
private void delete() {
Intent result = new Intent();
Intent result = getIntent();
if (result == null)
result = new Intent();
result.putExtra("html", (String) null);
setResult(RESULT_OK, result);
finish();
}
private void save() {
Intent result = new Intent();
Intent result = getIntent();
if (result == null)
result = new Intent();
result.putExtra("html", getHtml());
setResult(RESULT_OK, result);
finish();

@ -144,6 +144,9 @@ public interface DaoIdentity {
@Query("UPDATE identity SET max_size = :max_size WHERE id = :id AND NOT (max_size IS :max_size)")
int setIdentityMaxSize(long id, Long max_size);
@Query("UPDATE identity SET signature = :hmtl WHERE id = :id AND NOT (signature IS :hmtl)")
int setIdentitySignature(long id, String hmtl);
@Query("UPDATE identity SET error = :error WHERE id = :id AND NOT (error IS :error)")
int setIdentityError(long id, String error);

@ -0,0 +1,104 @@
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-2022 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import java.util.List;
public class FragmentDialogSelectIdentity extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Context context = getContext();
final int dp6 = Helper.dp2pixels(context, 6);
final int dp12 = Helper.dp2pixels(context, 12);
final ArrayAdapter<TupleIdentityEx> adapter = new ArrayAdapter<TupleIdentityEx>(context, R.layout.spinner_account, android.R.id.text1) {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TupleIdentityEx identity = (TupleIdentityEx) getItem(position);
View vwColor = view.findViewById(R.id.vwColor);
TextView tv = view.findViewById(android.R.id.text1);
int vpad = (getCount() > 10 ? dp6 : dp12);
tv.setPadding(0, vpad, 0, vpad);
vwColor.setBackgroundColor(identity.color == null ? Color.TRANSPARENT : identity.color);
tv.setText(identity.name);
return view;
}
};
// TODO: spinner
new SimpleTask<List<TupleIdentityEx>>() {
@Override
protected List<TupleIdentityEx> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
return db.identity().getComposableIdentities(null);
}
@Override
protected void onExecuted(Bundle args, List<TupleIdentityEx> identities) {
adapter.addAll(identities);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, getArguments(), "select:identity");
return new AlertDialog.Builder(context)
.setIcon(R.drawable.twotone_person_24)
.setTitle(R.string.title_list_identities)
.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TupleIdentityEx identity = adapter.getItem(which);
Bundle args = getArguments();
args.putLong("id", identity.id);
args.putString("html", identity.signature);
sendResult(RESULT_OK);
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}

@ -121,6 +121,7 @@ public class FragmentSetup extends FragmentBase {
private CardView cardExtra;
private TextView tvExtra;
private Button btnNotification;
private Button btnSignature;
private Button btnReorderAccounts;
private Button btnReorderFolders;
private Button btnDelete;
@ -202,6 +203,7 @@ public class FragmentSetup extends FragmentBase {
cardExtra = view.findViewById(R.id.cardExtra);
tvExtra = view.findViewById(R.id.tvExtra);
btnNotification = view.findViewById(R.id.btnNotification);
btnSignature = view.findViewById(R.id.btnSignature);
btnReorderAccounts = view.findViewById(R.id.btnReorderAccounts);
btnReorderFolders = view.findViewById(R.id.btnReorderFolders);
btnDelete = view.findViewById(R.id.btnDelete);
@ -657,6 +659,16 @@ public class FragmentSetup extends FragmentBase {
}
});
btnSignature.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentDialogSelectIdentity fragment = new FragmentDialogSelectIdentity();
fragment.setArguments(new Bundle());
fragment.setTargetFragment(FragmentSetup.this, ActivitySetup.REQUEST_SELECT_IDENTITY);
fragment.show(getParentFragmentManager(), "select:identity");
}
});
btnReorderAccounts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -1008,6 +1020,14 @@ public class FragmentSetup extends FragmentBase {
try {
switch (requestCode) {
case ActivitySetup.REQUEST_SELECT_IDENTITY:
if (resultCode == RESULT_OK && data != null)
onSelectIdentity(data.getBundleExtra("args"));
break;
case ActivitySetup.REQUEST_EDIT_SIGNATURE:
if (resultCode == RESULT_OK && data != null)
onEditIdentity(data.getExtras());
break;
case ActivitySetup.REQUEST_DELETE_ACCOUNT:
if (resultCode == RESULT_OK && data != null)
onDeleteAccount(data.getBundleExtra("args"));
@ -1068,6 +1088,33 @@ public class FragmentSetup extends FragmentBase {
btnPermissions.setEnabled(!all);
}
private void onSelectIdentity(Bundle args) {
Intent intent = new Intent(getContext(), ActivitySignature.class);
intent.putExtra("id", args.getLong("id"));
intent.putExtra("html", args.getString("html"));
startActivityForResult(intent, ActivitySetup.REQUEST_EDIT_SIGNATURE);
}
private void onEditIdentity(Bundle args) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
String html = args.getString("html");
DB db = DB.getInstance(context);
db.identity().setIdentitySignature(id, html);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "set:signature");
}
private void onDeleteAccount(Bundle args) {
long account = args.getLong("account");
String name = args.getString("name");

@ -954,6 +954,19 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnNotification" />
<Button
android:id="@+id/btnSignature"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_gesture_24"
android:drawablePadding="6dp"
android:tag="disable"
android:text="@string/title_edit_signature"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotificationHint" />
<Button
android:id="@+id/btnReorderAccounts"
style="?android:attr/buttonStyleSmall"
@ -964,7 +977,7 @@
android:drawablePadding="6dp"
android:text="@string/title_setup_reorder_accounts"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotificationHint" />
app:layout_constraintTop_toBottomOf="@id/btnSignature" />
<Button
android:id="@+id/btnReorderFolders"
@ -1082,7 +1095,7 @@
android:id="@+id/grpExtra"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="btnNotification,tvNotificationHint,btnReorderAccounts,btnReorderFolders,btnDelete,tvDeleteHint,btnApp,btnMore" />
app:constraint_referenced_ids="btnNotification,tvNotificationHint,btnSignature,btnReorderAccounts,btnReorderFolders,btnDelete,tvDeleteHint,btnApp,btnMore" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save