Added account selector to debug dialog

This commit is contained in:
M66B 2023-07-09 08:21:21 +02:00
parent c4559e0672
commit 05ee6e5e6f
3 changed files with 73 additions and 4 deletions

View File

@ -30,14 +30,19 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import java.util.ArrayList;
import java.util.List;
public class FragmentDialogDebug extends FragmentDialogBase {
private boolean enabled;
@ -50,8 +55,10 @@ public class FragmentDialogDebug extends FragmentDialogBase {
final Context context = getContext();
View view = LayoutInflater.from(context).inflate(R.layout.dialog_debug, null);
final EditText etIssue = view.findViewById(R.id.etIssue);
final Spinner spAccount = view.findViewById(R.id.spAccount);
final CheckBox cbContact = view.findViewById(R.id.cbContact);
final ArrayAdapter<EntityAccount> adapterAccount;
etIssue.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -78,6 +85,44 @@ public class FragmentDialogDebug extends FragmentDialogBase {
}
});
adapterAccount = new ArrayAdapter<>(context, R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityAccount>());
adapterAccount.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spAccount.setAdapter(adapterAccount);
new SimpleTask<List<EntityAccount>>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
return db.account().getSynchronizingAccounts(null);
}
@Override
protected void onExecuted(Bundle args, List<EntityAccount> accounts) {
if (accounts == null)
accounts = new ArrayList<>();
EntityAccount none = new EntityAccount();
none.id = -1L;
none.name = "-";
none.primary = false;
accounts.add(0, none);
EntityAccount all = new EntityAccount();
all.id = 0L;
all.name = getString(R.string.title_widget_account_all);
all.primary = false;
accounts.add(1, all);
adapterAccount.addAll(accounts);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, new Bundle(), "debug:accounts");
return new AlertDialog.Builder(context)
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@ -87,6 +132,10 @@ public class FragmentDialogDebug extends FragmentDialogBase {
args.putString("issue", etIssue.getText().toString());
args.putBoolean("contact", cbContact.isChecked());
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
if (account != null)
args.putString("account", account.id + "/" + account.name + "/" + account.user);
sendResult(RESULT_OK);
}
})

View File

@ -1790,9 +1790,11 @@ public class Log {
StringBuilder sb = new StringBuilder();
sb.append(context.getString(title)).append("\n\n");
if (args != null) {
sb.append(args.getString("issue"));
if (args.getBoolean("contact"))
sb.append("\n\n").append("Prior contact");
sb.append(args.getString("issue")).append('\n');
if (args.containsKey("account"))
sb.append('\n').append("Account: ").append(args.getString("account"));
if (args.containsKey("contact"))
sb.append('\n').append("Prior contact: ").append(args.getBoolean("contact"));
}
sb.append("\n\n");
sb.append(getAppInfo(context));

View File

@ -44,6 +44,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvIssue" />
<TextView
android:id="@+id/tvAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_widget_account"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etIssue" />
<Spinner
android:id="@+id/spAccount"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAccount" />
<CheckBox
android:id="@+id/cbContact"
android:layout_width="wrap_content"
@ -51,6 +69,6 @@
android:layout_marginTop="12dp"
android:text="@string/title_debug_info_contact"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etIssue" />
app:layout_constraintTop_toBottomOf="@+id/spAccount" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>